ezEngine  Milestone 7
ezGameObject Class Reference

This class represents an object inside the world. More...

#include <GameObject.h>

Classes

class  ChildIterator
 
class  ConstChildIterator
 Iterates over all children of one object. More...
 

Public Member Functions

ezGameObjectHandle GetHandle () const
 Returns a handle to this object.
 
bool IsDynamic () const
 Returns whether this object is dynamic.
 
bool IsStatic () const
 Returns whether this object is static.
 
void Activate ()
 Activates the object and all its components.
 
void Deactivate ()
 Deactivates the object and all its components.
 
bool IsActive () const
 Returns whether this object is active.
 
void SetName (const char *szName)
 
const char * GetName () const
 
void SetParent (const ezGameObjectHandle &parent)
 Sets the parent of this object to the given. Note that the actual re-parenting is postponed.
 
ezGameObjectGetParent ()
 Gets the parent of this object or nullptr if this is a top-level object.
 
const ezGameObjectGetParent () const
 Gets the parent of this object or nullptr if this is a top-level object.
 
void AddChild (const ezGameObjectHandle &child)
 Adds the given object as a child object. Note that the actual re-parenting is postponed.
 
void AddChildren (const ezArrayPtr< const ezGameObjectHandle > &children)
 Adds the given objects as child objects. Note that the actual re-parenting is postponed.
 
void DetachChild (const ezGameObjectHandle &child)
 Removes the given child object from this object and makes it a top-level object. Note that the actual re-parenting is postponed.
 
void DetachChildren (const ezArrayPtr< const ezGameObjectHandle > &children)
 Removes the given child objects from this object and makes them top-level objects. Note that the actual re-parenting is postponed.
 
ezUInt32 GetChildCount () const
 Returns the number of children.
 
ChildIterator GetChildren ()
 Returns an iterator over all children of this object.
 
ConstChildIterator GetChildren () const
 Returns an iterator over all children of this object.
 
ezWorldGetWorld ()
 
const ezWorldGetWorld () const
 
void SetLocalPosition (const ezVec3 &position)
 
const ezVec3GetLocalPosition () const
 
void SetLocalRotation (const ezQuat &rotation)
 
const ezQuatGetLocalRotation () const
 
void SetLocalScaling (const ezVec3 &scaling)
 
const ezVec3GetLocalScaling () const
 
void SetGlobalPosition (const ezVec3 &position)
 
const ezVec3GetGlobalPosition () const
 
void SetGlobalRotation (const ezQuat rotation)
 
const ezQuat GetGlobalRotation () const
 
void SetGlobalScaling (const ezVec3 scaling)
 
const ezVec3 GetGlobalScaling () const
 
void SetGlobalTransform (const ezTransform &transform)
 
const ezTransformGetGlobalTransform () const
 
void SetVelocity (const ezVec3 &vVelocity)
 
const ezVec3GetVelocity () const
 
void UpdateGlobalTransform ()
 Updates the global transform immediately. Usually this done during the world update after the "Post-async" phase.
 
const ezBoundingBoxSphereGetLocalBounds () const
 
const ezBoundingBoxSphereGetGlobalBounds () const
 
void UpdateLocalBounds ()
 Invalidates the local bounds and sends a message to all components so they can add their bounds.
 
void UpdateGlobalTransformAndBounds ()
 Updates the global transform and bounds immediately. Usually this done during the world update after the "Post-async" phase.
 
ezResult AddComponent (const ezComponentHandle &component)
 Attaches the component to the object. Calls the OnAttachedToObject method on the component.
 
ezResult AddComponent (ezComponent *pComponent)
 Attaches the component to the object. Calls the OnAttachedToObject method on the component.
 
ezResult RemoveComponent (const ezComponentHandle &component)
 Removes the component from this object. Calls the OnDetachedFromObject method on the component. The component is still valid afterwards.
 
ezResult RemoveComponent (ezComponent *pComponent)
 Removes the component from this object. Calls the OnDetachedFromObject method on the component. The component is still valid afterwards.
 
template<typename T >
bool TryGetComponentOfBaseType (T *&out_pComponent) const
 Tries to find a component of the given base type in the objects components list and returns the first match.
 
template<typename T >
void TryGetComponentsOfBaseType (ezHybridArray< T *, 8 > &out_components) const
 Tries to find components of the given base type in the objects components list and returns all matches.
 
ezArrayPtr< ezComponent *const > GetComponents ()
 Returns a list of all components attached to this object.
 
ezArrayPtr< const ezComponent
*const > 
GetComponents () const
 Returns a list of all components attached to this object.
 
void SendMessage (ezMessage &msg, ezObjectMsgRouting::Enum routing=ezObjectMsgRouting::Default)
 Sends a message to all components of this object. Depending on the routing options the message is also send to parents or children.
 
void SendMessage (ezMessage &msg, ezObjectMsgRouting::Enum routing=ezObjectMsgRouting::Default) const
 Sends a message to all components of this object. Depending on the routing options the message is also send to parents or children.
 
void PostMessage (ezMessage &msg, ezObjectMsgQueueType::Enum queueType, ezObjectMsgRouting::Enum routing=ezObjectMsgRouting::Default)
 Queues the message for the given phase and processes it later in that phase.
 
void PostMessage (ezMessage &msg, ezObjectMsgQueueType::Enum queueType, ezTime delay, ezObjectMsgRouting::Enum routing=ezObjectMsgRouting::Default)
 Queues the message for the given phase. The message is processed after the given delay in the corresponding phase.
 
ezTagSetGetTags ()
 Returns the tag set associated with this object.
 
const ezTagSetGetTags () const
 

Private Types

enum  { NUM_INPLACE_COMPONENTS = 6 }
 

Private Member Functions

 ezGameObject (const ezGameObject &other)
 
void operator= (const ezGameObject &other)
 
 EZ_ALLOW_PRIVATE_PROPERTIES (ezGameObject)
 
void Reflection_AddChild (ezGameObject *pChild)
 
void Reflection_DetachChild (ezGameObject *pChild)
 
ezHybridArray< ezGameObject *, 8 > Reflection_GetChildren () const
 
void Reflection_AddComponent (ezComponent *pComponent)
 
void Reflection_RemoveComponent (ezComponent *pComponent)
 
const ezHybridArray
< ezComponent
*, NUM_INPLACE_COMPONENTS > & 
Reflection_GetComponents () const
 
void OnDeleteObject (ezDeleteObjectMessage &msg)
 
void FixComponentPointer (ezComponent *pOldPtr, ezComponent *pNewPtr)
 
struct EZ_ALIGN_16 (TransformationData)
 

Private Attributes

ezGameObjectId m_InternalId
 
ezBitflags< ezObjectFlagsm_Flags
 
ezHashedString m_sName
 
struct {
ezUInt64 m_ParentIndex: 20
 
ezUInt64 m_FirstChildIndex: 20
 
ezUInt64 m_LastChildIndex: 20
 
}; 
 
struct {
ezUInt64 m_NextSiblingIndex: 20
 
ezUInt64 m_PrevSiblingIndex: 20
 
ezUInt64 m_ChildCount: 20
 
}; 
 
ezUInt32 m_uiReserved
 
struct {
ezUInt32 m_uiHierarchyLevel: 12
 
ezUInt32 m_uiTransformationDataIndex: 20
 
}; 
 
TransformationData * m_pTransformationData
 
ezWorldm_pWorld
 
ezHybridArray< ezComponent
*, NUM_INPLACE_COMPONENTS > 
m_Components
 
ezTagSet m_Tags
 

Friends

class ezWorld
 
class ezInternal::WorldData
 
class ezMemoryUtils
 
class ezGameObjectDummyAllocator
 
class ezGameObjectTest
 

Detailed Description

This class represents an object inside the world.

Game objects only consists of hierarchical data like transformation and a list of components. You cannot derive from the game object class. To add functionality to an object you have to attach components to it. To create an object instance call CreateObject on the world. Never store a direct pointer to an object but store an object handle instead.

See Also
ezWorld
ezComponent
Todo:

Implement Clone

Implement switching dynamic and static

Member Function Documentation

void ezGameObject::SetGlobalPosition ( const ezVec3 position)
Test:
This is not yet tested
void ezGameObject::SetGlobalRotation ( const ezQuat  rotation)
Test:
This is not yet tested
void ezGameObject::SetGlobalScaling ( const ezVec3  scaling)
Test:
This is not yet tested

Member Data Documentation

ezHybridArray<ezComponent*, NUM_INPLACE_COMPONENTS> ezGameObject::m_Components
private
Todo:
small array class to reduce memory overhead

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