Gorgon Game Engine
SceneManager Class Reference

This class is a Window that manages scenes, allowing swapping, handling input and game loop. More...

Inheritance diagram for SceneManager:
[legend]

Public Member Functions

 SceneManager ()
 
 SceneManager (SceneManager &&)=default
 
 ~SceneManager ()
 
void ActivateKeyboard ()
 Moves keyboard input event to the top if there is a layer that accepts keyboard input. More...
 
void Assume (Scene &scene)
 Assumes the ownership of the the given scene, adding it to the list of scenes. More...
 
auto begin ()
 Returns iterator to the first scene. More...
 
auto begin () const
 Returns iterator to the first scene. More...
 
void Deactivate ()
 Deactivates all scenes. More...
 
void DeleteScene (SceneID scene)
 Deletes the given scene, nothing is done if the scene is not found. More...
 
auto end ()
 Returns iterator to the end of scenes. More...
 
auto end () const
 Returns iterator to the end of scenes. More...
 
SceneGetScene (SceneID scene)
 Returns the requested scene. More...
 
int GetSceneCount () const
 Returns the number of scenes registered. More...
 
template<class S_ , class ... P_>
S_ & NewScene (SceneID id, P_ &&... params)
 Creates a new scene using the given type and parameters. More...
 
SceneManageroperator= (SceneManager &&)=default
 
void Quit () override
 Quits the scene manager, returning the execution to the point where Run function is called. More...
 
SceneRelease (SceneID id)
 Releases the ownership of the scene with the given ID, removing it from the manager. More...
 
void Run () override
 Runs the application by running the active scene, progressing OS events and rendering mechanism. More...
 
bool SceneExists (SceneID id) const
 Returns if the given scene exists. More...
 
void Step () override
 Steps the application by running the active scene, progressing OS events and rendering mechanism. More...
 
void SwitchScene (SceneID scene)
 Switches the current scene to the scene with the given id. More...
 
 Window ()
 Empty constructor creates a non-initialized window. More...
 
 Window (const FullscreenTag &, const WindowManager::Monitor &monitor, const std::string &name, const std::string &title="")
 Creates a fullscreen window. More...
 
 Window (const FullscreenTag &tag, const std::string &name, const std::string &title="")
 Creates a fullscreen window. More...
 
 Window (const Geometry::Size &size, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const char *name, const char *title, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const std::string &name, const std::string &title, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Window &)=delete
 Copy constructor is not allowed. More...
 
 Window (const WindowManager::Monitor &monitor, const Geometry::Size &size, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const WindowManager::Monitor &monitor, const Geometry::Size &size, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const WindowManager::Monitor &monitor, Geometry::Rectangle rect, const std::string &name, const std::string &title, bool allowresize, bool visible)
 
 Window (Geometry::Rectangle rect, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window. More...
 
 Window (Geometry::Rectangle rect, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window. More...
 
 Window (Window &&other)
 Move constructor. More...
 
- Public Member Functions inherited from Window
 Window ()
 Empty constructor creates a non-initialized window. More...
 
 Window (const FullscreenTag &, const WindowManager::Monitor &monitor, const std::string &name, const std::string &title="")
 Creates a fullscreen window. More...
 
 Window (const FullscreenTag &tag, const std::string &name, const std::string &title="")
 Creates a fullscreen window. More...
 
 Window (const Geometry::Size &size, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const char *name, const char *title, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Geometry::Size &size, const std::string &name, const std::string &title, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const Window &)=delete
 Copy constructor is not allowed. More...
 
 Window (const WindowManager::Monitor &monitor, const Geometry::Size &size, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (const WindowManager::Monitor &monitor, const Geometry::Size &size, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window at the center of the screen. More...
 
 Window (Geometry::Rectangle rect, const char *name, bool allowresize=false, bool visible=true)
 Creates a new window. More...
 
 Window (Geometry::Rectangle rect, const std::string &name, bool allowresize=false, bool visible=true)
 Creates a new window. More...
 
 Window (Window &&other)
 Move constructor. More...
 
 ~Window ()
 Destroys this window. More...
 
void activatecontext ()
 Activates the GL context of the window. More...
 
void AllowResize ()
 Allows window to be resized by the user. More...
 
void Center ()
 Centers the window to the default monitor. More...
 
void Center (const WindowManager::Monitor &monitor)
 Centers the window to the given monitor. More...
 
void Close ()
 Closes the window. After this function, any use of this object might fail. More...
 
void Destroy ()
 Destroys this window. More...
 
void Focus ()
 Focuses this window. More...
 
Geometry::Bounds GetExteriorBounds () const
 Returns the exterior bounding box of the window. More...
 
const WindowManager::MonitorGetMonitor () const
 Returns the monitor that the window is currently on. More...
 
Geometry::Point GetMouseLocation () const
 Returns the mouse location on the window. More...
 
std::string GetName () const
 Returns the name of the window that is set at creation time. More...
 
Geometry::Point GetPosition () const
 Returns the current position of the window. More...
 
std::string GetTitle () const
 Returns the current title of the window. More...
 
virtual void Hide () override
 Hides this window, may generate Deactivated event. More...
 
void HidePointer ()
 Hides the pointer. More...
 
bool IsClosed () const
 Whether the window is currently closed and cannot be acted on. More...
 
bool IsFocused () const
 Returns if this window has the focus. More...
 
bool IsLeftButtonPressed () const
 Query whether the left mouse button is pressed. More...
 
bool IsLocalPointer () const
 Returns whether the current pointer is a local pointer. More...
 
bool IsMaximized () const
 Returns if the window is maximized. More...
 
bool IsMiddleButtonPressed () const
 Query whether the middle mouse button is pressed. More...
 
bool IsMinimized () const
 Returns if the window is minimized. More...
 
bool IsPointerVisible () const
 Returns whether the pointer is visible. More...
 
bool IsRightButtonPressed () const
 Query whether the right mouse button is pressed. More...
 
virtual bool IsVisible () const override
 Returns whether this layer is effectively visible. More...
 
bool IsX1ButtonPressed () const
 Query whether the X1 mouse button is pressed. More...
 
bool IsX2ButtonPressed () const
 Query whether the X2 mouse button is pressed. More...
 
void Maximize ()
 Maximizes the window to cover the usable area of the screen. More...
 
void Minimize ()
 Minimizes the window. More...
 
void mouse_down (Geometry::Point location, Input::Mouse::Button button)
 These functions are used internally. More...
 
void mouse_event (Input::Mouse::EventType event, Geometry::Point location, Input::Mouse::Button button, float amount)
 These functions are used internally. More...
 
void mouse_location ()
 These functions are used internally. More...
 
void mouse_up (Geometry::Point location, Input::Mouse::Button button)
 These functions are used internally. More...
 
virtual void Move (const Geometry::Point &position) override
 Moves the window to the given position. More...
 
virtual void Move (int x, int y) override
 Moves the window to the given position. More...
 
Windowoperator= (Window &&other)
 Moves another window into this one. More...
 
Input::Mouse::Button PressedButtons () const
 Returns currently pressed buttons. More...
 
void PreventResize ()
 Prevents window to be resized by the user. More...
 
void processmessages ()
 This method is automatically called by the system.Unless its necessary, do not use it. More...
 
virtual void Render () override
 Renders the contents of the window. More...
 
virtual void Resize (const Geometry::Size &size) override
 Resizes the window to the given size. More...
 
virtual void Resize (int width, int height) override
 Resizes the window to the given size. More...
 
void Restore ()
 Restores a minimized or maximized window. More...
 
void SetIcon (const WindowManager::Icon &icon)
 Changes the icon of the window. More...
 
void SetTitle (const std::string &title)
 Changes the title of the window to the specified string. More...
 
virtual void Show () override
 Displays this window, may generate Activated event. More...
 
void ShowPointer ()
 Displays the pointer. More...
 
void Swap (Window &other)
 Used for move semantics. More...
 
void SwitchToLocalPointers ()
 Removes the operating system pointer and starts using Locally defined pointers. More...
 
void SwitchToWMPointers ()
 Stops showing local pointers and makes window manager pointer visible. More...
 
- Public Member Functions inherited from Layer
 Layer ()
 Constructor that sets the layer to cover entire parent, no matter how big it is. More...
 
 Layer (const Geometry::Bounds &bounds)
 Initializing constructor. More...
 
 Layer (const Geometry::Point &location)
 Constructor that places the layer to the given location. More...
 
 Layer (const Layer &)=delete
 Copy constructor is disabled. More...
 
 Layer (Layer &&other)
 Move constructor. More...
 
virtual ~Layer ()
 Destructor. More...
 
Layeroperator= (const Layer &)=delete
 Copy assignment is deleted. More...
 
Layeroperator= (Layer &&other)
 Move assignment. More...
 
virtual bool propagate_mouseevent (Input::Mouse::EventType evet, Geometry::Point location, Input::Mouse::Button button, float amount, MouseHandler &handlers)
 Propagates a mouse event. More...
 
void Swap (Layer &other)
 Swaps two layers, mostly used for move semantics. More...
 
void Add (Layer &layer)
 Adds the given layer as a child. More...
 
void Add (Layer *layer)
 Adds the given layer as a child. More...
 
void setname (std::string value)
 For debugging. More...
 
void Insert (Layer &layer, long under)
 Inserts the given layer before the given index. More...
 
void Insert (Layer *layer, long under)
 Inserts the given layer before the given index. More...
 
void Remove (Layer &layer)
 Removes the given layer. More...
 
void Remove (Layer *layer)
 Removes the given layer. More...
 
bool HasParent () const
 Returns whether this layer has a parent. More...
 
virtual LayerGetParent () const
 Returns the parent of this layer. More...
 
LayerGetTopLevel () const
 Returns the top level layer that contains this layer. More...
 
virtual Geometry::Point TranslateToTopLevel (Geometry::Point location={0, 0}) const
 Translates the given location to the top level. More...
 
LayerGetTopLevel ()
 
Containers::Collection< Layer >::ConstIterator begin () const
 An iterator pointing to the start of the children. More...
 
Containers::Collection< Layer >::ConstIterator end () const
 An iterator pointing to the end of the children. More...
 
Containers::Collection< Layer >::ConstIterator First () const
 An iterator pointing to the start of the children. More...
 
Containers::Collection< Layer >::ConstIterator Last () const
 An iterator pointing to the last item of the children. More...
 
void PlaceBefore (int before)
 Places this layer before the given index. More...
 
void PlaceToTop ()
 Places this layer to the top of the layer stack its in. More...
 
void PlaceToBottom ()
 Places this layer to the bottom of the layer stack. More...
 
int GetOrder () const
 Gets the current order of the stack. More...
 
void SetWidth (int width)
 Resizes the layer to the given size. More...
 
void SetHeight (int height)
 Resizes the layer to the given size. More...
 
void SetBounds (const Geometry::Bounds &bounds)
 Sets the boundaries of this layer. More...
 
Geometry::Size GetSize () const
 Returns the size of the layer. More...
 
Geometry::Size GetCalculatedSize () const
 Returns the size of the layer. More...
 
int GetWidth () const
 Returns the width of the layer. More...
 
int GetHeight () const
 Returns the height of the layer. More...
 
Geometry::Point GetLocation () const
 Returns the current location of the layer. More...
 
int GetLeft () const
 Returns the current location of the layer. More...
 
int GetTop () const
 Returns the current location of the layer. More...
 
Geometry::Bounds GetBounds () const
 Returns the boundaries of the layer. More...
 
Geometry::Bounds GetEffectiveBounds () const
 Returns the effective boundaries of the layer. More...
 

Public Attributes

Gorgon::Event< SceneManager, Scene & > ActivatedEvent
 This event will be fired whenever a scene is activated. More...
 
- Public Attributes inherited from Window
Graphics::PointerStack Pointers
 Pointer system to be used within the window. More...
 
Event< WindowFocusedEvent
 Called when this window is focused. More...
 
Event< WindowLostFocusEvent
 Called when this window is deactivated. More...
 
Event< WindowDestroyedEvent
 Called when this window is destroyed. More...
 
Event< Window, bool & > ClosingEvent
 Called when user tries to close the window. More...
 
Event< WindowMovedEvent
 Called after the window is moved, either by the user or programmatically. More...
 
Event< WindowResizedEvent
 Called after the window is resized, either by the user or programmatically. More...
 
Event< WindowMinimizedEvent
 Called after the window is minimized, either by the user or programmatically. More...
 
Event< WindowRestoredEvent
 Called after the window is restored from minimized state, either by the user or programmatically. More...
 
ConsumableEvent< Window, Input::Key, float > KeyEvent
 Called when a key is pressed or released. More...
 
ConsumableEvent< Window, Input::Keyboard::CharCharacterEvent
 Called when a character is received. More...
 
- Public Attributes inherited from Layer
const Containers::Collection< Layer > & Children
 Sub-layers that this layer holds, all the sub-layers are considered to be above current layer. More...
 

Protected Member Functions

decltype(KeyEvent) ::Token init ()
 
- Protected Member Functions inherited from Window
 Window (const WindowManager::Monitor &monitor, Geometry::Rectangle rect, const std::string &name, const std::string &title, bool allowresize, bool visible)
 
virtual void added (Layer &layer) override
 Will be called when a layer is added. More...
 
void deleting (Layer *layer)
 
virtual void located (Layer *) override
 A window cannot be placed in another layer. This function always fails. More...
 
- Protected Member Functions inherited from Layer
void dotransformandclip (bool inverse=false)
 Performs transformation and clipping. Use inverse for reverse mapping for mouse events. More...
 
virtual void removed (Layer &layer)
 Will be called when a layer is removed. More...
 
void reverttransformandclip ()
 Reverts previously done transformation. More...
 

Protected Attributes

Sceneactive
 
decltype(KeyEvent) ::Token inputtoken
 
bool quiting
 
Gorgon::Containers::Hashmap< SceneID, Scenescenes
 
- Protected Attributes inherited from Layer
Geometry::Bounds bounds
 Bounds of this layer. More...
 
Containers::Collection< Layerchildren
 Child layers that this layer holds, all child layers are considered to be above current layer. More...
 
bool isvisible
 Whether this layer is visible, invisible layers will not be drawn or receive any events. More...
 
std::string name
 For debugging. More...
 
Layerparent
 Parent layer, could be nullptr. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static Geometry::Size GetMinimumRequiredSize ()
 Returns the minimum size required to fit any window inside. More...
 
- Static Public Attributes inherited from Window
static const struct Gorgon::Window::FullscreenTag Fullscreen
 
static const Containers::Collection< Window > & Windows
 List of currently created windows. More...
 
- Static Public Attributes inherited from Layer
static const Geometry::Bounds EntireRegion
 When used as layer bounds, represents the entire region its placed in. More...
 

Detailed Description

This class is a Window that manages scenes, allowing swapping, handling input and game loop.

This runner is most suitable for games where there would be multiple scenes (intro, how to play, game, pause screen, etc...) that compete with each other for input and rendering.

Constructor & Destructor Documentation

◆ SceneManager() [1/2]

◆ SceneManager() [2/2]

SceneManager ( SceneManager &&  )
default

◆ ~SceneManager()

Member Function Documentation

◆ ActivateKeyboard()

void ActivateKeyboard ( )

Moves keyboard input event to the top if there is a layer that accepts keyboard input.

References SceneManager::active, SceneManager::inputtoken, Window::KeyEvent, and Scene::RequiresKeyInput().

◆ Assume()

void Assume ( Scene scene)

Assumes the ownership of the the given scene, adding it to the list of scenes.

References Scene::id, Scene::parent, and SceneManager::scenes.

◆ begin() [1/2]

auto begin ( )

Returns iterator to the first scene.

References SceneManager::scenes.

◆ begin() [2/2]

auto begin ( ) const

Returns iterator to the first scene.

References SceneManager::scenes.

◆ Deactivate()

void Deactivate ( )

Deactivates all scenes.

References SceneManager::active, SceneManager::inputtoken, and Window::KeyEvent.

◆ DeleteScene()

void DeleteScene ( SceneID  scene)

Deletes the given scene, nothing is done if the scene is not found.

References SceneManager::scenes.

◆ end() [1/2]

auto end ( )

Returns iterator to the end of scenes.

References SceneManager::scenes.

◆ end() [2/2]

auto end ( ) const

Returns iterator to the end of scenes.

References SceneManager::scenes.

◆ GetScene()

Scene& GetScene ( SceneID  scene)

Returns the requested scene.

If it does not exist, this function will throw runtime error.

References SceneManager::scenes.

◆ GetSceneCount()

int GetSceneCount ( ) const

Returns the number of scenes registered.

References SceneManager::scenes.

◆ init()

◆ NewScene()

S_& NewScene ( SceneID  id,
P_ &&...  params 
)

Creates a new scene using the given type and parameters.

Scene class should always take parent layer first, then id and then the other parameters if they exists. When using this function, only specify the class as template parameter, the others will be resolved. If a scene with the same id exists, it will be deleted. It is advisable to add new scenes at the start without activating any scene.

enum SceneIDs {
SCENE_MENU,
SCENE_GAME
};
//...
class GameScene : public Scene {
public:
GameScene(Gorgon::SceneManager &parent, SceneID id, int players);
//...
};
//...
//Create the game scene with a single player.
manager.NewScene<GameScene>(SCENE_GAME, 1);
manager.SwitchScene(SCENE_GAME);

References SceneManager::scenes.

◆ operator=()

SceneManager& operator= ( SceneManager &&  )
default

◆ Quit()

void Quit ( )
overridevirtual

Quits the scene manager, returning the execution to the point where Run function is called.

It allows current frame to be completed before quiting. It also deactives the current scene.

Implements Runner.

References SceneManager::quiting.

◆ Release()

Scene& Release ( SceneID  id)

Releases the ownership of the scene with the given ID, removing it from the manager.

Using scene while it does not have parent might cause problems.

References SceneManager::scenes.

◆ Run()

void Run ( )
overridevirtual

Runs the application by running the active scene, progressing OS events and rendering mechanism.

This function will run until Quit is called.

Implements Runner.

References SceneManager::active, Gorgon::Time::DeltaTime(), Scene::doframe(), Gorgon::NextFrame(), SceneManager::quiting, Scene::render(), and SceneManager::SwitchScene().

◆ SceneExists()

bool SceneExists ( SceneID  id) const

Returns if the given scene exists.

References SceneManager::scenes.

◆ Step()

void Step ( )
overridevirtual

Steps the application by running the active scene, progressing OS events and rendering mechanism.

Implements Runner.

References SceneManager::active, Gorgon::Time::DeltaTime(), Scene::doframe(), Gorgon::NextFrame(), and Scene::render().

◆ SwitchScene()

void SwitchScene ( SceneID  scene)

Switches the current scene to the scene with the given id.

Will throw std::runtime_error if scene is not found. If given id is NoSceneID, all scenes will be deactivated.

References SceneManager::ActivatedEvent, SceneManager::active, SceneManager::Deactivate(), Scene::GetID(), SceneManager::inputtoken, Window::KeyEvent, Scene::RequiresKeyInput(), and SceneManager::scenes.

◆ Window() [1/14]

Empty constructor creates a non-initialized window.

This constructor is there support move semantics. Any action on non-initialized window may result in a crash.

◆ Window() [2/14]

Creates a fullscreen window.

Fullscreen windows do not have chrome and covers entire screen, including any panels it contains.

◆ Window() [3/14]

Creates a fullscreen window.

Fullscreen windows do not have chrome and covers entire screen, including any panels it contains.

◆ Window() [4/14]

Creates a new window at the center of the screen.

Parameters
sizeof the window
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [5/14]

Creates a new window at the center of the screen.

Parameters
sizeof the window
nameof the window
titleof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [6/14]

Creates a new window at the center of the screen.

Parameters
sizeof the window
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [7/14]

Creates a new window at the center of the screen.

Parameters
sizeof the window
nameof the window
titleof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [8/14]

Window
delete

Copy constructor is not allowed.

◆ Window() [9/14]

Creates a new window at the center of the screen.

Parameters
monitorthat the window will be centered on
sizeof the window
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [10/14]

Creates a new window at the center of the screen.

Parameters
monitorthat the window will be centered on
sizeof the window
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [11/14]

◆ Window() [12/14]

Creates a new window.

Parameters
rectthe position and the interior size of the window unless use outer metrics is set to true
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [13/14]

Creates a new window.

Parameters
rectthe position and the interior size of the window unless use outer metrics is set to true
nameof the window
visibleafter creation, window will be visible or invisible depending on this value.

◆ Window() [14/14]

Move constructor.

References Window::Swap().

Member Data Documentation

◆ ActivatedEvent

Gorgon::Event<SceneManager, Scene&> ActivatedEvent

This event will be fired whenever a scene is activated.

◆ active

Scene* active
protected

◆ inputtoken

decltype(KeyEvent) ::Token inputtoken
protected

◆ quiting

bool quiting
protected

◆ scenes


The documentation for this class was generated from the following file:
Gorgon::Layer::parent
Layer * parent
Parent layer, could be nullptr.
Definition: Layer.h:504
Gorgon::SceneManager
This class is a Window that manages scenes, allowing swapping, handling input and game loop.
Definition: Scene.h:163
Gorgon::SceneID
int SceneID
Can be used to identify scenes.
Definition: Scene.h:45