Ocean
Ocean::SceneDescription::Manager Class Reference

This class implements the manager for all scene descriptions. More...

Inheritance diagram for Ocean::SceneDescription::Manager:

Public Types

typedef std::vector< std::string > LibraryNames
 Definition of a vector holding library names. More...
 
- Public Types inherited from Ocean::IO::FileManager
typedef std::map< std::string, std::string > FileExtensions
 Definition of a map mapping supported file extensions to file type descriptions. More...
 

Public Member Functions

SceneRef load (const std::string &filename, const Rendering::EngineRef &engine, const Timestamp &timestamp, const DescriptionType preferredDescriptionType=TYPE_PERMANENT, float *progress=nullptr, bool *cancel=nullptr)
 Loads a new scene and creates a scene description hierarchy. More...
 
bool unload (const SceneId sceneId)
 Unloads a given permanent scene description objects. More...
 
void unloadScenes ()
 Unloads all permanent scene description objects. More...
 
LibraryNames libraries ()
 Returns a list of all registered libraries. More...
 
FileExtensions supportedExtensions ()
 Returns all currently supported file extensions. More...
 
bool handlesMouseEvents () const
 Returns whether currently at least one scene description node handles mouse events. More...
 
void mouseEvent (const ButtonType button, const ButtonEvent buttonEvent, const Vector2 &screenPosition, const Vector3 &objectPosition, const Rendering::ObjectId objectId, const Timestamp timestamp)
 Sends a mouse event to be handled by the scene description. More...
 
void keyEvent (const int key, const ButtonEvent buttonEvent, const Rendering::ObjectId objectId, const Timestamp timestamp)
 Sends a key event to be handled by the scene description. More...
 
Timestamp preUpdate (const Rendering::ViewRef &view, const Timestamp timestamp)
 Pre-updates all scene description objects needing regularly pre updates. More...
 
Timestamp preUpdate (const std::string &library, const Rendering::ViewRef &view, const Timestamp timestamp)
 Pre-updates all scene description objects of a specified library only. More...
 
void update (const Rendering::ViewRef &view, const Timestamp timestamp)
 Updates all scene description objects needing regularly updates. More...
 
void update (const std::string &library, const Rendering::ViewRef &view, const Timestamp timestamp)
 Updates all scene description objects of a specified library only. More...
 
NodeRef node (const std::string &name) const
 Returns the node reference of the first available scene description node with a specified name. More...
 
NodeRef node (const std::string &library, const std::string &name) const
 Returns the node reference of the first available scene description node with a specified name defined inside a specific library. More...
 
NodeRefs nodes (const std::string &name) const
 Returns all node references of all available scene description nodes with a specified name. More...
 
NodeRefs nodes (const std::string &library, const std::string &name) const
 Returns all node references of all available scene description nodes with a specified name defined inside a specific library. More...
 
void release ()
 Releases all scene library. More...
 
template<typename T >
bool registerLibrary (const std::string &name)
 Registers a new library. More...
 
bool unregisterLibrary (const std::string &name)
 Unregisters a library. More...
 
- Public Member Functions inherited from Ocean::IO::FileManager
virtual bool isSupported (const std::string &extension)
 Returns whether a specified file extension is supported. More...
 

Protected Types

typedef std::pair< LibraryRef, unsigned int > LibraryCounterPair
 Definition of a pair combining a library with a reference counter. More...
 
typedef std::vector< LibraryCounterPairLibraries
 Definition of a vector holding library pairs. More...
 
typedef std::unordered_set< std::string > NameSet
 Definition of a set holding library names. More...
 
typedef std::unordered_map< NodeId, SDXEventNode * > EventNodes
 Definition of a map mapping scene description node ids to event nodes. More...
 
typedef std::unordered_map< NodeId, SDXUpdateNode * > UpdateNodes
 Definition of a map mapping scene description node ids to update nodes. More...
 
typedef std::map< SceneId, SDXSceneRefPermanentSceneMap
 Definition of a set holding permanent scene description objects. More...
 

Protected Member Functions

 Manager ()
 Creates a new manager. More...
 
virtual ~Manager ()
 Destructs a manager. More...
 
void registerEventNode (SDXEventNode &node)
 Registers a new event node. More...
 
void unregisterEventNode (SDXEventNode &node)
 Unregisters an event node. More...
 
void registerUpdateNode (SDXUpdateNode &node)
 Registers a new update node. More...
 
void unregisterUpdateNode (SDXUpdateNode &node)
 Unregisters an update node. More...
 
- Protected Member Functions inherited from Ocean::IO::FileManager
 FileManager ()
 Creates a new file manager object. More...
 
virtual ~FileManager ()
 Destructs a file manager object. More...
 
- Protected Member Functions inherited from Ocean::Singleton< Manager >
 Singleton ()=default
 Default constructor. More...
 

Protected Attributes

Libraries libraries_
 The vector holding all registered scene description libraries. More...
 
PermanentSceneMap permanentSceneMap_
 Map holding all permanent scene description objects. More...
 
EventNodes eventNodes_
 Map holding all event nodes. More...
 
UpdateNodes updateNodes_
 Map holding all update nodes. More...
 
Lock managerLock_
 Manager lock. More...
 
Lock libraryLock_
 Library lock. More...
 

Friends

class Singleton< Manager >
 
class Library
 
class SDXEventNode
 
class SDXUpdateNode
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Singleton< Manager >
static Manager & get ()
 Returns a reference to the unique object. More...
 

Detailed Description

This class implements the manager for all scene descriptions.

The manager encapsulates all registered scene description libraries.
Use the load() function to load a new scene description object.

Example demonstrating the manager usage:

// This example shows how to use the load() function and how to determine which type of scene description has been returned
// Get the rendering engine from e.g. the application
Rendering::EngineRef renderingEngine = application.getRenderingEngine();
ocean_assert(renderingEngine);
// Get the rendering framebuffer from e.g. the application
Rendering::FramebufferRef renderingFramebuffer = application.getRenderingFramebuffer();
ocean_assert(renderingFramebuffer);
// Load a scene description file - a permanent scene description is preferred
SceneRef scene = Manager::get().load("scenefile.x3dv", renderingEngine, SceneDescription::TYPE_PERMANENT);
if (scene)
{
if (scene->descriptionType() == SceneDescription::TYPE_PERMANENT)
{
SDXSceneRef sdxScene(scene);
ocean_assert(sdxScene);
// The rendering scene object of the permanent scene description object can be added to the used rendering framebuffer directly
renderingFramebuffer->addScene(sdxScene->renderingScene());
}
else
{
ocean_assert(scene->descriptionType() == SceneDescription::TYPE_TRANSIENT);
SDLSceneRef sdlScene(scene);
ocean_assert(sdlScene);
// We have a transient scene description object, thus we have to apply the description to the rendering engine explicitly
Rendering::SceneRef renderingScene = sdlScene->apply(renderingEngine);
// If the created rendering scene object is valid is can be added to the used rendering framebuffer
if (renderingScene)
renderingFramebuffer->addScene(renderingScene);
}
}
else
{
// The scene could not be loaded, e.g. the file did not exist, or an error occurred.
Log::error() << "The scene description file could not be loaded.";
}
static MessageObject error()
Returns the message for error messages.
Definition: Messenger.h:1074
static Manager & get()
Returns a reference to the unique object.
Definition: Singleton.h:115
Ocean::ObjectRef< Engine > EngineRef
Definition of an engine reference object.
Definition: Engine.h:24
SmartObjectRef< Scene > SceneRef
Definition of a smart object reference holding a scene node.
Definition: rendering/Scene.h:22
SmartObjectRef< Framebuffer > FramebufferRef
Definition of a smart object reference holding a framebuffer.
Definition: rendering/Framebuffer.h:31
SmartObjectRef< SDXScene, Node > SDXSceneRef
Definition of a smart object reference for scene desciption X scenes.
Definition: SDXScene.h:22
SmartObjectRef< SDLScene, Node > SDLSceneRef
Definition of a smart object reference for scene desciption loader scenes.
Definition: SDLScene.h:22
SmartObjectRef< Scene, Node > SceneRef
Definition of a smart object reference for scene desciption scenes.
Definition: scenedescription/Scene.h:21
@ TYPE_TRANSIENT
A scene description holding a transient scene hierarchy only.
Definition: SceneDescription.h:66
@ TYPE_PERMANENT
A scene description holding a permanent scene hierarchy allowing permanent access.
Definition: SceneDescription.h:68

Member Typedef Documentation

◆ EventNodes

typedef std::unordered_map<NodeId, SDXEventNode*> Ocean::SceneDescription::Manager::EventNodes
protected

Definition of a map mapping scene description node ids to event nodes.

◆ Libraries

Definition of a vector holding library pairs.

◆ LibraryCounterPair

typedef std::pair<LibraryRef, unsigned int> Ocean::SceneDescription::Manager::LibraryCounterPair
protected

Definition of a pair combining a library with a reference counter.

◆ LibraryNames

typedef std::vector<std::string> Ocean::SceneDescription::Manager::LibraryNames

Definition of a vector holding library names.

◆ NameSet

typedef std::unordered_set<std::string> Ocean::SceneDescription::Manager::NameSet
protected

Definition of a set holding library names.

◆ PermanentSceneMap

Definition of a set holding permanent scene description objects.

◆ UpdateNodes

typedef std::unordered_map<NodeId, SDXUpdateNode*> Ocean::SceneDescription::Manager::UpdateNodes
protected

Definition of a map mapping scene description node ids to update nodes.

Constructor & Destructor Documentation

◆ Manager()

Ocean::SceneDescription::Manager::Manager ( )
protected

Creates a new manager.

◆ ~Manager()

virtual Ocean::SceneDescription::Manager::~Manager ( )
protectedvirtual

Destructs a manager.

Member Function Documentation

◆ handlesMouseEvents()

bool Ocean::SceneDescription::Manager::handlesMouseEvents ( ) const
inline

Returns whether currently at least one scene description node handles mouse events.

The state change with every new frame.
Because mouse events can produce high computational overhead this test can safe computational time.

Returns
True, if so

◆ keyEvent()

void Ocean::SceneDescription::Manager::keyEvent ( const int  key,
const ButtonEvent  buttonEvent,
const Rendering::ObjectId  objectId,
const Timestamp  timestamp 
)

Sends a key event to be handled by the scene description.

Parameters
keyThe key type
buttonEventType of the event
objectIdId of a rendering object associated with the event
timestampEvent timestamp

◆ libraries()

LibraryNames Ocean::SceneDescription::Manager::libraries ( )

Returns a list of all registered libraries.

Returns
Registered libraries

◆ load()

SceneRef Ocean::SceneDescription::Manager::load ( const std::string &  filename,
const Rendering::EngineRef engine,
const Timestamp timestamp,
const DescriptionType  preferredDescriptionType = TYPE_PERMANENT,
float *  progress = nullptr,
bool *  cancel = nullptr 
)

Loads a new scene and creates a scene description hierarchy.

Two different scene description types are available.
First: A transient scene description creates a scene and object hierarchy and must be applied to a rendering engine afterwards explicitly.
After that all scene description objects are not needed anymore and can be disposed.

Second: a permanent scene description creates a scene and object hierarchy and directly creates corresponding rendering engine objects.
Therefore, all rendering objects exist as long as the corresponding scene description object exist.
The scene description object allows for easy scene manipulation without knowledge of the underling rendering structure.
This manager will hold a copy of all permanent scene description objects as long as they are unloaded explicitly.

Beware: Check the type of returned scene description object.
Depending on the available scene description libraries the description type may vary.
To not hold a reference of the returned object longer than necessary!

Parameters
filenameThe filename of the scene to load
engineRendering engine to be connected with the scene description, must be defined for permanent scene description objects only
timestampThe current timestamp, must be valid
preferredDescriptionTypePreferred description type of the scene to load
progressThe progress state receiving recurrently information about the load state with range [0, 1]
cancelThe cancel state allows the cancellation of a load process while loading process hasn't finished, if the cancel state is used the load process stops if the value is set to True
Returns
Resulting scene
See also
unload().

◆ mouseEvent()

void Ocean::SceneDescription::Manager::mouseEvent ( const ButtonType  button,
const ButtonEvent  buttonEvent,
const Vector2 screenPosition,
const Vector3 objectPosition,
const Rendering::ObjectId  objectId,
const Timestamp  timestamp 
)

Sends a mouse event to be handled by the scene description.

Parameters
buttonThe button type
buttonEventType of the event
screenPositionScreen device position
objectPositionObject position
objectIdId of a rendering object associated with the event
timestampEvent timestamp

◆ node() [1/2]

NodeRef Ocean::SceneDescription::Manager::node ( const std::string &  library,
const std::string &  name 
) const

Returns the node reference of the first available scene description node with a specified name defined inside a specific library.

Parameters
libraryThe library to be searched
nameThe name of the node to return
Returns
Node reference of the node, the reference will be empty if the node does not exist

◆ node() [2/2]

NodeRef Ocean::SceneDescription::Manager::node ( const std::string &  name) const

Returns the node reference of the first available scene description node with a specified name.

This function searches in all libraries and all description types.

Parameters
nameThe name of the node to return
Returns
Node reference of the node, the reference will be empty if the node does not exist

◆ nodes() [1/2]

NodeRefs Ocean::SceneDescription::Manager::nodes ( const std::string &  library,
const std::string &  name 
) const

Returns all node references of all available scene description nodes with a specified name defined inside a specific library.

Parameters
libraryThe library to be searched
nameThe name of the nodes to return
Returns
All node references found

◆ nodes() [2/2]

NodeRefs Ocean::SceneDescription::Manager::nodes ( const std::string &  name) const

Returns all node references of all available scene description nodes with a specified name.

This function searches in all libraries and all description types.

Parameters
nameThe name of the nodes to return
Returns
All node references found

◆ preUpdate() [1/2]

Timestamp Ocean::SceneDescription::Manager::preUpdate ( const Rendering::ViewRef view,
const Timestamp  timestamp 
)

Pre-updates all scene description objects needing regularly pre updates.

Parameters
viewRendering view to be used for rendering
timestampPreferred update timestamp
Returns
Actually used update timestamp

◆ preUpdate() [2/2]

Timestamp Ocean::SceneDescription::Manager::preUpdate ( const std::string &  library,
const Rendering::ViewRef view,
const Timestamp  timestamp 
)

Pre-updates all scene description objects of a specified library only.

Parameters
libraryName of the library
viewRendering view to be used for rendering
timestampPreferred Update timestamp
Returns
Actually used update timestamp

◆ registerEventNode()

void Ocean::SceneDescription::Manager::registerEventNode ( SDXEventNode node)
protected

Registers a new event node.

Parameters
nodeEvent node to register

◆ registerLibrary()

template<typename T >
bool Ocean::SceneDescription::Manager::registerLibrary ( const std::string &  name)

Registers a new library.

With each register call, the reference counter for a specific library will be incremented. Each call to registerLibrary() needs to be balanced with a corresponding call of unregisterLibrary() before shutting down.

Parameters
nameThe name of the library to register, must be valid
Returns
True, if the library has not been registered before
Template Parameters
TThe data type of the library to register
See also
unregisterLibrary().

◆ registerUpdateNode()

void Ocean::SceneDescription::Manager::registerUpdateNode ( SDXUpdateNode node)
protected

Registers a new update node.

Parameters
nodeUpdate node to register

◆ release()

void Ocean::SceneDescription::Manager::release ( )

Releases all scene library.

◆ supportedExtensions()

FileExtensions Ocean::SceneDescription::Manager::supportedExtensions ( )
virtual

Returns all currently supported file extensions.

See also
FileManager::supportedFormats().

Implements Ocean::IO::FileManager.

◆ unload()

bool Ocean::SceneDescription::Manager::unload ( const SceneId  sceneId)

Unloads a given permanent scene description objects.

Transient description objects must not be unloaded because the manager does not hold a copy of transient scene objects.
Beware: At the moment the scene is unloaded there should not be any other resource holding a reference to this object!

Parameters
sceneIdScene id of the permanent scene description object to be unloaded
Returns
True, if succeeded
See also
load().

◆ unloadScenes()

void Ocean::SceneDescription::Manager::unloadScenes ( )

Unloads all permanent scene description objects.

◆ unregisterEventNode()

void Ocean::SceneDescription::Manager::unregisterEventNode ( SDXEventNode node)
protected

Unregisters an event node.

Parameters
nodeEvent node to unregister

◆ unregisterLibrary()

bool Ocean::SceneDescription::Manager::unregisterLibrary ( const std::string &  name)

Unregisters a library.

With each unregister call, the reference counter for a specific library will be decremented and removed from the system if the counter reaches zero. Each call to registerLibrary() needs to be balanced with a corresponding call of unregisterLibrary() before shutting down.

Parameters
nameThe name of the library to unregister, must be valid
Returns
True, if the library was actually removed from the system (as the reference counter reached zero); False, if the library is still used by someone else
See also
registerLibrary().

◆ unregisterUpdateNode()

void Ocean::SceneDescription::Manager::unregisterUpdateNode ( SDXUpdateNode node)
protected

Unregisters an update node.

Parameters
nodeUpdate node to unregister

◆ update() [1/2]

void Ocean::SceneDescription::Manager::update ( const Rendering::ViewRef view,
const Timestamp  timestamp 
)

Updates all scene description objects needing regularly updates.

Parameters
viewRendering view to be used for rendering
timestampUpdate timestamp

◆ update() [2/2]

void Ocean::SceneDescription::Manager::update ( const std::string &  library,
const Rendering::ViewRef view,
const Timestamp  timestamp 
)

Updates all scene description objects of a specified library only.

Parameters
libraryName of the library
viewRendering view to be used for rendering
timestampUpdate timestamp

Friends And Related Function Documentation

◆ Library

friend class Library
friend

◆ SDXEventNode

friend class SDXEventNode
friend

◆ SDXUpdateNode

friend class SDXUpdateNode
friend

◆ Singleton< Manager >

friend class Singleton< Manager >
friend

Field Documentation

◆ eventNodes_

EventNodes Ocean::SceneDescription::Manager::eventNodes_
protected

Map holding all event nodes.

◆ libraries_

Libraries Ocean::SceneDescription::Manager::libraries_
protected

The vector holding all registered scene description libraries.

◆ libraryLock_

Lock Ocean::SceneDescription::Manager::libraryLock_
protected

Library lock.

◆ managerLock_

Lock Ocean::SceneDescription::Manager::managerLock_
mutableprotected

Manager lock.

◆ permanentSceneMap_

PermanentSceneMap Ocean::SceneDescription::Manager::permanentSceneMap_
protected

Map holding all permanent scene description objects.

◆ updateNodes_

UpdateNodes Ocean::SceneDescription::Manager::updateNodes_
protected

Map holding all update nodes.


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