A container for GameObject instances. More...
#include <GameObjectContainer.h>
Public Types | |
using | Callback = std::function< void(Args...)> |
For each callback. More... | |
using | Predicate = std::function< bool(const GameObject *)> |
Predicate callback. More... | |
using | ObjectPtr = std::unique_ptr< GameObject > |
Unique Object pointer. More... | |
Public Member Functions | |
GameObjectContainer (RenderLayerContainer &renderLayers) | |
Constructor. More... | |
GameObject * | add (GameObject::Ptr gameObject, int renderOrder=0u, const std::string &renderLayer="default") |
Add a game object to the container. More... | |
template<typename T > | |
T * | add (GameObject::Ptr gameObject, int renderOrder=0u, const std::string &renderLayer="default") |
Add a game object to the container. More... | |
GameObject * | add (const std::string &group, GameObject::Ptr gameObject, int renderOrder=0u, const std::string &renderLayer="default") |
Add a game object to a group in the container. More... | |
GameObject * | addObject (ObjectPtr object, const std::string &group="none") |
Add an object to the container. More... | |
GameObject * | findByTag (const std::string &tag) |
Get an object with a given tag. More... | |
const GameObject * | findByTag (const std::string &tag) const |
U * | findByTag (const std::string &tag) |
Get an object with a given tag. More... | |
const U * | findByTag (const std::string &tag) const |
GameObject * | findById (unsigned int id) |
Get an object with the given id. More... | |
const GameObject * | findById (unsigned int id) const |
U * | findById (unsigned int id) |
Get an object with the given id. More... | |
const U * | findById (unsigned int id) const |
GameObject * | findIf (const Predicate &predicate) |
Conditionally find an object in the container. More... | |
const GameObject * | findIf (const Predicate &predicate) const |
void | removeByTag (const std::string &tag) |
Remove all objects with the given tag. More... | |
void | removeById (unsigned int id) |
Remove an object with the given id. More... | |
bool | remove (GameObject *object) |
Remove an object from the container. More... | |
void | removeIf (const Predicate &predicate) |
Conditionally remove objects from the container. More... | |
void | removeAll () |
Remove all objects from the container. More... | |
std::size_t | getCount () const |
Get the number of objects in the container. More... | |
ObjectContainer< GameObject > & | createGroup (const std::string &name) |
Create a group to add objects to. More... | |
ObjectContainer< GameObject > & | getGroup (const std::string &name) const |
Get a group in the container. More... | |
bool | hasGroup (const std::string &name) const |
Check whether or not the container has a given group. More... | |
bool | removeGroup (const std::string &name) |
Remove a group from the container. More... | |
void | removeAllGroups () |
Remove all groups from the container. More... | |
void | forEach (const Callback< GameObject * > &callback) const |
Apply a callback function to each object in the container. More... | |
void | forEachInGroup (const std::string &name, const Callback< GameObject * > &callback) const |
Apply a callback to each object in a specific group. More... | |
void | forEachInGroups (const std::initializer_list< std::string > &groups, const Callback< GameObject * > &callback) const |
Apply a callback to each object in specific groups. More... | |
void | forEachNotInGroup (const Callback< GameObject * > &callback) const |
Apply a callback to all objects that do not belong to a group. More... | |
A container for GameObject instances.
Definition at line 37 of file GameObjectContainer.h.
|
inherited |
For each callback.
Definition at line 44 of file ObjectContainer.h.
|
inherited |
Unique Object pointer.
Definition at line 47 of file ObjectContainer.h.
|
inherited |
Predicate callback.
Definition at line 46 of file ObjectContainer.h.
|
explicit |
Constructor.
renderLayers | The render layer container for |
GameObject * ime::GameObjectContainer::add | ( | const std::string & | group, |
GameObject::Ptr | gameObject, | ||
int | renderOrder = 0u , |
||
const std::string & | renderLayer = "default" |
||
) |
Add a game object to a group in the container.
group | The group to assign the game object to |
gameObject | The game object to be added |
renderOrder | The render order of the game object |
renderLayer | The render layer the game object belongs to |
GameObject * ime::GameObjectContainer::add | ( | GameObject::Ptr | gameObject, |
int | renderOrder = 0u , |
||
const std::string & | renderLayer = "default" |
||
) |
Add a game object to the container.
gameObject | The game object to be added |
renderOrder | The render order of the game object |
renderLayer | The render layer the game object belongs to |
If the render layer is unspecified or the specified layer cannot be found then the game object will be added to the default layer. The default layer is created by the Scene when you instantiate it. Note that the default layer may be deleted from the scenes render layers, however you must make sure that the layer you specify during a call to this function already exists otherwise undefined behavior
|
inline |
Add a game object to the container.
gameObject | The game object to be added |
renderOrder | The render order of the game object |
renderLayer | The render layer the game object belongs to |
If the render layer is unspecified or the specified layer cannot be found then the game object will be added to the default layer. The default layer is created by the Scene when you instantiate it. Note that the default layer may be deleted from the scenes render layers, however you must make sure that the layer you specify during a call to this function already exists otherwise undefined behavior
Definition at line 80 of file GameObjectContainer.h.
|
inherited |
Add an object to the container.
object | The object to be added |
group | The name of the group to add the object to |
If the group is not found, it will be created and the object will be the first member of it. Groups are useful if you want to refer to objects that are the same or similar as a whole
By default the object does not belong to any group
|
inherited |
Create a group to add objects to.
name | The name of the group |
This function is useful if you want to relate some objects and refer to them as a whole using a common group name instead of using a common tag name and looping though the container to find which objects have a given tag. Note that the name of the group must be unique
|
inherited |
Get an object with the given id.
id | The id of the object to be retrieved |
|
inherited |
Get an object with the given id.
id | The id of the object to be retrieved |
You can use this function to get the derived class type U if T is a base class
|
inherited |
Get an object with a given tag.
tag | The tag of the object to be searched |
Note that this function will return the first object it finds with the the given tag if the container has multiple objects with the same tag
|
inherited |
Get an object with a given tag.
tag | The tag of the object to be searched |
Note that this function will return the first object it finds with the the given tag if the container has multiple objects with the same tag. You can use this function to get the derived class type U if T is a base class:
|
inherited |
Conditionally find an object in the container.
predicate | A function which returns true if the object should be returned or false if the search should continue |
|
inherited |
Apply a callback function to each object in the container.
callback | The function to be applied to each object |
Note that the callback is applied to all objects, this includes those that are assigned to groups
|
inherited |
Apply a callback to each object in a specific group.
name | The name of the group to apply callback on |
callback | The function to be applied to each object in the group |
This function is a shortcut for:
|
inherited |
Apply a callback to each object in specific groups.
groups | The name of the groups to apply the callback on |
callback | The function to be applied to each object in the groups |
For example, the following code deactivates all the game objects in the groups "bombs" and "guns":
|
inherited |
Apply a callback to all objects that do not belong to a group.
callback | The function to be applied to each object in the container that does not belong to any group |
|
inherited |
Get the number of objects in the container.
|
inherited |
Get a group in the container.
name | The name of the group |
|
inherited |
Check whether or not the container has a given group.
name | The name of the group to be checked |
|
inherited |
Remove an object from the container.
object | The object to be removed |
|
inherited |
Remove all objects from the container.
|
inherited |
Remove all groups from the container.
This function will remove all objects that belong to a group from the container, leaving only objects that do not belong to a group if any. Note that pointers to the removed objects will be invalidated
|
inherited |
Remove an object with the given id.
id | The id of the object to be removed |
|
inherited |
Remove all objects with the given tag.
tag | The tag of the objects to be removed |
|
inherited |
Remove a group from the container.
name | The name of the group to be removed |
|
inherited |
Conditionally remove objects from the container.
predicate | A function which returns true if the object should be removed or false if it should not be removed from the container |
Note that this function will remove all objects for which the predicate return true