Tramway SDK
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
tram::Entity Class Referenceabstract

Entity base class. More...

#include <framework/entity.h>

Inheritance diagram for tram::Entity:
tram::Crate tram::Decoration tram::Ext::Kitchensink::Breakable tram::Ext::Kitchensink::Button tram::Ext::Kitchensink::DebugShape tram::Ext::Kitchensink::DebugText tram::Ext::Kitchensink::Pickup tram::Ext::Kitchensink::QuestEntity tram::Ext::Kitchensink::Train tram::Ext::Kitchensink::TriggerAutosave tram::Ext::Kitchensink::TriggerHurt tram::Ext::Kitchensink::TriggerMultiple tram::Ext::Kitchensink::TriggerOnce tram::Ext::Kitchensink::TriggerPlayerMovement tram::Ext::Kitchensink::TriggerPush tram::Ext::Kitchensink::TriggerRemove tram::Ext::Kitchensink::TriggerTeleport tram::Ext::Kitchensink::Water tram::Light tram::Marker tram::Player tram::Sound tram::StaticWorldObject tram::Trigger

Classes

struct  FieldInfo
 

Public Types

enum  : uint32_t { FIELD_SERIALIZE = 1 }
 

Public Member Functions

virtual void Load ()=0
 Loads an entity. More...
 
virtual void Unload ()=0
 Unloads an entity. More...
 
virtual void Serialize ()=0
 
 Entity ()
 Creates an unnamed entity with a random ID. More...
 
 Entity (name_t name)
 Creates a named entity with a random ID. More...
 
 Entity (const SharedEntityData &)
 Creates an entity from a SharedEntityData. More...
 
virtual ~Entity ()
 Destructs the entity. More...
 
name_t GetName () const
 
id_t GetID () const
 
WorldCellGetCell ()
 Returns the entity's parent cell. More...
 
bool IsLoaded () const
 Returns the entity load status. More...
 
bool IsAutoLoad () const
 Returns the auto load flag status. More...
 
bool IsPersistent () const
 Returns the persistence status of an entity. More...
 
bool IsChanged () const
 
bool IsDeleted () const
 Returns the entity deletion status. More...
 
bool IsLoadedFromDisk () const
 
virtual void UpdateParameters ()=0
 Called when Entity::UpdateTransform is called. More...
 
virtual void SetParameters ()=0
 Called when either Entity::SetLocation or Entity::SetRotation is called. More...
 
void Yeet ()
 Purges the entity. More...
 
void SetAutoLoad (bool is)
 
void SetPersistent (bool is)
 
void SetLocation (vec3 loc)
 
void SetRotation (quat rot)
 
void UpdateTransform (const vec3 &loc, const quat &rot)
 
const vec3GetLocation ()
 
const quatGetRotation ()
 
virtual void MessageHandler (Message &msg)=0
 Allows entities to receive messages. More...
 
virtual void EventHandler (Event &event)
 Allows entities to receive events. More...
 
virtual name_t GetType ()=0
 Returns the type of the entity. More...
 
void CheckTransition ()
 Check whether an entity has entered a different cell. More...
 
SignalTableGetSignalTable ()
 

Static Public Member Functions

static void Update ()
 Updates entities. More...
 
static void RegisterType (name_t name, entity_make, entity_clear, const Type *fields, size_t fieldcount)
 Registers a new entity type. More...
 
static void RegisterType (name_t name, entity_make, entity_clear, const FieldInfo *fields, size_t fieldcount)
 Registers a new entity type. More...
 
static void RegisterType (name_t name, entity_make, entity_clear, std::initializer_list< FieldInfo > fields)
 Registers a new entity type. More...
 
static EntityMake (name_t type, File *file)
 Loads an Entity from a File. More...
 
static EntityMake (name_t type, const SharedEntityData &, const ValueArray &)
 Creates an entity. More...
 
static EntityFind (id_t entity_id)
 Finds the entity by its ID number. More...
 
static EntityFind (name_t entity_name)
 Finds the entity by its name. More...
 

Protected Types

enum  : uint32_t {
  NON_PERSISTENT = 1 , LOADED = 2 , DISABLE_AUTO_LOAD = 4 , NON_SERIALIZABLE = 8 ,
  DIRTY = 16 , DELETED = 32 , LOADED_FROM_DISK = 64
}
 

Protected Member Functions

void Register ()
 Registers the entity. More...
 
void Unregister ()
 Unregisters the entity. More...
 
void FireSignal (signal_t type)
 
void FireSignal (signal_t type, Value value)
 
void SetFlag (uint32_t flag, bool value)
 

Protected Attributes

id_t id = 0
 
name_t name
 
WorldCellcell = nullptr
 
SignalTablesignals = nullptr
 
quat rotation = {1.0f, 0.0f, 0.0f, 0.0f}
 
vec3 location = {0.0f, 0.0f, 0.0f}
 
uint32_t flags = 0
 

Friends

class WorldCell
 

Detailed Description

Entity base class.

Provides API for entities and some basic functionality.

See also
https://racenis.github.io/tram-sdk/documentation/framework/entity.html

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : uint32_t
Enumerator
FIELD_SERIALIZE 

◆ anonymous enum

anonymous enum : uint32_t
protected
Enumerator
NON_PERSISTENT 
LOADED 
DISABLE_AUTO_LOAD 
NON_SERIALIZABLE 
DIRTY 
DELETED 
LOADED_FROM_DISK 

Constructor & Destructor Documentation

◆ Entity() [1/3]

tram::Entity::Entity ( )

Creates an unnamed entity with a random ID.

◆ Entity() [2/3]

tram::Entity::Entity ( name_t  name)

Creates a named entity with a random ID.

◆ Entity() [3/3]

tram::Entity::Entity ( const SharedEntityData shared_data)

Creates an entity from a SharedEntityData.

◆ ~Entity()

tram::Entity::~Entity ( )
virtual

Destructs the entity.

This automatically also removes the entity from its parent cell, and also unregisters it.

Member Function Documentation

◆ CheckTransition()

void tram::Entity::CheckTransition ( )

Check whether an entity has entered a different cell.

◆ EventHandler()

void tram::Entity::EventHandler ( Event event)
inlinevirtual

Allows entities to receive events.

Whenever an entity registers an event, an event of the same type as the event listener is posted and Event::Dispatch() has been called, the entity will receive the event through this method.

Reimplemented in tram::Ext::Kitchensink::Button.

◆ Find() [1/2]

Entity * tram::Entity::Find ( id_t  entityID)
static

Finds the entity by its ID number.

Returns
If an entity with the given ID number has been found, a pointer to it will be returned. Otherwise a nullptr will be returned.

◆ Find() [2/2]

Entity * tram::Entity::Find ( name_t  entityName)
static

Finds the entity by its name.

Returns
If an entity with the given name has been found, a pointer to it will be returned. Otherwise a nullptr will be returned.

◆ FireSignal() [1/2]

void tram::Entity::FireSignal ( signal_t  type)
inlineprotected

◆ FireSignal() [2/2]

void tram::Entity::FireSignal ( signal_t  type,
Value  value 
)
inlineprotected

◆ GetCell()

WorldCell * tram::Entity::GetCell ( )
inline

Returns the entity's parent cell.

If an entity is inside a WorldCell, this method will return a pointer to it, otherwise it will return a nullptr.

◆ GetID()

id_t tram::Entity::GetID ( ) const
inline

◆ GetLocation()

const vec3 & tram::Entity::GetLocation ( )
inline

◆ GetName()

name_t tram::Entity::GetName ( ) const
inline

◆ GetRotation()

const quat & tram::Entity::GetRotation ( )
inline

◆ GetSignalTable()

SignalTable * tram::Entity::GetSignalTable ( )
inline

◆ GetType()

void tram::Entity::GetType ( )
pure virtual

Returns the type of the entity.

Usually this method returns the same name that is used to Entity::RegisterType() its type.

Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, and tram::Ext::Kitchensink::QuestEntity.

◆ IsAutoLoad()

WorldCell * tram::Entity::IsAutoLoad ( ) const
inline

Returns the auto load flag status.

By default all entities are automatically loaded, i.e. when the WorldCell in which they reside is loaded. Sometimes you might want to override this, so the automatic loading disablement flag is provided.

◆ IsChanged()

bool tram::Entity::IsChanged ( ) const
inline

◆ IsDeleted()

WorldCell * tram::Entity::IsDeleted ( ) const
inline

Returns the entity deletion status.

When an entity is yeeted, it is marked as deleted. They continue existing for some time until the Entity::Update() static method is called and they are destructed.

Even then, entities that have been loaded from the disk will continue existing, so that their status as being deleted can be written back to disk.

This also allows to ressurect them, if the need arises.

◆ IsLoaded()

WorldCell * tram::Entity::IsLoaded ( ) const
inline

Returns the entity load status.

◆ IsLoadedFromDisk()

bool tram::Entity::IsLoadedFromDisk ( ) const
inline

◆ IsPersistent()

WorldCell * tram::Entity::IsPersistent ( ) const
inline

Returns the persistence status of an entity.

Entities that have been marked as non-persistent will be yeeted when their parent cell is unloaded, instead of the usual unloading.

This is useful when creating small decoration entities, e.g. debris and giblets, which don't need to be saved.

◆ Load()

void tram::Entity::Load ( )
pure virtual

◆ Make() [1/2]

Entity * tram::Entity::Make ( name_t  type,
const SharedEntityData shared_data,
const ValueArray field_array 
)
static

Creates an entity.

Uses data provided in a Entity::RegisterType() call to find the construction function of an entity type and then constructs it.

Parameters
typeType of the entity, this should be the same name that was used when using Register() to register an entity type.
shared_dataShared data of the entity.
field_arrayValues to be filled in the entity's fields.
Returns
Pointer to an entity if successful, otherwise a nullptr.

◆ Make() [2/2]

Entity * tram::Entity::Make ( name_t  type,
File file 
)
static

Loads an Entity from a File.

◆ MessageHandler()

void tram::Entity::MessageHandler ( Message msg)
pure virtual

◆ Register()

void tram::Entity::Register ( )
protected

Registers the entity.

Inserts the entity into the entity ID list, so that it can be found using the Entity::Find(id_t) static method. If the entity has a name, then it is also inserted into the name list, so that it can be found using the Entity::Find(name_t) static method.

◆ RegisterType() [1/3]

void tram::Entity::RegisterType ( name_t  name,
entity_make  constr_func,
entity_clear  destr_func,
const FieldInfo fields,
size_t  fieldcount 
)
static

Registers a new entity type.

Parameters
nameName of the entity, should be the same as what its GetType() method returns.
constr_funcThis function will be called when a new entity of this type is requested, e.g. when deserializing a worldcell file.
destr_funcThis function will be called when an entity of this type is yeeted.
fieldsPointer to an array of serialization fields.
fieldcountSize of the fields array.

◆ RegisterType() [2/3]

void tram::Entity::RegisterType ( name_t  name,
entity_make  constr_func,
entity_clear  destr_func,
const Type fields,
size_t  fieldcount 
)
static

Registers a new entity type.

Deprecated:
Use other RegisterType() methods instead.

◆ RegisterType() [3/3]

void tram::Entity::RegisterType ( name_t  name,
entity_make  constr_func,
entity_clear  destr_func,
std::initializer_list< FieldInfo fields 
)
static

Registers a new entity type.

Same as the other RegisterType() method, but uses an initializer list instead of an array. They are functionally identical, use whichever you like.

◆ Serialize()

virtual void tram::Entity::Serialize ( )
pure virtual

◆ SetAutoLoad()

void tram::Entity::SetAutoLoad ( bool  is)
inline

◆ SetFlag()

void tram::Entity::SetFlag ( uint32_t  flag,
bool  value 
)
inlineprotected

◆ SetLocation()

void tram::Entity::SetLocation ( vec3  loc)
inline

◆ SetParameters()

void tram::Entity::SetParameters ( )
pure virtual

◆ SetPersistent()

void tram::Entity::SetPersistent ( bool  is)
inline

◆ SetRotation()

void tram::Entity::SetRotation ( quat  rot)
inline

◆ Unload()

void tram::Entity::Unload ( )
pure virtual

◆ Unregister()

void tram::Entity::Unregister ( )
protected

Unregisters the entity.

Essentially, this is the reversal of what the Entity::Register() method has done. This method will remove the entity from the ID list and from the name list, if it has a name. It will no longer be possible to find the entity by using the Entity::Find() method and its overloads.

◆ Update()

void tram::Entity::Update ( )
static

Updates entities.

Should be called once per update cycle. This method will go through the list of all yeeted entities and will destruct the ones that need to be destructed.

◆ UpdateParameters()

void tram::Entity::UpdateParameters ( )
pure virtual

◆ UpdateTransform()

void tram::Entity::UpdateTransform ( const vec3 loc,
const quat rot 
)
inline

◆ Yeet()

void tram::Entity::Yeet ( )

Purges the entity.

The entity will be flagged as deleted, unloaded, unregistered and then it will be held in internment until Entity::Update() is called and then, if needed, it will also be destructed.

Friends And Related Function Documentation

◆ WorldCell

friend class WorldCell
friend

Member Data Documentation

◆ cell

WorldCell* tram::Entity::cell = nullptr
protected

◆ flags

uint32_t tram::Entity::flags = 0
protected

◆ id

id_t tram::Entity::id = 0
protected

◆ location

vec3 tram::Entity::location = {0.0f, 0.0f, 0.0f}
protected

◆ name

name_t tram::Entity::name
protected

◆ rotation

quat tram::Entity::rotation = {1.0f, 0.0f, 0.0f, 0.0f}
protected

◆ signals

SignalTable* tram::Entity::signals = nullptr
protected

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