Skip to content

Engine main game loop description

Michele edited this page Aug 2, 2019 · 2 revisions

Events on the main game loop

As every other engine, the ScrapEngine has a main loop that run few tasks.

In this page you can find a small description of how it works.

Pre-game loop

Before it, an event is called:

game_start() is called to every SGameObject registered, allowing initializations or other stuff to be made before the game starts.

Running Game loop

Here is what happens in the main game loop:

  1. The time spent to generating a frame is computed;
  2. game_update(float time) is called to every SGameObject registered, allowing update or other stuff to be made every frame. float time is the time spent generating the last frame, also called "delta time";
  3. on_gui() is called to every SGameObject registered, allowing gui operations to be made (for example a gui that show the current score or time left);
  4. It runs the "physics update", updating all rigidbodies locations and connected meshes. For more informations about the physics update accumulator see reactphysics3d documentation;
  5. It runs the "audio update", reading the camera location to update the listener location and rotation, allowing 3D audio to work correctly;
  6. Finally, it generate and draw the frame.

Other tasks

It is not possible to do everything in the main game loop, as some tasks are too heavy and would slow down the framerate a lot. For more informations about that, you can read Tasks running in background.