|
Engine²
Open-source game engine written in C++.
|
The core is the place where all the data of the engine is stored. It contains the registry (entities), the resources and the schedulers(+systems). It allows to manage entities so to create, delete them. It also allows to manage dependencies between schedulers. It also allows to aggregate plugins to it, and then plugins will be able to add resources and systems to the core. More...
#include <Core.hpp>
Public Types | |
| using | Registry = entt::basic_registry<Id> |
| The type of the registry used by the core. It is an alias for entt::basic_registry with Id as entity identifier. | |
Public Member Functions | |
| Core () | |
| Default constructor of the core. It will initialize the registry and the scheduler container. Some schedulers will be automatically registered like Startup, Update and Shutdown. | |
| ~Core () | |
| Destructor of the core. It will clear the registry and the scheduler container. | |
| Registry & | GetRegistry () |
| Get the entt::registry that contains all components. It should be used to update component through systems. | |
| const Registry & | GetRegistry () const |
| Get the entt::registry that contains all components. It should be used to update component through systems. | |
| Entity | CreateEntity () |
| Create an entity in the context of the registry. | |
| void | KillEntity (Id entity) |
| Kill an entity. It will remove all components from the entity. | |
| template<typename TResource> | |
| TResource & | RegisterResource (TResource &&resource) |
| Store a resource instance. | |
| template<typename TResource> | |
| TResource & | GetResource () |
| Get a reference of a resource. | |
| template<typename TResource> | |
| const TResource & | GetResource () const |
| Get a const reference of a resource. | |
| template<typename TResource> | |
| bool | HasResource () const |
| Check if a resource is registered in the core. | |
| template<typename TResource> | |
| void | DeleteResource () |
| Delete a resource from the core. | |
| template<CScheduler TScheduler, typename... Args> | |
| TScheduler & | RegisterScheduler (Args &&...args) |
| Add a new scheduler to the registry. | |
| template<CScheduler TScheduler> | |
| TScheduler & | GetScheduler () |
| Get a scheduler from the registry by its type. | |
| Scheduler::AScheduler & | GetScheduler (std::type_index id) |
| Get a scheduler from the registry by its type index. | |
| template<typename TSchedulerA, typename TSchedulerB> | |
| void | SetSchedulerBefore () |
| Sets the execution order of two schedulers, ensuring that TSchedulerA is executed before TSchedulerB. | |
| template<typename TSchedulerA, typename TSchedulerB> | |
| void | SetSchedulerAfter () |
| Sets the execution order of two schedulers by specifying that one scheduler should execute after another. | |
| template<typename TSchedulerA, typename TSchedulerB> | |
| void | RemoveDependencyAfter () |
| Removes a dependency between two schedulers, ensuring that TSchedulerB is no longer dependent on TSchedulerA. | |
| template<typename TSchedulerA, typename TSchedulerB> | |
| void | RemoveDependencyBefore () |
| Removes a dependency between two schedulers, ensuring that TSchedulerA is no longer dependent on TSchedulerB. | |
| bool | IsRunning () |
| Get the running state of the core. | |
| void | Stop () |
| Stop the core execution. It will finish the current loop, call shutdown systems if any and stop. | |
| void | RunCore () |
| Execute the core loop, which will run all the schedulers. | |
| template<CScheduler TScheduler, typename... Systems> | |
| decltype(auto) | RegisterSystem (Systems... systems) |
| Add one or multiple systems associated with a specific scheduler. | |
| template<typename... Systems> | |
| decltype(auto) | RegisterSystem (Systems... systems) |
| Add one or multiple systems associated to the default scheduler. | |
| template<CScheduler TScheduler, typename System, typename ErrorCallback> | |
| decltype(auto) | RegisterSystemWithErrorHandler (System system, ErrorCallback callback) |
| Add a system to a specific scheduler, associated with a callback that should run if the system fails (throw). | |
| template<typename System, typename ErrorCallback> | |
| decltype(auto) | RegisterSystemWithErrorHandler (System system, ErrorCallback callback) |
| Add a system to the default scheduler, associated with a callback that should run if the system fails (throw). | |
| template<CScheduler TScheduler> | |
| void | DeleteScheduler () |
| Deletes a scheduler. | |
| void | RunSystems () |
| Run all the systems once by calling each scheduler. | |
| bool | IsEntityValid (Id entity) const |
| Check if entity is valid in the context of the registry. It check if the id of the entity exist. | |
| template<CPlugin... TPlugins> | |
| void | AddPlugins () |
| Adds multiple plugins that will be call instantly through the Bind method to agregate their systems and resources to the core. | |
| template<CPlugin TPlugin> | |
| bool | HasPlugin () const |
| Checks if a plugin is present. | |
| bool | HasPlugin (std::type_index type) const |
| Checks if a plugin of the specified type is present. | |
| void | ClearEntities () |
| Clear all entities and components from the registry. | |
| template<CScheduler TScheduler> | |
| void | SetDefaultScheduler () |
| Sets the default scheduler. | |
| void | SetDefaultScheduler (std::type_index scheduler) |
| Sets the default scheduler. | |
| void | SetErrorPolicyForAllSchedulers (Scheduler::SchedulerErrorPolicy policy) |
| Sets the error policy for all schedulers. | |
Private Member Functions | |
| template<CPlugin TPlugin> | |
| void | AddPlugin () |
| Adds a plugin. | |
Private Attributes | |
| std::unique_ptr< Registry > | _registry |
| The registry that contains all components (and by definition, the entities). | |
| Engine::SchedulerContainer | _schedulers |
| The container that contains all the schedulers. | |
| std::type_index | _defaultScheduler = typeid(Engine::Scheduler::Update) |
| The default scheduler type index. It is used when adding systems without specifying a scheduler. | |
| std::vector< std::type_index > | _schedulersToDelete |
| The list of schedulers to delete at the end of the current loop. | |
| std::unordered_map< std::type_index, std::unique_ptr< IPlugin > > | _plugins |
| The plugins added to the core. | |
| bool | _running = false |
| The running state of the core. It is true if the core is running, false otherwise. It is used to stop the core loop. | |
The core is the place where all the data of the engine is stored. It contains the registry (entities), the resources and the schedulers(+systems). It allows to manage entities so to create, delete them. It also allows to manage dependencies between schedulers. It also allows to aggregate plugins to it, and then plugins will be able to add resources and systems to the core.
| using Engine::Core::Registry = entt::basic_registry<Id> |
The type of the registry used by the core. It is an alias for entt::basic_registry with Id as entity identifier.
| Engine::Core::Core | ( | ) |
Default constructor of the core. It will initialize the registry and the scheduler container. Some schedulers will be automatically registered like Startup, Update and Shutdown.
| Engine::Core::~Core | ( | ) |
Destructor of the core. It will clear the registry and the scheduler container.
|
private |
Adds a plugin.
| TPlugin | The type of the plugin to add. See Engine::CPlugin. |
| void Engine::Core::AddPlugins | ( | ) |
Adds multiple plugins that will be call instantly through the Bind method to agregate their systems and resources to the core.
| TPlugins | Types of the plugins to add. See Engine::CPlugin. |
| void Engine::Core::ClearEntities | ( | ) |
Clear all entities and components from the registry.
| Engine::Entity Engine::Core::CreateEntity | ( | ) |
Create an entity in the context of the registry.
|
inline |
Delete a resource from the core.
| TResource | type of the resource to delete |
| void Engine::Core::DeleteScheduler | ( | ) |
Deletes a scheduler.
| TScheduler | The type of scheduler to delete. See Engine::CScheduler. |
|
inline |
Get the entt::registry that contains all components. It should be used to update component through systems.
|
inline |
Get the entt::registry that contains all components. It should be used to update component through systems.
|
inline |
Get a reference of a resource.
| TResource | type of the resource to get |
|
inline |
Get a const reference of a resource.
| TResource | type of the resource to get |
|
inline |
Get a scheduler from the registry by its type.
| TScheduler | The type of scheduler to get. |
|
inline |
Get a scheduler from the registry by its type index.
| id | The type index of the scheduler to get. |
| bool Engine::Core::HasPlugin | ( | ) | const |
Checks if a plugin is present.
| TPlugin | The type of the plugin to check for. See Engine::CPlugin. |
| bool Engine::Core::HasPlugin | ( | std::type_index | type | ) | const |
Checks if a plugin of the specified type is present.
| type | The type of the plugin to check for. |
|
inline |
Check if a resource is registered in the core.
| TResource | type of the resource to check |
| bool Engine::Core::IsEntityValid | ( | Engine::Id | entity | ) | const |
Check if entity is valid in the context of the registry. It check if the id of the entity exist.
| bool Engine::Core::IsRunning | ( | ) |
Get the running state of the core.
| void Engine::Core::KillEntity | ( | Engine::Id | entity | ) |
Kill an entity. It will remove all components from the entity.
| entity | The entity to kill. |
|
inline |
Store a resource instance.
| TResource | type of the resource to add |
| resource | rvalue of the resource to add |
|
inline |
Add a new scheduler to the registry.
| TScheduler | The type of scheduler to use. |
| args | The scheduler to add. |
|
inline |
Add one or multiple systems associated to the default scheduler.
| Systems | The types of the systems to add. This is not a mandatory template parameter, you can add only the system variable and it will be deduced by the compiler. You can add as many systems as you want, they will be called in the order they were added. |
| systems | The systems to add. |
|
inline |
Add one or multiple systems associated with a specific scheduler.
| TScheduler | The type of the scheduler to use. It must be derived from AScheduler. You can look at CScheduler |
| Systems | The types of the systems to add. This is not a mandatory template parameter, you can add only the system variable and it will be deduced by the compiler. You can add as many systems as you want, they will be called in the order they were added. |
| systems | The systems to add. |
|
inline |
Add a system to the default scheduler, associated with a callback that should run if the system fails (throw).
| TScheduler | The type of scheduler to use. |
| system | The system to add. |
| callback | The callback to run if the system fails (throw). |
|
inline |
Add a system to a specific scheduler, associated with a callback that should run if the system fails (throw).
| TScheduler | The type of scheduler to use. It must be derived from AScheduler. See Engine::CScheduler. |
| system | The system to add. |
| callback | The callback to run if the system fails (throw). |
|
inline |
Removes a dependency between two schedulers, ensuring that TSchedulerB is no longer dependent on TSchedulerA.
| TSchedulerA | The type of the first scheduler (the one being depended on). |
| TSchedulerB | The type of the second scheduler (the one depending on TSchedulerA). |
|
inline |
Removes a dependency between two schedulers, ensuring that TSchedulerA is no longer dependent on TSchedulerB.
| TSchedulerA | The type of the first scheduler (the one depending on TSchedulerB). |
| TSchedulerB | The type of the second scheduler (the one being depended on). |
| void Engine::Core::RunCore | ( | ) |
Execute the core loop, which will run all the schedulers.
| void Engine::Core::RunSystems | ( | ) |
Run all the systems once by calling each scheduler.
|
inline |
Sets the default scheduler.
| TScheduler | The type of the scheduler to be set as default. See Engine::CScheduler. |
|
inline |
Sets the default scheduler.
| scheduler | The type index of the scheduler to be set as default. |
| void Engine::Core::SetErrorPolicyForAllSchedulers | ( | Scheduler::SchedulerErrorPolicy | policy | ) |
Sets the error policy for all schedulers.
| policy | The error policy to set for all schedulers. See Engine::Scheduler::SchedulerErrorPolicy. |
|
inline |
Sets the execution order of two schedulers by specifying that one scheduler should execute after another.
| TSchedulerA | The type of the scheduler that should execute first. |
| TSchedulerB | The type of the scheduler that should execute after TSchedulerA. |
|
inline |
Sets the execution order of two schedulers, ensuring that TSchedulerA is executed before TSchedulerB.
| TSchedulerA | The type of the scheduler that should execute first. |
| TSchedulerB | The type of the scheduler that should execute after TSchedulerA. |
| void Engine::Core::Stop | ( | ) |
Stop the core execution. It will finish the current loop, call shutdown systems if any and stop.
|
private |
The default scheduler type index. It is used when adding systems without specifying a scheduler.
|
private |
The plugins added to the core.
|
private |
The registry that contains all components (and by definition, the entities).
|
private |
The running state of the core. It is true if the core is running, false otherwise. It is used to stop the core loop.
|
private |
The container that contains all the schedulers.
|
private |
The list of schedulers to delete at the end of the current loop.