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

onTick

Declaration
Parameters
Remarks
Revisions
Example
See Also

Declaration

void __stdcall onTick(
	double &time  	// simulation time
);
Top of page

Parameters

time
Simulation time.
Top of page

Remarks

onTick() is the model's main loop: it is called repeatedly while the simulation is running. Set the variable time to override the default increment. On exit from the function time is compared to its value on entry and, if it has not been increased by onTick(), it is automatically incremented by one unit.
Top of page

Revisions

API v1.5
  • new! Replaces timestep.
Top of page

Example

//--------------------------------------------------------------------------- bool stage1(pState state, int x, int y, pState *nbr, int nbrCount, int feaMode) // count live neighbours (called in onTick) { if (feaMode!=feaContinue) return true; // store # live neighbours in state[1] state[1] = 0; for (int i=0; i<nbrCount; i++) state[1] += nbr[i][0]; return true; } //--------------------------------------------------------------------------- bool stage2(pState state, int x, int y, pState *nbr, int nbrCount, int feaMode) // update alive/dead state (called in onTick) { if (feaMode!=feaContinue) return true; // Conway's game of Life if (state[1] == 3) state[0] = 1; else if (state[1] != 2) state[0] = 0; // else no change (count==2) return true; } //--------------------------------------------------------------------------- void __stdcall onTick(double &time) { forEachAgent(stage1); // count live neighbours forEachAgent(stage2); // update alive/dead state // next line not required // time++; } //--------------------------------------------------------------------------- Top of page

See Also

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