Main Game Loop - JayhawkZombie/EECS581Project GitHub Wiki

##Main Game Loop

The engine is started in main by:

return Engine.GO();  

This invokes Engine::Go(), which then calls Engine::Init(), which then calls Engine::Startup()
This is the startup process, which is where initialization is done, window handles are acquired, and things like the resource manager are created and started by the engine, before any of your derived class objects are ever created.

After Engine::Startup() is finished, it calls Engine::GameLoop(), which is where the main game loop is located.

Some resource are made to do diagnostics and timing, but the main operation sequence is:

  • Poll Events (get events from the OS queue)

    • If the sf::Event::Closed event was received, break out of the main loop - go to 7)
  • Updating timing (amount of time passed since the last frame was updated), and pass the amount of time passed since the last frame was updated, with double precision

  • Call TickUpdate for the main level, which in turn should call TickUpdate for all the objects in the level

  • Call Render for the main level, which in turn should call Render for all the objects in the level

  • Call Render on the UI overlay, if there is one active

  • Repeat Loop

  • Initiate shutdown

    • Calls Engine::Shutdown()
    • Engine::Shutdown() calls OnShutDown() for the main level, which should do the same for every object in the level
    • The resource manager is then shut down, releasing all currently pooled resources and closing any open file handles
    • The main thread waits for the resource manager threads to return (.join())
  • After all other threads have returned and all resources are released, the program returns. 0 should be returned if no error occurred during the shutdown process.