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.
How do the system works ?
Systems
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.
This game loop is based on the gafferon on games tutorial: Fix your timestep.
Diagram
system_type
Description
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.
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.
// Called from a const contextauto[system_foo, system_bar] =system_manager.get_systems<system_foo, system_bar>();// Called from a non const contextauto[system_foo_nc, system_bar_nc] =system_manager.get_systems<system_foo, system_bar>();// Get it as a tupleauto tuple_systems =system_manager.get_systems<system_foo, system_bar>();
This function recursively calls the get_system function
represents a list of systems that needs to be verified
Return value
Possible name
Description
result
boolean
true if the list of systems has been loaded
false otherwise
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}
This function recursively calls the has_system function
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.
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?}
represents a list of systems that needs to be enabled
Return value
Possible name
Description
result
boolean
true if the list of systems has been enabled
false otherwise
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.}
This function recursively calls the enable_system function
represents a list of systems that needs to be disabled
Return value
Possible name
Description
result
boolean
true if the list of systems has been disabled
false otherwise
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.}
This function recursively calls the disable_system function
(second overload) number of systems of a specific type
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);
load_plugins
boolload_plugins() noexcept;
Return value
Possible name
Description
result
boolean
true if all the plugins has been successfully loaded
false otherwise
Example
bool result =system_manager.load_plugins();if (!result) { // Oh no, atleast one of the plugins could not be loaded.}
Notes
This function allow you to load the plugins of the plugins_registry and create systems with the creator function of each plugins.
pointer to the base system which match this name, nullptr otherwise.
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.
base_system
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.
This function unmark the system, allows the prevention of a destruction in the next tick of the game loop by the system_manager.
is_marked
boolis_marked() constnoexcept
Return value
Possible name
Description
result
boolean
true if the system is marked
false otherwise
Example
auto& render_system =system_manager.get_system<my_game::render>();bool result =render_system.is_marked();if (!result) { //! render_system is not marked}
auto& render_system = system_manager.get_system<my_game::render>();
bool result = render_system.is_enabled();
if (!result) {
//! render_system is not enable
}
This function defines the system as a plugin, and therefore use more feature in runtime to work properly
By default this function is called on plugins.
is_a_plugin
bool is_a_plugin() const noexcept
Return value
Possible name
Description
result
boolean
true if the system is a plugin
false otherwise
Example
auto& render_system = system_manager.get_system<my_game::render>();
bool result = render_system.is_a_plugin();
if (!result) {
//! render_system is not a plugin
}
get_user_data
void *get_user_data() noexcept;
Return value
Possible name
Description
data
void *
user data of a system (nullptr by default)
Example
auto render_system = system_manager_.get_system_by_name("render_system", shiva::ecs::system_type::post_update);
auto input_system = system_manager_.get_system_by_name("input_system", shiva::ecs::system_type::pre_update);
input_system->set_user_data(render_system->get_user_data());
This function retrieve a user data previously set by set_user_data
by default a user_data is a void pointer equal to nullptr.
auto sys_type = shiva::lua_system::get_system_type();
if (sys_type == shiva::ecs::system_type::logic_update) {
//! Do things.
}
auto render_system = system_manager_.get_system_by_name("render_system", shiva::ecs::system_type::post_update);
sys_type = render_system.get_system_type_RTTI();
if (sys_type == shiva::ecs::system_type::post_update) {
//! Do things.
}
get_system_type_RTTI
system_type get_system_type_RTTI() const noexcept final