The base class of every component.
More...
#include <deki/Component.h>
Inherited by Deki::CoreProjectSettings, Deki::PlatformSetupComponent, Deki::ScreenAnchor, Deki::SetupComponent, and Deki::UnitProjectSettings.
|
| | 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.
|
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:
- InternalAwake (engine) - resolves AssetRefs and ObjectRefs
- Awake() - once, after the references are resolved
- Start() - once, before the first Update, after every Awake has run
- Update() - every frame
- Render (RendererComponent)
◆ Component() [1/2]
| Deki::Component::Component |
( |
| ) |
|
|
inline |
◆ ~Component()
| virtual Deki::Component::~Component |
( |
| ) |
|
|
virtualdefault |
◆ Component() [2/2]
| Deki::Component::Component |
( |
const Component & | | ) |
|
|
delete |
◆ operator=()
◆ GetType()
The class's type id (TypeId<T>()), 0 for an instance with no type info.
◆ GetBaseType()
The direct component base's type id, so GetComponent<Base>() finds subclasses.
◆ GetTypeInfo()
The class entry this instance runs through.
nullptr only for an instance created outside the engine's paths (a bare new).
◆ SetTypeInfo()
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 |
◆ 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 |
◆ NeedsRuntimeUpdate()
| virtual bool Deki::Component::NeedsRuntimeUpdate |
( |
| ) |
const |
|
inlinevirtual |
◆ Deserialize()
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 |
◆ 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.
◆ m_Owner
| Object* Deki::Component::m_Owner |
|
protected |
◆ m_TypeInfo
◆ 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: