Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Base class for all components (data-only). More...

#include <DekiComponent.h>

Inherited by CoreProjectSettings, DekiBehaviour, DisplayProjectSettings, MissingComponent, and UnitProjectSettings.

Public Member Functions

 DekiComponent ()
virtual ~DekiComponent ()=default
 DekiComponent (const DekiComponent &)=delete
DekiComponentoperator= (const DekiComponent &)=delete
virtual ComponentType GetType () const =0
virtual ComponentType GetBaseType () const
virtual DekiBehaviourAsBehaviour ()
virtual bool DeclaresUpdate () const
 Does this class (or a reflected base) declare Update()?
DekiObjectGetOwner () const
void SetOwner (DekiObject *owner)
virtual void LoadAssets ()
 Load assets needed by this component.
virtual void UnloadAssets ()
 Unload/clear assets held by this component.
virtual void RuntimeUpdate (float deltaTime)
 Update this component (runtime only).
virtual void OnAssetRefResolved (const char *propertyName, void *asset, const char *guid)
 Called after an AssetRef property is resolved by LifecycleManager.
virtual bool NeedsAssetLoading () const
 Check if this component needs asset loading.
virtual bool NeedsRuntimeUpdate () const
 Check if this component needs runtime updates.
virtual bool Deserialize (SceneFormat::SceneMsgPackParser &parser, uint32_t mapSize)
 Deserialize component data from MessagePack.
virtual void ResolveObjectRefs (class Scene *scene)
 Resolve all ObjectRef properties in this component.
virtual void RemapObjectRefs (const std::unordered_map< uint32_t, uint32_t > &idRemap)
 Remap ObjectRef IDs after cloning/instantiation.
bool HasRefsResolved () const
void MarkRefsResolved ()
void ResetRefsResolved ()
virtual void OnPropertyChanged (const char *propertyName)
 Called when a property is modified via the editor.

Static Public Attributes

static constexpr ComponentType StaticType = 0

Protected Attributes

DekiObjectm_Owner
bool m_RefsResolved

Detailed Description

Base class for all components (data-only).

DekiComponent provides:

  • Runtime type identification via GetType()/GetBaseType()
  • Owner reference for accessing the parent DekiObject

For components that need lifecycle methods (PreRender, Start, Update), inherit from DekiBehaviour instead.

Constructor & Destructor Documentation

◆ DekiComponent() [1/2]

DekiComponent::DekiComponent ( )
inline

◆ ~DekiComponent()

virtual DekiComponent::~DekiComponent ( )
virtualdefault

◆ DekiComponent() [2/2]

DekiComponent::DekiComponent ( const DekiComponent & )
delete

Member Function Documentation

◆ operator=()

DekiComponent & DekiComponent::operator= ( const DekiComponent & )
delete

◆ GetType()

virtual ComponentType DekiComponent::GetType ( ) const
pure virtual

Implemented in DekiBehaviour, and MissingComponent.

◆ GetBaseType()

virtual ComponentType DekiComponent::GetBaseType ( ) const
inlinevirtual

Reimplemented in DekiBehaviour, and MissingComponent.

◆ AsBehaviour()

virtual DekiBehaviour * DekiComponent::AsBehaviour ( )
inlinevirtual

Reimplemented in DekiBehaviour.

◆ DeclaresUpdate()

virtual bool DekiComponent::DeclaresUpdate ( ) const
inlinevirtual

Does this class (or a reflected base) declare Update()?

Generated by the reflection codegen for every DEKI_COMPONENT: true when the class itself declares an Update member, otherwise whatever the reflected base answers. LifecycleManager only calls Update() on behaviours that answer true, so a behaviour with no Update costs nothing per frame. Hand-written components outside the codegen (tests) override it themselves.

◆ GetOwner()

DekiObject * DekiComponent::GetOwner ( ) const
inline

◆ SetOwner()

void DekiComponent::SetOwner ( DekiObject * owner)
inline

◆ LoadAssets()

virtual void DekiComponent::LoadAssets ( )
inlinevirtual

Load assets needed by this component.

Components override this to load their assets (sprites, fonts, etc.) Called by Play Mode during initialization. Use Deki::AssetManager::Get() to access the asset manager.

◆ UnloadAssets()

virtual void DekiComponent::UnloadAssets ( )
inlinevirtual

Unload/clear assets held by this component.

Components override this to clear asset pointers before shutdown. The asset manager owns the memory, so just set pointers to nullptr.

◆ RuntimeUpdate()

virtual void DekiComponent::RuntimeUpdate ( float deltaTime)
inlinevirtual

Update this component (runtime only).

Parameters
deltaTimeTime since last frame in seconds

Components that need per-frame updates (physics, animation, etc.) override this. Different from DekiBehaviour::Update() which is for scripts.

◆ OnAssetRefResolved()

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

Called after an AssetRef property is resolved by LifecycleManager.

Parameters
propertyNameName of the property that was resolved
assetPointer to the loaded asset
guidThe GUID that was used to load the asset

Components can override this to perform post-load processing — e.g. inspecting whether the GUID resolves to a sub-asset and deriving extra runtime state from it.

◆ NeedsAssetLoading()

virtual bool DekiComponent::NeedsAssetLoading ( ) const
inlinevirtual

Check if this component needs asset loading.

Returns
true if LoadAssets() should be called

◆ NeedsRuntimeUpdate()

virtual bool DekiComponent::NeedsRuntimeUpdate ( ) const
inlinevirtual

Check if this component needs runtime updates.

Returns
true if RuntimeUpdate() should be called each frame

◆ Deserialize()

virtual bool DekiComponent::Deserialize ( SceneFormat::SceneMsgPackParser & parser,
uint32_t mapSize )
inlinevirtual

Deserialize component data from MessagePack.

Parameters
parserThe msgpack parser positioned at component data map
mapSizeNumber of key-value pairs in the data map
Returns
true if deserialization succeeded

Generated by the reflection codegen for each component. Uses hash-switch on property names for performance.

◆ ResolveObjectRefs()

virtual void DekiComponent::ResolveObjectRefs ( class Scene * scene)
inlinevirtual

Resolve all ObjectRef properties in this component.

Parameters
sceneThe scene to look up objects in

Generated by the reflection codegen for components with ObjectRef properties. Called by LifecycleManager before Awake() to resolve ObjectRef.idObjectRef.resolved. Zero-overhead: direct field access, no metadata iteration.

◆ RemapObjectRefs()

virtual void DekiComponent::RemapObjectRefs ( const std::unordered_map< uint32_t, uint32_t > & idRemap)
inlinevirtual

Remap ObjectRef IDs after cloning/instantiation.

Parameters
idRemapMap of old object ID → new object ID

Generated by the reflection codegen for components with ObjectRef properties. Called after Instantiate() to update ObjectRef.id fields to new unique IDs.

◆ HasRefsResolved()

bool DekiComponent::HasRefsResolved ( ) const
inline

◆ MarkRefsResolved()

void DekiComponent::MarkRefsResolved ( )
inline

◆ ResetRefsResolved()

void DekiComponent::ResetRefsResolved ( )
inline

◆ OnPropertyChanged()

virtual void DekiComponent::OnPropertyChanged ( const char * propertyName)
inlinevirtual

Called when a property is modified via the editor.

Parameters
propertyNameName of the property that changed

Components can override this to react to property changes. Called after Execute() and Undo() in ModifyComponentPropertyCommand.

Member Data Documentation

◆ StaticType

ComponentType DekiComponent::StaticType = 0
staticconstexpr

◆ m_Owner

DekiObject* DekiComponent::m_Owner
protected

◆ m_RefsResolved

bool DekiComponent::m_RefsResolved
protected

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