Runs the main loop. More...
#include <Engine.h>
Public Member Functions | |
Engine (const std::string &gameTitle, const std::string &settingsFile="default") | |
Constructor. More... | |
Engine (const std::string &gameName, const PropertyContainer &settings) | |
Constructor. More... | |
Engine (Engine &&)=delete | |
Move constructor. More... | |
Engine & | operator= (Engine &&)=delete |
Move Assignment operator. More... | |
void | initialize () |
Initialize the engine. More... | |
void | run () |
Start the main loop. More... | |
void | quit () |
Stop the engine. More... | |
bool | isRunning () const |
Check if the engine is running or not. More... | |
const PropertyContainer & | getSettings () const |
Get the engines settings. More... | |
PropertyContainer & | getPersistentData () |
Get persistent data. More... | |
const std::string & | getGameName () const |
Get the name of the game run by the engine. More... | |
void | pushScene (Scene::Ptr scene, Callback<> callback=nullptr) |
Add a scene to the engine. More... | |
void | popScene () |
Remove the current scene from the engine. More... | |
Time | getElapsedTime () const |
Get the time passed since the engine was started. More... | |
ResourceManager & | getResourceManager () |
Get the global resource manager. More... | |
audio::AudioManager & | getAudioManager () |
Get the global audio manager. More... | |
input::InputManager & | getInputManager () |
Get the global input manager. More... | |
Window & | getRenderTarget () |
Get access to the engines render target. More... | |
void | setTimeout (Time delay, ime::Callback< Timer & > callback) |
Schedule a callback to be executed after a delay. More... | |
void | setInterval (Time delay, ime::Callback< Timer & > callback, int repeatCount=-1) |
Schedule a callback to be executed every interval. More... | |
void | onWindowClose (Callback<> callback) |
Add an event lister to a window close event. More... | |
void | onFrameStart (Callback<> callback) |
Execute a function at the start of a frame. More... | |
void | onFrameEnd (Callback<> callback) |
Execute a function at the end of the current frame. More... | |
void | onShutDown (Callback<> callback) |
Execute a callback before the engine is shutdown. More... | |
|
explicit |
Constructor.
gameTitle | Name of the game run by the engine |
settingsFile | Filename of the file that contains the engines settings |
settingsFile must have the filename preceded by the path to the file. The path must be relative to the directory that contains the game executable. If settingsFile is left unspecified the engine will be constructed from default settings
ime::Engine::Engine | ( | const std::string & | gameName, |
const PropertyContainer & | settings | ||
) |
Constructor.
gameName | Name of the game to be run by the engine |
settings | Engine settings |
|
delete |
Move constructor.
audio::AudioManager& ime::Engine::getAudioManager | ( | ) |
Get the global audio manager.
Time ime::Engine::getElapsedTime | ( | ) | const |
Get the time passed since the engine was started.
const std::string& ime::Engine::getGameName | ( | ) | const |
Get the name of the game run by the engine.
This is the name provided during construction of the engine
input::InputManager& ime::Engine::getInputManager | ( | ) |
Get the global input manager.
PropertyContainer& ime::Engine::getPersistentData | ( | ) |
Get persistent data.
Data stored in the this object persists from scene to scene. This means that the data is preserved during a scene push or pop. This is useful if you want share data between scenes. For example, a scene may save data before its destroyed/paused and the next scene can access the data and update for the next scene or for the previous scene when it is resumed
Window& ime::Engine::getRenderTarget | ( | ) |
Get access to the engines render target.
ResourceManager& ime::Engine::getResourceManager | ( | ) |
Get the global resource manager.
const PropertyContainer& ime::Engine::getSettings | ( | ) | const |
Get the engines settings.
void ime::Engine::initialize | ( | ) |
Initialize the engine.
This function will perform all the necessary initialization and create the games render target, therefore calling the function getRenderTarget() prior to this function is undefined behaviour
bool ime::Engine::isRunning | ( | ) | const |
Check if the engine is running or not.
void ime::Engine::onFrameEnd | ( | Callback<> | callback | ) |
Execute a function at the end of the current frame.
callback | Function to be executed |
By default, no callback is registered
void ime::Engine::onFrameStart | ( | Callback<> | callback | ) |
Execute a function at the start of a frame.
callback | Function to execute |
Only one callback may be registered at a time. Pass nullptr to stop the callback from being invoked. By default no callback is registered
void ime::Engine::onShutDown | ( | Callback<> | callback | ) |
Execute a callback before the engine is shutdown.
callback | The function to be executed |
This function is called before the engine executes its shutdown sequence
void ime::Engine::onWindowClose | ( | Callback<> | callback | ) |
Add an event lister to a window close event.
callback | Function to execute when a window close event is fired |
The callback function will be called by the engine when a request to close the window is made by the user. The default behavior stops the engine and closes the render window.
void ime::Engine::popScene | ( | ) |
Remove the current scene from the engine.
The scene will not be removed immediately but rather at the end of the current frame
void ime::Engine::pushScene | ( | Scene::Ptr | scene, |
Callback<> | callback = nullptr |
||
) |
Add a scene to the engine.
scene | Scene to be added |
callback | Optional function to be executed after the scene is added |
The scene will NOT be pushed immediately but rather at the end of the current frame. Any operation performed on the engine before the end of the current frame will reflect on the current scene and not the scene to be pushed. A callback must be provided if the need to perform an operation immediately after a scene is pushed arises
void ime::Engine::quit | ( | ) |
Stop the engine.
This function will remove all scenes that have been added to the engine and reset it's initialization state. Therefore, the engine must be reinitialized before it is re-run
void ime::Engine::run | ( | ) |
Start the main loop.
void ime::Engine::setInterval | ( | Time | delay, |
ime::Callback< Timer & > | callback, | ||
int | repeatCount = -1 |
||
) |
Schedule a callback to be executed every interval.
delay | Time to wait before executing the callback |
callback | Function to be executed |
repeatCount | The number of times to repeat the interval |
Unlike setTimeout, this function will execute a callback every delay seconds for a specified number of times while the engine is running. By default the repeat counter is -1, this means that the callback will repeat forever. The repetition can be also be cancelled by calling setRepeat(0) on the returned timer
void ime::Engine::setTimeout | ( | Time | delay, |
ime::Callback< Timer & > | callback | ||
) |
Schedule a callback to be executed after a delay.
delay | Time to wait before executing the callback |
callback | Function to be executed |
This function will execute a callback function once after delay seconds. To execute a callback repeatedly every interval, checkout the setInterval function