![]() |
VR-Forces 5.0.3 Developer's Guide
|
As described in Modifying and Extending the Simulation, the only function that needs to be called periodically for the simulation engine to execute properly is DtCgf::tick().
This causes managers and objects to be ticked, for example, DtLocalObjectManager (and therefore DtLocalObject instances and their components). If you have registered custom subclasses of any of the VR-Forces classes with the simulation engine (either through factories, or through DtVrfCreator), instances of your subclasses will automatically be ticked at the appropriate times.
However, there may be cases where you want objects that exist outside of the VR-Forces simulation engine to be automatically ticked each time the simulation engine is ticked. VR-Forces provides a tick callback mechanism to support this. You can obtain a pointer to the DtCgf's DtSimulationServices, and use its addTickEntry() member function to register the callback that you would like to have executed each frame. In fact, the way that VR-Forces classes like DtLocalObjectManager ensure that they are ticked each frame is by registering their own tick callbacks with the DtSimulationServices.
The following example shows how to add a function named tickCallback() that will get invoked each tick:
Register your function with the DtSimulationServices. You can optionally configure the callback with a pointer to some user-defined data (usr). This data pointer will be passed into the callback function when it is invoked.
When you no longer want your callback to be called, unregister the callback function with the DtSimulationServices, as follows:
DtSimulationServices also has functions to register callbacks to be called at the end of each tick. See the addPostTickEntry() and removePostTickEntry() functions. See Tick Callbacks.