Hummingbird Framework
|
GameObject (also known as Actor). More...
#include <GameObject.h>
Classes | |
class | Component |
Base class for implementing custom Components. More... | |
Public Member Functions | |
GameObject () | |
Default constructor. | |
GameObject (const std::initializer_list< Component * > &components) | |
Class constructor. Adds all given components to the new GameObject instance. More... | |
~GameObject () | |
Class destructor. More... | |
int | getId () const |
Get the GameObject's id. More... | |
const std::string & | getName () const |
Get the GameObject's name. More... | |
void | setName (const std::string &name) |
Set the GameObject's name. | |
void | setActive (bool active) |
Set if GameObject is active. More... | |
bool | isActive () const |
Get if GameObject is active. More... | |
void | preUpdate () |
Runs all its Component's preUpdate(). | |
void | update () |
Runs all its Component's update(). | |
void | postUpdate () |
Runs all its Component's postUpdate(). | |
void | destroy () |
Marks the GameObject to be destroyed. More... | |
void | addComponent (Component *component) |
Add a Component to the GameObject. | |
void | addComponents (const std::vector< Component * > &components) |
Add a group of Components to the GameObject. | |
template<typename ComponentType > | |
ComponentType * | getComponent () const |
Get first Component of type ComponentType. More... | |
template<typename ComponentType > | |
std::vector< ComponentType * > | getComponents () const |
Get all Components of type ComponentType. More... | |
void | sendMessage (const std::string &name, DataRepository &data) |
Send message to this GameObject's Components. | |
![]() | |
Transform () | |
Default constructor. More... | |
Transform (const Vector3d &init_pos) | |
Constructor with initial position. | |
~Transform () | |
Class destructor. | |
const Vector3d & | getPosition () const |
Get Transform position. More... | |
void | setPosition (const Vector3d &p) |
Set position from a Vector3d. More... | |
void | setPosition (double p_x, double p_y, double p_z) |
Set position from doubles. More... | |
const Vector3d & | getRotation () const |
Get Transform rotation. More... | |
void | setRotation (const Vector3d &rotation) |
Set rotation from a Vector3d. More... | |
void | setRotation (double rotation_x, double rotation_y, double rotation_z) |
Set rotation from doubles. More... | |
const Vector3d & | getScale () const |
Get Transform scale. More... | |
void | setScale (const Vector3d &scale) |
Set scale from a Vector3d. More... | |
void | setScale (double scale_x, double scale_y, double scale_z) |
Set position from doubles. More... | |
Static Public Member Functions | |
static GameObject * | getGameObjectById (int id) |
Get GameObject instance given its id. More... | |
static const std::vector < GameObject * > & | getGameObjectsByName (const std::string &name) |
Get vector of GameObjects with the given name. More... | |
static void | destroyAll () |
Destroy all existing GameObjects. | |
static void | updateAll () |
Run the Update for all existing GameObjects. | |
Advanced usage | |
Used for messing with the unique id system of the GameObjects. | |
static void | setNextGameObjectId (int id) |
Set next GameObject id. More... | |
GameObject (int id) | |
Class constructor for manually setting the GameObject id. | |
GameObject (also known as Actor).
This class creates a object in the Game. It, by default, doesn't have any behaviour and you should not inherit from it. Instead GameObjects are composed by Components.
These Components are the ones that must implement the behaviour of the GameObject composed by them.
GameObjects are identified by a unique id that is assigned to every GameObject created and you can get it by querying its id (see getGameObjectById()). They can also be grouped by name, that is, you can set the same name to a group of GameObjects and later you can get them all by querying their name (see getGameObjectsByName()).
The Update of a GameObject consists in three steps: pre-update, update and post-update. These are used for respectively running its Components pre-update, update and post-update functions. The GameObject will also send a message to its MessageManager with the name of the event ("pre-update", "update" and "post-update") with an empty DataRepository as the parameter.
To destroy a GameObject you must call destroy(), not its destructor. The GameObject then, will be marked to be destroyed and after the next update step it'll be deleted. Just before being deleted, the GameObject will send a message to its MessageManager with the name "destroy" and an empty DataRepository as the parameter.
A GameObject can be active or inactive. If a GameObject is inactive it exists, has a unique id and may be grouped by name; all its Components also exist and have been instantiated. But it won't be updated. Same applies to Components.
hb::GameObject::GameObject | ( | const std::initializer_list< Component * > & | components | ) |
Class constructor. Adds all given components to the new GameObject instance.
components | List of components to be added to the new GameObject. |
hb::GameObject::~GameObject | ( | ) |
Class destructor.
It takes care of the destruction of all Components assigned to the GameObject.
void hb::GameObject::destroy | ( | ) |
Marks the GameObject to be destroyed.
The GameObject will be destroyed if it is marked to be destroyed after the update step.
|
inline |
|
inline |
|
static |
Get GameObject instance given its id.
id | GameObject id. |
|
static |
Get vector of GameObjects with the given name.
name | Name of the GameObjects. |
int hb::GameObject::getId | ( | ) | const |
Get the GameObject's id.
const std::string& hb::GameObject::getName | ( | ) | const |
Get the GameObject's name.
bool hb::GameObject::isActive | ( | ) | const |
Get if GameObject is active.
void hb::GameObject::setActive | ( | bool | active | ) |
Set if GameObject is active.
active | Is GameObject active. |
|
static |
Set next GameObject id.
id | Next GameObject id |
The auto-increment of the GameObject unique id will start from id after this is set.