GameEntity Class Reference
The game entity class.
More...
#include <GameEntity.h>
Inherits AbstractStreamedObject.
List of all members.
Public Member Functions |
| GameEntity () |
| Standard GameEntity constructor.
|
| ~GameEntity () |
| GameEntity destructor, destroys all components that have been created on this entity.
|
const Vector2 & | GetPosition () const |
void | SetPosition (const Vector2 &position) |
| Sets the current position of the entity.
|
float | GetRotation () const |
void | SetRotation (const float &fRotation) |
| Sets the rotation of the entity.
|
Matrix | GetXForm () const |
| Get a combined translation & rotation in the form of a matrix.
|
const UNIQUEID & | GetId () const |
| Retrieve the unique identifier assigned to this entity by the game.
|
void | SetId (const UNIQUEID &id) |
| Sets the uniqueid of the entity, note: this function should not be called by anything other than the Game.
|
bool | GetActive () const |
| Returns whether this entity is active.
|
void | SetActive (bool bActive) |
| Sets whether this entity should be active or not.
|
Game * | GetGame () const |
| Retrieves a pointer to the Game instance that created this entity.
|
void | SetGame (Game *pGame) |
| Sets the game logic that created this entity, note: this function should never be called on an entity, this function is only called when a new entity is created by the Game.
|
template<class T > |
T * | GetComponent (const ComponentId &familyId) const |
| Retrieve a casted pointer to a component given a familyId.
|
template<class T > |
T * | CreateComponentCast (const ComponentId &id) |
| Creates a component on this entity and then casts it to the given typename.
|
AbstractComponent * | CreateComponent (const ComponentId &id) |
| Creates a component with the given id (type) and then returns a pointer to the component as an AbstractComponent.
|
void | RemoveComponent (const ComponentId &id) |
| Removes a component with the given type from the entities component map.
|
void | Update (const int nDelta) |
| Updates the entity.
|
bool | FromAttribute (const Attribute *pAttributes) |
| Initializes the game entity from an AttributeTree.
|
virtual void | ToStream (std::ostream &stream) const |
| This function is called from the Game class Save method.
|
virtual void | FromStream (std::istream &stream) |
| This function is called from the Game class Load method.
|
Detailed Description
The game entity class.
A game entity is any object or group of related objects within the world (in the case of a puzzle for example). Each game entity begins it's life devoid of content, it is not until components are added to the entity that it becomes something. A game entity is therefore nothing more than a container for components, but it provides a convienient way to think about a collection of related components and also provides an interface which the game can use to manage said related components.
- See also:
- AbstractComponent
-
BaseComponent
Member Function Documentation
Creates a component with the given id (type) and then returns a pointer to the component as an AbstractComponent.
This is the primary method for which to create components on an object, this function makes calls to the ComponentFactory.
- Parameters:
-
| id | The id (type) of component to create. |
- Returns:
- A pointer to the component as an AbstractComponent or a null pointer if no component of that type could be found.
template<class T >
T * GameEntity::CreateComponentCast |
( |
const ComponentId & |
id |
) |
[inline] |
Creates a component on this entity and then casts it to the given typename.
- Parameters:
-
| id | The type of component to create. |
- See also:
- CreateComponent(const ComponentId& id)
- Returns:
- A pointer to the casted component that has been created, or a null pointer if no component of that type could be found.
bool GameEntity::FromAttribute |
( |
const Attribute * |
pAttributes |
) |
|
Initializes the game entity from an AttributeTree.
This method pulls components from the attribute tree in turn and then creates a component depending on the type. If the attribute tree contains invalid components then this function will sill work but invalid components will not be added. As each component is being loaded this function called FromAttribute(const Attribute * pAttributes) on each of the components which allows the component to do any custom loading from the attribute tree.
- Parameters:
-
| pAttributes | A pointer to the root of the attribute tree for this entity. |
- Returns:
- true if the components were loaded successfully, false otherwise.
void GameEntity::FromStream |
( |
std::istream & |
stream |
) |
[virtual] |
This function is called from the Game class Load method.
This method first determines how many components are present in the stream relating to this entity and then creates each component in turn,calling the functions FromStream method in order for the components to do custom loading.
- Parameters:
-
Implements AbstractStreamedObject.
bool GameEntity::GetActive |
( |
|
) |
const [inline] |
Returns whether this entity is active.
Active entities can update & render, inactive ones do not, can be useful to hide an entity from the player without actually destroying it.
template<class T >
T * GameEntity::GetComponent |
( |
const ComponentId & |
familyId |
) |
const [inline] |
Retrieve a casted pointer to a component given a familyId.
Family's are registered when the component is registered, which represents a class of similar components that should be considered mutually exclusive to one another.
- Parameters:
-
| familyId | A componentId of the family of the component to retrieve. |
- See also:
- ComponentId
-
AbstractComponent
- Returns:
- A casted pointer to typename T of the component belonging to that family or a null pointer if there is no such component.
Game* GameEntity::GetGame |
( |
|
) |
const [inline] |
Retrieves a pointer to the Game instance that created this entity.
- Returns:
- A pointer to the game logic.
const UNIQUEID& GameEntity::GetId |
( |
|
) |
const [inline] |
Retrieve the unique identifier assigned to this entity by the game.
- Returns:
- The UNIQUEID of this entity.
const Vector2& GameEntity::GetPosition |
( |
|
) |
const [inline] |
- Returns:
- The current position of the entity in the world (in pixels).
float GameEntity::GetRotation |
( |
|
) |
const [inline] |
- Returns:
- The current rotation of the entity.
Matrix GameEntity::GetXForm |
( |
|
) |
const [inline] |
Get a combined translation & rotation in the form of a matrix.
- Returns:
- The matrix containing this entities transform.
void GameEntity::RemoveComponent |
( |
const ComponentId & |
id |
) |
|
Removes a component with the given type from the entities component map.
[i]Warning[/i]: be careful how you use this function because some components are dependent on one another moving a component with dependents could cause odd behaviour or perhaps even crashes.
- Parameters:
-
| id | The component id of the component to remove. |
- See also:
- ComponentId
void GameEntity::SetActive |
( |
bool |
bActive |
) |
[inline] |
Sets whether this entity should be active or not.
- Parameters:
-
| bActive | A boolean signifying whether the entity is active. |
- See also:
- GetActive()
void GameEntity::SetGame |
( |
Game * |
pGame |
) |
[inline] |
Sets the game logic that created this entity, note: this function should never be called on an entity, this function is only called when a new entity is created by the Game.
- Parameters:
-
| pGame | A pointer to the Game logic. |
void GameEntity::SetId |
( |
const UNIQUEID & |
id |
) |
[inline] |
Sets the uniqueid of the entity, note: this function should not be called by anything other than the Game.
- Parameters:
-
void GameEntity::SetPosition |
( |
const Vector2 & |
position |
) |
[inline] |
Sets the current position of the entity.
- Parameters:
-
| position | The position to set in pixels (note: this way be overridden if the entity contains a ComplexPhysicsComponent). |
void GameEntity::SetRotation |
( |
const float & |
fRotation |
) |
[inline] |
Sets the rotation of the entity.
- Parameters:
-
| fRotation | The rotation of the entity in radians (note: this way be overridden if the entity contains a ComplexPhysicsComponent). |
void GameEntity::ToStream |
( |
std::ostream & |
stream |
) |
const [virtual] |
This function is called from the Game class Save method.
This method iterates through all components created on this entity and calls eachs components ToStream function, passing it the stream. This allows components to do custom saving.
- Parameters:
-
| stream | The output stream. |
Implements AbstractStreamedObject.
void GameEntity::Update |
( |
const int |
nDelta |
) |
|
Updates the entity.
This function is very basic, it simply iterates through all components that have been created on this entity and calls each components update function in turn.
- Parameters:
-
| nDelta | The time difference (in ms) between the the last game update and this one. |
The documentation for this class was generated from the following files:
- C:/Users/Marc/Desktop/Phystank/trunk/src/game/GameEntity.h
- C:/Users/Marc/Desktop/Phystank/trunk/src/game/GameEntity.cpp