Entity base class.
More...
#include <framework/entity.h>
|
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 Entity * | Make (name_t type, File *file) |
| Loads an Entity from a File. More...
|
|
static Entity * | Make (name_t type, const SharedEntityData &, const ValueArray &) |
| Creates an entity. More...
|
|
static Entity * | Find (id_t entity_id) |
| Finds the entity by its ID number. More...
|
|
static Entity * | Find (name_t entity_name) |
| Finds the entity by its name. More...
|
|
Entity base class.
Provides API for entities and some basic functionality.
- See also
- https://racenis.github.io/tram-sdk/documentation/framework/entity.html
◆ 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 | |
◆ Entity() [1/3]
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]
◆ ~Entity()
tram::Entity::~Entity |
( |
| ) |
|
|
virtual |
Destructs the entity.
This automatically also removes the entity from its parent cell, and also unregisters it.
◆ 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]
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]
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]
◆ GetCell()
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()
◆ GetType()
void tram::Entity::GetType |
( |
| ) |
|
|
pure virtual |
◆ 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()
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 |
Loads an entity.
Usually the Load() method for an entity type will set up its components, event listeners, etc. After being loaded, the entity will be ready for simulation.
When implementing this method, make sure to flag the entity with the LOADED
flag, so that world streaming system doesn't try to load your entity twice.
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ Make() [1/2]
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
-
type | Type of the entity, this should be the same name that was used when using Register() to register an entity type. |
shared_data | Shared data of the entity. |
field_array | Values to be filled in the entity's fields. |
- Returns
- Pointer to an entity if successful, otherwise a
nullptr
.
◆ Make() [2/2]
◆ MessageHandler()
void tram::Entity::MessageHandler |
( |
Message & |
msg | ) |
|
|
pure virtual |
Allows entities to receive messages.
Whenever an entity is sent a Message, once the Message::Dispatch() function has been called, the entity will gets the message passed to it through this method.
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ 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]
Registers a new entity type.
- Parameters
-
name | Name of the entity, should be the same as what its GetType() method returns. |
constr_func | This function will be called when a new entity of this type is requested, e.g. when deserializing a worldcell file. |
destr_func | This function will be called when an entity of this type is yeeted. |
fields | Pointer to an array of serialization fields. |
fieldcount | Size of the fields array. |
◆ RegisterType() [2/3]
◆ RegisterType() [3/3]
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 |
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ 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 |
Called when either Entity::SetLocation or Entity::SetRotation is called.
Usually this method is used to relocate or rerotate an entity.
If the entity has a PhysicsComponent, its position or rotation is usually set from this method, otherwise in the next Physics update step, the entity's previous rotation and location will be restored.
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ SetPersistent()
void tram::Entity::SetPersistent |
( |
bool |
is | ) |
|
|
inline |
◆ SetRotation()
void tram::Entity::SetRotation |
( |
quat |
rot | ) |
|
|
inline |
◆ Unload()
void tram::Entity::Unload |
( |
| ) |
|
|
pure virtual |
Unloads an entity.
Usually the Load() method for an entity type will destroy its its components, event listeners, etc. After being unloaded, the entity have been removed from the simulation.
When implementing this method, make sure to clear your entity's LOADED flag, so that world streaming system can load the entity again.
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ 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 |
Called when Entity::UpdateTransform is called.
From the runtime's side, only the Physics system will call the Entity::UpdateTransform() method, and through it, this method.
Usually this method is used to forward the entity's new position and rotation to its RenderComponent, if it has one.
If the entity has a PhysicsComponent, its position or rotation is never updated from this method.
Implemented in tram::Crate, tram::Decoration, tram::Light, tram::Marker, tram::Player, tram::Sound, tram::StaticWorldObject, tram::Trigger, tram::Ext::Kitchensink::Button, tram::Ext::Kitchensink::Breakable, tram::Ext::Kitchensink::Water, tram::Ext::Kitchensink::Train, tram::Ext::Kitchensink::Pickup, tram::Ext::Kitchensink::DebugText, tram::Ext::Kitchensink::DebugShape, tram::Ext::Kitchensink::TriggerAutosave, tram::Ext::Kitchensink::TriggerHurt, tram::Ext::Kitchensink::TriggerOnce, tram::Ext::Kitchensink::TriggerMultiple, tram::Ext::Kitchensink::TriggerPush, tram::Ext::Kitchensink::TriggerRemove, tram::Ext::Kitchensink::TriggerTeleport, tram::Ext::Kitchensink::TriggerPlayerMovement, and tram::Ext::Kitchensink::QuestEntity.
◆ 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.
◆ WorldCell
◆ cell
◆ 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
◆ rotation
quat tram::Entity::rotation = {1.0f, 0.0f, 0.0f, 0.0f} |
|
protected |
◆ signals
The documentation for this class was generated from the following files:
- C:/Users/Poga/Desktop/painis/tram-sdk/src/framework/entity.h
- C:/Users/Poga/Desktop/painis/tram-sdk/src/framework/entity.cpp