antara::gaming::ecs¶
antara::gaming::ecs::system_manager¶
-
class
system_manager
¶ This class allows the manipulation of systems, the addition, deletion, update of systems, deactivation of a system, etc.
Public Functions
-
system_manager
(entt::registry ®istry, bool subscribe_to_internal_events = true)¶ Constructor.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager mgr{entity_registry}; }
- Parameters
registry
: The entity_registry is provided to the system when it is created.subscribe_to_internal_events
: Choose whether to subscribe to default system_manager eventsNote
Principal Constructor.
-
~system_manager
()¶ Destructor.
-
void
receive_add_base_system
(const ecs::event::add_base_system &evt)¶ Public member functions.
- Parameters
evt
: The event that contains the system to add
-
void
start
()¶ This function tells the system manager that you start your game.
Note
This function, which indicates the game is spinning, allows actions to be done at each end of the frame like delete systems or add them while
we are going to iterate on
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; system_manager.start(); return 0; }
-
std::size_t
update
()¶ Note
This is the function that update your systems.
Based on the logic of the different kinds of antara systems, this function takes care of updating your systems in the right order.Warning
If you have not loaded any system into the system_manager the function returns 0.
If you decide to mark a system, it’s automatically deleted at the end of the current loop tick through this function.
If you decide to add a system through an ecs::event::add_base_system event, it’s automatically added at the end of the current loop tickthrough this function.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; system_manager.start(); // ... added 5 differents systems here std::size_t nb_systems_updated = system_manager.update(); if (nb_systems_updated != 5) { // Oh no, i expected 5 systems to be executed in this game loop tick } return 0; }
- Return
number of systems which are successfully updated
-
std::size_t
update_systems
(system_type system_type_to_update)¶ Note
This function is called multiple times by update().
It is useful if you want to program your own update function without going through the one provided by us.- Return
number of systems which are successfully updated
- See
- Parameters
system_type_to_update
: kind of systems to update (pre_update, logic_update, post_update)
-
template<typename
TSystem
>
const TSystem &get_system
() const¶ This function allows you to get a system through a template parameter.
- Return
A reference to the system obtained.
- Template Parameters
TSystem
: represents the system to get.
-
template<typename
TSystem
>
TSystem &get_system
()¶ This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; system_manager.start(); // ... added 2 differents systems here (render_system, and a log_system) auto& render_system = system_manager.get_system<game::render_system>(); const auto& log_system = system_manager.get_system<game::log_system>(); return 0; }
-
template<typename ...
TSystems
>
std::tuple<std::add_lvalue_reference_t<TSystems>...>get_systems
()¶ This function allow you to get multiple system through multiple templates parameters.
Note
This function recursively calls the get_system function Based on the logic of the different kinds of antara systems, this function takes care of updating your systems in the right order.
- Return
Tuple of systems obtained.
- See
- Template Parameters
TSystems
: represents a list of systems to get
-
template<typename ...
TSystems
>
std::tuple<std::add_lvalue_reference_t<std::add_const_t<TSystems>>...>get_systems
() const¶ const version overload of get_systems
Note
This function is marked as nodiscard.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; // ... added differents systems here // 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>(); return 0; }
- See
-
template<typename
TSystem
>
boolhas_system
() const¶ This function allow you to verify if a system is already registered in the system_manager.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.has_system<my_game::render_system>(); if (!result) { // Oh no, i don't have a rendering system. } return 0; }
- Template Parameters
TSystem
: Represents the system that needs to be verifiedNote
This function is marked as nodiscard.
- Return
true if the system has been loaded, false otherwise
-
template<typename ...
TSystems
>
boolhas_systems
() const¶ This function allow you to verify if a list of systems is already registered in the system_manager.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.has_systems<my_game::render_system, my_game::input_systems>(); if (!result) { // Oh no, atleast one of the systems is not present } return 0; }
- See
Note
This function is marked as nodiscard.
This function recursively calls the has_system function.- Template Parameters
TSystems
: represents a list of system that needs to be verified
- Return
true if the list of systems has been loaded, false otherwise
-
template<typename
TSystem
>
boolmark_system
()¶ This function marks a system that will be destroyed at the next tick of the game loop.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; 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 ? } return 0; }
- Template Parameters
TSystem
: Represents the system that needs to be marked
- Return
true if the system has been marked, false otherwise
-
template<typename ...
TSystems
>
boolmark_systems
()¶ This function marks a list of systems, marked systems will be destroyed at the next tick of the game loop.
Note
This function is marked as nodiscard.
This function recursively calls the mark_system function.- Template Parameters
TSystems
: Represents a list of systems that needs to be marked
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.mark_systems<my_game::render, my_game::input>(); if (!result) { // Oh no, atleast one of the system has not been marked. // Did you mark a system that is not present in the system_manager ? } return 0; }
- Return
true if the list of systems has been marked, false otherwise
- See
-
template<typename
TSystem
>
boolenable_system
()¶ This function enable a system.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.enable_system<my_game::input>(); if (!result) { // Oh no, this system cannot be enabled. // Did you enable a system that is not present in the system_manager ? } return 0; }
- Template Parameters
TSystem
: Represents the system that needs to be enabled.
- Return
true if the system has been enabled, false otherwise
-
template<typename ...
TSystems
>
boolenable_systems
()¶ This function enable a list of systems.
Note
This function recursively calls the enable_system function
- Template Parameters
TSystems
: Represents a list of systems that needs to be enabled
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.enable_systems<my_game::input, my_game::render>(); if (!result) { // Oh no, atleast one of the requested systems cannot be enabled. } return 0; }
- Return
true if the list of systems has been enabled, false otherwise
- See
-
template<typename
TSystem
>
booldisable_system
()¶ This function disable a system.
Warning
If you deactivate a system, it will not be destroyed but simply ignored during the game loop.
- Template Parameters
TSystem
: Represents the system that needs to be disabled
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.disable_system<my_game::input>(); if (!result) { // Oh no the system_manager cannot disable this system. } return 0; }
- Return
true if the the system has been disabled, false otherwise
-
template<typename ...
TSystems
>
booldisable_systems
()¶ This function disable a list of systems.
Note
This function recursively calls the disable_system function
- Template Parameters
TSystems
: Represents a list of systems that needs to be disabled
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; bool result = system_manager.disable_systems<my_game::input, my_game::render>(); if (!result) { // Oh no, atleast one of the requested systems cannot be disabled. } return 0; }
- Return
true if the list of systems has been disabled, false otherwise
-
std::size_t
nb_systems
() const¶ This function returns the number of systems registered in the system manager.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; // added 2 systems here auto nb_systems = system_manager.nb_systems(); if (nb_systems) { // Oh no, was expecting atleast 2 systems. } return 0; }
- Return
number of systems
-
std::size_t
nb_systems
(system_type sys_type) const¶ This function returns the system number of a certain type to register in the system manager.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; // added 2 systems of update type here auto nb_systems = system_manager.nb_systems(system_type::pre_update); if (nb_systems) { // Oh no, was expecting atleast 2 systems of pre_update type. } return 0; }
- Parameters
sys_type
: represent the type of systems.
- Return
number of systems of a specific type.
-
template<typename
TSystem
, typename ...TSystemArgs
>
TSystem &create_system
(TSystemArgs&&... args)¶ This function allow you to create a system with the given argument.
This function is a factory.
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; auto& foo_system = system_manager.create_system<my_system::foo>(); // you can send argument of the foo constructor here. foo_system.update(); return 0; }
- Template Parameters
TSystem
: represents the type of system to createTSystemArgs
: represents the arguments needed to construct the system to create
- Return
Returns a reference to the created system
-
template<typename
TSystem
, typename ...TSystemArgs
>
voidcreate_system_rt
(TSystemArgs&&... args)¶ TODO: Document it.
-
template<typename ...
TSystems
, typename ...TArgs
>
autoload_systems
(TArgs&&... args)¶ This function load a bunch os systems.
Note
This function recursively calls the create_system function
- Template Parameters
TSystems
: represents a list of systems to be loaded
Example:
#include <entt/entity/registry.hpp> #include <entt/dispatcher/dispatcher.hpp> #include <antara/gaming/ecs/system.manager.hpp> int main() { entt::registry entity_registry; entt::dispatcher& dispatcher{registry.set<entt::dispatcher>()}; antara::gaming::ecs::system_manager system_manager{entity_registry}; auto&& [foo_system, bar_system] = system_manager.load_systems<my_system::foo, my_system::bar>(); foo_system.update(); bar_system.update(); return 0; }
- Return
Tuple of systems loaded
- See
Private Types
-
using
clock
= std::chrono::steady_clock¶ Private typedefs.
sugar name for an chrono steady clock
-
using
system_ptr
= std::unique_ptr<base_system>¶ sugar name for a pointer to base_system
-
using
system_array
= std::vector<system_ptr>¶ sugar name for an array of system_ptr
-
using
system_registry
= std::array<system_array, system_type::size>¶ sugar name for a multidimensional array of system_array (pre_update, logic_update, post_update)
-
using
systems_queue
= std::queue<system_ptr>¶ sugar name for a queue of system pointer to add.
Private Functions
-
base_system &
add_system_
(system_ptr &&system, system_type sys_type)¶ Private member functions.
Private Members
-
entt::registry &
entity_registry_
¶ Private data members.
-
antara::gaming::ecs::system_type¶
-
enum
antara::gaming::ecs
::
system_type
¶ Enumeration that represents all possible system types in sdk gaming.
Values:
-
pre_update
¶ Represents a pre_update system.
-
logic_update
¶ Represents a logic system.
-
post_update
¶ Represents a post_update system.
-
size
¶ Represents the size of the enum.
-
-
using
antara::gaming::ecs
::
st_system_pre_update
= st::type<system_type, struct system_pre_update_tag>¶ strong_type relative to system_type::pre_update
-
using
antara::gaming::ecs
::
st_system_logic_update
= st::type<system_type, struct system_logic_update_tag>¶ strong_type relative to system_type::logic_update
-
using
antara::gaming::ecs
::
st_system_post_update
= st::type<system_type, struct system_post_update_tag>¶ strong_type relative to system_type::post_update