The Simulation’s Entry points

MORSE’s internal functioning is based on Blender’s Game Engine events. These are defined in the Logic buttons window, using the graphical interface called “Logic Bricks”. These are a set of predefined Sensor, Controller and Actuator events which can be linked together. Actuators in particular are important because they are the places where Python scripts are called.

Each object in Blender has its own set of Logic Bricks. A Morse scene’s entry point is defined in the Scene_Script_Holder object which is available in ${MORSE_ROOT}/data/props/basics.blend (this object is automatically added by the Builder API if it is not found in the simulation). This specific object contains the entry point morse.blender.main.init() and the finalisation point morse.blender.main.finish(). It also contains the “Logic Bricks” to control cameras, reset the simulation, etc.

Let’s take a look at the module morse.blender.main.

The init method

The morse.blender.main.init() is responsible for initializing all the Morse subsystems. It includes:

  • Create the dictionary of robots (morse.core.blender.persistantstorage.robotDict)
  • Create the dictionary of components, and the robot they are associated with (morse.core.blender.persistantstorage.componentDict)
  • Create the dictionary of modifiers (morse.core.blender.persistantstorage.modifierDict)
  • Create the dictionary of datastream managers (morse.core.blender.persistantstorage.stream_managers)
  • Create the dictionary of datastream handlers (morse.core.blender.persistantstorage.datastreams)
  • Create the dictionary of services (morse.core.blender.persistantstorage.morse_services)
  • Create the dictionary of overlays (morse.core.blender.persistantstorage.overlayDict)
  • Link the modifiers, middlewares, and services overlays to their associated components, as specified in the file component_config.py (see How are arguments passed between the builder and the simulator ?).
  • Initialise the logging system.

The initialization of all the components, including middlewares and modifiers, is done by instantiating an object of the Python class specified in each component by the variable classpath. This classpath is not stored in a Blender file, but described in the builder component (see morse.builder.sensors for example).

The finalization method

The method which terminates the simulation (called when you press ESC) is morse.blender.main.finish()). However, the real cleanup logic is in morse.blender.main.close_all(), which attempts to properly finalize all resources used by the simulator, in particular, resources used by the different middlewares.

The main method

The Scene_Script_Holder also defines a method which it calls at each simulator loop. It is the morse.blender.main.simulation_main() method which:

  • updates the simulation clock
  • dispatches services, if any
  • synchronises with the multi-node master in the multi-node case