FYP  1.0.0
Final Year Project -- Alexander Meuer
SceneManager Class Reference

Singleton class to handle scenes and the navigation between them. More...

#include <SceneManager.hpp>

Collaboration diagram for SceneManager:
Collaboration graph

Public Member Functions

std::string getCurrentScene ()
 
template<class SceneType >
void createScene (std::string const &name, std::string const &xmlPath, bool goToScene=true)
 
void updateCurrentScene (sf::Time const &elapsedTime)
 
void drawCurrentScene (sf::RenderWindow &w)
 
bool passEventToCurrentScene (sf::Event &theEvent)
 
void navigateToScene (std::string const &path)
 
void stopTranslatingMouse ()
 Stops translating mouse until the scene is changed. Be default, the manager translates mouse posititions from screen coordinates to game coordinates.
 
void showDialogueBox (gui::DialogueBox *dialogueBox)
 

Static Public Member Functions

static std::unique_ptr< SceneManager > const & instance ()
 
static void destruct ()
 Destroys the instance.
 

Private Member Functions

void handleSceneRequests ()
 Waits to be notified about a pending scene change, then does cleanup and assignment.
 
void processAddRequest (detail::SceneRequest const &request)
 Adds a scene to the map.
 
void processNavigateRequest (detail::SceneRequest const &request)
 Transitions to a scene.
 
void processDialogueRequest (detail::SceneRequest const &request)
 Show a dialog box on top of the current scene.
 

Private Attributes

std::map< std::string, std::unique_ptr< SceneProxy > > mScenes
 
bool mTranslateMouseEvents
 True if we should translate mouse positions from screen to game.
 
gui::DialogueBoxmActiveDialogue
 
std::string mCurrentSceneName
 The current scenes map key.
 
SceneProxymCurrentScene
 
std::atomic_bool mStopRequestThread
 Must be set to true before we try and join switcher thread.
 
std::thread mRequestThread
 
std::mutex mSceneMutex
 Locked whenever we need to do something involving the current scene.
 
std::mutex mRequestMutex
 Locked whenever we need to access the request queue.
 
std::condition_variable mRequestPending
 Notified whenever a request is pushed onto the queue.
 
std::queue< detail::SceneRequestmRequests
 Queue of pending requests.
 

Static Private Attributes

static std::unique_ptr< SceneManagermInstance
 

Detailed Description

Singleton class to handle scenes and the navigation between them.

Member Function Documentation

template<class SceneType >
void SceneManager::createScene ( std::string const &  name,
std::string const &  xmlPath,
bool  goToScene = true 
)

Adds a scene to the map under the specified name.

Parameters
nameThe name of the scene (its key in the map)
derivedSceneObjectThe scene to be added.
goToSceneTrue if the new scene should become the current scene (i.e. navigated to immediately)
void SceneManager::drawCurrentScene ( sf::RenderWindow &  w)

Calls the current scene's draw method

std::string SceneManager::getCurrentScene ( )

Gets the name of the current scene (its key in the map of scenes)

Returns
The name of the current scene.
void SceneManager::navigateToScene ( std::string const &  path)

Sets the current scene to be path.

Parameters
pathThe name of the scene to be navigated to.
Returns
True if the path matched an existing scene.
bool SceneManager::passEventToCurrentScene ( sf::Event &  theEvent)

Calls handleEvent on the current scene, passing theEvent.

Parameters
theEventThe event that will be passes to the current scene.
Returns
True if the event has been processed and no further processing of this event is required. (i.e. event is used up)
void SceneManager::updateCurrentScene ( sf::Time const &  elapsedTime)

Calls the current scene's update method.

Member Data Documentation

std::thread SceneManager::mRequestThread
private

Thread for handling scene requests.

See also
handleSceneRequests()
std::map<std::string, std::unique_ptr<SceneProxy> > SceneManager::mScenes
private

A map of all scenes managed by the SceneManager. Each scene is identified by its name.


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