XII Release 0.1.0
Loading...
Searching...
No Matches
xiiComponent Class Referenceabstract

Base class of all component types. More...

#include <Component.h>

Inheritance diagram for xiiComponent:
[legend]

Public Member Functions

void SetActiveFlag (bool bEnabled)
 Sets the active flag of the component, which affects its active state.
 
bool GetActiveFlag () const
 Checks whether the 'active flag' is set on this component. Note that this does not mean that the component is also 'active'.
 
bool IsActive () const
 Checks whether this component is in an active state.
 
bool IsActiveAndInitialized () const
 Returns whether this component is active and initialized.
 
bool IsActiveAndSimulating () const
 Whether the component is currently active and simulation has been started as well.
 
xiiComponentManagerBaseGetOwningManager ()
 Returns the corresponding manager for this component.
 
const xiiComponentManagerBaseGetOwningManager () const
 Returns the corresponding manager for this component.
 
xiiGameObjectGetOwner ()
 Returns the owner game object if the component is attached to one or nullptr.
 
const xiiGameObjectGetOwner () const
 Returns the owner game object if the component is attached to one or nullptr.
 
xiiWorldGetWorld ()
 Returns the corresponding world for this component.
 
const xiiWorldGetWorld () const
 Returns the corresponding world for this component.
 
xiiComponentHandle GetHandle () const
 Returns a handle to this component.
 
xiiUInt32 GetUniqueID () const
 Returns the unique id for this component.
 
void SetUniqueID (xiiUInt32 uiUniqueID)
 Sets the unique id for this component.
 
virtual void SerializeComponent (xiiWorldWriter &ref_stream) const
 Override this to save the current state of the component to the given stream.
 
virtual void DeserializeComponent (xiiWorldReader &ref_stream)
 Override this to load the current state of the component from the given stream.
 
void EnsureInitialized ()
 Ensures that the component is initialized. Must only be called from another component's Initialize callback.
 
void EnsureSimulationStarted ()
 Ensures that the OnSimulationStarted method has been called. Must only be called from another component's OnSimulationStarted callback.
 
XII_ALWAYS_INLINE bool SendMessage (xiiMessage &ref_msg)
 Sends a message to this component.
 
XII_ALWAYS_INLINE bool SendMessage (xiiMessage &ref_msg) const
 
void PostMessage (const xiiMessage &msg, xiiTime delay=xiiTime::MakeZero(), xiiObjectMsgQueueType::Enum queueType=xiiObjectMsgQueueType::NextFrame) const
 Queues the message for the given phase. The message is processed after the given delay in the corresponding phase.
 
virtual bool HandlesMessage (const xiiMessage &msg) const
 Returns whether the given Message is handled by this component.
 
void SetUserFlag (xiiUInt8 uiFlagIndex, bool bSet)
 Be careful to check which flags may already be in use by base classes.
 
bool GetUserFlag (xiiUInt8 uiFlagIndex) const
 Retrieves a custom flag. Index must be between 0 and 7.
 
void SetCreatedByPrefab ()
 Adds xiiObjectFlags::CreatedByPrefab to the component. See the flag for details.
 
bool WasCreatedByPrefab () const
 Checks whether the xiiObjectFlags::CreatedByPrefab flag is set on this component.
 
- Public Member Functions inherited from xiiReflectedClass
virtual const xiiRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const xiiRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T>
XII_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Protected Member Functions

 xiiComponent ()
 Keep the constructor private or protected in derived classes, so it cannot be called manually.
 
bool IsDynamic () const
 Returns whether this component is dynamic and thus can only be attached to dynamic game objects.
 
virtual xiiWorldModuleTypeId GetTypeId () const =0
 
virtual xiiComponentMode::Enum GetMode () const =0
 
virtual void Initialize ()
 Can be overridden for basic initialization that depends on a valid hierarchy and position.
 
virtual void Deinitialize ()
 This method is called before the component is destroyed. A derived type can override this method to do common de-initialization work.
 
virtual void OnActivated ()
 This method is called when the component gets activated.
 
virtual void OnDeactivated ()
 This method is called when the component gets deactivated.
 
virtual void OnSimulationStarted ()
 This method is called once for active components, at the start of the next world update, but only when the world is simulated.
 
void EnableUnhandledMessageHandler (bool enable)
 By default disabled. Enable to have OnUnhandledMessage() called for every unhandled message.
 
virtual bool OnUnhandledMessage (xiiMessage &msg, bool bWasPostedMsg)
 When EnableUnhandledMessageHandler() was activated, this is called for all messages for which there is no dedicated message handler.
 
virtual bool OnUnhandledMessage (xiiMessage &msg, bool bWasPostedMsg) const
 When EnableUnhandledMessageHandler() was activated, this is called for all messages for which there is no dedicated message handler.
 
bool IsInitialized () const
 
bool IsInitializing () const
 
bool IsSimulationStarted () const
 

Protected Attributes

const xiiRTTIm_pMessageDispatchType = nullptr
 Messages will be dispatched to this type. Default is what GetDynamicRTTI() returns, can be redirected if necessary.
 

Friends

class xiiWorld
 
class xiiGameObject
 
class xiiComponentManagerBase
 

Additional Inherited Members

- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 

Detailed Description

Base class of all component types.

Derive from this class to implement custom component types. Also add the XII_DECLARE_COMPONENT_TYPE macro to your class declaration. Also add a XII_BEGIN_COMPONENT_TYPE/XII_END_COMPONENT_TYPE block to a cpp file. In that block you can add reflected members or message handlers. Note that every component type needs a corresponding manager type. Take a look at xiiComponentManagerSimple for a simple manager implementation that calls an update method on its components every frame. To create a component instance call CreateComponent on the corresponding manager. Never store a direct pointer to a component but store a xiiComponentHandle instead.

Member Function Documentation

◆ Deinitialize()

void xiiComponent::Deinitialize ( )
protectedvirtual

This method is called before the component is destroyed. A derived type can override this method to do common de-initialization work.

This function is always called before destruction, even if the component is currently not active. The default implementation checks whether the component is currently active and will ensure OnDeactivated() gets called if necessary. For typical game code, prefer to use OnDeactivated().

See also
OnActivated(), OnDeactivated(), Initialize(), Deinitialize(), OnSimulationStarted()

Reimplemented in xiiAmbientLightComponent, xiiEventMessageHandlerComponent, xiiFogComponent, xiiPostProcessingComponent, xiiPrefabReferenceComponent, xiiRaycastComponent, xiiRenderComponent, and xiiScriptComponent.

◆ DeserializeComponent()

void xiiComponent::DeserializeComponent ( xiiWorldReader & ref_stream)
virtual

Override this to load the current state of the component from the given stream.

The active state will be automatically serialized. The 'initialized' state is not serialized, all components will be initialized after creation, even if they were already in an initialized state when they were serialized.

Reimplemented in xiiAimIKComponent, xiiAmbientLightComponent, xiiAnimatedMeshComponent, xiiAnimationControllerComponent, xiiAreaDamageComponent, xiiBakedProbesComponent, xiiBakedProbesVolumeComponent, xiiBeamComponent, xiiBlackboardComponent, xiiBoxReflectionProbeComponent, xiiCameraComponent, xiiCameraShakeComponent, xiiCameraShakeVolumeComponent, xiiCameraShakeVolumeSphereComponent, xiiCharacterControllerComponent, xiiClothSheetComponent, xiiCollectionComponent, xiiColorAnimationComponent, xiiCreatureCrawlComponent, xiiCustomMeshComponent, xiiDebugTextComponent, xiiDecalComponent, xiiDeviceTrackingComponent, xiiDirectionalLightComponent, xiiEventMessageHandlerComponent, xiiFakeRopeComponent, xiiFogComponent, xiiFollowPathComponent, xiiGlobalBlackboardComponent, xiiGrabbableItemComponent, xiiGreyBoxComponent, xiiHeadBoneComponent, xiiHeightfieldComponent, xiiInputComponent, xiiInstancedMeshComponent, xiiJointAttachmentComponent, xiiJointOverrideComponent, xiiLensFlareComponent, xiiLightComponent, xiiLineToComponent, xiiLocalBlackboardComponent, xiiLodAnimatedMeshComponent, xiiLodMeshComponent, xiiMarkerComponent, xiiMeshComponentBase, xiiMoveToComponent, xiiOccluderComponent, xiiPathComponent, xiiPlayerStartPointComponent, xiiPointLightComponent, xiiPostProcessingComponent, xiiPowerConnectorComponent, xiiPrefabReferenceComponent, xiiProjectileComponent, xiiPropertyAnimComponent, xiiRaycastComponent, xiiReflectionProbeComponentBase, xiiRenderTargetActivatorComponent, xiiResetTransformComponent, xiiRopeRenderComponent, xiiRotorComponent, xiiScriptComponent, xiiSensorComponent, xiiSensorConeComponent, xiiSensorCylinderComponent, xiiSensorSphereComponent, xiiSimpleAnimationComponent, xiiSimpleWindComponent, xiiSkeletonComponent, xiiSkeletonPoseComponent, xiiSkyBoxComponent, xiiSkyLightComponent, xiiSliderComponent, xiiSpatialAnchorComponent, xiiSpawnBoxComponent, xiiSpawnComponent, xiiSphereReflectionProbeComponent, xiiSpotLightComponent, xiiSpriteComponent, xiiStageSpaceComponent, xiiStateMachineComponent, xiiTimedDeathComponent, xiiTransformComponent, xiiTriggerDelayModifierComponent, xiiTwoBoneIKComponent, xiiVolumeBoxComponent, xiiVolumeComponent, xiiVolumeSphereComponent, xiiWindVolumeComponent, xiiWindVolumeConeComponent, xiiWindVolumeCylinderComponent, and xiiWindVolumeSphereComponent.

◆ GetActiveFlag()

XII_ALWAYS_INLINE bool xiiComponent::GetActiveFlag ( ) const

Checks whether the 'active flag' is set on this component. Note that this does not mean that the component is also 'active'.

See also
IsActive(), SetActiveFlag()

◆ HandlesMessage()

bool xiiComponent::HandlesMessage ( const xiiMessage & msg) const
virtual

Returns whether the given Message is handled by this component.

Reimplemented in xiiForwardEventsToGameStateComponent.

◆ Initialize()

void xiiComponent::Initialize ( )
protectedvirtual

Can be overridden for basic initialization that depends on a valid hierarchy and position.

All trivial initialization should be done in the constructor. For typical game code, you should prefer to use OnSimulationStarted(). This method is called once for every component, after creation but only at the start of the next world update. Therefore the global position has already been computed and the owner xiiGameObject is set. Contrary to OnActivated() and OnSimulationStarted(), this function is always called for all components.

See also
OnActivated(), OnDeactivated(), Initialize(), Deinitialize(), OnSimulationStarted()

Reimplemented in xiiForwardEventsToGameStateComponent, xiiGlobalBlackboardComponent, xiiLocalBlackboardComponent, xiiPostProcessingComponent, xiiScriptComponent, xiiSimpleWindComponent, xiiSkyBoxComponent, and xiiTriggerDelayModifierComponent.

◆ IsActive()

XII_ALWAYS_INLINE bool xiiComponent::IsActive ( ) const

Checks whether this component is in an active state.

The active state is determined by the active state of the owning game object and the 'active flag' of this component. Only if the owning game object is active (and thus all of its parent objects as well) and the component has the active flag set, will this component be active.

See also
xiiGameObject::IsActive(), xiiGameObject::SetActiveFlag()

◆ IsActiveAndInitialized()

XII_ALWAYS_INLINE bool xiiComponent::IsActiveAndInitialized ( ) const

Returns whether this component is active and initialized.

See also
IsActive()

◆ IsActiveAndSimulating()

XII_ALWAYS_INLINE bool xiiComponent::IsActiveAndSimulating ( ) const

Whether the component is currently active and simulation has been started as well.

See also
IsActive()

◆ OnActivated()

void xiiComponent::OnActivated ( )
protectedvirtual

This method is called when the component gets activated.

By default a component is active, but it can be created in an inactive state. In such a case OnActivated() is only called once a component is activated. If a component gets switched between active and inactive at runtime, OnActivated() and OnDeactivated() are called accordingly. In contrast Initialize() and Deinitialize() are only ever called once.

See also
OnActivated(), OnDeactivated(), Initialize(), Deinitialize(), OnSimulationStarted()

Reimplemented in xiiAmbientLightComponent, xiiAnimatedMeshComponent, xiiBakedProbesComponent, xiiBakedProbesVolumeComponent, xiiBeamComponent, xiiBlackboardComponent, xiiBoxReflectionProbeComponent, xiiCameraComponent, xiiCameraShakeVolumeComponent, xiiClothSheetComponent, xiiCustomMeshComponent, xiiDecalComponent, xiiFakeRopeComponent, xiiFogComponent, xiiFollowPathComponent, xiiGlobalBlackboardComponent, xiiGreyBoxComponent, xiiHeightfieldComponent, xiiInstancedMeshComponent, xiiLensFlareComponent, xiiLocalBlackboardComponent, xiiLodAnimatedMeshComponent, xiiMarkerComponent, xiiOccluderComponent, xiiPathComponent, xiiPathNodeComponent, xiiPostProcessingComponent, xiiPrefabReferenceComponent, xiiRaycastComponent, xiiRenderComponent, xiiRopeRenderComponent, xiiScriptComponent, xiiSensorComponent, xiiSimpleWindComponent, xiiSkeletonComponent, xiiSkeletonPoseComponent, xiiSkyBoxComponent, xiiSkyLightComponent, xiiSphereReflectionProbeComponent, xiiStageSpaceComponent, xiiStateMachineComponent, xiiVolumeComponent, and xiiWindVolumeComponent.

◆ OnDeactivated()

◆ OnSimulationStarted()

void xiiComponent::OnSimulationStarted ( )
protectedvirtual

This method is called once for active components, at the start of the next world update, but only when the world is simulated.

This is the one preferred method to setup typical game logic. In a pure game environment there is no practical difference between OnActivated() and OnSimulationStarted(), as OnSimulationStarted() will be called right after OnActivated().

However, when a scene is open inside the editor, there is an important difference: OnActivated() is called once the component was created. OnSimulationStarted() is only called once the game simulation is started inside the editor. As an example, if a component starts a sound in OnActivated(), that sound will play right after the scene has been loaded into the editor. If instead the sound gets started in OnSimulationStarted(), it will only play once the user starts the game mode inside the editor.

Additionally, OnSimulationStarted() is only executed once, even if the xiiWorld pauses and resumes world simulation multiple times. However, note that it will be called again after the component has been deactivated and is activated again.

See also
OnActivated(), OnDeactivated(), Initialize(), Deinitialize(), OnSimulationStarted()

Reimplemented in xiiAnimationControllerComponent, xiiAreaDamageComponent, xiiCameraShakeVolumeComponent, xiiClothSheetComponent, xiiCollectionComponent, xiiColorAnimationComponent, xiiCreatureCrawlComponent, xiiDecalComponent, xiiFollowPathComponent, xiiGlobalBlackboardComponent, xiiLocalBlackboardComponent, xiiPowerConnectorComponent, xiiPrefabReferenceComponent, xiiProjectileComponent, xiiPropertyAnimComponent, xiiRaycastComponent, xiiResetTransformComponent, xiiRotorComponent, xiiScriptComponent, xiiSimpleAnimationComponent, xiiSkeletonPoseComponent, xiiSliderComponent, xiiSpatialAnchorComponent, xiiSpawnBoxComponent, xiiSpawnComponent, xiiTimedDeathComponent, xiiTransformComponent, and xiiWindVolumeComponent.

◆ OnUnhandledMessage() [1/2]

bool xiiComponent::OnUnhandledMessage ( xiiMessage & msg,
bool bWasPostedMsg )
protectedvirtual

When EnableUnhandledMessageHandler() was activated, this is called for all messages for which there is no dedicated message handler.

Returns
Should return true if the given message was handled, false otherwise.

Reimplemented in xiiForwardEventsToGameStateComponent.

◆ OnUnhandledMessage() [2/2]

bool xiiComponent::OnUnhandledMessage ( xiiMessage & msg,
bool bWasPostedMsg ) const
protectedvirtual

When EnableUnhandledMessageHandler() was activated, this is called for all messages for which there is no dedicated message handler.

Returns
Should return true if the given message was handled, false otherwise.

Reimplemented in xiiForwardEventsToGameStateComponent.

◆ SerializeComponent()

void xiiComponent::SerializeComponent ( xiiWorldWriter & ref_stream) const
virtual

Override this to save the current state of the component to the given stream.

Reimplemented in xiiAimIKComponent, xiiAmbientLightComponent, xiiAnimatedMeshComponent, xiiAnimationControllerComponent, xiiAreaDamageComponent, xiiBakedProbesComponent, xiiBakedProbesVolumeComponent, xiiBeamComponent, xiiBlackboardComponent, xiiBoxReflectionProbeComponent, xiiCameraComponent, xiiCameraShakeComponent, xiiCameraShakeVolumeComponent, xiiCameraShakeVolumeSphereComponent, xiiCharacterControllerComponent, xiiClothSheetComponent, xiiCollectionComponent, xiiColorAnimationComponent, xiiCreatureCrawlComponent, xiiCustomMeshComponent, xiiDebugTextComponent, xiiDecalComponent, xiiDeviceTrackingComponent, xiiDirectionalLightComponent, xiiEventMessageHandlerComponent, xiiFakeRopeComponent, xiiFogComponent, xiiFollowPathComponent, xiiGlobalBlackboardComponent, xiiGrabbableItemComponent, xiiGreyBoxComponent, xiiHeadBoneComponent, xiiHeightfieldComponent, xiiInputComponent, xiiInstancedMeshComponent, xiiJointAttachmentComponent, xiiJointOverrideComponent, xiiLensFlareComponent, xiiLightComponent, xiiLineToComponent, xiiLocalBlackboardComponent, xiiLodAnimatedMeshComponent, xiiLodMeshComponent, xiiMarkerComponent, xiiMeshComponentBase, xiiMoveToComponent, xiiOccluderComponent, xiiPathComponent, xiiPlayerStartPointComponent, xiiPointLightComponent, xiiPostProcessingComponent, xiiPowerConnectorComponent, xiiPrefabReferenceComponent, xiiProjectileComponent, xiiPropertyAnimComponent, xiiRaycastComponent, xiiReflectionProbeComponentBase, xiiRenderTargetActivatorComponent, xiiResetTransformComponent, xiiRopeRenderComponent, xiiRotorComponent, xiiScriptComponent, xiiSensorComponent, xiiSensorConeComponent, xiiSensorCylinderComponent, xiiSensorSphereComponent, xiiSimpleAnimationComponent, xiiSimpleWindComponent, xiiSkeletonComponent, xiiSkeletonPoseComponent, xiiSkyBoxComponent, xiiSkyLightComponent, xiiSliderComponent, xiiSpatialAnchorComponent, xiiSpawnBoxComponent, xiiSpawnComponent, xiiSphereReflectionProbeComponent, xiiSpotLightComponent, xiiSpriteComponent, xiiStageSpaceComponent, xiiStateMachineComponent, xiiTimedDeathComponent, xiiTransformComponent, xiiTriggerDelayModifierComponent, xiiTwoBoneIKComponent, xiiVolumeBoxComponent, xiiVolumeComponent, xiiVolumeSphereComponent, xiiWindVolumeComponent, xiiWindVolumeConeComponent, xiiWindVolumeCylinderComponent, and xiiWindVolumeSphereComponent.

◆ SetActiveFlag()

void xiiComponent::SetActiveFlag ( bool bEnabled)

Sets the active flag of the component, which affects its active state.

The active flag affects the 'active state' of the component. Ie. a component without the active flag will always be inactive. However, the active state is also affected by the active state of the owning game object. Thus a component attached to an inactive game object, will also be inactive.

Note that it is up to the component manager though, whether it differentiates between active and inactive components.

See also
xiiGameObject::IsActive(), xiiGameObject::SetActiveFlag()

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