viotecs 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< entity_t > * get_entities ()
 Get the entities container.
 
static UMap< std::type_index, resource > * get_resources ()
 Get the resources container.
 
static UMapVec< std::type_index, component > * get_components ()
 Get the components container.
 
static entity_t new_entity ()
 Create a new entity.
 
template<typename R >
static R * get_resource ()
 Get a pointer to a resource.
 
template<typename C >
static void add_component (entity_t entity, C new_component)
 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 (entity_t entity)
 Remove an entity.
 
template<typename R >
static void remove_resource ()
 Remove a resource.
 
template<typename C >
static C * entity_to_component (entity_t entity)
 Get the component of an entity.
 
static 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 57 of file world.hpp.

Constructor & Destructor Documentation

◆ world()

viotecs::world::world ( )
delete

Member Function Documentation

◆ add_component()

template<typename C >
static void viotecs::world::add_component ( entity_t 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::add_component<position>(entity, {0, 0, 0});

Definition at line 155 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});

Definition at line 189 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 ( entity_t 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::entity_to_component<position_comp>(entity);
Component class.
Definition component.hpp:58

Definition at line 262 of file world.hpp.

◆ get_components()

static UMapVec< std::type_index, component > * viotecs::world::get_components ( )
static

Get the components container.

Returns
The components container

◆ get_entities()

static std::set< entity_t > * viotecs::world::get_entities ( )
static

Get the entities container.

Returns
The entities container

◆ 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>();
Resource type.
Definition resource.hpp:54

Definition at line 119 of file world.hpp.

◆ get_resources()

static UMap< std::type_index, resource > * viotecs::world::get_resources ( )
static

Get the resources container.

Returns
The resources container

◆ 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_t viotecs::world::new_entity ( )
static

Create a new entity.

Returns
The new entity

◆ remove_entity()

static void viotecs::world::remove_entity ( entity_t 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 remove_entity(entity_t entity)
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 229 of file world.hpp.

◆ run_systems()

static void viotecs::world::run_systems ( )
static

Run all systems.

This method runs all the systems in the world.

◆ tick()

static void viotecs::world::tick ( )
static

Tick the world.

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


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