MochiEngine
Loading...
Searching...
No Matches
Mochi::Engine Class Reference

Main class of the MochiEngine. It owns and coordinates all subsystems and layers, and drives the application lifecycle. More...

#include <Engine.h>

Public Member Functions

 Engine ()
 Constructs the Engine class without initializing some core systems to allow the user to use Setup to initialize them manually. Doesn't initialize:
 Engine (const char *appName, const char *appVersion, const char *appId, const char *windowName)
 Constructs the Engine class and setups it with default core subsystems.
void Run ()
 Runs the engine, starting the per-frame lifecycle. Once called, it won't stop until receiving ApplicationQuitEvent or getting "false" when updating a layer.
void Setup (std::unique_ptr< Graphics::IRenderer > &&renderer, std::unique_ptr< Input::IActionManager > &&actionManager, std::unique_ptr< Audio::IAudioManager > &&audioManager)
 Manually setups some subsystems for the engine. Setup should only be called once, and it will keep ownership of the subsystems.
void PushLayer (Layer *layer)
 Pushes a layer in the list of layers to initialize. Then initializes it at the end of the frame and gets ownership of it to update it each frame. The same layer should only be pushed once. However, several instances of the same layer type can be pushed safely.
void PopLayer (Layer *layer)
 Pushes a layer in the list of layers to deactivate. At the end of the frame (when it is safe) the layer is removed from the list and destroyed.
float GetLastRealDelta () const
void AddRenderCommand (const Graphics::RenderCommand &command)
 Adds a single render command to be rendered this frame.
void AddRenderCommands (const std::vector< Graphics::RenderCommand > &commands)
 Adds a range of render commands to be rendered this frame.
Graphics::IRendererGetRenderer () const
Audio::IAudioManagerGetAudio () const
Input::IActionManagerGetActionManager () const
FS::PackCatalogGetCatalog () const
Graphics::CameraGetCamera () const
Graphics::AbstractGUIGetGUI () const
Event::EventBusGetEventBus () const
Scripting::ScriptingManagerGetScriptingManager () const
Debug::IGizmosGetGizmos () const
void SwapAudioManager (std::unique_ptr< Audio::IAudioManager > &&)
void SwapActionManager (std::unique_ptr< Input::IActionManager > &&)
void SwapCamera (std::unique_ptr< Graphics::Camera > &&)
void SwapRenderer (std::unique_ptr< Graphics::IRenderer > &&)
void Pause ()
 Pauses the engine setting the delta time scale to 0. Pause can be called several times in succession, but it will only be applied once.
void Resume ()
 Resumes the game setting the delta time scale to the last value it was before it was paused. Resume can be called several times in succession, but it will only be applied once.

Static Public Member Functions

static EngineGet ()
 Access Engine from anywhere Access is only available after default construction or after setup. Otherwise, it returns nullptr.

Detailed Description

Main class of the MochiEngine. It owns and coordinates all subsystems and layers, and drives the application lifecycle.

Ownership:

  • Engine has ownership of most of the subsystems.
  • Layers are created outside of the class and injected into the engine.

Lifecycle:

  • Create with default constructor and call "Setup" after to initialize.
  • Call Run to start the main loop. Run will end automatically when the game receives an exit signal.
  • When created, Engine is a singleton accessible everywhere, providing centralized access to core subsystems and giving ability to inject layers and render commands.

Guarantees:

  • Full initialization before entering the main loop. Failures in this step are detected early and exit the application.
  • Update is called each frame with a delta time
  • Subsystems are automatically updated
  • Layers are automatically managed and updated
  • Rendering is done once per frame, separated between Graphics and UI

Thread safety:

  • This class is not thread-safe.

Non responsible:

  • Game logic
  • Automatic rendering
  • Entity management

Constructor & Destructor Documentation

◆ Engine() [1/2]

Mochi::Engine::Engine ( )

Constructs the Engine class without initializing some core systems to allow the user to use Setup to initialize them manually. Doesn't initialize:

  • Renderer
  • Action Manager
  • Audio Manager

◆ Engine() [2/2]

Mochi::Engine::Engine ( const char * appName,
const char * appVersion,
const char * appId,
const char * windowName )

Constructs the Engine class and setups it with default core subsystems.

  • Renderer: SDLRenderer
  • Action Manager: Default action manager
  • Audio Manager: FMOD
    Parameters
    appNameThe name of the application.
    appVersionThe version of the application.
    appIdA unique string in reverse order identifying the application.
    windowNameThe name the window will receive in the OS.

Member Function Documentation

◆ AddRenderCommand()

void Mochi::Engine::AddRenderCommand ( const Graphics::RenderCommand & command)

Adds a single render command to be rendered this frame.

Parameters
commandThe render command

◆ AddRenderCommands()

void Mochi::Engine::AddRenderCommands ( const std::vector< Graphics::RenderCommand > & commands)

Adds a range of render commands to be rendered this frame.

Parameters
commandsThe vector of commands

◆ PopLayer()

void Mochi::Engine::PopLayer ( Layer * layer)

Pushes a layer in the list of layers to deactivate. At the end of the frame (when it is safe) the layer is removed from the list and destroyed.

Parameters
layerThe pointer to the layer to remove.

◆ PushLayer()

void Mochi::Engine::PushLayer ( Layer * layer)

Pushes a layer in the list of layers to initialize. Then initializes it at the end of the frame and gets ownership of it to update it each frame. The same layer should only be pushed once. However, several instances of the same layer type can be pushed safely.

Parameters
layerA pointer to the layer. Note that several layers of the same type can be active at a time and is the user responsability to manage which layers to push.

◆ Setup()

void Mochi::Engine::Setup ( std::unique_ptr< Graphics::IRenderer > && renderer,
std::unique_ptr< Input::IActionManager > && actionManager,
std::unique_ptr< Audio::IAudioManager > && audioManager )

Manually setups some subsystems for the engine. Setup should only be called once, and it will keep ownership of the subsystems.

Parameters
rendererThe renderer. It will have rendering and UI responsabilities.
actionManagerThe action manager that will define how input will be interpreted.
audioManagerThe audio manager.

The documentation for this class was generated from the following files:
  • Engine/src/Engine.h
  • Engine/src/Engine.cpp