Simulation for animation is no easy task. There are many steps when constructing an animation and figuring out when particular data should be instantiated can be tricky. I am going to go over one method I have been using to help organize the steps and structure that could be used to construct the simulation flow of control.
This is for a Simulation Engine that I have been using in my work.
The main steps in the Simulation engine
- init() (allocating libraries and structures)
- Create empty data structures
- Create spatial database
- Create planning domain
- Initialize any modules that are going to be used in the simulation
- At this point the libraries the user specified are loaded and some global structures are created. Some examples of global structures are the spatial database and the pathPlanning envirionment.
- Fill the global data structures
- Add all the obstacles to the simulation (All Static geometry and items)
- Must be in place before agents are reset/initialized.
- All obstacles should be loaded into the environment
- Preprocess all modules
- refresh the planning domain
- add agents to simulation
- The simulation should be completely setup and ready for simulation.
- Store simulation data
- Maybe you want to collect some data on the performance of the simulation
- Step all of the modules in the system
- Update metrics from preprocessFrame
- Maybe save a picture or continue creating video
- Collect data of metrics for simulation
- Do not remove or clear data yet.
- Maybe write out data to file.
- This function is the best time to perform any kind of processing over data collected from the simulation.
- Now data allocated data for the scenario can be reclaimed
- Here is when the data structures can be emptied and delete before now that any data collected from the simulation has been processed.
- Now simulation components can be deleted because no more simulation will be done.
I find this separation of allocating objects and data structures and creation of items that go in the data structures very helpful. In helps avoid accidentally accessing data structures before they are done being created. It also helps define the ordering in which types of objects should be added to the simulation. As with any software you never really know what is going to be done with it in the future and I think this structure covers many unseen possibilities.