Rik's Treehouse > Babbling in Binary > My Software > Orphanware > R2DToo > R2DToo Help > For the Programmer > forEachAgentVar

forEachAgentVar

Declaration
Parameters
Remarks
Revisions
Example
See Also

Declaration

void __stdcall forEachAgentVar(
	bool (*func)(pState,int,int,pState*,         // name of function
	             int,int,double*,int),      
	double* var,                                 // workspace
	int varCount                                 // size of workspace
);
Top of page

Parameters

func
The name of a function to apply to each agent in turn.
var
Allocated array of storage space for extra parameters.
varCount
Size of array, var[0..varCount-1].
Top of page

Remarks

This function is available through the API. It provides an efficient way to process every agent in turn.

func

func is the name of a function with the following declaration:
bool func(
	pState state,  	// array of agent state variables
	int x,        	// X-coordinate of agent
	int y,        	// Y-coordinate of agent
	pState *nbr,   	// array of neighbours
	int nbrCount, 	// size of nbr array, nbr[0..nbrCount-1]
	int feaMode,   	// calling mode, one of feaBegin, feaContinue or feaEnd
	double *var,  	// workspace
	int varCount  	// size of workspace
);
The details of this function are the same as that for
forEachAgent except for the addition of two extra parameters, var and varCount. var[0..varCount-1] is an array of double values (allocated by the model programmer) which are passed through the call to forEachAgentVar to the function func, providing storage space.
Top of page

Revisions

API v1.5
  • no longer passes param to func
Top of page

Example

bool calcAverage(pState state, int x, int y, pState *nbr, int nbrCount, int feaMode, double *var, int varCount) // Used by onTick. Assumes varCount >= 1. { static double n; switch (feaMode) { case feaBegin: var[0] = 0; n=0; break; case feaContinue: var[0] += state[0]; n++; break; case feaEnd: var[0] /= n; } return true; } void __stdcall onTick(double &time) { // standard way to call forEachAgentVar double *ave = new double[1]; forEachAgentVar(calcAverage,ave,1); delete [] ave; // or a shortcut if just one variable passed in double ave2; forEachAgentVar(calcAverage,&ave2,1); } Top of page

See Also

forEachAgent.
Top of page
[Rik's Office Hours] [Contact Rik]
Last updated: Fri Apr 30 2004, 1:37pm