shiva::ecs
In this page you will find all the information you need on the ecs part of shiva, the api of the different classes, the game loop architecture.
Shiva has 3 different kinds of systems:
- PreUpdate: These systems are the first to be updated in the game loop, they are generally used to retrieve user input, or manage network events for example.
- LogicUpdate: These systems are the second to be updated in the game loop, they are generally used for game logic such as movement or collisions for example.
- PostUpdate: These systems are the last to be updated in the game loop, they are generally used for rendering or interpolation for example.
The pseudo code look like this:
function update()
{
user defined;
}
function update_systems_type(system_type)
{
for_each_systems;
call update();
}
function update_systems()
{
call update_systems_type(pre_logic);
while (frame_rate) {
call update_systems_type(logic);
}
call update_systems_type(post_logic);
return nb_systems_updated
}
GameLoop;
while (game_running) {
call update_systems
}
return game_return_value;

complete diagram

simple diagram
This file contains an enum representing the different types of systems presented previously, and three strong types, later used in template parameter by the system class.
Enum
Typedefs
enum system_type
{
pre_update = 0,
logic_update = 1,
post_update = 2,
size = 3,
};
using system_pre_update = NamedType<system_type,struct system_pre_update_tag>;
using system_post_update = NamedType<system_type, struct system_post_update_tag>;
using system_logic_update = NamedType<system_type, struct system_logic_update_tag>;
This class manage the systems of the entity component system. You are able to
add
, remove
, retrieve
, update
or delete
systems through it.
system_manager
Signature
Constructor
Functions
class system_manager;
explicit system_manager(entt::dispatcher &dispatcher,
entt::entity_registry ®istry,
plugins_registry_t &plugins_registry) noexcept;
Parameters
- entt::dispatcher The
dispatcher
will be provided to the system when it is created. - entt::entity_registry The
entity_registry
will be provided to the system when it is created.
Function Name | Description |
update the systems | |
get a single system | |
get multiple systems | |
check if a system is present | |
check if multiple systems are present | |
mark a single system | |
mark multiple systems | |
enable a single system | |
enable multiple systems | |
disable a single system | |
disable multiple systems | |
create a single system | |
create multiple systems | |
get the number of systems | |
load plugins and add it as systems | |
get a single system by his name |
size_t update() noexcept
Return value
Possible Name | Description |
nb_systems_updated | size_t
|
Example
size_t nb_systems_updated = system_manager.update();
if (nb_systems_updated != 5) {
/* Oh no, i was expected 5 systems to be executed in this game loop tick */
}
Notes
This is the function that updates your systems. Based on the logic of the different kinds of shiva systems, this function take care of updating your systems in the right order.
If you have not loaded any system into the system_manager the function return 0.
If you decide to mark a system, it will be automatically deleted at the next loop tick through this function.
template <typename TSystem>
const TSystem &get_system() const noexcept;
template <typename TSystem>
TSystem &get_system() noexcept;
Template parameters
Name | Description |
TSystem | TSystem
|
Return value
Possible name | Description |
render_system, log_system | TSystem &
const TSystem &
|
Example
//! Non const version
auto& render_system = system_manager.get_system<game::render_system>();
//! const version
const auto& log_system = system_manager.get_system<game::log_system>();
template <typename ...TSystems>
std::tuple<std::add_lvalue_reference_t<TSystems>...> get_systems() noexcept;
template <typename ...TSystems>
std::tuple<std::add_lvalue_reference_t<std::add_const_t<TSystems>>...> get_systems() const noexcept;
Template parameters
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
tuple_systems, [system_foo, system_bar] | Tuple<TSystems &>
Tuple<const TSystems &>
|
Example
// Called from a const context
auto[system_foo, system_bar] = system_manager.get_systems<system_foo, system_bar>();
// Called from a non const context
auto[system_foo_nc, system_bar_nc] = system_manager.get_systems<system_foo, system_bar>();
// Get it as a tuple
auto tuple_systems = system_manager.get_systems<system_foo, system_bar>();
template <typename TSystem>
bool has_system() const noexcept;
Template parameters
Name | Description |
TSystem | TSystem
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.has_system<my_game::render_system>();
if (!result) {
//! Oh no, i don't have a rendering system.
}
template <typename ... TSystems>
bool has_systems() const noexcept
Template parameters
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.has_systems<my_game::render_system,
my_game::audio_system>();
if (!result) {
//! Oh no, atleast one of the systems is not present
}
template <typename TSystem>
bool mark_system() noexcept
Template parameters
Name | Description |
TSystem | TSystem
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.mark_system<my_game::render>();
if (!result) {
//! Oh no the system has not been marked.
//! Did you mark a system that is not present in the system_manager?
}
This function marks a system that will be destroyed at the next tick of the game loop.
template <typename ... TSystems>
bool mark_systems() noexcept
Template parameters
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.mark_systems<my_game::render, my_game::audio>();
if (!result) {
//! Oh no, atleast one of the system has not been marked.
}
template <typename TSystem>
bool enable_system() noexcept
Template parameters
Name | Description |
TSystem | TSystem
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.enable_system<my_game::render>();
if (!result) {
//! Oh no, this system cannot be enabled.
//! Did you enable a system that is not present in the system_manager?
}
by default, a system is enabled.
template <typename ... TSystems>
bool enable_systems() noexcept
Template parameters
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
result | boolean
|
bool result = system_manager.enable_systems<my_game::render, my_game::audio>();
if (!result) {
//! Oh no, atleast one of the requested systems cannot be enabled.
}
template <typename TSystem>
bool disable_system() noexcept
Template parameters
Name | Description |
TSystem | TSystem
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.disable_system<my_game::render>();
if (!result) {
//! Oh no the system_manager cannot disable this system.
}
If you deactivate a system, it will not be destroyed but simply ignore during the game loop
template <typename ... TSystems>
bool disable_systems() noexcept
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.disable_systems<my_game::render, my_game::audio>();
if (!result) {
//! Oh no, atleast one of the requested systems cannot be disabled.
}
template <typename TSystem, typename ... TSystemArgs>
TSystem &create_system(TSystemArgs &&...args)
Name | Description |
TSystem | TSystem
|
args | TSystemArgs
|
Possible name | Description |
render_system | TSystem &
|
Example
auto& render_system = system_manager.create_system<my_game::render>(/* args */);
template <typename ...TSystems>
std::tuple<std::add_lvalue_reference_t<TSystems>...> load_systems() noexcept;
Template parameters
Name | Description |
TSystems | TSystems
|
Return value
Possible name | Description |
tuple_systems, [system_foo, system_bar] | Tuple<TSystem &>
|
Example
// Tuple packed
auto tuple_systems = system_manager.load_systems<system_foo, system_bar>();
// Tuple unpacked
auto [system_foo, system_bar] = system_manager.load_systems<system_foo, system_bar>();
size_t nb_systems() const noexcept;
size_t nb_systems(system_type sys_type) const noexcept;
Name | Description |
sys_type |
|
Possible name | Description |
nb_systems | size_t
|
Example
//! Retrieve the number of systems.
size_t nb_systems = system_manager.nb_systems();
//! Retrieve the number of systems by a specific system_type.
size_t nb_systems_logic = system_manager.nb_systems(shiva::ecs::system_type::logic_update);
bool load_plugins() noexcept;
Possible name | Description |
result | boolean
|
Example
bool result = system_manager.load_plugins();
if (!result) {
// Oh no, atleast one of the plugins could not be loaded.
}
This function allow you to load the plugins of the plugins_registry and create systems with the creator function of each plugins.
const base_system *get_system_by_name(std::string system_name,
shiva::ecs::system_type type) const noexcept;
base_system *get_system_by_name(std::string system_name,
shiva::ecs::system_type type) noexcept;
Name | Description |
system_name | string
|
type |
|
Return value
Possible name | Description |
render_system | base_system *
|
Example
base_system* render_system = system_manager.get_system_by_name("render_system", shiva::ecs::system_type::post_update);
if (render_system == nullptr) {
//! Oh no, could not get the system properly.
}
Notes
- This function allow you to get a system by his name, used for get a specific plugin for example.
This class is an abstract class, it is documented but is present only to make type-erasure of the class system which is templated
This class can be manipulated when using plugins to share data between them.
base class of shiva systems

base_system
Signature
Constructor
Functions
class base_system;
explicit base_system(entt::dispatcher &dispatcher,
entt::entity_registry &entity_registry,
const float &fixed_delta_time) noexcept
Function Name | Description |
update | Pure virtual function, must be overriden by the client.
update the system. |
get_name | Pure virtual function, must be overriden by the client.
get the system name. |
get_system_type_RTTI | Pure virtual function, override by the system class.
get the system type at runtime (for plugins). |
mark the system | |
unmark the system | |
check if the system is marked. | |
enable the system | |