Public Member Functions | List of all members
ime::Engine Class Reference

Runs the main loop. More...

#include <Engine.h>

Inheritance diagram for ime::Engine:
ime::utility::NonCopyable

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...
 
Engineoperator= (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 PropertyContainergetSettings () const
 Get the engines settings. More...
 
PropertyContainergetPersistentData ()
 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...
 
ResourceManagergetResourceManager ()
 Get the global resource manager. More...
 
audio::AudioManagergetAudioManager ()
 Get the global audio manager. More...
 
input::InputManagergetInputManager ()
 Get the global input manager. More...
 
WindowgetRenderTarget ()
 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...
 

Detailed Description

Runs the main loop.

Definition at line 46 of file Engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/3]

ime::Engine::Engine ( const std::string &  gameTitle,
const std::string &  settingsFile = "default" 
)
explicit

Constructor.

Parameters
gameTitleName of the game run by the engine
settingsFileFilename 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

◆ Engine() [2/3]

ime::Engine::Engine ( const std::string &  gameName,
const PropertyContainer settings 
)

Constructor.

Parameters
gameNameName of the game to be run by the engine
settingsEngine settings

◆ Engine() [3/3]

ime::Engine::Engine ( Engine &&  )
delete

Move constructor.

Member Function Documentation

◆ getAudioManager()

audio::AudioManager& ime::Engine::getAudioManager ( )

Get the global audio manager.

Returns
The global audio manager

◆ getElapsedTime()

Time ime::Engine::getElapsedTime ( ) const

Get the time passed since the engine was started.

Returns
The time passed since the engine was started
Note
The elapsed time will reset to zero when the engine is shutdown

◆ getGameName()

const std::string& ime::Engine::getGameName ( ) const

Get the name of the game run by the engine.

Returns
The name of the game run by the engine

This is the name provided during construction of the engine

◆ getInputManager()

input::InputManager& ime::Engine::getInputManager ( )

Get the global input manager.

Returns
The global input manager

◆ getPersistentData()

PropertyContainer& ime::Engine::getPersistentData ( )

Get persistent data.

Returns
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

Warning
The data is destroyed when the engine is shutdown
See also
quit

◆ getRenderTarget()

Window& ime::Engine::getRenderTarget ( )

Get access to the engines render target.

Returns
The engines render target
Warning
This function must only be called after the engine has been initialized
See also
initialize

◆ getResourceManager()

ResourceManager& ime::Engine::getResourceManager ( )

Get the global resource manager.

Returns
The global resource manager

◆ getSettings()

const PropertyContainer& ime::Engine::getSettings ( ) const

Get the engines settings.

Returns
The engines settings

◆ initialize()

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

See also
getRenderTarget

◆ isRunning()

bool ime::Engine::isRunning ( ) const

Check if the engine is running or not.

Returns
True if the engine is running, otherwise false

◆ onFrameEnd()

void ime::Engine::onFrameEnd ( Callback<>  callback)

Execute a function at the end of the current frame.

Parameters
callbackFunction to be executed
Note
Only one callback may be registered at a time. Pass nullptr to stop the callback from being invoked.

By default, no callback is registered

◆ onFrameStart()

void ime::Engine::onFrameStart ( Callback<>  callback)

Execute a function at the start of a frame.

Parameters
callbackFunction 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

◆ onShutDown()

void ime::Engine::onShutDown ( Callback<>  callback)

Execute a callback before the engine is shutdown.

Parameters
callbackThe function to be executed

This function is called before the engine executes its shutdown sequence

◆ onWindowClose()

void ime::Engine::onWindowClose ( Callback<>  callback)

Add an event lister to a window close event.

Parameters
callbackFunction 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.

Note
Only one event listener may be registered to this event. This means that when a new event listener is added, the previous one is removed. As a result, adding a window close event listener overwrites the default behavior

◆ operator=()

Engine& ime::Engine::operator= ( Engine &&  )
delete

Move Assignment operator.

◆ popScene()

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

◆ pushScene()

void ime::Engine::pushScene ( Scene::Ptr  scene,
Callback<>  callback = nullptr 
)

Add a scene to the engine.

Parameters
sceneScene to be added
callbackOptional 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

Warning
If multiple scenes are pushed to the engine in the same frame, the last scene to be received before the frame end will be the active scene. All the other scenes will be pushed without initialization. This means that only the optional callback attached to the last scene will be invoked

◆ quit()

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

◆ run()

void ime::Engine::run ( )

Start the main loop.

Warning
The engine must be initialized before it is run. In addition, there must be at least one scene added for the engine to run
See also
initialize
pushScene

◆ setInterval()

void ime::Engine::setInterval ( Time  delay,
ime::Callback< Timer & >  callback,
int  repeatCount = -1 
)

Schedule a callback to be executed every interval.

Parameters
delayTime to wait before executing the callback
callbackFunction to be executed
repeatCountThe 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

Note
The callback is executed by a global timer, therefore the interval will continue to execute until the engine is shutdown or the interval is stopped via the argument passed to the callback
Warning
The timer will be destroyed if the timer is externally stopped or the repetition is cancelled
See also
setTimeout

◆ setTimeout()

void ime::Engine::setTimeout ( Time  delay,
ime::Callback< Timer & >  callback 
)

Schedule a callback to be executed after a delay.

Parameters
delayTime to wait before executing the callback
callbackFunction 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

Note
The callback is executed by a global timer
Warning
The timer will be destroyed after the callback is invoked or if it is externally stopped before the callback is invoked
See also
setInterval

The documentation for this class was generated from the following file: