DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches

The base class of every component. More...

#include <deki/Component.h>

Inherited by Deki::CoreProjectSettings, Deki::PlatformSetupComponent, Deki::ScreenAnchor, Deki::SetupComponent, and Deki::UnitProjectSettings.

Public Member Functions

 Component ()
 Component (const Component &)=delete
virtual ~Component ()=default
virtual void Awake ()
 Called once, after AssetRefs and ObjectRefs are resolved.
bool DeclaresUpdate () const
 True when this class (or a reflected base) declares Update(), as the codegen read it from the class declaration.
bool Deserialize (SceneFormat::SceneMsgPackParser &parser, uint32_t mapSize)
 Reads this component's fields from the MessagePack map the parser is at (mapSize key-value pairs), through the codegen's hash-switch deserializer.
ComponentType GetBaseType () const
 The direct component base's type id, so GetComponent<Base>() finds subclasses.
Object * GetOwner () const
ComponentType GetType () const
 The class's type id (TypeId<T>()), 0 for an instance with no type info.
const ComponentTypeInfo * GetTypeInfo () const
 The class entry this instance runs through.
bool HasAwoken () const
bool HasRefsResolved () const
bool HasStarted () const
bool IsRemoved () const
 True once RemoveComponent() has been called and the component is waiting for the end of the lifecycle phase to be deleted.
virtual void LoadAssets ()
 Loads the assets this component needs (sprites, fonts, ...).
void MarkAwoken ()
void MarkRefsResolved ()
void MarkRemoved ()
void MarkStarted ()
virtual bool NeedsAssetLoading () const
 True when LoadAssets() should be called.
virtual bool NeedsRuntimeUpdate () const
 True when RuntimeUpdate() should be called each frame.
virtual void OnAssetRefResolved (const char *propertyName, void *asset, const char *guid)
 Called after LifecycleManager resolves the AssetRef field propertyName to asset, loaded from guid.
virtual void OnPropertyChanged (const char *propertyName)
 Called when the editor changes the field propertyName, after both Execute() and Undo() of ModifyComponentPropertyCommand.
Component & operator= (const Component &)=delete
void RemapObjectRefs (const std::unordered_map< uint32_t, uint32_t > &idRemap)
 Rewrites ObjectRef ids through idRemap (old id -> new id), after Instantiate() gave the copies new ids.
void ResetRefsResolved ()
void ResolveObjectRefs (Scene *scene)
 Points every ObjectRef field at its object in scene (ObjectRef.id -> ObjectRef.resolved).
virtual void RuntimeUpdate (float deltaTime)
 Engine-driven per-frame work (physics, animation, ...), separate from the script-facing Update(): it runs in every mode, including the editor in edit mode, on components whose NeedsRuntimeUpdate() is true.
void SetOwner (Object *owner)
void SetTypeInfo (const ComponentTypeInfo *info)
 Attaches the class entry.
virtual void Start ()
 Called once before the first Update, after every component's Awake has run.
virtual void UnloadAssets ()
 Drops this component's asset pointers before shutdown.
virtual void Update ()
 Called every frame, only on classes that declare it.

Protected Attributes

bool m_HasAwoken
bool m_HasStarted
Object * m_Owner
bool m_RefsResolved
bool m_Removed
const ComponentTypeInfo * m_TypeInfo

Detailed Description

The base class of every component.

A component is any class deriving publicly from Component; it declares nothing else. The reflection codegen finds the class by its base, its identity is its qualified name (see TypeId.h), and the per-class operations below run through the ComponentTypeInfo the engine attaches when the instance is created (AddComponent<T>, the scene loader, the factory).

A component with exported fields and no lifecycle methods is data. One that declares Awake(), Start() or Update() takes part in the lifecycle. Only a class that declares Update() is ticked, so a data component costs nothing per frame.

Lifecycle order:

  1. InternalAwake (engine) - resolves AssetRefs and ObjectRefs
  2. Awake() - once, after the references are resolved
  3. Start() - once, before the first Update, after every Awake has run
  4. Update() - every frame
  5. Render (RendererComponent)

Constructor & Destructor Documentation

◆ Component() [1/2]

Deki::Component::Component ( )
inline

◆ ~Component()

virtual Deki::Component::~Component ( )
virtualdefault

◆ Component() [2/2]

Deki::Component::Component ( const Component & )
delete

Member Function Documentation

◆ Awake()

virtual void Deki::Component::Awake ( )
inlinevirtual

Called once, after AssetRefs and ObjectRefs are resolved.

Use it for self-initialisation.

◆ DeclaresUpdate()

bool Deki::Component::DeclaresUpdate ( ) const
inline

True when this class (or a reflected base) declares Update(), as the codegen read it from the class declaration.

LifecycleManager calls Update() only on these.

◆ Deserialize()

bool Deki::Component::Deserialize ( SceneFormat::SceneMsgPackParser & parser,
uint32_t mapSize )

Reads this component's fields from the MessagePack map the parser is at (mapSize key-value pairs), through the codegen's hash-switch deserializer.

An instance without type info skips the map so the parser stays in step. Returns false on failure.

◆ GetBaseType()

ComponentType Deki::Component::GetBaseType ( ) const
inline

The direct component base's type id, so GetComponent<Base>() finds subclasses.

◆ GetOwner()

Object * Deki::Component::GetOwner ( ) const
inline

◆ GetType()

ComponentType Deki::Component::GetType ( ) const
inline

The class's type id (TypeId<T>()), 0 for an instance with no type info.

◆ GetTypeInfo()

const ComponentTypeInfo * Deki::Component::GetTypeInfo ( ) const
inline

The class entry this instance runs through.

nullptr only for an instance created outside the engine's paths (a bare new).

◆ HasAwoken()

bool Deki::Component::HasAwoken ( ) const
inline

◆ HasRefsResolved()

bool Deki::Component::HasRefsResolved ( ) const
inline

◆ HasStarted()

bool Deki::Component::HasStarted ( ) const
inline

◆ IsRemoved()

bool Deki::Component::IsRemoved ( ) const
inline

True once RemoveComponent() has been called and the component is waiting for the end of the lifecycle phase to be deleted.

It gets no more calls.

◆ LoadAssets()

virtual void Deki::Component::LoadAssets ( )
inlinevirtual

Loads the assets this component needs (sprites, fonts, ...).

Play Mode calls it during initialisation. Use Deki::AssetManager::Get().

◆ MarkAwoken()

void Deki::Component::MarkAwoken ( )
inline

◆ MarkRefsResolved()

void Deki::Component::MarkRefsResolved ( )
inline

◆ MarkRemoved()

void Deki::Component::MarkRemoved ( )
inline

◆ MarkStarted()

void Deki::Component::MarkStarted ( )
inline

◆ NeedsAssetLoading()

virtual bool Deki::Component::NeedsAssetLoading ( ) const
inlinevirtual

True when LoadAssets() should be called.

◆ NeedsRuntimeUpdate()

virtual bool Deki::Component::NeedsRuntimeUpdate ( ) const
inlinevirtual

True when RuntimeUpdate() should be called each frame.

◆ OnAssetRefResolved()

virtual void Deki::Component::OnAssetRefResolved ( const char * propertyName,
void * asset,
const char * guid )
inlinevirtual

Called after LifecycleManager resolves the AssetRef field propertyName to asset, loaded from guid.

Override it for post-load work, such as checking whether the GUID names a sub-asset and deriving state from it.

◆ OnPropertyChanged()

virtual void Deki::Component::OnPropertyChanged ( const char * propertyName)
inlinevirtual

Called when the editor changes the field propertyName, after both Execute() and Undo() of ModifyComponentPropertyCommand.

◆ operator=()

Component & Deki::Component::operator= ( const Component & )
delete

◆ RemapObjectRefs()

void Deki::Component::RemapObjectRefs ( const std::unordered_map< uint32_t, uint32_t > & idRemap)
inline

Rewrites ObjectRef ids through idRemap (old id -> new id), after Instantiate() gave the copies new ids.

◆ ResetRefsResolved()

void Deki::Component::ResetRefsResolved ( )
inline

◆ ResolveObjectRefs()

void Deki::Component::ResolveObjectRefs ( Scene * scene)
inline

Points every ObjectRef field at its object in scene (ObjectRef.id -> ObjectRef.resolved).

LifecycleManager calls it before Awake(). The generated code reads the fields directly, with no metadata walk.

◆ RuntimeUpdate()

virtual void Deki::Component::RuntimeUpdate ( float deltaTime)
inlinevirtual

Engine-driven per-frame work (physics, animation, ...), separate from the script-facing Update(): it runs in every mode, including the editor in edit mode, on components whose NeedsRuntimeUpdate() is true.

deltaTime is in seconds.

◆ SetOwner()

void Deki::Component::SetOwner ( Object * owner)
inline

◆ SetTypeInfo()

void Deki::Component::SetTypeInfo ( const ComponentTypeInfo * info)
inline

Attaches the class entry.

AddComponent<T>, the factory and the scene loader call this; user code never needs it.

◆ Start()

virtual void Deki::Component::Start ( )
inlinevirtual

Called once before the first Update, after every component's Awake has run.

Use it for setup that touches other components.

Reimplemented in Deki::PlatformSetupComponent.

◆ UnloadAssets()

virtual void Deki::Component::UnloadAssets ( )
inlinevirtual

Drops this component's asset pointers before shutdown.

The asset manager owns the memory, so only set the pointers to nullptr.

◆ Update()

virtual void Deki::Component::Update ( )
inlinevirtual

Called every frame, only on classes that declare it.

Reimplemented in Deki::PlatformSetupComponent.

Member Data Documentation

◆ m_HasAwoken

bool Deki::Component::m_HasAwoken
protected

◆ m_HasStarted

bool Deki::Component::m_HasStarted
protected

◆ m_Owner

Object* Deki::Component::m_Owner
protected

◆ m_RefsResolved

bool Deki::Component::m_RefsResolved
protected

◆ m_Removed

bool Deki::Component::m_Removed
protected

◆ m_TypeInfo

const ComponentTypeInfo* Deki::Component::m_TypeInfo
protected

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