Animation/Simulation System flow of control


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

  1. init() (allocating libraries and structures)
    1. Create empty data structures
    2. Create spatial database
    3. Create planning domain
    4. Modules::init()
      1. Initialize any modules that are going to be used in the simulation
    1. 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.
    2. initializeSimulation()
      1. Fill the global data structures
      2. Add all the obstacles to the simulation (All Static geometry and items)
        1. Must be in place before agents are reset/initialized.
    3. preprocessSimulation()
      1. Preconditions
        1. All obstacles should be loaded into the environment
      2. Preprocess all modules
      3. refresh the planning domain
      4. add agents to simulation 
      5. The simulation should be completely setup and ready for simulation.
    4. preprocessFrame()
      1. Store simulation data
      2. Maybe you want to collect some data on the performance of the simulation
    5. update()
      1. Step all of the modules in the system
    6. postprocessFrame()
      1. Update metrics from preprocessFrame
      2. Maybe save a picture or continue creating video
    7. postprocessSimulation()
      1. Collect data of metrics for simulation
      2. Do not remove or clear data yet. 
      3. Maybe write out data to file.
      4. This function is the best time to perform any kind of processing over data collected from the simulation.
    8. cleanupSimulation()
      1. Now data allocated data for the scenario can be reclaimed
      2. Here is when the data structures can be emptied and delete before now that any data collected from the simulation has been processed.
    9. finish()
      1. 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.