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.
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.
The pseudo code look like this:
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.
system_type API
system_manager
Description
This class manage the systems of the entity component system. You are able to add
, remove
, retrieve
, update
or delete
systems through it.
Diagram
system_manager API
update
Return value
Possible Name
Description
nb_systems_updated
size_t
number of systems successfully updated
Example
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.
get_system
Template parameters
Name
Description
TSystem
TSystem
represents the type of system to get
Return value
Possible name
Description
render_system, log_system
TSystem &
a reference to the system obtained
const TSystem &
a const reference to the system obtained
Example
get_systems
Template parameters
Name
Description
TSystems
TSystems
represents a list of systems to get
Return value
Possible name
Description
tuple_systems, [system_foo, system_bar]
Tuple<TSystems &>
Tuple of systems obtained.
Tuple<const TSystems &>
Tuple of systems obtained (const ref)
Example
This function recursively calls the get_system function
has_system
Template parameters
Name
Description
TSystem
TSystem
represents the system that needs to be verified
Return value
Possible name
Description
result
boolean
true if the system has been loaded
false otherwise
Example
has_systems
Template parameters
Name
Description
TSystems
TSystems
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
This function recursively calls the has_system function
mark_system
Template parameters
Name
Description
TSystem
TSystem
represents the system that needs to be marked
Return value
Possible name
Description
result
boolean
true if the system has been marked
false otherwise
Example
This function marks a system that will be destroyed at the next tick of the game loop.
mark_systems
Template parameters
Name
Description
TSystems
TSystems
represents a list of systems that needs to be marked
Return value
Possible name
Description
result
boolean
true if the list of systems has been marked
false otherwise
Example
This function recursively calls the mark_system function
enable_system
Template parameters
Name
Description
TSystem
TSystem
represents the system that needs to be enabled
Return value
Possible name
Description
result
boolean
true if the system has been enabled
false otherwise
Example
by default, a system is enabled.
enable_systems
Template parameters
Name
Description
TSystems
TSystems
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
This function recursively calls the enable_system function
disable_system
Template parameters
Name
Description
TSystem
TSystem
represents the system that needs to be disabled
Return value
Possible name
Description
result
boolean
true if the the system has been disabled
false otherwise
Example
If you deactivate a system, it will not be destroyed but simply ignore during the game loop
disable_systems
Template parameters
Name
Description
TSystems
TSystems
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
This function recursively calls the disable_system function
create_system
Template parameters
Name
Description
TSystem
TSystem
represents the type of system to create
args
TSystemArgs
represents the arguments needed to construct the system to create
Return value
Possible name
Description
render_system
TSystem &
a reference to the created system
Example
load_systems
Template parameters
Name
Description
TSystems
TSystems
represents a list of systems to be loaded
Return value
Possible name
Description
tuple_systems, [system_foo, system_bar]
Tuple<TSystem &>
Tuple of systems loaded.
Example
nb_systems
Parameters
Name
Description
sys_type
represent the type of systems
Return value
Possible name
Description
nb_systems
size_t
(first overload) number of systems
(second overload) number of systems of a specific type
Example
load_plugins
Return value
Possible name
Description
result
boolean
true if all the plugins has been successfully loaded
false otherwise
Example
Notes
This function allow you to load the plugins of the plugins_registry and create systems with the creator function of each plugins.
get_system_by_name
Parameters
Name
Description
system_name
string
name of the system to get
type
system_type of the system to get
Return value
Possible name
Description
render_system
base_system *
pointer to the base system which match this name, nullptr otherwise.
Example
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.
Description
base class of shiva systems
Diagram
base_system API
mark
Example
This function marks the system, it will be destroyed in the next tick of the game loop by the system_manager.
unmark
Example
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
Return value
Possible name
Description
result
boolean
true if the system is marked
false otherwise
Example
enable
Example
disable
Example
Take a look @ disable_system
is_enabled
Return value
Possible name
Description
result
boolean
true if the system is enabled
false otherwise
Example
im_a_plugin
Example
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
Return value
Possible name
Description
result
boolean
true if the system is a plugin
false otherwise
Example
get_user_data
Return value
Possible name
Description
data
void *
user data of a system (nullptr by default)
Example
This function retrieve a user data previously set by set_user_data
by default a user_data is a void pointer equal to
nullptr
.
set_user_data
Parameters
Name
Description
data
void *
a void pointer representing the user data
Example
See the example above.
This function set a user data for this system
This function is very useful to transfer (with get_user_data) data between plugins since they are base_class.
This function wcall on_set_user_data callback at the epilogue, by default on_set_user_data is empty and you need to override it if you need it.
user should be aware here, that's manipulating void pointer is as your own risk.
system
Description
This class is the class that you have to inherit to create your systems
Diagram
system API
Template Parameters
TSystemDerived CRTP implementation of the system
TSystemType Strong type representing the system_type of the implemented system
This class is the class you will have to inherit to create your systems
get_system_type
Return value
Possible name
Description
sys_type
system_type
Example
get_system_type_RTTI
Return value
Possible name
Description
sys_type
system_type
Example
See the example above.
get_name
Return value
Possible name
Description
sys_name
string
name of the derived system.
Example
Last updated