DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
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 ()
virtual ~Component ()=default
 Component (const Component &)=delete
Component & operator= (const Component &)=delete
ComponentType GetType () const
 The class's type id (TypeId<T>()), 0 for an instance with no type info.
ComponentType GetBaseType () const
 The direct component base's type id, so GetComponent<Base>() finds subclasses.
const ComponentTypeInfo * GetTypeInfo () const
 The class entry this instance runs through.
void SetTypeInfo (const ComponentTypeInfo *info)
 Attaches the class entry.
bool DeclaresUpdate () const
 True when this class (or a reflected base) declares Update(), as the codegen read it from the class declaration.
Object * GetOwner () const
void SetOwner (Object *owner)
virtual void Awake ()
 Called once, after AssetRefs and ObjectRefs are resolved.
virtual void Start ()
 Called once before the first Update, after every component's Awake has run.
virtual void Update ()
 Called every frame, only on classes that declare it.
bool HasAwoken () const
bool HasStarted () const
void MarkAwoken ()
void MarkStarted ()
virtual void LoadAssets ()
 Loads the assets this component needs (sprites, fonts, ...).
virtual void UnloadAssets ()
 Drops this component's asset pointers before shutdown.
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.
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 bool NeedsAssetLoading () const
 True when LoadAssets() should be called.
virtual bool NeedsRuntimeUpdate () const
 True when RuntimeUpdate() should be called each frame.
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.
void ResolveObjectRefs (Scene *scene)
 Points every ObjectRef field at its object in scene (ObjectRef.id -> ObjectRef.resolved).
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.
bool HasRefsResolved () const
void MarkRefsResolved ()
void ResetRefsResolved ()
virtual void OnPropertyChanged (const char *propertyName)
 Called when the editor changes the field propertyName, after both Execute() and Undo() of ModifyComponentPropertyCommand.

Protected Attributes

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

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

◆ operator=()

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

◆ GetType()

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

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

◆ GetBaseType()

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

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

◆ 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).

◆ 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.

◆ 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.

◆ GetOwner()

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

◆ SetOwner()

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

◆ Awake()

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

Called once, after AssetRefs and ObjectRefs are resolved.

Use it for self-initialisation.

◆ 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.

◆ Update()

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

Called every frame, only on classes that declare it.

Reimplemented in Deki::PlatformSetupComponent.

◆ HasAwoken()

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

◆ HasStarted()

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

◆ MarkAwoken()

void Deki::Component::MarkAwoken ( )
inline

◆ MarkStarted()

void Deki::Component::MarkStarted ( )
inline

◆ 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().

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ HasRefsResolved()

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

◆ MarkRefsResolved()

void Deki::Component::MarkRefsResolved ( )
inline

◆ ResetRefsResolved()

void Deki::Component::ResetRefsResolved ( )
inline

◆ 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.

Member Data Documentation

◆ m_Owner

Object* Deki::Component::m_Owner
protected

◆ m_TypeInfo

const ComponentTypeInfo* Deki::Component::m_TypeInfo
protected

◆ m_RefsResolved

bool Deki::Component::m_RefsResolved
protected

◆ m_HasAwoken

bool Deki::Component::m_HasAwoken
protected

◆ m_HasStarted

bool Deki::Component::m_HasStarted
protected

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