ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::ECS::Nexus Class Reference

the Nexus is the brain of the ECS world. It is the object the user will use to interact with everything ECS related within systems. More...

#include <Imago/ECS/Nexus.hpp>

Public Member Functions

 Nexus ()
 Construct a new Nexus object and instantiates the command buffer.
 Nexus (const Nexus &)=delete
Nexus & operator= (const Nexus &)=delete
 Nexus (Nexus &&)=delete
Nexus & operator= (Nexus &&)=delete
Entity create ()
 Creates a new Entity.
void destroy (Entity e)
 Destroys an Entity and removes it from every component pool it is in.
bool is_valid (Entity e) const
 Checks whether an Entity is still valid.
template<typename T>
void bind (Entity e, T component)
 Binds a component of type T to Entity e.
template<typename T>
void unbind (Entity e)
 Unbinds a component of type T from Entity e if possible.
template<typename T>
void patch (Entity e, T component)
 Overwrites an Entity's existing component of type T with new component data.
template<typename T>
T & get (Entity e)
 Returns a reference to the Entity's component of type T.
template<typename T>
T * try_to_get (Entity e)
 Returns a reference to the Entity's component of type T if it has it and nullptr otherwise.
template<typename T>
bool has (Entity e)
 Check whether an Entity currently has a component of type T.
template<typename... Components>
SurveyHandle< Components... > survey ()
 Returns a survey of the specified components.
template<typename... Components>
BondHandle< Components... > bond ()
 Does one of three things depending on the current state of Bonds already in the Nexus:
void flush ()
 calls _commandBuffer.flush() to call the immediate methods that actually apply the deferred changes that the CommandBuffer is storing

Friends

class CommandBuffer

Detailed Description

the Nexus is the brain of the ECS world. It is the object the user will use to interact with everything ECS related within systems.

It handles:

  • creating/destroying entities
  • binding/unbinding components
  • returning and creating bonds and surveys

Member Function Documentation

◆ bind()

template<typename T>
void Imago::ECS::Nexus::bind ( Entity e,
T component )

Binds a component of type T to Entity e.

  • Bind<T>(e, component) creates or fetches a pool for component type T depending on if it already exists or not.
  • Binding a component to an Entity that already has that component will flag a warning and do nothing, replacing component data must be done through Patch<T>()
  • This is a structual change so it is automatically routed to the command buffer and the change is actually made in bind_immediate at the end of the current frame.
Template Parameters
TThe component type to bind.
Parameters
eThe entity to bind the component to.
componentThe actual component data to bind

◆ bond()

template<typename... Components>
BondHandle< Components... > Imago::ECS::Nexus::bond ( )

Does one of three things depending on the current state of Bonds already in the Nexus:

  • Returns a BondHandle (a view of the Bond) if one already exists for the components
  • Creates a Bond if possible for those components and returns its BondHandle
  • Asserts in debug or std::aborts in release if a Bond cannot be created for those component types
Template Parameters
Componentsto Bond
Returns
The BondHandle of bonded components

◆ create()

Entity Imago::ECS::Nexus::create ( )

Creates a new Entity.

Returns
The Entity packed uint32_t that was just created

◆ destroy()

void Imago::ECS::Nexus::destroy ( Entity e)

Destroys an Entity and removes it from every component pool it is in.

This is a structual change so it is automatically routed to the command buffer and the change is actually made in destroy_immediate at the end of the current frame.

Parameters
eThe Entity to destroy

◆ get()

template<typename T>
T & Imago::ECS::Nexus::get ( Entity e)

Returns a reference to the Entity's component of type T.

Get<T>(e) assumes e has that component type and should be used only in Surveys/Bonds where the entity is already guaranteed to have that component. See try_to_get<T>(e) for a safer version

Template Parameters
TThe component type to return
Parameters
eThe entity whose component to return

◆ has()

template<typename T>
bool Imago::ECS::Nexus::has ( Entity e)

Check whether an Entity currently has a component of type T.

Template Parameters
TThe component type to check for.
Parameters
eThe Entity to check for the component.
Returns
Whether or not the Entity has the component

◆ is_valid()

bool Imago::ECS::Nexus::is_valid ( Entity e) const

Checks whether an Entity is still valid.

Parameters
eThe Entity to check
Returns
whether or not the Entity is valid

◆ patch()

template<typename T>
void Imago::ECS::Nexus::patch ( Entity e,
T component )

Overwrites an Entity's existing component of type T with new component data.

The Entity must already have this component bound. See Bind<T>() for adding a brand new component

Template Parameters
TThe component type to patch.
Parameters
eThe Entity whose component to patch.
componentThe actual new component data.

◆ survey()

template<typename... Components>
SurveyHandle< Components... > Imago::ECS::Nexus::survey ( )

Returns a survey of the specified components.

Template Parameters
Componentsto survey
Returns
The SurveyHandle of the queried components

◆ try_to_get()

template<typename T>
T * Imago::ECS::Nexus::try_to_get ( Entity e)

Returns a reference to the Entity's component of type T if it has it and nullptr otherwise.

Template Parameters
TThe component type to return
Parameters
eThe Entity whose component to return
Returns
Pointer to the component if the Entity has the component
nullptr if the Entity does not have the component

◆ unbind()

template<typename T>
void Imago::ECS::Nexus::unbind ( Entity e)

Unbinds a component of type T from Entity e if possible.

This is a structual change so it is automatically routed to the command buffer and the change is actually made in unbind_immediate at the end of the current frame.

Template Parameters
TThe component type to unbind.
Parameters
eThe entity to unbind the component from.

The documentation for this class was generated from the following files:
  • engine/include/Imago/ECS/Nexus.hpp
  • engine/src/ECS/Nexus.cpp