ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::Engine::Game Class Reference

The owner of the engine. Creates the window and every persistent engine object, filling in SceneContext with those objects before passing it down to the Scenes. More...

#include <Imago/Engine/Game.hpp>

Public Member Functions

 Game (const GameConfig &config)
 Construct a new Game object, building a new window based on GameSettings and filling in the SceneContext with its persistent engine objects.
 ~Game ()
 closes any controllers and quits SDL
 Game (const Game &)=delete
Game & operator= (const Game &)=delete
 Game (Game &&)=delete
Game & operator= (Game &&)=delete
template<typename T>
void register_scene (const std::string &name)
 Registers a Scene type under a name. Simply forwards to its SceneManager.
ActionId register_action (const std::string &name)
 Registers an action name and returns its id. Forwards to the InputHandler.
void add_input (const std::string &action, sf::Keyboard::Scancode scancode)
 adds a key press, mouse button, or gamepad button to an action.
void add_input (const std::string &action, sf::Mouse::Button button)
void add_input (const std::string &action, GamepadButton button)
void add_input (const std::string &action, GamepadAxis axis, float deadZone=0.2f, float threshold=0.5f)
 adds a gamepad axis to an action. dead zone and threshold values are defualted to fit standard player movement.
void run ()
 Starts config.firstScene and runs the main loop until the game quits.

Detailed Description

The owner of the engine. Creates the window and every persistent engine object, filling in SceneContext with those objects before passing it down to the Scenes.

Game is infastructure, it does not execute any logic. It measures delta time, polls window events, updates the SceneManager, applies requests made through EngineControl, and handles the window. Requess are applied at the end of each frame, after the update, so the Scene is never destroyed while it is still running.

Scenes and systems never reference Game directly. They only see the SceneContext it builds and talk to the Game through ctx.engine.

Constructor & Destructor Documentation

◆ Game()

Imago::Engine::Game::Game ( const GameConfig & config)
explicit

Construct a new Game object, building a new window based on GameSettings and filling in the SceneContext with its persistent engine objects.

Parameters
configSettings for the window, pacing, and first Scene

Member Function Documentation

◆ add_input()

void Imago::Engine::Game::add_input ( const std::string & action,
GamepadAxis axis,
float deadZone = 0.2f,
float threshold = 0.5f )

adds a gamepad axis to an action. dead zone and threshold values are defualted to fit standard player movement.

Parameters
deadZonehow much axis travel nearest the center counts as not moved. Everything past it is rescaled to 0-1. Defaulted to 0.2f
thresholdminimum magnitude axis needs to be pressed before it counts as being down. Defualted to 0.5f

◆ register_action()

ActionId Imago::Engine::Game::register_action ( const std::string & name)

Registers an action name and returns its id. Forwards to the InputHandler.

Parameters
nameName of the action to register.

◆ register_scene()

template<typename T>
void Imago::Engine::Game::register_scene ( const std::string & name)
inline

Registers a Scene type under a name. Simply forwards to its SceneManager.

Template Parameters
TScene type, must satisfy SceneManager::register_scene's requiremenets.
Parameters
nameName of the Scene. Used to switch between Scenes and instantiate the first scene.

The documentation for this class was generated from the following files:
  • engine/include/Imago/Engine/Game.hpp
  • engine/src/Engine/Game.cpp