xyginext  0.2.0
Second generation of xygine game creation framework
Public Member Functions | List of all members
xy::CallbackSystem Class Referencefinal

Performs a given callback function on an entity. This is useful for behaviour code on entities which aren't used often. For example when a single entity of a type exists and is used rarely it can mean a lot of overhead writing a specific system and component for behaviour which is not often employed. In these cases it's easier to attach a Callback component and supply a function with entity specific behaviour. Overuse of this system is not recommended, however, as there is a certain amount of overhead in calling the behavioural functions, so this system should be reserved for specific cases where it makes sense or for rapid prototying of ideas that may or may not be expanded to a full system. More...

#include <CallbackSystem.hpp>

Inheritance diagram for xy::CallbackSystem:
xy::System

Public Member Functions

 CallbackSystem (MessageBus &)
 
void process (float) override
 Implement this for system specific processing to entities.
 
- Public Member Functions inherited from xy::System
 System (MessageBus &mb, UniqueType t)
 Constructor. Pass in a reference to the concrete implementation to generate a unique type ID for this system.
 
UniqueType getType () const
 Returns the unique type ID of the system.
 
const std::vector< Entity > & getEntities () const
 Returns a list of entities that this system is currently interested in.
 
void addEntity (Entity)
 Adds an entity to the list to process.
 
void removeEntity (Entity)
 Removes an entity from the list to process.
 
const ComponentMask & getComponentMask () const
 Returns the component mask used to mask entities with corresponding components for this system to process.
 
virtual void handleMessage (const Message &)
 Used to process any incoming system messages.
 
bool isActive () const
 Returns true if the system is currently active. Systems can be activeated and deactivated with Scene::setSystemActive()
 
template<typename T >
void requireComponent ()
 
template<typename T >
T * postMessage (Message::ID id)
 

Additional Inherited Members

- Public Types inherited from xy::System
using Ptr = std::unique_ptr< System >
 
- Protected Member Functions inherited from xy::System
template<typename T >
void requireComponent ()
 Adds a component type to the list of components required by the system for it to be interested in a particular entity. This should only be used in the constructor of the System else types will not be registered.
 
std::vector< Entity > & getEntities ()
 
virtual void onEntityAdded (Entity)
 Optional callback performed when an entity is added.
 
virtual void onEntityRemoved (Entity)
 Optional callback performed when an entity is removed.
 
template<typename T >
T * postMessage (Message::ID id)
 Posts a message on the system wide message bus.
 
MessageBusgetMessageBus ()
 Returns a reference to the MessageBus.
 
void setScene (Scene &)
 
ScenegetScene ()
 Returns a pointer to the scene to which this system belongs.
 

Detailed Description

Performs a given callback function on an entity. This is useful for behaviour code on entities which aren't used often. For example when a single entity of a type exists and is used rarely it can mean a lot of overhead writing a specific system and component for behaviour which is not often employed. In these cases it's easier to attach a Callback component and supply a function with entity specific behaviour. Overuse of this system is not recommended, however, as there is a certain amount of overhead in calling the behavioural functions, so this system should be reserved for specific cases where it makes sense or for rapid prototying of ideas that may or may not be expanded to a full system.