Engines - simple-entertainment/simplicity GitHub Wiki

Engines make the world go around. Well, if you were coding the world in simplicity, chances are that's not too far from the truth.

Engines could do anything from rendering to physics to scripting to window management to turning the world. If you want something to happen every frame and it isn't specific to a particular entity (in which case its better to use a script), an engine is what you need.

When an engine is attached to the current scene, its advance() function will be called every frame.

That's basically it, it's that simple!

Creating an Engine

To create your own engine just extend the Engine class. The only function that needs to be defined is advance() but there are also a set of callback functions that you can choose to implement. See the API documentation for details on when they are called.

  • onAddEntity(Entity& entity)
  • onCloseScene(Scene& scene)
  • onOpenScene(Scene& scene)
  • onPause()
  • onPauseScene(Scene& scene)
  • onPlay()
  • onRemoveEntity(Entity& entity)
  • onResume()
  • onResumeScene(Scene& scene)
  • onStop()

Composite Engines

Composite engines are engines that are themselves composed of multiple engines which they manage. The standard composite engine used by simplicity is the SerialCompositeEngine which runs its managed engines in serial i.e. one after the other on a single thread. Engines can be added and removed easily:

std::unique_ptr<CompositeEngine> compositeEngine(new SerialCompositeEngine);
std::unique_ptr<Engine> engine(...);
Engine* rawEngine = engine.get();

compositeEngine->addEngine(move(engine));
compositeEngine->removeEngine(rawEngine); // rawEngine will be set to NULL as a result of this function call.

When you add/remove engines using Simplicity::addEngine and Simplicity::removeEngine you are actually adding/removing them in a composite engine. By default it is a SerialCompositeEngine but you can change it to any CompositeEngine:

std::unique_ptr<CompositeEngine> myCompositeEngine(new MyCompositeEngine);
Simplicity::setCompositeEngine(move(myCompositeEngine));
⚠️ **GitHub.com Fallback** ⚠️