viotecs 1.1.0
Loading...
Searching...
No Matches
viotecs::World Class Reference

World class. More...

#include <world.hpp>

Public Member Functions

 World ()=delete
 

Static Public Member Functions

static void init ()
 Initialize the world.
 
static void destroy ()
 Delete the world.
 
static void tick ()
 Tick the world.
 
static std::set< EntityId > * get_entities ()
 Get the entities container.
 
static UMap< TypeId, Resource > * get_resources ()
 Get the resources container.
 
static UMapVec< TypeId, Component > * get_components ()
 Get the components container.
 
static Entity new_entity ()
 Create a new entity.
 
template<typename R >
static Rget_resource ()
 Get a pointer to a resource.
 
template<typename C , typename... Args>
static void add_component (EntityId e, Args &&... args)
 Add a component to an entity.
 
template<typename R >
static void add_resource (R resource)
 Add a resource to the world.
 
static void remove_entity (EntityId e)
 Remove an entity.
 
template<typename R >
static void remove_resource ()
 Remove a resource.
 
template<typename C >
static Centity_to_component (EntityId e)
 Get the component of an entity.
 
template<typename... S>
static void register_systems ()
 

Static Public Attributes

static std::function< void()> run_systems
 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 66 of file world.hpp.

Constructor & Destructor Documentation

◆ World()

viotecs::World::World ( )
delete

Member Function Documentation

◆ add_component()

template<typename C , typename... Args>
static void viotecs::World::add_component ( EntityId  e,
Args &&...  args 
)
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
argsThe argument to construct the component

Example:

World::add_component<Position>(entity, 0, 0, 0);

Definition at line 162 of file world.hpp.

◆ add_resource()

template<typename R >
static void viotecs::World::add_resource ( R  resource)
inlinestatic

Add a resource to the world.

This method adds a resource to the world.

Example:

World::add_resource<shader_res>(shader);
constexpr TypeId type_id
Definition world.hpp:57

Definition at line 195 of file world.hpp.

◆ destroy()

static void viotecs::World::destroy ( )
static

Delete the world.

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

◆ entity_to_component()

template<typename C >
static C * viotecs::World::entity_to_component ( EntityId  e)
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::entity_to_component<PositionComponent>(e);

Definition at line 264 of file world.hpp.

◆ get_components()

static UMapVec< TypeId, Component > * viotecs::World::get_components ( )
static

Get the components container.

Returns
The components container, may be nullptr if not found

◆ get_entities()

static std::set< EntityId > * viotecs::World::get_entities ( )
static

Get the entities container.

Returns
The entities container, may be nullptr if not found

◆ get_resource()

template<typename R >
static R * viotecs::World::get_resource ( )
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::get_resource<Shader>();

Definition at line 128 of file world.hpp.

◆ get_resources()

static UMap< TypeId, Resource > * viotecs::World::get_resources ( )
static

Get the resources container.

Returns
The resources container, may be nullptr if not found

◆ init()

static void viotecs::World::init ( )
static

Initialize the world.

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

◆ new_entity()

static Entity viotecs::World::new_entity ( )
static

Create a new entity.

Returns
The new entity

◆ register_systems()

template<typename... S>
static void viotecs::World::register_systems ( )
inlinestatic

Definition at line 295 of file world.hpp.

◆ remove_entity()

static void viotecs::World::remove_entity ( EntityId  e)
static

Remove an entity.

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

Parameters
entityThe entity to remove

Example:

static void remove_entity(EntityId e)
Remove an entity.

◆ remove_resource()

template<typename R >
static void viotecs::World::remove_resource ( )
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 233 of file world.hpp.

◆ tick()

static void viotecs::World::tick ( )
static

Tick the world.

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

Field Documentation

◆ run_systems

std::function<void()> viotecs::World::run_systems
static

Run all systems.

This method runs all the systems in the world.

Definition at line 292 of file world.hpp.


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