viotecs 1.0
|
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. | |
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.
|
delete |
|
inlinestatic |
Add a component to an entity.
This method adds a component to an entity. The component is copied and stored in the world.
C | The type of the component |
entity | The entity to add the component to |
new_component | The component to add |
Example:
|
inlinestatic |
|
static |
Delete the world.
This method deletes the world, freeing the entities, components, and resources containers, freeing the memory.
|
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.
C | The type of the component |
entity | The entity to get the component from |
Example:
Get the components container.
|
static |
Get the entities container.
|
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.
R | The type of the resource |
Example:
Get the resources container.
|
static |
Initialize the world.
This method initializes the world, creating the entities, components, and resources containers.
|
static |
Create a new entity.
|
static |
Remove an entity.
This method removes an entity from the world, deleting all its components.
entity | The entity to remove |
Example:
|
inlinestatic |
|
static |
Run all systems.
This method runs all the systems in the world.
|
static |
Tick the world.
This method ticks the world, calling each system in the world.