Namespace: dmGameObject
Language: C++
Type: Defold C++
File: component.h
Source: engine/gameobject/src/dmsdk/gameobject/component.h
Include: dmsdk/gameobject/component.h
Api for manipulating game object components (WIP)
Type: TYPEDEF Component add to update function. Only components called with this function should be included in the update passes.
Parameters
params (const dmGameObject::ComponentAddToUpdateParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentAddToUpdate callback.
Members
m_Collection (HCollection) - Collection handlem_Instance (HInstance) - Game object instancem_World (void*) - Component worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Component create function. Should allocate all necessary resources for the component. The game object instance is guaranteed to have its id, scene hierarchy and transform data updated when this is called.
Parameters
params (const dmGameObject::ComponentCreateParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentCreate callback.
Members
m_Instance (HInstance) - Game object instancem_Position (dmVMath::Point3) - Local component positionm_Rotation (dmVMath::Quat) - Local component rotationm_Scale (dmVMath::Vector3) - Local component scalem_PropertySet (PropertySet) - Set of propertiesm_Resource (void*) - Component resourcem_World (void*) - Component world, as created in the ComponentNewWorld callbackm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerm_ComponentIndex (uint16_t) - Index of the component type being created (among all component types)Type: TYPEDEF Component world destroy function
Parameters
params (const dmGameObject::ComponentDeleteWorldParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentDeleteWorld callback.
Members
m_Context - [type void*] Context for the component typem_World - [type void*] The pointer to the world to destroyType: TYPEDEF Component destroy function. Should deallocate all necessary resources.
Parameters
params (const dmGameObject::ComponentDestroyParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentDestroy callback.
Members
m_Collection (HCollection) - Collection handlem_Instance (HInstance) - Game object instancem_World (void*) - Component worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Component finalize function. Should clean up as it is called when the component is disabled.
Parameters
params (const dmGameObject::ComponentFinalParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentFinal callback.
Members
m_Collection (HCollection) - Collection handlem_Instance (HInstance) - Game object instancem_World (void*) - Component worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF A simple way to get the component instance from the user_data (which was set during creation)
Parameters
params (const dmGameObject::ComponentGetParams&) - Update parametersReturns
component (void*) - The internal component pointerType: STRUCT Parameters to ComponentGet callback.
Members
m_World (HComponentWorld) - Component worldm_UserData (HComponentInternal) - Component internal representationType: TYPEDEF Callback for retrieving a property value of the component.
Parameters
params (const dmGameObject::ComponentGetPropertyParams&) - the parametersout_value (dmGameObject::PropertyDesc&) - (out) the propertyReturns
result (dmGameObject::PropertyResult) - PROPERTY_RESULT_OK if retrieving the property was okType: STRUCT Parameters to ComponentGetProperty callback.
Members
m_Context (void*) - Context for the component typem_World (void*) - Component worldm_Instance (HInstance) - Game object instancem_PropertyId (dmhash_t) - Id of the propertym_UserData (uintptr_t*) - User data storage pointerm_Options (HPropertyOptions) - Options for getting the propertyType: TYPEDEF Component init function. Should set the components initial state as it is called when the component is enabled.
Parameters
params (const dmGameObject::ComponentInitParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentInit callback.
Members
m_Collection (HCollection) - Collection handlem_Instance (HInstance) - Game object instancem_World (void*) - Component worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Callback when iterating over the properties for a component.
Notes
Parameters
pit (dmGameObject::SceneNodePropertyIterator) - the property iteratornode (dmGameObject::SceneNode*) - the scene nodeType: TYPEDEF Component world create function
Parameters
params (const dmGameObject::ComponentNewWorldParams&)Returns
result (CreateResult) - CREATE_RESULT_OK on successType: STRUCT Parameters to ComponentNewWorld callback.
Members
m_Context (void*) - Context for the component typem_ComponentIndex (uint8_t) - Component type index that can be used later with GetWorld()m_MaxInstances (uint32_t) - Max component game object instance count (if applicable)m_World (void**) - Out-parameter of the pointer in which to store the created worldm_MaxComponentInstances (uint32_t) - Max components count of this type in current collection counted at the build stage.
If component in factory then value is 0xFFFFFFFFType: TYPEDEF Component on-input function. Called when input is sent to this component
Parameters
params (const dmGameObject::ComponentOnInputParams&) - Input parametersReturns
result (InputResult) - How the component handled the inputType: STRUCT Parameters to ComponentOnInput callback.
Members
m_Instance (HInstance) - Instance handlem_InputAction (const InputAction*) - Information about the input that occurred (note that input being released is also treated as input)m_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Component on-message function. Called when message is sent to this component
Parameters
params (const dmGameObject::ComponentOnMessageParams&) - Update parametersReturns
result (UpdateResult) - UPDATE_RESULT_OK on successType: STRUCT Parameters to ComponentOnMessage callback.
Members
m_Instance (HInstance) - Instance handlem_World (void*) - Worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerm_Message (dmMessage::Message*) - MessageType: FUNCTION Called when the resource the component is based on has been reloaded.
Parameters
params (const dmGameObject::ComponentOnReloadParams&) - the parametersType: STRUCT Parameters to ComponentOnReload callback.
Members
m_Instance (HInstance) - Instance handlem_Resource (void*) - Resource that was reloadedm_World (void*) - Component worldm_Context (void*) - User contextm_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Set a property set for the component.
Parameters
params (const dmGameObject::ComponentSetPropertiesParams&) - the parametersReturns
result (dmGameObject::PropertyResult) - PROPERTY_RESULT_OK if property was setType: STRUCT Parameters to ComponentSetProperties callback.
Members
m_Instance (HInstance) - Instance handlem_PropertySet (PropertySet) - Property set to usem_UserData (uintptr_t*) - User data storage pointerType: TYPEDEF Callback for setting a property value of the component.
Parameters
params (const dmGameObject::ComponentSetPropertyParams&) - the parametersReturns
result (dmGameObject::PropertyResult) - PROPERTY_RESULT_OK if property was setType: STRUCT Parameters to ComponentSetProperty callback.
Members
m_Context (void*) - Context for the component typem_World (void*) - Component worldm_Instance (HInstance) - Game object instancem_PropertyId (dmhash_t) - Id of the propertym_UserData (uintptr_t*) - User data storage pointerm_Value (PropertyVar) - New value of the propertym_Options (HPropertyOptions) - Options for setting the propertyType: TYPEDEF Component post update function. The component state should never be modified in this function.
Parameters
params (const dmGameObject::ComponentsPostUpdateParams&) - Update parametersReturns
result (UpdateResult) - UPDATE_RESULT_OK on successType: STRUCT Parameters for ComponentsPostUpdate callback.
Members
m_Collection (HCollection) - Collection handlem_World (void*) - Component worldm_Context (void*) - User contextType: TYPEDEF Component render function.
Parameters
params (const dmGameObject::ComponentsRenderParams&) - Update parametersReturns
result (UpdateResult) - UPDATE_RESULT_OK on successType: STRUCT Parameters to ComponentsRender callback.
Members
m_Collection (HCollection) - Collection handlem_World (void*) - Component worldm_Context (void*) - User contextType: TYPEDEF Component update function. Updates all component of this type for all game objects
Parameters
params (const dmGameObject::ComponentsUpdateParams&) - Update parametersparams (dmGameObject::ComponentsUpdateResult&) - (out) Update resultReturns
result (UpdateResult) - UPDATE_RESULT_OK on successType: STRUCT Parameters to ComponentsUpdate callback.
Members
m_Collection (HCollection) - Collection handlem_UpdateContext (const UpdateContext*) - Update contextm_World (void*) - Component worldm_Context (void*) - User contextType: STRUCT Parameters to ComponentsUpdate callback.
Members
m_TransformsUpdated (bool) - True if a component type updated any game object transformsType: STRUCT Context used when registering a new component type
Members
m_Config (dmConfigFile::HConfig) - The config filem_Factory (dmResource::HFactory) - The resource factorym_Register (dmGameObject::HRegister) - The game object registrym_Script (dmScript::HContext) - The shared script contextm_Contexts (dmHashTable64<void*>) - Mappings between names and contextxType: FUNCTION get the component type global context
Parameters
type (HComponentType) - the typeReturns
context (void*) - component type global contextType: FUNCTION Get the component type index. Used for with e.g. dmGameObject::GetWorld()/GetContext()
Parameters
type (HComponentType) - the typeReturns
type_index (uint32_t) - The type index.Type: FUNCTION Set the component add-to-update callback. Called for each component instal, when the game object is spawned.
Parameters
type (HComponentType) - the typefn (ComponentAddToUpdate) - callbackType: FUNCTION set the component child iterator function. Called during inspection
Parameters
type (HComponentType) - the typefn (dmGameObject::FIteratorChildren) - child iterator functionType: FUNCTION Set the component type global context. Usually set when registering the component type.
Parameters
type (HComponentType) - the typecontext (void*) - component type global contextType: FUNCTION Set the component create callback. Called when a component instance is created.
Parameters
type (HComponentType) - the typefn (ComponentCreate) - callbackType: FUNCTION Set the world destroy callback. Called when a collection (i.e. a “world”) is destroyed.
Parameters
type (HComponentType) - the typefn (ComponentDeleteWorld) - callbackType: FUNCTION Set the component destroy callback. Called when a component instance is destroyed.
Parameters
type (HComponentType) - the typefn (ComponentDestroy) - callbackType: FUNCTION Set the component finalize callback. Called on each gameobject’s components, during a gameobject’s finalization.
Parameters
type (HComponentType) - the typefn (ComponentFinal) - callbackType: FUNCTION Set the component update callback. Called when it’s time to update all component instances.
Parameters
type (HComponentType) - the typefn (ComponentsUpdate) - callbackType: FUNCTION Set the component get callback. Called when the scripts want to retrieve the individual component user data given an url.
Parameters
type (HComponentType) - the typefn (ComponentGet) - callbackType: FUNCTION Set the component get property callback. Called when accessing a property via go.get()
Parameters
type (HComponentType) - the typefn (ComponentGetProperty) - callbackType: FUNCTION Set the component type need for a per component instance user data. Defaults to true.
Parameters
type (HComponentType) - the typehas_user_data (bool) - does each component instance need user dataType: FUNCTION Set the component init callback. Called on each gameobject’s components, during a gameobject’s initialization.
Parameters
type (HComponentType) - the typefn (ComponentInit) - callbackType: FUNCTION Set the component late update callback. Called after regular update of all component instances but before render and before post update.
Parameters
type (HComponentType) - the typefn (ComponentsUpdate) - callbackType: FUNCTION Set the new world callback. Called when a collection (i.e. a “world”) is created.
Parameters
type (HComponentType) - the typefn (ComponentNewWorld) - callbackType: FUNCTION Set the component on-input callback. Called once per frame, before the Update function.
Parameters
type (HComponentType) - the typefn (ComponentOnInput) - callbackType: FUNCTION Set the component on-message callback. Called multiple times per frame, to flush messages.
Parameters
type (HComponentType) - the typefn (ComponentOnMessage) - callbackType: FUNCTION Set the component on-reload callback. Called when the resource of a component instance is reloaded.
Parameters
type (HComponentType) - the typefn (ComponentOnReload) - callbackType: FUNCTION Set the component post update callback. Called for each collection after the update, before the render.
Parameters
type (HComponentType) - the typefn (ComponentsPostUpdate) - callbackType: FUNCTION Set the component type prio order. Defines the update order of the component types.
Parameters
type (HComponentType) - the typeprio (uint16_t) - prio orderType: FUNCTION set the component property iterator function. Called during inspection
Parameters
type (HComponentType) - the typefn (dmGameObject::FIteratorProperties) - property iterator functionType: FUNCTION Set the component type transform dependency flag. If this flag is set, it might trigger an dmGameObject::UpdateTransforms() (if there are dirty transforms)
Parameters
type (HComponentType) - the typereads_transforms (bool) - transform dependency flagType: FUNCTION Set the component render callback. Called when it’s time to render all component instances.
Parameters
type (HComponentType) - the typefn (ComponentsRender) - callbackType: FUNCTION Set the component set properties callback. Called when the component instance is being spwned.
Parameters
type (HComponentType) - the typefn (ComponentSetProperties) - callbackType: FUNCTION Set the component set property callback. Called when accessing a property via go.set()
Parameters
type (HComponentType) - the typefn (ComponentSetProperty) - callbackType: FUNCTION Set the component update callback. Called when it’s time to update all component instances.
Parameters
type (HComponentType) - the typefn (ComponentsUpdate) - callbackType: MACRO Register a new component type
Parameters
symbol (symbol) - The unique C++ symbol namename (const char*) - name of the component type (i.e. the resource suffix)create_fn (dmGameObject::Result (fn)(const ComponentTypeCreateCtx ctx, HComponentType type)) - The type configuration function. May not be 0.destroy_fn (dmGameObject::Result (fn)(const ComponentTypeCreateCtx ctx, HComponentType type)) - The type destruction function. May be 0.Type: TYPEDEF Component type handle. It holds the life time functions for a type.