Gamedev Framework (gf)  0.14.0
A C++14 framework for 2D games
Public Member Functions | Protected Member Functions | List of all members
gf::Scene Class Reference

A scene in the game. More...

#include <gf/Scene.h>

Public Member Functions

 Scene (Vector2i initialSize)
 Constructor. More...
 
virtual ~Scene ()
 Destructor. More...
 
Game loop
void processEvent (Event &event)
 Process an event. More...
 
void handleActions (Window &window)
 Handle actions. More...
 
void update (Time time)
 Update the scene. More...
 
void render (RenderTarget &target)
 Render the scene. More...
 
Scene properties
void setActive (bool active=true)
 Change the active state of the scene. More...
 
bool isActive () const
 Check if the scene is active. More...
 
void pause ()
 Pause the scene. More...
 
void resume ()
 Resume the scene. More...
 
bool isPaused () const
 Check if the scene is paused. More...
 
void hide ()
 Hide the scene. More...
 
void show ()
 Show the scene. More...
 
bool isHidden () const
 Check if the scene is hidden. More...
 
Scene content
void addView (AdaptativeView &view)
 Add a view to the scene. More...
 
void addAction (Action &action)
 Add an action to the scene. More...
 
void addModel (Model &model)
 Add a model to the scene. More...
 
void addWorldEntity (Entity &entity)
 Add a world entity to the scene. More...
 
void addHudEntity (Entity &entity)
 Add a HUD entity to the scene. More...
 
World view management
void setWorldViewCenter (Vector2f center)
 Set the center of the world view. More...
 
void setWorldViewSize (Vector2f size)
 Set the size of the world view. More...
 

Protected Member Functions

void renderWorldEntities (RenderTarget &target)
 Render the world entities. More...
 
void renderHudEntities (RenderTarget &target)
 Render the HUD entities. More...
 
ViewgetWorldView ()
 Get the world view. More...
 
virtual void doProcessEvent (Event &event)
 Customization point for processEvent() More...
 
virtual void doHandleActions (Window &window)
 Customization point for handleActions() More...
 
virtual void doUpdate (Time time)
 Customization point for update() More...
 
virtual void doRender (RenderTarget &target)
 Customization point for render() More...
 
virtual void doPause ()
 Customization point for pause() More...
 
virtual void doResume ()
 Customization point for resume() More...
 
virtual void doHide ()
 Customization point for hide() More...
 
virtual void doShow ()
 Customization point for show() More...
 

Detailed Description

A scene in the game.

A scene is a set of entities that are handled together in the game. A scene is associated with a set of user actions. A scene is responsible for handling the steps of a game: handling the input (and the actions), updating the entities, rendering the entities.

A scene can be associated to a scene manager, with other scenes. A scene is active when it is the top scene on the stack of scenes. The scene manager is responsible for activating and desactivating the scenes.

A scene can be either paused or resumed. A paused scene is not updated. In other words, the update step is discarded. It is the user's responsability to pause or resume a scene. An active scene is always resumed when becoming active.

A scene can be either hidden or shown. A hidden scene is not rendererd. In other words, the render step is discarded. It is the user's responsability to hide or show a scene. An active scene is always shown when becoming active.

See also
gf::SceneManager

Constructor & Destructor Documentation

◆ Scene()

gf::Scene::Scene ( Vector2i  initialSize)

Constructor.

At construction, a scene is paused, hidden and inactive.

Parameters
initialSizeThe initial screen size
See also
gf::ViewContainer::setInitialScreenSize()

◆ ~Scene()

virtual gf::Scene::~Scene ( )
virtual

Destructor.

Member Function Documentation

◆ addAction()

void gf::Scene::addAction ( Action action)
inline

Add an action to the scene.

Parameters
actionThe action

◆ addHudEntity()

void gf::Scene::addHudEntity ( Entity entity)
inline

Add a HUD entity to the scene.

Parameters
entityThe entity

◆ addModel()

void gf::Scene::addModel ( Model model)
inline

Add a model to the scene.

Parameters
modelThe model

◆ addView()

void gf::Scene::addView ( AdaptativeView view)
inline

Add a view to the scene.

Parameters
viewA custom view

◆ addWorldEntity()

void gf::Scene::addWorldEntity ( Entity entity)
inline

Add a world entity to the scene.

Parameters
entityThe entity

◆ doHandleActions()

virtual void gf::Scene::doHandleActions ( Window window)
protectedvirtual

Customization point for handleActions()

◆ doHide()

virtual void gf::Scene::doHide ( )
protectedvirtual

Customization point for hide()

◆ doPause()

virtual void gf::Scene::doPause ( )
protectedvirtual

Customization point for pause()

◆ doProcessEvent()

virtual void gf::Scene::doProcessEvent ( Event event)
protectedvirtual

Customization point for processEvent()

◆ doRender()

virtual void gf::Scene::doRender ( RenderTarget target)
protectedvirtual

Customization point for render()

◆ doResume()

virtual void gf::Scene::doResume ( )
protectedvirtual

Customization point for resume()

◆ doShow()

virtual void gf::Scene::doShow ( )
protectedvirtual

Customization point for show()

◆ doUpdate()

virtual void gf::Scene::doUpdate ( Time  time)
protectedvirtual

Customization point for update()

◆ getWorldView()

View& gf::Scene::getWorldView ( )
inlineprotected

Get the world view.

◆ handleActions()

void gf::Scene::handleActions ( Window window)

Handle actions.

This function must be customized with doHandleActions() in order to handle the actions that have been updated with the event processing.

At the end of this function, all the actions are resetted.

Parameters
windowThe current window
See also
gf::ActionContainer::reset()

◆ hide()

void gf::Scene::hide ( )

Hide the scene.

When a scene is hidden, the entities are not rendered.

See also
show(), isHidden()

◆ isActive()

bool gf::Scene::isActive ( ) const

Check if the scene is active.

Returns
True if the scene is active, and false otherwise
See also
setActive()

◆ isHidden()

bool gf::Scene::isHidden ( ) const

Check if the scene is hidden.

Returns
True if the scene is hidden
See also
hide(), show()

◆ isPaused()

bool gf::Scene::isPaused ( ) const

Check if the scene is paused.

Returns
True if the scene is paused, and false otherwise
See also
pause(), resume()

◆ pause()

void gf::Scene::pause ( )

Pause the scene.

When a scene is paused, the entities are not updated.

See also
resume(), isPaused()

◆ processEvent()

void gf::Scene::processEvent ( Event event)

Process an event.

All the registered views and actions are updated with the event.

This function can be customized with doProcessEvent() that is called after all other event processing.

Parameters
eventThe event
See also
gf::ActionContainer::processEvent(), gf::ViewContainer::processEvent()

◆ render()

void gf::Scene::render ( RenderTarget target)

Render the scene.

This function render all the entities of the scene, if the scene is not hidden. It can be customized with doRender().

By default, it first renders the world entities (with a gf::ExtendView) through a call to renderWorldEntities() and then it renders the HUD entities (with a gf::ScreenView) through a call to renderHudEntities().

Parameters
targetThe target to render the scene
See also
gf::EntityContainer::render()

◆ renderHudEntities()

void gf::Scene::renderHudEntities ( RenderTarget target)
protected

Render the HUD entities.

◆ renderWorldEntities()

void gf::Scene::renderWorldEntities ( RenderTarget target)
protected

Render the world entities.

◆ resume()

void gf::Scene::resume ( )

Resume the scene.

See also
pause(), isPaused()

◆ setActive()

void gf::Scene::setActive ( bool  active = true)

Change the active state of the scene.

Parameters
activeThe new state of the scene
See also
isActive()

◆ setWorldViewCenter()

void gf::Scene::setWorldViewCenter ( Vector2f  center)

Set the center of the world view.

Parameters
centerThe new center

◆ setWorldViewSize()

void gf::Scene::setWorldViewSize ( Vector2f  size)

Set the size of the world view.

Parameters
sizeThe new size

◆ show()

void gf::Scene::show ( )

Show the scene.

See also
hide(), isHidden()

◆ update()

void gf::Scene::update ( Time  time)

Update the scene.

This function updates all the models and entities of the scene, if the scene is not paused. It can be customized with doUpdate() that is called after all other updates.

Parameters
timeThe time since the last frame
See also
gf::ModelContainer::update(), gf::EntityContainer::update()