NAP
Public Types | Public Member Functions | Public Attributes | List of all members
Scene Class Reference

#include <scene.h>

Public Types

using EntityByIDMap = std::unordered_map< std::string, std::unique_ptr< EntityInstance > >
 
using EntityIterator = utility::UniquePtrMapWrapper< EntityByIDMap, EntityInstance * >
 
using RootEntityList = std::vector< RootEntity >
 
using InstanceByIDMap = std::unordered_map< std::string, rtti::Object * >
 
using SortedComponentInstanceList = std::vector< ComponentInstance * >
 
using SpawnedComponentInstanceMap = std::unordered_map< EntityInstance *, SortedComponentInstanceList >
 

Public Member Functions

 Scene (Core &core)
 
virtual ~Scene () override
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual void onDestroy () override
 
void update (double deltaTime)
 
SpawnedEntityInstance spawn (const Entity &entity, utility::ErrorState &errorState)
 
SpawnedEntityInstance spawn (const Entity &entity, const std::vector< ComponentInstanceProperties > &instanceProperties, utility::ErrorState &errorState)
 
void destroy (SpawnedEntityInstance &entity)
 
void updateTransforms (double deltaTime)
 
EntityIterator getEntities ()
 
const rtti::ObjectPtr< EntityInstancefindEntity (const std::string &inID) const
 
const EntityInstancegetRootEntity () const
 
EntityInstancegetRootEntity ()
 
RootEntityList getEntityResources ()
 
RootEntityListgetEntityResourcesRef ()
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

RootEntityList mEntities
 List of root entities owned by the Scene. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Container for entities. The Scene is responsible for instantiation and management of all contained entities.

Inheritance diagram for Scene:
[legend]
Collaboration diagram for Scene:
[legend]

Member Typedef Documentation

◆ EntityByIDMap

using EntityByIDMap = std::unordered_map<std::string, std::unique_ptr<EntityInstance> >

◆ EntityIterator

◆ InstanceByIDMap

using InstanceByIDMap = std::unordered_map<std::string, rtti::Object*>

◆ RootEntityList

using RootEntityList = std::vector<RootEntity>

◆ SortedComponentInstanceList

◆ SpawnedComponentInstanceMap

Constructor & Destructor Documentation

◆ Scene()

Scene ( Core core)

◆ ~Scene()

virtual ~Scene ( )
overridevirtual

Member Function Documentation

◆ destroy()

void destroy ( SpawnedEntityInstance entity)

Destroys a spawned Entity hierarchy. The entity must have been obtained by the spawn() function.

Parameters
entitythe Entity to destroy.

◆ findEntity()

const rtti::ObjectPtr<EntityInstance> findEntity ( const std::string &  inID) const

Locate an entity in this scene with the given unique id. Note that the given id needs to match the id of an entity resource, not instance.

Example:

// Fetch world and text
auto world_entity = scene->findEntity("World");
auto laser_entity = scene->findEntity("Laser");
Parameters
inIDthe unique id of the entity to find.
Returns
EntityInstance with the specified unique identifier from this scene.

◆ getEntities()

EntityIterator getEntities ( )
Returns
Iterator to all entity instances in this scene.

◆ getEntityResources()

RootEntityList getEntityResources ( )
Returns
The RootEntity resources in the scene.

◆ getEntityResourcesRef()

RootEntityList& getEntityResourcesRef ( )
Returns
The RootEntity resources in the scene as a reference.

◆ getRootEntity() [1/2]

EntityInstance& getRootEntity ( )
Returns
The root EntityInstance of this scene

◆ getRootEntity() [2/2]

const EntityInstance& getRootEntity ( ) const
Returns
The root EntityInstance of this scene

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initialize the scene. Will spawn all entities contained in this scene. As soon as this is called, EntityInstances will become available and are accessible through getRootEntity() and getEntities()

Reimplemented from Object.

◆ onDestroy()

virtual void onDestroy ( )
overridevirtual

Destroy the scene. Will call onDestroy for all ComponentInstances and EntityInstances in the scene.

Reimplemented from Object.

◆ spawn() [1/2]

SpawnedEntityInstance spawn ( const Entity entity,
const std::vector< ComponentInstanceProperties > &  instanceProperties,
utility::ErrorState errorState 
)

Spawns an entity hierarchy. The Entity (hierarchy) can be destroyed by calling destroy with the value returned from this function.

Parameters
entityentity resource to spawn.
instancePropertiesinstance properties to apply to the entity's properties
errorStatecontains error information if the returned object is nullptr.
Returns
The EntityInstance that was spawned on success, nullptr otherwise.

◆ spawn() [2/2]

SpawnedEntityInstance spawn ( const Entity entity,
utility::ErrorState errorState 
)

Spawns an entity hierarchy. The Entity (hierarchy) can be destroyed by calling destroy with the value returned from this function.

Parameters
entityentity resource to spawn.
errorStatecontains error information if the returned object is nullptr.
Returns
The EntityInstance that was spawned on success, nullptr otherwise.

◆ update()

void update ( double  deltaTime)

Update all entities contained in this scene

Parameters
deltaTimetime in seconds between calls.

◆ updateTransforms()

void updateTransforms ( double  deltaTime)

Update the transform hierarchy of the entities contained in this scene. For any TransformComponent the world transform is updated.

Parameters
deltaTimetime in seconds in between calls.

Member Data Documentation

◆ mEntities

RootEntityList mEntities

List of root entities owned by the Scene.