Class OfflineRealtimeEngine
Defined in File OfflineRealtimeEngine.h
Inheritance Relationships
Base Type
public csp::common::IRealtimeEngine
(Class IRealtimeEngine)
Class Documentation
-
class OfflineRealtimeEngine : public csp::common::IRealtimeEngine
Class for creating and managing objects in an offline context.
This provides functionality to create and manage a player avatar and other objects while being offline. The callbacks that are injected into functions are all synchronous, meaning they are called before the funciton ends.
Public Types
-
typedef std::function<void(SpaceEntity*)> EntityCreatedCallback
Public Functions
-
OfflineRealtimeEngine(const CSPSceneDescription &SceneDescription, csp::common::LogSystem &LogSystem, csp::common::IJSScriptRunner &RemoteScriptRunner)
OfflineRealtimeEngine constructor.
Creates a realtime engine pre-populated from a scene description. (Usually parsed from a checkpoint file)
- Parameters
SceneDescription – CSPSceneDescription : The scene description containing entities within the scene. These entities will be populated in the RealtimeEngine.
LogSystem – csp::common::LogSystem : Logger such that this system can print status and debug output
RemoteScriptRunner – csp::common::IJSScriptRunner& : Object capable of running a script.
-
OfflineRealtimeEngine(csp::common::LogSystem &LogSystem, csp::common::IJSScriptRunner &RemoteScriptRunner)
OfflineRealtimeEngine constructor Creates an empty realtime engine.
- Parameters
LogSystem – csp::common::LogSystem : Logger such that this system can print status and debug output
RemoteScriptRunner – csp::common::IJSScriptRunner& : Object capable of running a script.
-
~OfflineRealtimeEngine()
OfflineRealtimeEngine destructor Removes entity script bindings and deregisters tick event listeners.
-
virtual csp::common::RealtimeEngineType GetRealtimeEngineType() const override
Returns the concrete type of the instantiation of the abstract IRealtimeEngine.
-
virtual void CreateAvatar(const csp::common::String &Name, const csp::common::String &UserId, const csp::multiplayer::SpaceTransform &Transform, bool IsVisible, csp::multiplayer::AvatarState State, const csp::common::String &AvatarId, csp::multiplayer::AvatarPlayMode AvatarPlayMode, csp::multiplayer::EntityCreatedCallback Callback) override
Create and add a SpaceEntity with type Avatar, and relevant components and default states as specified.
- Parameters
Name – csp::common::String : The entity name of the newly created avatar entity.
UserId – csp::common::String : The Id of the user creating the avatar. This can be fetched from csp::systems::UserSystem::GetLoginState
Transform – csp::multiplayer::SpaceTransform : The initial transform to set the SpaceEntity to.
State – csp::multiplayer::AvatarState : The initial Avatar State to set.
AvatarId – csp::common::String : The ID to be set on the AvatarSpaceComponent
AvatarPlayMode – csp::multiplayer::AvatarPlayMode : The Initial AvatarPlayMode to set.
Callback – csp::multiplayer::EntityCreatedCallback A callback that executes when the creation is complete, which will provide a non-owning pointer to the new SpaceEntity so that it can be used on the local client.
-
virtual void CreateEntity(const csp::common::String &Name, const csp::multiplayer::SpaceTransform &Transform, const csp::common::Optional<uint64_t> &ParentID, csp::multiplayer::EntityCreatedCallback Callback) override
Create and add a SpaceEntity, with relevant default values.
- Parameters
Name – csp::common::String : The name of the newly created SpaceEntity.
Transform – csp::multiplayer::SpaceTransform : The initial transform to set the SpaceEntity to.
ParentID – csp::common::Optional<int64_t> : ID of another entity in the space that this entity should be created as a child to. If empty, entity is created as a root entity.
Callback – csp::multiplayer::EntityCreatedCallback : A callback that executes when the creation is complete, which will provide a non-owning pointer to the new SpaceEntity so that it can be used on the local client.
-
virtual void DestroyEntity(csp::multiplayer::SpaceEntity *Entity, csp::multiplayer::CallbackHandler Callback) override
Destroy the specified entity.
- Parameters
Entity – csp::multiplayer::SpaceEntity : A non-owning pointer to the entity to be destroyed.
Callback – csp::multiplayer::CallbackHandler : A callback that executes when the entity destruction is complete.
-
virtual bool AddEntityToSelectedEntities(csp::multiplayer::SpaceEntity *Entity) override
Adds an entity to the set of selected entities.
- Parameters
Entity – csp::multiplayer::SpaceEntity* Entity to set as selected
- Returns
True if the entity was succesfully added, false if the entity already existed in the selection and thus could not be added.
-
virtual bool RemoveEntityFromSelectedEntities(csp::multiplayer::SpaceEntity *Entity) override
Removes an entity to the set of selected entities.
- Parameters
Entity – csp::multiplayer::SpaceEntity* Entity to set as selected
- Returns
True if the entity was succesfully removed, false if the entity did not exist in the selection and thus could not be removed.
-
virtual csp::multiplayer::SpaceEntity *FindSpaceEntity(const csp::common::String &Name) override
Finds the first found SpaceEntity of a matching Name.
- Parameters
Name – csp::common::String : The name to search.
- Returns
A non-owning pointer to the first found matching SpaceEntity.
-
virtual csp::multiplayer::SpaceEntity *FindSpaceEntityById(uint64_t EntityId) override
Finds the first found SpaceEntity that has the ID EntityId.
- Parameters
EntityId – uint64_t : The Id to look for.
- Returns
A non-owning pointer to the first found matching SpaceEntity.
-
virtual csp::multiplayer::SpaceEntity *FindSpaceAvatar(const csp::common::String &Name) override
Finds the first found SpaceEntity of a matching Name.
The found SpaceEntity will contain an AvatarSpaceComponent.
- Parameters
Name – The name to search for.
- Returns
A pointer to the first found matching SpaceEntity.
-
virtual csp::multiplayer::SpaceEntity *FindSpaceObject(const csp::common::String &Name) override
Finds the first found SpaceEntity of a matching Name.
The found SpaceEntity will not contain an AvatarSpaceComponent.
- Parameters
Name – The name to search for.
- Returns
A pointer to the first found matching SpaceEntity.
-
virtual csp::multiplayer::SpaceEntity *GetEntityByIndex(size_t EntityIndex) override
Get an Entity by its index.
- Parameters
EntityIndex – size_t : The index of the entity to get.
- Returns
A non-owning pointer to the entity at the given index.
-
virtual csp::multiplayer::SpaceEntity *GetAvatarByIndex(size_t AvatarIndex) override
Get an Avatar by its index.
The returned pointer will be an entity that contains an AvatarSpaceComponent.
- Parameters
AvatarIndex – size_t : The index of the avatar entity to get.
- Returns
A non-owning pointer to the avatar entity with the given index.
-
virtual csp::multiplayer::SpaceEntity *GetObjectByIndex(size_t ObjectIndex) override
Get an Object by its index.
The returned pointer will be an entity that does not contain an AvatarSpaceComponent.
- Parameters
ObjectIndex – size_t : The index of the object entity to get.
- Returns
A non-owning pointer to the object entity with the given index.
-
virtual size_t GetNumEntities() const override
Get the number of total entities in the system.
- Returns
The total number of entities.
-
virtual size_t GetNumAvatars() const override
Get the number of total Avatars in the system.
Avatars are entities that contain AvatarSpaceComponents.
- Returns
The total number of Avatar entities.
-
virtual size_t GetNumObjects() const override
Get the number of total Objects in the system.
Objects are entities that do not contain AvatarSpaceComponents.
- Returns
The total number of object entities.
-
virtual const csp::common::List<csp::multiplayer::SpaceEntity*> *GetAllEntities() const override
Return all the entities currently known to the realtime engine.
Warning
This list may be extremely large.
- Returns
A non-owning pointer to a List of non-owning pointers to all entities.
-
virtual const csp::common::List<csp::multiplayer::SpaceEntity*> *GetRootHierarchyEntities() const override
Retrieves all entities that exist at the root level (do not have a parent entity).
- Returns
A list of root entities containing non-owning pointers to entities.
-
virtual void ResolveEntityHierarchy(csp::multiplayer::SpaceEntity *Entity) override
“Resolves” the entity heirarchy for the given entity, setting all internal parent/child buffers correctly.
This method is called whenever parent/child relationships are changed for a given entity, including when one is first created.
- Parameters
Entity – csp::multiplayer::SpaceEntity* : The Entity to resolve
-
virtual void FetchAllEntitiesAndPopulateBuffers(const csp::common::String &SpaceId, csp::common::EntityFetchStartedCallback FetchStartedCallback) override
Fetch entities from our data source.
As the offline realtime engine constructs any pre-existing entities in the constructor, both csp::common::EntityFetchStartedCallback and csp::common::EntityFetchCompleteCallback are called immediately. Also initialises the script system.
- Parameters
SpaceId – const csp::common::String& : MCS formatted SpaceId
FetchStartedCallback – EntityFetchStartedCallback Callback called once scopes are reset and entity fetch has begun.
- Pre
Space represented by SpaceId must exist on the configured server endpoint. See csp::systems::SpaceSystem::CreateSpace
- Post
FetchStartedCallback and the csp::common::EntityFetchCompleteCallback passed in the constructor will be called .
-
virtual void LockEntityUpdate() override
Lock a mutex that guards against any changes to the entity list.
If the mutex is already locked, will wait until it is able to acquire the lock. May cause deadlocks.
-
virtual bool TryLockEntityUpdate() override
Lock a mutex that guards against any changes to the entity list.
- Returns
Whether the mutex successfully locked. The mutex will fail to lock if already locked in order to avoid deadlocks.
-
virtual void UnlockEntityUpdate() override
Unlock a mutex that guards against any changes to the entity list.
-
virtual csp::multiplayer::SpaceEntityStatePatcher *MakeStatePatcher(csp::multiplayer::SpaceEntity &SpaceEntity) const override
Creates the state patcher to use for space entities created with this engine Offline realtime engine syncronously sets data, rather than use a patch flow, so this returns null.
- Parameters
SpaceEntity – cs::multiplayer::SpaceEntity The SpaceEntity to create the patcher for.
- Returns
nullptr
-
std::recursive_mutex &GetEntitiesLock()
Public Static Functions
-
static uint64_t LocalClientId()
The client ID of the local client.
An arbitrary unchanging value.
- Returns
INT53_MAX, the maximum number expressible in all our interop languages (you can thank javascript for the weird sizing).
-
typedef std::function<void(SpaceEntity*)> EntityCreatedCallback