Skip to content
Adrian edited this page Feb 5, 2021 · 10 revisions

Overview

While ZServices provides utilities across the entire engine, a ZGame acts as the heart of a single simulation experience. It is responsible for running the main, high-level game loop, it keeps track of loaded scenes and it holds together game specific subsystems, including

  • A Domain
  • A Physics Universe
  • An Audio Provider
  • An Asset Store
  • Game Configuration

All of these game systems are passed down to scenes when they are added to the game, in order to avoid long call chains and pointer dereferences and somewhat honor The Law of Demeter.

The main purpose of the ZGame class is to handle the main game loop, so it would behoove us not to call the appreciably important Loop method when we are ready to run the game:

    game->Loop();

We can always call Provide methods for any of the above systems if we wish to change out the implementation at runtime

    ZDomainOptions domainOptions;
    domainOptions.windowSize.x = 3840;
    domainOptions.windowSize.y = 2160;
    auto newContext = ZDomain::Create(domainOptions);
    game->Provide(newContext);

The CleanUp method should be called after Loop in order to properly free up any resources after the game loop completes.

Take a look at the editor startup file and feel the simplicity.