Rebel Fork Framework
Urho3D::Scene Class Reference

Root scene node, represents the whole scene. More...

#include <Urho3D/Scene/Scene.h>

Inheritance diagram for Urho3D::Scene:

Public Member Functions

 Scene (Context *context)
 Construct.
 
 ~Scene () override
 Destruct.
 
bool CreateComponentIndex (StringHash componentType)
 Create component index. Scene must be empty.
 
template<class T >
void CreateComponentIndex ()
 Create component index for template type. Scene must be empty.
 
const SceneComponentIndexGetComponentIndex (StringHash componentType)
 Return component index. Iterable. Invalidated when indexed component is added or removed!
 
template<class T >
const SceneComponentIndexGetComponentIndex ()
 Return component index for template type. Invalidated when indexed component is added or removed!
 
void SerializeInBlock (Archive &archive) override
 Serialize object. May throw ArchiveException.
 
void SerializeInBlock (Archive &archive, bool serializeTemporary, PrefabSaveFlags saveFlags, PrefabLoadFlags loadFlags)
 
bool Load (Deserializer &source) override
 Load from binary data. Removes all existing child nodes and components first. Return true if successful.
 
bool Save (Serializer &dest) const override
 Save to binary data. Return true if successful.
 
bool LoadXML (const XMLElement &source) override
 Load from XML data. Removes all existing child nodes and components first. Return true if successful.
 
bool LoadJSON (const JSONValue &source) override
 Load from JSON data. Removes all existing child nodes and components first. Return true if successful.
 
unsigned GetNumLightmaps () const
 Return number of lightmaps.
 
void ResetLightmaps ()
 Reset lightmaps.
 
void AddLightmap (const ea::string &lightmapTextureName)
 Add lightmap texture.
 
Texture2DGetLightmapTexture (unsigned index) const
 Return lightmap texture.
 
void SetUpdateEvents (const StringVector &events)
 Set update events.
 
const StringVectorGetUpdateEvents () const
 Return update events.
 
bool LoadXML (Deserializer &source)
 Load from an XML file. Return true if successful.
 
bool LoadJSON (Deserializer &source)
 Load from a JSON file. Return true if successful.
 
bool SaveXML (Serializer &dest, const ea::string &indentation="\t") const
 Save to an XML file. Return true if successful.
 
bool SaveJSON (Serializer &dest, const ea::string &indentation="\t") const
 Save to a JSON file. Return true if successful.
 
bool LoadAsync (AbstractFilePtr file, LoadMode mode=LOAD_SCENE_AND_RESOURCES)
 Load from a binary file asynchronously. Return true if started successfully. The LOAD_RESOURCES_ONLY mode can also be used to preload resources from object prefab files.
 
bool LoadAsyncXML (AbstractFilePtr file, LoadMode mode=LOAD_SCENE_AND_RESOURCES)
 Load from an XML file asynchronously. Return true if started successfully. The LOAD_RESOURCES_ONLY mode can also be used to preload resources from object prefab files.
 
bool LoadAsyncJSON (AbstractFilePtr file, LoadMode mode=LOAD_SCENE_AND_RESOURCES)
 Load from a JSON file asynchronously. Return true if started successfully. The LOAD_RESOURCES_ONLY mode can also be used to preload resources from object prefab files.
 
void StopAsyncLoading ()
 Stop asynchronous loading.
 
Node * Instantiate (Deserializer &source, const Vector3 &position, const Quaternion &rotation)
 Instantiate scene content from binary data. Return root node if successful.
 
Node * InstantiateXML (const XMLElement &source, const Vector3 &position, const Quaternion &rotation)
 Instantiate scene content from XML data. Return root node if successful.
 
Node * InstantiateXML (Deserializer &source, const Vector3 &position, const Quaternion &rotation)
 Instantiate scene content from XML data. Return root node if successful.
 
Node * InstantiateJSON (const JSONValue &source, const Vector3 &position, const Quaternion &rotation)
 Instantiate scene content from JSON data. Return root node if successful.
 
Node * InstantiateJSON (Deserializer &source, const Vector3 &position, const Quaternion &rotation)
 Instantiate scene content from JSON data. Return root node if successful.
 
void Clear ()
 Clear scene completely.
 
void SetUpdateEnabled (bool enable)
 
void SetTimeScale (float scale)
 
void SetElapsedTime (float time)
 
void SetAsyncLoadingMs (int ms)
 
void AddRequiredPackageFile (PackageFile *package)
 Add a required package file for networking. To be called on the server.
 
void ClearRequiredPackageFiles ()
 Clear required package files.
 
void SetFileName (const ea::string_view fileName)
 Set source file name.
 
bool IsEmpty (bool ignoreComponents=false) const
 Return whether the Scene is empty.
 
Node * GetNode (unsigned id) const
 Return node from the whole scene by ID, or null if not found.
 
ComponentGetComponent (unsigned id) const
 Return component from the whole scene by ID, or null if not found.
 
bool GetNodesWithTag (ea::vector< Node * > &dest, const ea::string &tag) const
 Get nodes with specific tag from the whole scene, return false if empty.
 
bool IsUpdateEnabled () const
 
bool IsAsyncLoading () const
 
float GetAsyncProgress () const
 
LoadMode GetAsyncLoadMode () const
 
const ea::string & GetFileName () const
 
unsigned GetChecksum () const
 
float GetTimeScale () const
 
float GetElapsedTime () const
 
int GetAsyncLoadingMs () const
 
const ea::vector< SharedPtr< PackageFile > > & GetRequiredPackageFiles () const
 
const ea::unordered_map< unsigned, Node * > & GetAllNodes () const
 Return all nodes parented by this Scene.
 
const ea::unordered_map< unsigned, Component * > & GetAllComponents () const
 Return all components parented by this Scene.
 
void Update (float timeStep)
 Update scene. Called by HandleUpdate.
 
void BeginThreadedUpdate ()
 Begin a threaded update. During threaded update components can choose to delay dirty processing.
 
void EndThreadedUpdate ()
 End a threaded update. Notify components that marked themselves for delayed dirty processing.
 
void DelayedMarkedDirty (Component *component)
 Add a component to the delayed dirty notify queue. Is thread-safe.
 
bool IsThreadedUpdate () const
 Return threaded update flag.
 
unsigned GetFreeNodeID ()
 Get free node ID.
 
unsigned GetFreeComponentID ()
 Get free component ID.
 
void NodeTagAdded (Node *node, const ea::string &tag)
 Cache node by tag if tag not zero, no checking if already added. Used internaly in Node::AddTag.
 
void NodeTagRemoved (Node *node, const ea::string &tag)
 Cache node by tag if tag not zero.
 
void NodeAdded (Node *node)
 Node added. Assign scene pointer and add to ID map.
 
void NodeRemoved (Node *node)
 Node removed. Remove from ID map.
 
void ComponentAdded (Component *component)
 Component added. Add to ID map.
 
void ComponentRemoved (Component *component)
 Component removed. Remove from ID map.
 

Static Public Member Functions

static void RegisterObject (Context *context)
 

Static Public Attributes

static const StringVector DefaultUpdateEvents
 Default Scene update events. More...
 

Private Member Functions

 URHO3D_OBJECT (Scene, Node)
 
void HandleUpdate (StringHash eventType, VariantMap &eventData)
 Handle the logic update event to update the scene, if active.
 
void HandleResourceBackgroundLoaded (StringHash eventType, VariantMap &eventData)
 Handle a background loaded resource completing.
 
void UpdateAsyncLoading ()
 Update asynchronous loading. More...
 
void FinishAsyncLoading ()
 Finish asynchronous loading.
 
void FinishLoading (Deserializer *source)
 Finish loading. Sets the scene filename and checksum.
 
void FinishSaving (Serializer *dest) const
 Finish saving. Sets the scene filename and checksum.
 
void PreloadResources (AbstractFilePtr file, bool isSceneFile)
 Preload resources from a binary scene or object prefab file.
 
void PreloadResourcesXML (const XMLElement &element)
 Preload resources from an XML scene or object prefab file.
 
void PreloadResourcesJSON (const JSONValue &value)
 Preload resources from a JSON scene or object prefab file.
 
SceneComponentIndexGetMutableComponentIndex (StringHash componentType)
 Return component index storage for given type.
 
void ReloadLightmaps ()
 Reload lightmap textures.
 

Private Attributes

ea::vector< StringHashindexedComponentTypes_
 Types of components that should be indexed.
 
ea::vector< SceneComponentIndexcomponentIndexes_
 Indexes of components.
 
ea::unordered_map< unsigned, Node * > replicatedNodes_
 Replicated scene nodes by ID.
 
ea::unordered_map< unsigned, Component * > replicatedComponents_
 Replicated components by ID.
 
ea::unordered_map< StringHash, ea::vector< Node * > > taggedNodes_
 Cached tagged nodes by tag.
 
AsyncProgress asyncProgress_
 Asynchronous loading progress.
 
SceneResolver resolver_
 Node and component ID resolver for asynchronous loading.
 
ea::string fileName_
 Source file name.
 
ea::vector< SharedPtr< PackageFile > > requiredPackageFiles_
 Required package files for networking.
 
ea::vector< Component * > delayedDirtyComponents_
 Delayed dirty notification queue for components.
 
Mutex sceneMutex_
 Mutex for the delayed dirty notification queue.
 
unsigned replicatedNodeID_
 Next free non-local node ID.
 
unsigned replicatedComponentID_
 Next free non-local component ID.
 
unsigned checksum_
 Scene source file checksum.
 
int asyncLoadingMs_
 Maximum milliseconds per frame to spend on async scene loading.
 
float timeScale_
 Scene update time scale.
 
float elapsedTime_
 Elapsed time accumulator.
 
bool updateEnabled_
 Update enabled flag.
 
bool asyncLoading_
 Asynchronous loading flag.
 
bool threadedUpdate_
 Threaded update flag.
 
ResourceRefList lightmaps_
 Lightmap textures names.
 
ea::vector< SharedPtr< Texture2D > > lightmapTextures_
 Loaded lightmap textures.
 
StringVector updateEvents_
 Update events to be sent on every update.
 
ea::vector< ea::pair< StringHash, bool > > cookedUpdateEvents_
 

Detailed Description

Root scene node, represents the whole scene.

Member Function Documentation

◆ GetAsyncLoadingMs()

int Urho3D::Scene::GetAsyncLoadingMs ( ) const
inline

Return maximum milliseconds per frame to spend on async loading.

◆ GetAsyncLoadMode()

LoadMode Urho3D::Scene::GetAsyncLoadMode ( ) const
inline

Return the load mode of the current asynchronous loading operation.

◆ GetAsyncProgress()

float Urho3D::Scene::GetAsyncProgress ( ) const

Return asynchronous loading progress between 0.0 and 1.0, or 1.0 if not in progress.

◆ GetChecksum()

unsigned Urho3D::Scene::GetChecksum ( ) const
inline

Return source file checksum.

◆ GetElapsedTime()

float Urho3D::Scene::GetElapsedTime ( ) const
inline

Return elapsed time in seconds.

◆ GetFileName()

const ea::string& Urho3D::Scene::GetFileName ( ) const
inline

Return source file name.

◆ GetRequiredPackageFiles()

const ea::vector<SharedPtr<PackageFile> >& Urho3D::Scene::GetRequiredPackageFiles ( ) const
inline

Return required package files.

◆ GetTimeScale()

float Urho3D::Scene::GetTimeScale ( ) const
inline

Return update time scale.

◆ IsAsyncLoading()

bool Urho3D::Scene::IsAsyncLoading ( ) const
inline

Return whether an asynchronous loading operation is in progress.

◆ IsUpdateEnabled()

bool Urho3D::Scene::IsUpdateEnabled ( ) const
inline

Return whether updates are enabled.

◆ RegisterObject()

void Urho3D::Scene::RegisterObject ( Context context)
static

Register object factory. Node must be registered first.

◆ SetAsyncLoadingMs()

void Urho3D::Scene::SetAsyncLoadingMs ( int  ms)

Set maximum milliseconds per frame to spend on async scene loading.

◆ SetElapsedTime()

void Urho3D::Scene::SetElapsedTime ( float  time)

Set elapsed time in seconds. This can be used to prevent inaccuracy in the timer if the scene runs for a long time.

◆ SetTimeScale()

void Urho3D::Scene::SetTimeScale ( float  scale)

Set update time scale. 1.0 = real time (default).

◆ SetUpdateEnabled()

void Urho3D::Scene::SetUpdateEnabled ( bool  enable)

Enable or disable scene update.

◆ UpdateAsyncLoading()

void Urho3D::Scene::UpdateAsyncLoading ( )
private

Update asynchronous loading.

Member Data Documentation

◆ DefaultUpdateEvents

const StringVector Urho3D::Scene::DefaultUpdateEvents
static
Initial value:
= {
"@SceneForcedUpdate",
"SceneUpdate",
"AttributeAnimationUpdate",
"SceneSubsystemUpdate",
"ScenePostUpdate",
"@SceneForcedPostUpdate",
}

Default Scene update events.


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