Brenta Engine 1.0
Loading...
Searching...
No Matches
Brenta::ECS::World Class Reference

World class. More...

#include <world.hpp>

Static Public Member Functions

static void Init ()
 Initialize the world.
 
static void Delete ()
 Delete the world.
 
static void Tick ()
 Tick the world.
 
static std::set< Entity > * getEntities ()
 Get the entities container.
 
static UMap< std::type_index, Resource > * getResources ()
 Get the resources container.
 
static UMapVec< std::type_index, Component > * getComponents ()
 Get the components container.
 
static Entity NewEntity ()
 Create a new entity.
 
template<typename R >
static R * GetResource ()
 Get a pointer to a resource.
 
template<typename C >
static void AddComponent (Entity entity, C new_component)
 Add a component to an entity.
 
template<typename R >
static void AddResource (R resource)
 Add a resource to the world.
 
static void RemoveEntity (Entity entity)
 Remove an entity.
 
template<typename R >
static void RemoveResource ()
 Remove a resource.
 
template<typename C >
static C * EntityToComponent (Entity entity)
 Get the component of an entity.
 
static void RunSystems ()
 Run all systems.
 

Detailed Description

World class.

This class is a singleton that contains all the entities, components and systems in the game world, provides acces to them through queries and is responsible for updating the game world.

Definition at line 57 of file world.hpp.

Member Function Documentation

◆ AddComponent()

template<typename C >
static void Brenta::ECS::World::AddComponent ( Entity entity,
C new_component )
inlinestatic

Add a component to an entity.

This method adds a component to an entity. The component is copied and stored in the world.

Template Parameters
CThe type of the component
Parameters
entityThe entity to add the component to
new_componentThe component to add

Example:

World::AddComponent<Position>(entity, {0, 0, 0});

Definition at line 155 of file world.hpp.

◆ AddResource()

template<typename R >
static void Brenta::ECS::World::AddResource ( R resource)
inlinestatic

Add a resource to the world.

This method adds a resource to the world.

Example:

World::AddResource<Shader>({shader});

Definition at line 189 of file world.hpp.

◆ Delete()

void World::Delete ( )
static

Delete the world.

This method deletes the world, freeing the entities, components, and resources containers, freeing the memory.

Definition at line 55 of file world.cpp.

◆ EntityToComponent()

template<typename C >
static C * Brenta::ECS::World::EntityToComponent ( Entity entity)
inlinestatic

Get the component of an entity.

This method returns a pointer to the component of the specified type of the specified entity. If the component is not found, it returns nullptr.

Template Parameters
CThe type of the component
Parameters
entityThe entity to get the component from
Returns
A pointer to the component

Example:

auto component = World::EntityToComponent<Position>(entity);

Definition at line 262 of file world.hpp.

◆ getComponents()

UMapVec< std::type_index, Component > * World::getComponents ( )
static

Get the components container.

Returns
The components container

Definition at line 111 of file world.cpp.

◆ getEntities()

std::set< Entity > * World::getEntities ( )
static

Get the entities container.

Returns
The entities container

Definition at line 91 of file world.cpp.

◆ GetResource()

template<typename R >
static R * Brenta::ECS::World::GetResource ( )
inlinestatic

Get a pointer to a resource.

This method returns a pointer to a resource of the specified type. If the resource is not found, it returns nullptr.

Template Parameters
RThe type of the resource
Returns
A pointer to the resource

Example:

auto resource = World::GetResource<Shader>();

Definition at line 119 of file world.hpp.

◆ getResources()

UMap< std::type_index, Resource > * World::getResources ( )
static

Get the resources container.

Returns
The resources container

Definition at line 101 of file world.cpp.

◆ Init()

void World::Init ( )
static

Initialize the world.

This method initializes the world, creating the entities, components, and resources containers.

Definition at line 45 of file world.cpp.

◆ NewEntity()

Entity World::NewEntity ( )
static

Create a new entity.

Returns
The new entity

Definition at line 69 of file world.cpp.

◆ RemoveEntity()

void World::RemoveEntity ( Entity entity)
static

Remove an entity.

This method removes an entity from the world, deleting all its components.

Parameters
entityThe entity to remove

Example:

static void RemoveEntity(Entity entity)
Remove an entity.
Definition world.cpp:121

Definition at line 121 of file world.cpp.

◆ RemoveResource()

template<typename R >
static void Brenta::ECS::World::RemoveResource ( )
inlinestatic

Remove a resource.

This method removes a resource of the specified type from the world.

Template Parameters
RThe type of the resource

Example:

World::RemoveResource<Shader>();

Definition at line 229 of file world.hpp.

◆ RunSystems()

static void Brenta::ECS::World::RunSystems ( )
static

Run all systems.

This method runs all the systems in the world.

◆ Tick()

void World::Tick ( )
static

Tick the world.

This method ticks the world, calling each system in the world.

Definition at line 64 of file world.cpp.


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