Lums
Public Member Functions | List of all members
lm::GameObject< Derived, ComponentType > Class Template Reference

A composite class representing any object in a game. More...

#include <GameObject.hpp>

Public Member Functions

template<typename... Ts>
bool send (int slot, Ts...params)
 
template<typename... Ts>
bool send (const char *slot, Ts...params)
 
template<typename T >
T * recv (int slot)
 
template<typename T >
T * recv (const char *slot)
 
template<typename T , typename... Ts>
void attach (Ts...params)
 
template<typename T >
bool composed () const
 
template<typename T >
void detach ()
 
template<typename T >
T * get () const
 
template<typename... Ts>
void update (Ts...params)
 
template<typename... Ts>
void render (Ts...params)
 
template<typename... Ts>
void handleEvent (Ts...params)
 

Detailed Description

template<typename Derived, typename ComponentType>
class lm::GameObject< Derived, ComponentType >

A composite class representing any object in a game.

This class should be used as a CRTP.

Template Parameters
DerivedThe derived class, for CRTP
ComponentTypeThe derived component type

Member Function Documentation

template<typename Derived , typename ComponentType >
template<typename T , typename... Ts>
void lm::GameObject< Derived, ComponentType >::attach ( Ts...  params)
inline

Attach a new component to the game object It's undefined behavior to attach multiples instances of the same component.

Template Parameters
TThe component to create
TsConstructor parameter types
Parameters
paramsConstructor parameters
template<typename Derived , typename ComponentType >
template<typename T >
bool lm::GameObject< Derived, ComponentType >::composed ( ) const
inline

Check wether a component is attached to this object.

Template Parameters
TThe component type to check
Returns
True if the object holds a component of type T
template<typename Derived , typename ComponentType >
template<typename T >
void lm::GameObject< Derived, ComponentType >::detach ( )
inline

Detach the component of type T attached to this object. If there is no such component, do nothing.

Template Parameters
TThe component type
template<typename Derived , typename ComponentType >
template<typename T >
T* lm::GameObject< Derived, ComponentType >::get ( ) const
inline

Get a pointer to the component of type T attached to this object. If there is no such component, return nullptr.

Template Parameters
TThe component type.
Returns
A pointer to the component, or nullptr.
template<typename Derived , typename ComponentType >
template<typename... Ts>
void lm::GameObject< Derived, ComponentType >::handleEvent ( Ts...  params)
inline

Iterate over each component, and call handleEvent on them.

Template Parameters
TsParameter types
Parameters
paramsParameters
template<typename Derived , typename ComponentType >
template<typename T >
T* lm::GameObject< Derived, ComponentType >::recv ( int  slot)
inline

Get a response from a component

Template Parameters
Thereturn type
Parameters
slotThe slot to listen to.
Returns
A pointer to data, or nullptr.
template<typename Derived , typename ComponentType >
template<typename T >
T* lm::GameObject< Derived, ComponentType >::recv ( const char *  slot)
inline

Get a response from a component

Template Parameters
Thereturn type
Parameters
slotThe slot to listen to - it will be hashed at compile time if possible
Returns
A pointer to data, or nullptr.
template<typename Derived , typename ComponentType >
template<typename... Ts>
void lm::GameObject< Derived, ComponentType >::render ( Ts...  params)
inline

Iterate over each component, and call render on them.

Template Parameters
TsParameter types
Parameters
paramsParameters
template<typename Derived , typename ComponentType >
template<typename... Ts>
bool lm::GameObject< Derived, ComponentType >::send ( int  slot,
Ts...  params 
)
inline

Send a message to every components this GameObject holds

Template Parameters
TsUsed for type erasure
Parameters
slotThe destination slot
paramsParameters
Returns
True if the message was received by at least one component
template<typename Derived , typename ComponentType >
template<typename... Ts>
bool lm::GameObject< Derived, ComponentType >::send ( const char *  slot,
Ts...  params 
)
inline

Send a message to every components this GameObject holds

Template Parameters
TsUsed for type erasure
Parameters
slotThe destination slot - it will be hashed at compile time
paramsParameters
Returns
True if the message was received by at least one component
template<typename Derived , typename ComponentType >
template<typename... Ts>
void lm::GameObject< Derived, ComponentType >::update ( Ts...  params)
inline

Iterate over each component, and call update on them.

Template Parameters
TsParameter types
Parameters
paramsParameters

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