Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
ime::Scene Class Reference

A base class for game scenes. More...

#include <Scene.h>

Inheritance diagram for ime::Scene:
ime::Object

Public Types

using Ptr = std::unique_ptr< Scene >
 Unique Scene pointer. More...
 

Public Member Functions

 Scene ()
 Default Constructor. More...
 
 Scene (const Scene &)=delete
 Copy constructor. More...
 
Sceneoperator= (const Scene &)=delete
 Copy assignment operator. More...
 
 Scene (Scene &&) noexcept
 Move constructor. More...
 
Sceneoperator= (Scene &&) noexcept
 Move assignment operator. More...
 
virtual void onInit ()
 Handle a scene initialization. More...
 
virtual void onEnter ()
 Handle a scene enter. More...
 
virtual void onHandleEvent (Event event)
 Handle a scene system event. More...
 
virtual void onPreUpdate (Time deltaTime)
 Handle a scene pre-update. More...
 
virtual void onUpdate (Time deltaTime)
 Handle a scene frame-rate dependent update. More...
 
virtual void onFixedUpdate (Time deltaTime)
 Handle a scene frame-rate independent update. More...
 
virtual void onPostUpdate (Time deltaTime)
 Handle a scene post-update update. More...
 
virtual void onPreRender ()
 Handle a scene pre-render event. More...
 
virtual void onPostRender ()
 Handle a scene post-render event. More...
 
virtual void onPause ()
 Handle a scene pause event. More...
 
virtual void onResume ()
 Handle a scene resume event. More...
 
virtual void onCache ()
 Handle a scene cache event. More...
 
virtual void onResumeFromCache ()
 Handle a scene 'resume from cache' event. More...
 
virtual void onExit ()
 Handle a scene exit event. More...
 
virtual void onFrameBegin ()
 Handle a scene frame begin event. More...
 
virtual void onFrameEnd ()
 Handle a scene frame end event. More...
 
std::string getClassName () const override
 Get the name of this class. More...
 
bool isEntered () const
 Check if the scene has been entered or not. More...
 
bool isPaused () const
 Check if the scene is paused or not. More...
 
void setVisibleOnPause (bool visible)
 Set whether or not the scene is visible when it is paused. More...
 
bool isVisibleOnPause () const
 Check if the scene is visible when paused. More...
 
void setBackgroundScene (Scene::Ptr scene)
 Add a background scene to this scene. More...
 
ScenegetParentScene ()
 Get the scene this scene is a background of. More...
 
const ScenegetParentScene () const
 
ScenegetBackgroundScene ()
 Get the background scene of this scene. More...
 
const ScenegetBackgroundScene () const
 
bool isBackgroundScene () const
 Check if the scene is in a background scene. More...
 
bool hasBackgroundScene () const
 Check if the scene has a background scene or not. More...
 
void setBackgroundSceneDrawable (bool drawable)
 Set whether or not the scenes background scene is rendered. More...
 
bool isBackgroundSceneDrawable () const
 Check if the scenes background scene is rendered. More...
 
void setBackgroundSceneUpdateEnable (bool enable)
 Set whether or not the scenes background scene receives time updates. More...
 
bool isBackgroundSceneUpdateEnabled () const
 Check if the scenes background scene receives time updates or not. More...
 
void setBackgroundSceneEventsEnable (bool enable)
 Enable or disable events for the scenes background scene. More...
 
bool isBackgroundSceneEventsEnabled () const
 Check if events are enabled for the background scene or not. More...
 
void setCached (bool cache, const std::string &alias="")
 Cache or uncahe the scene. More...
 
bool isCached () const
 Check if the scene is cached or not. More...
 
void setTimescale (float timescale)
 Set the scene timescale factor. More...
 
float getTimescale () const
 Get the scenes timescale factor. More...
 
EnginegetEngine ()
 Get a reference to the game engine. More...
 
const EnginegetEngine () const
 
WindowgetWindow ()
 Get the game window. More...
 
const WindowgetWindow () const
 
CameragetCamera ()
 Get the scene level camera. More...
 
const CameragetCamera () const
 
CameraContainergetCameras ()
 Get the scene level camera container. More...
 
const CameraContainergetCameras () const
 
PhysicsEnginegetPhysicsEngine ()
 Get the scene level physics engine/simulation. More...
 
const PhysicsEnginegetPhysicsEngine () const
 
GridMoverContainergetGridMovers ()
 Get the scene level GridMover container. More...
 
const GridMoverContainergetGridMovers () const
 
EventEmittergetEventEmitter ()
 Get the scene level event EventEmitter. More...
 
const EventEmittergetEventEmitter () const
 
EventDispatchergetGlobalEventEmitter ()
 Get the global event emitter. More...
 
input::InputManagergetInput ()
 Get the scene level input manager. More...
 
const input::InputManagergetInput () const
 
audio::AudioManagergetAudio ()
 Get the scene level audio manager. More...
 
const audio::AudioManagergetAudio () const
 
TimerManagergetTimer ()
 Get the scene level timer manager. More...
 
const TimerManagergetTimer () const
 
PropertyContainergetCache ()
 Get the engine level cache. More...
 
const PropertyContainergetCache () const
 
PrefContainergetSCache ()
 Get the engine level savable cache. More...
 
const PrefContainergetSCache () const
 
RenderLayerContainergetRenderLayers ()
 Get the scene render layers. More...
 
const RenderLayerContainergetRenderLayers () const
 
Grid2DgetGrid ()
 Get the scene level grid. More...
 
const Grid2DgetGrid () const
 
ui::GuiContainergetGui ()
 Get the scene level gui container. More...
 
const ui::GuiContainergetGui () const
 
ShapeContainergetShapes ()
 Get the scene geometry shape container. More...
 
const ShapeContainergetShapes () const
 
GameObjectContainergetGameObjects ()
 Get the scene level game object container. More...
 
const GameObjectContainergetGameObjects () const
 
SpriteContainergetSprites ()
 Get the scene level sprite container. More...
 
const SpriteContainergetSprites () const
 
void createPhysicsEngine (const Vector2f &gravity, const PhysIterations &iterations={3, 8})
 Create a scene level physics simulation. More...
 
void createGrid2D (unsigned int tileWidth, unsigned int tileHeight)
 Create the scene level grid instance. More...
 
void init (Engine &engine)
 
template<typename ... Args>
int on_ (const std::string &event, Callback< Args... > callback)
 
bool unsubscribe_ (const std::string &event, int id)
 
 ~Scene () override
 Destructor. More...
 
void setTag (const std::string &tag)
 Assign the object an alias. More...
 
const std::string & getTag () const
 Get the tag assigned to the object. More...
 
unsigned int getObjectId () const
 Get the unique id of the object. More...
 
virtual std::string getClassType () const
 Get the name of the direct parent of an object instance. More...
 
int onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to a specific property change event. More...
 
int onPropertyChange (const Callback< Property > &callback, bool oneTime=false)
 Add an event listener to any property change event. More...
 
void suspendedEventListener (int id, bool suspend)
 Pause or resume execution of an event listener. More...
 
bool isEventListenerSuspended (int id) const
 Check if an event listener is suspended or not. More...
 
bool removeEventListener (const std::string &event, int id)
 Remove an event listener from an event. More...
 
bool removeEventListener (int id)
 Remove an event listener. More...
 
int onDestruction (const Callback<> &callback)
 Add a destruction listener. More...
 
bool isSameObjectAs (const Object &other) const
 Check if another object is the same instance as this object. More...
 

Static Public Member Functions

static Scene::Ptr create ()
 Create an empty scene. More...
 

Protected Member Functions

void emitChange (const Property &property)
 Dispatch a property change event. More...
 
void emitDestruction ()
 Emit a destruction event. More...
 

Friends

class priv::SceneManager
 Pre updates the scene. More...
 

Detailed Description

A base class for game scenes.

A ime::Scene represents a distinct state of your game, for example loading, main menu, gameplay, paused and so on.

All game scenes exist in isolation and have no knowledge of each other. Only one scene can be active at a time. For example, the game cannot be in a main menu state and a gameplay state at the same time.

The transition between scenes is managed using the Last In First Out (LIFO) technique (The same way std::stack works). Therefore you cannot transition between scenes at random. The order in which scenes are added to the Engine is important.

For example, if while in the "gameplay" scene, you push a "pause" scene to the game engine, the "gameplay" scene will be paused (onPause called) and the "pause" scene will be entered (onEnter called on the pause scene instance) and the "pause" scene will become the active scene (gets system events, updates and rendered). If you pop the "pause" scene, the engine will destroy it (onExit called on the pause scene instance) and return to the "gameplay" scene (onResume called on the gameplay scene instance). However, if you push (transition to) another scene while in the "pause" scene, the process repeats; the "pause" scene gets paused and the the new scene becomes active)

Usage example:

class StartUpScene : public ime::Scene {
void onEnter() override {
ime::ui::Label::Ptr greeting = ime::ui::Label::create("Thank you for using Infinite Motion Engine");
greeting->setOrigin(0.5f, 0.5f);
greeting->setPosition("50%", "50%");
getGui().addWidget(std::move(greeting), "lblGreeting");
}
}
...
engine.pushScene(std::make_unique<StartUpScene>());
A base class for game scenes.
Definition: Scene.h:63
virtual void onEnter()
Handle a scene enter.
Definition: Scene.h:124
ui::GuiContainer & getGui()
Get the scene level gui container.
Widget * addWidget(Widget::Ptr widget, const std::string &name="")
Add a widget to the gui.
static Label::Ptr create(const std::string &text="")
Create a new label widget.
std::unique_ptr< Label > Ptr
Unique widget pointer.
Definition: Label.h:44

Definition at line 63 of file Scene.h.

Member Typedef Documentation

◆ Ptr

using ime::Scene::Ptr = std::unique_ptr<Scene>

Unique Scene pointer.

Definition at line 65 of file Scene.h.

Constructor & Destructor Documentation

◆ Scene() [1/3]

ime::Scene::Scene ( )

Default Constructor.

◆ Scene() [2/3]

ime::Scene::Scene ( const Scene )
delete

Copy constructor.

◆ Scene() [3/3]

ime::Scene::Scene ( Scene &&  )
noexcept

Move constructor.

◆ ~Scene()

ime::Scene::~Scene ( )
override

Destructor.

Member Function Documentation

◆ create()

static Scene::Ptr ime::Scene::create ( )
static

Create an empty scene.

Returns
The created scene

◆ createGrid2D()

void ime::Scene::createGrid2D ( unsigned int  tileWidth,
unsigned int  tileHeight 
)

Create the scene level grid instance.

Parameters
tileWidthThe width of the grid
tileHeightThe height of the grid

Note that this function only creates a grid instance so that it can be used. You still need to construct the grid using the appropriate member function

Warning
Only a single grid can be created, therefore calling this function will destroy the previous grid
See also
getGrid

◆ createPhysicsEngine()

void ime::Scene::createPhysicsEngine ( const Vector2f gravity,
const PhysIterations iterations = {3, 8} 
)

Create a scene level physics simulation.

Parameters
gravityAcceleration of bodies in the simulation due to gravity
iterationsPosition and velocity iterations (see ime::PhysIterations)
Note
This function should only be called by scenes that require a physics simulation (i.e. scenes that make use of ime::RigidBody). If the scene uses no physics at all or only makes use of grid-based physics (see ime::GridMover) then there is no need to create the physics world. Grid-based physics do not use a physics engine.
See also
getPhysicsEngine

◆ emitChange()

void ime::Object::emitChange ( const Property property)
protectedinherited

Dispatch a property change event.

Parameters
propertyThe property that changed

This function will invoke all the event listeners of the specified property

See also
emit

◆ emitDestruction()

void ime::Object::emitDestruction ( )
protectedinherited

Emit a destruction event.

Note
This function must be the first statement in the definition of a destructor to avoid undefined behavior. In addition, note that destruction listeners are invoked once. Therefore, multiple classes in a hierarchy may call this function but the class that makes the call first will be the one that invokes the destruction listeners

◆ getAudio()

audio::AudioManager & ime::Scene::getAudio ( )

Get the scene level audio manager.

Returns
The scene level audio manager

The audio manager is local to the scene instance. All audio played by it is destroyed when the scene is destroyed

See also
ime::Engine::getAudioManager

◆ getBackgroundScene()

Scene * ime::Scene::getBackgroundScene ( )

Get the background scene of this scene.

Returns
A pointer to the background scene if it exists, otherwise a nullptr
See also
setBackgroundScene

◆ getCache()

PropertyContainer & ime::Scene::getCache ( )

Get the engine level cache.

Returns
The engine level cache
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

Data stored in the cache persists from scene to scene. This means that another scene can access or modify data stored by another scene. The data can also be accessed using ime::Engine::getCache

Note
The cache only stores data, while the engine is running. When the engine is shutdown, the data in the cache is destroyed
See also
getSCache

◆ getCamera()

Camera & ime::Scene::getCamera ( )

Get the scene level camera.

Returns
The scene level camera
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

Note that this camera is the default/main camera and is always rendered last. You can add other cameras to the scene using getCameras()

See also
getCameras

◆ getCameras()

CameraContainer & ime::Scene::getCameras ( )

Get the scene level camera container.

Returns
The scene level camera container
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized
See also
getCamera

◆ getClassName()

std::string ime::Scene::getClassName ( ) const
overridevirtual

Get the name of this class.

Returns
The name of this class
See also
getClassType

Implements ime::Object.

◆ getClassType()

virtual std::string ime::Object::getClassType ( ) const
virtualinherited

Get the name of the direct parent of an object instance.

Returns
The name of the direct parent of an object instance

In contrast to getClassName() which returns the name of the concrete class, this function returns the name of the concrete class's base class. This function is implemented by all derived classes of ime::Object which also serve as base classes. For classes whose direct parent is this class, this function will return the name of this class

auto rectangle = ime::RectangleShape(); // RectangleShape is derived from Shape
std::cout << rectangle->getClassName(); // Prints "RectangleShape"
std::cout << rectangle->getClassType(); // Prints "Shape"
A 2D shape having four sides and four corners (90 degree angles)
See also
getClassName

Reimplemented in ime::audio::Audio, ime::GameObject, ime::GridMover, ime::Collider, ime::Joint, ime::Drawable, ime::Shape, and ime::SpriteImage.

◆ getEngine()

Engine & ime::Scene::getEngine ( )

Get a reference to the game engine.

Returns
A reference to the game engine
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

Note that all scenes refer to the same Engine instance

◆ getEventEmitter()

EventEmitter & ime::Scene::getEventEmitter ( )

Get the scene level event EventEmitter.

Returns
The scene level event event emitter

The event emitter is local to the scene instance. This means that events registered on it are only dispatched when the scene is active and de-registered when the scene is destroyed.

See also
getGlobalEventEmitter

◆ getGameObjects()

GameObjectContainer & ime::Scene::getGameObjects ( )

Get the scene level game object container.

Returns
The scene level game object container

This class stores game objects that belong to this scene. All game objects in this container are automatically updated

Warning
Do not keep the returned reference

◆ getGlobalEventEmitter()

EventDispatcher & ime::Scene::getGlobalEventEmitter ( )

Get the global event emitter.

Returns
The global event emitter

The global event emitter is available to anything that needs it (a class, function etc...). Events registered to it are always dispatched regardless of the active scene. As a result you must remove event listeners that are local to the scene when the scene is destroyed. For example, a lambda that captures "this" will result in undefined behavior if not removed after the scene is destroyed

Warning
Always remove local event listeners

◆ getGrid()

Grid2D & ime::Scene::getGrid ( )

Get the scene level grid.

Returns
The scene level grid
Exceptions
AccessViolationExceptionIf this function is called without creating the grid first

Note that only one grid can be created per scene

Warning
The grid must be created before it is used. Calling this function before the grid is created is undefined behavior
See also
createGrid2D

◆ getGridMovers()

GridMoverContainer & ime::Scene::getGridMovers ( )

Get the scene level GridMover container.

Returns
The scene level grid mover container

◆ getGui()

ui::GuiContainer & ime::Scene::getGui ( )

Get the scene level gui container.

Returns
The scene level gui container
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

The gui container is local to the scene. This means that all widgets in it are destroyed when the scene is destroyed

See also
ime::Engine::getGui

◆ getInput()

input::InputManager & ime::Scene::getInput ( )

Get the scene level input manager.

Returns
The scene level input manager

The input manager is local to the scene instance. This means that input listeners registered on it are only invoked when the scene is active and de-registered when the scene is destroyed

See also
ime::Engine::getInputManager

◆ getObjectId()

unsigned int ime::Object::getObjectId ( ) const
inherited

Get the unique id of the object.

Returns
The unique id of the object

Note that each instance of ime::Object has a unique id

See also
setTag

◆ getParentScene()

Scene * ime::Scene::getParentScene ( )

Get the scene this scene is a background of.

Returns
Pointer to the parent scene if this scene is a background scene, otherwise a nullptr

The scene has a parent scene when it is set as the background of another scene. The scene it is set as the background of becomes its parent scene

By default, the scene does not have a parent scene

See also
setBackgroundScene

◆ getPhysicsEngine()

PhysicsEngine & ime::Scene::getPhysicsEngine ( )

Get the scene level physics engine/simulation.

Returns
The scene level physics engine/simulation
Exceptions
AccessViolationExceptionIf this function is called without creating the physics engine first

The physics engine is responsible for creating, managing, colliding and updating all of the RigidBody's in it.

Warning
By default, the scene does not have a physics engine. As a result, calling this function prior to creating the physics engine is undefined behavior. Use createPhysicsEngine() to instantiate a scene level physics engine
See also
createPhysicEngine

◆ getRenderLayers()

RenderLayerContainer & ime::Scene::getRenderLayers ( )

Get the scene render layers.

Returns
The scene render layers

Render layers allow the scene to be rendered in separate layers which are then composed back together. By default the scene has a "default" layer at index 0. When a drawable object is added to the scene without an explicit layer, it will be added to the default layer. You can add objects to the "default" layer or even remove the "default" layer from the render layer container, however you mus not forget to reallocate the objects in the "default" layer to another layer, otherwise they will not be drawn to the screen

◆ getSCache()

PrefContainer & ime::Scene::getSCache ( )

Get the engine level savable cache.

Returns
The engine level savable cache
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

Data stored in the cache persists from scene to scene. This means that another scene can access or modify data stored by another scene. Unlike ime::Scene::getCache, this cache can be initialized with data read from a file and can also be saved to a file. The data can also be accessed using ime::Engine::getSavableCache

Note
The cache only stores data, while the engine is running. When the engine is shutdown, the data in the cache is destroyed
See also
getCache

◆ getShapes()

ShapeContainer & ime::Scene::getShapes ( )

Get the scene geometry shape container.

Returns
The geometry shape container

You may use this class to create geometry shape instead of using their respective constructors. Consult the ShapeContainer class definition for more info

Warning
Do not keep the returned reference

◆ getSprites()

SpriteContainer & ime::Scene::getSprites ( )

Get the scene level sprite container.

Returns
The scene level sprite container

This class stores the sprites in the scene. The sprite's animator will automatically be updated

◆ getTag()

const std::string & ime::Object::getTag ( ) const
inherited

Get the tag assigned to the object.

Returns
The tag of the object
See also
setTag

◆ getTimer()

TimerManager & ime::Scene::getTimer ( )

Get the scene level timer manager.

Returns
The scene level timer manager

The timer manager is local to the scene instance. This means that callbacks scheduled on it will only be dispatched when the scene is active

See also
ime::Engine::getTimer

◆ getTimescale()

float ime::Scene::getTimescale ( ) const

Get the scenes timescale factor.

Returns
The scenes timescale factor
See also
setTimescale

◆ getWindow()

Window & ime::Scene::getWindow ( )

Get the game window.

Returns
The game window
Exceptions
AccessViolationExceptionIf this function is called before the scene is initialized

Note that all scenes refer to the same game Window instance

◆ hasBackgroundScene()

bool ime::Scene::hasBackgroundScene ( ) const

Check if the scene has a background scene or not.

Returns
True if it has a background scene, otherwise false
See also
setBackgroundScene

◆ isBackgroundScene()

bool ime::Scene::isBackgroundScene ( ) const

Check if the scene is in a background scene.

Returns
True if it is a background scene, otherwise false

The scene becomes a background scene when it is set as the background of another scene

By default, the scene is not a background scene

See also
setBackgroundScene

◆ isBackgroundSceneDrawable()

bool ime::Scene::isBackgroundSceneDrawable ( ) const

Check if the scenes background scene is rendered.

Returns
True if the background scene is rendered, otherwise false
See also
setBackgroundSceneDrawable

◆ isBackgroundSceneEventsEnabled()

bool ime::Scene::isBackgroundSceneEventsEnabled ( ) const

Check if events are enabled for the background scene or not.

Returns
True if events are enabled, otherwise false
See also
setBackgroundSceneEventsEnable

◆ isBackgroundSceneUpdateEnabled()

bool ime::Scene::isBackgroundSceneUpdateEnabled ( ) const

Check if the scenes background scene receives time updates or not.

Returns
True if it receives time updates, otherwise false
See also
setBackgroundSceneUpdateEnable

◆ isCached()

bool ime::Scene::isCached ( ) const

Check if the scene is cached or not.

Returns
True if cached, otherwise false
See also
setCached

◆ isEntered()

bool ime::Scene::isEntered ( ) const

Check if the scene has been entered or not.

Returns
True if the scene has been entered, otherwise false
See also
onEnter

◆ isEventListenerSuspended()

bool ime::Object::isEventListenerSuspended ( int  id) const
inherited

Check if an event listener is suspended or not.

Parameters
idThe identification number of the listener to be checked
Returns
True if suspended, otherwise false

This function also returns false if the specified event listener does not exist

See also
suspendedEventListener

◆ isPaused()

bool ime::Scene::isPaused ( ) const

Check if the scene is paused or not.

Returns
True if paused, otherwise false
See also
onPause

◆ isSameObjectAs()

bool ime::Object::isSameObjectAs ( const Object other) const
inherited

Check if another object is the same instance as this object.

Parameters
otherThe object to compare against this object
Returns
True if other is the same instance as this object, otherwise false

◆ isVisibleOnPause()

bool ime::Scene::isVisibleOnPause ( ) const

Check if the scene is visible when paused.

Returns
True if visible, otherwise false
See also
setVisibleOnPause

◆ on_()

template<typename ... Args>
int ime::Scene::on_ ( const std::string &  event,
Callback< Args... >  callback 
)
inline

Definition at line 889 of file Scene.h.

◆ onCache()

virtual void ime::Scene::onCache ( )
inlinevirtual

Handle a scene cache event.

This function is called by IME when this scene is cached. (see setCached() and ime::Engine::cacheScene)

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onResumeFromCache

Definition at line 277 of file Scene.h.

◆ onDestruction()

int ime::Object::onDestruction ( const Callback<> &  callback)
inherited

Add a destruction listener.

Parameters
callbackFunction to be executed when the object is destroyed
Returns
The unique id of the destruction listener

The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it

Warning
It's not advised to call virtual functions in the destruction callback as some parts of the object may have already been destroyed by the time the callback is invoked. In such an event, the behavior is undefined
See also
removeEventListener

◆ onEnter()

virtual void ime::Scene::onEnter ( )
inlinevirtual

Handle a scene enter.

This function is called once by IME when the scene is entered for the first time

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

Definition at line 124 of file Scene.h.

◆ onExit()

virtual void ime::Scene::onExit ( )
inlinevirtual

Handle a scene exit event.

This function is called by IME when the scene is removed from the engine (either by destruction or by caching). See ime::Engine::popScene

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
setCached, ime::Engine::cacheScene

Definition at line 305 of file Scene.h.

◆ onFixedUpdate()

virtual void ime::Scene::onFixedUpdate ( Time  deltaTime)
inlinevirtual

Handle a scene frame-rate independent update.

Parameters
deltaTimeThe time passed since last update

This function is called by IME every fixed frame-rate frame. It is called before onUpdate() and may be called once per frame, multiple times per frame or not called at all. The delta passed to it is always the same and is independent of the render fps. see ime::Engine::setPhysicsUpdateFrameRate to determine the delta

Note that implementing this function is optional and must be overridden if needed. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onUpdate

Definition at line 190 of file Scene.h.

◆ onFrameBegin()

virtual void ime::Scene::onFrameBegin ( )
inlinevirtual

Handle a scene frame begin event.

This function is called by IME when the current frame begins while this scene is active

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onFrameEnd

Definition at line 319 of file Scene.h.

◆ onFrameEnd()

virtual void ime::Scene::onFrameEnd ( )
inlinevirtual

Handle a scene frame end event.

This function is called by IME when the current frame ends and this scene is active

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onFrameBegin

Definition at line 333 of file Scene.h.

◆ onHandleEvent()

virtual void ime::Scene::onHandleEvent ( Event  event)
inlinevirtual

Handle a scene system event.

Parameters
eventA system event to be handled

This function is called by IME when a system event is triggered. It is called before the scene is updated and rendered.

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

Definition at line 137 of file Scene.h.

◆ onInit()

virtual void ime::Scene::onInit ( )
inlinevirtual

Handle a scene initialization.

This function is called by IME when the base scene is ready to be used. It is called once after the constructor but before onEnter(). Note that ime::Scene functions cannot be called in the constructor, doing so is undefined behavior. Thus, this function is intended for situation where IME scene functions need to be accessed before the scene is entered.

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

Definition at line 112 of file Scene.h.

◆ onPause()

virtual void ime::Scene::onPause ( )
inlinevirtual

Handle a scene pause event.

This function is called by IME if another scene is pushed over this scene while it was active (see ime::Engine::pushScene)

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onResume

Definition at line 248 of file Scene.h.

◆ onPostRender()

virtual void ime::Scene::onPostRender ( )
inlinevirtual

Handle a scene post-render event.

This function is called by IME once per frame after the scene is rendered.

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onPreRender

Definition at line 234 of file Scene.h.

◆ onPostUpdate()

virtual void ime::Scene::onPostUpdate ( Time  deltaTime)
inlinevirtual

Handle a scene post-update update.

Parameters
deltaTimeThe time passed since the last update

This function is called by IME once per frame. It is called after onUpdate() and onFixedUpdate(). It may be useful if you want to do something after all normal updates have completed such as tracking the position of an object whose position may have changed in onFixedUpdate() or onUpdate().

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

Definition at line 206 of file Scene.h.

◆ onPreRender()

virtual void ime::Scene::onPreRender ( )
inlinevirtual

Handle a scene pre-render event.

This function is called by IME once per frame before the scene is rendered

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onPostRender

Definition at line 220 of file Scene.h.

◆ onPreUpdate()

virtual void ime::Scene::onPreUpdate ( Time  deltaTime)
inlinevirtual

Handle a scene pre-update.

Parameters
deltaTimeThe time passed since the last update

This function is called by IME before the scene is updated. This include physics, animations, timer updates etc. It is called before onUpdate() and onFixedUpdate()

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

Definition at line 151 of file Scene.h.

◆ onPropertyChange() [1/2]

int ime::Object::onPropertyChange ( const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to any property change event.

Parameters
callbackThe function to be executed when any property changes
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
Returns
The unique id of the event listener

When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event

See also
onPropertyChange(const std::string&, const ime::Callback<ime::Property>&)

◆ onPropertyChange() [2/2]

int ime::Object::onPropertyChange ( const std::string &  property,
const Callback< Property > &  callback,
bool  oneTime = false 
)
inherited

Add an event listener to a specific property change event.

Parameters
propertyThe name of the property to add an event listener to
oneTimeTrue to execute the callback one-time or false to execute it every time the event is triggered
callbackThe function to be executed when the property changes
Returns
The unique id of the event listener

A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called

Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.

// Prints the tag of the player object to the console everytime it changes
player.onPropertyChange("tag", [](const Property& property) {
cout << "New tag: " << property.getValue<std::string>() << endl;
});
...
//Sets tag = "player1" and invokes event listener(s)
player.setTag("player1");
See also
unsubscribe and onPropertyChange(const ime::Callback<ime::Property>&)

◆ onResume()

virtual void ime::Scene::onResume ( )
inlinevirtual

Handle a scene resume event.

This function is called by IME when this scene is resumed from a paused state. This occurs when a scene that was pushed over this scene is removed from the Engine (see ime::Engine::popScene)

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onPause

Definition at line 263 of file Scene.h.

◆ onResumeFromCache()

virtual void ime::Scene::onResumeFromCache ( )
inlinevirtual

Handle a scene 'resume from cache' event.

This function is called by IME when this scene is pushed to the Engine from the engines scene cache list (see ime::Engine::PushCachedScene)

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onCache, ime::Engine::PushCachedScene, onPause, onResume

Definition at line 291 of file Scene.h.

◆ onUpdate()

virtual void ime::Scene::onUpdate ( Time  deltaTime)
inlinevirtual

Handle a scene frame-rate dependent update.

Parameters
deltaTimeThe time passed since the last update

This function is called by IME once per frame. The delta passed to it is frame rate dependent. This means that it depends on how long the previous frame took to complete. Note that this function is called after onFixedUpdate()

All updates that should be synced with the render fps must be done in this function.

Note that implementing this function is optional. IME will never put anything inside this function, therefore you don't have to call the base class method in your implementation

See also
onFixedUpdate

Definition at line 171 of file Scene.h.

◆ operator=() [1/2]

Scene & ime::Scene::operator= ( const Scene )
delete

Copy assignment operator.

◆ operator=() [2/2]

Scene & ime::Scene::operator= ( Scene &&  )
noexcept

Move assignment operator.

◆ removeEventListener() [1/2]

bool ime::Object::removeEventListener ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from an event.

Parameters
eventThe name of the event to remove an event listener from
idThe unique id of the event listener to be removed
Returns
True if the event listener was removed or false if the event or the event listener is does not exist
// Display the tag of the object to console every time it changes
auto tagChangeId = object.onPropertyChange("tag", [](ime::Property tag) {
std::cout << name.getValue<std::string>() << std::endl;
});
// Stop displaying the tag of the object when it changes
object.removeEventListener("tag", tagChangeId);
Class that can store a value of any type.
Definition: Property.h:38

◆ removeEventListener() [2/2]

bool ime::Object::removeEventListener ( int  id)
inherited

Remove an event listener.

Parameters
idThe id of the event listener to be removed
Returns
True if the event listener was removed or false if no such handler exists

◆ setBackgroundScene()

void ime::Scene::setBackgroundScene ( Scene::Ptr  scene)

Add a background scene to this scene.

Parameters
sceneThe scene to be the background of this scene
Exceptions
AccessViolationExceptionIf this function is called before this scene is initialized or entered. Furthermore, the exception is thrown if this scene is a background scene or the scene that is passed in is as an argument is already a background scene of another scene or it has a background scene

Note that the scene manages the lifecycle of its background scene. That is, the background scene is destroyed when its parent scene is destroyed. Furthermore, a scene can only have one background scene at a time. Setting a new background scene destroys the previous scene. Pass nullptr to remove the background scene.

Warning
IME does not support nested background scene. That is, a background scene of another scene cannot itself have a background scene. Setting a scene that has a background scene as a background scene for another scene throws a ime::AccessViolationException exception

By default, the scene does not have a background scene

See also
onInit, onEnter

◆ setBackgroundSceneDrawable()

void ime::Scene::setBackgroundSceneDrawable ( bool  drawable)

Set whether or not the scenes background scene is rendered.

Parameters
drawableTrue to render the background scene, otherwise false

When the drawable argument is set to false, the background scene is not rendered when this scene is rendered and when it is set to true, the background scene is rendered behind this scene

By default, the background scene is rendered when the parent scene is rendered

See also
isBackgroundSceneDrawable

◆ setBackgroundSceneEventsEnable()

void ime::Scene::setBackgroundSceneEventsEnable ( bool  enable)

Enable or disable events for the scenes background scene.

Parameters
enableTrue to enable background scene events, otherwise false

When events for a background scene are disabled, the background scene does not receive system updates such as input (keyboard, mouse, joystick etc), window events etc. Furthermore its onHandleEvent() function is not invoked

By default, background scene events are disabled

See also
isBackgroundSceneEventsEnabled

◆ setBackgroundSceneUpdateEnable()

void ime::Scene::setBackgroundSceneUpdateEnable ( bool  enable)

Set whether or not the scenes background scene receives time updates.

Parameters
enableTrue to enable background scene time updates, otherwise false

When updates for a background scene is disabled, its onUpdate(), onFixedUpdate(), onPreUpdate() and onPostUpdate() functions are not invoked

By default, the background scene is updated

See also
setBackgroundScene, isBackgroundSceneUpdateEnabled

◆ setCached()

void ime::Scene::setCached ( bool  cache,
const std::string &  alias = "" 
)

Cache or uncahe the scene.

Parameters
cacheTrue to cache or false to uncache
aliasA unique name for identification during retrieval

A cached scene is not destroyed when popped from the Engine but rather saved for reuse. For example, instead of instantiating a new pause menu scene every time the game is paused, you can cache the pause menu scene instance and return to it whenever the game is paused. This may improve performance.

Unlike ime::Engine::cacheScene, this function will cache the scene after it was active. To remove the scene from the cache simply call setCached(false)

By default the scene is not cached

See also
isCached, ime::Engine::cacheScene, ime::Engine::uncacheScene

◆ setTag()

void ime::Object::setTag ( const std::string &  tag)
inherited

Assign the object an alias.

Parameters
tagThe alias of the object

This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag

By default, the tag is an empty string

See also
getObjectId

◆ setTimescale()

void ime::Scene::setTimescale ( float  timescale)

Set the scene timescale factor.

Parameters
timescaleThe new scene timescale factor

A timescale factor affects everything that requires a time update. This includes timers, animations, physics etc...

For example, if the timescale is set to 2.0f, then scene timers will count twice as fast, animations will play twice as fast, physics objects will move twice as fast etc..

By default the timescale is 1.0f (real-time)

See also
getTimescale

◆ setVisibleOnPause()

void ime::Scene::setVisibleOnPause ( bool  visible)

Set whether or not the scene is visible when it is paused.

Parameters
visibleTrue to set visible, otherwise false

By default, the scene is hidden when it is paused

See also
onPause

◆ suspendedEventListener()

void ime::Object::suspendedEventListener ( int  id,
bool  suspend 
)
inherited

Pause or resume execution of an event listener.

Parameters
idThe event listeners unique identification number
suspendTrue to suspend/pause or false to unsuspend/resume
See also
isEventListenerSuspended

Friends And Related Function Documentation

◆ priv::SceneManager

friend class priv::SceneManager
friend

Pre updates the scene.

Definition at line 936 of file Scene.h.


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