Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Engine::Core Class Reference

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.
RegistryGetRegistry ()
 Get the entt::registry that contains all components. It should be used to update component through systems.
const RegistryGetRegistry () 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::ASchedulerGetScheduler (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.

Detailed Description

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.

Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/physics/src/system/ConstraintSystem.hpp, and /home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

Member Typedef Documentation

◆ Registry

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.

Constructor & Destructor Documentation

◆ Core()

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.

◆ ~Core()

Engine::Core::~Core ( )

Destructor of the core. It will clear the registry and the scheduler container.

Member Function Documentation

◆ AddPlugin()

template<CPlugin TPlugin>
void Engine::Core::AddPlugin ( )
private

Adds a plugin.

Template Parameters
TPluginThe type of the plugin to add. See Engine::CPlugin.

◆ AddPlugins()

template<CPlugin... TPlugins>
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.

Note
2 same plugins can't be added.
Template Parameters
TPluginsTypes of the plugins to add. See Engine::CPlugin.

◆ ClearEntities()

void Engine::Core::ClearEntities ( )

Clear all entities and components from the registry.

◆ CreateEntity()

Engine::Entity Engine::Core::CreateEntity ( )

Create an entity in the context of the registry.

Returns
The entity created.

◆ DeleteResource()

template<typename TResource>
void Engine::Core::DeleteResource ( )
inline

Delete a resource from the core.

Template Parameters
TResourcetype of the resource to delete

◆ DeleteScheduler()

template<CScheduler TScheduler>
void Engine::Core::DeleteScheduler ( )

Deletes a scheduler.

Template Parameters
TSchedulerThe type of scheduler to delete. See Engine::CScheduler.
Note
This function will not delete the scheduler immediately, but it will mark it for deletion. The scheduler will be deleted at the end of the current loop, after all systems have been executed.

◆ GetRegistry() [1/2]

Registry & Engine::Core::GetRegistry ( )
inline

Get the entt::registry that contains all components. It should be used to update component through systems.

Returns
registry that contains all components.
Todo
put the implementation in the cpp file, (remove inline)

◆ GetRegistry() [2/2]

const Registry & Engine::Core::GetRegistry ( ) const
inline

Get the entt::registry that contains all components. It should be used to update component through systems.

Returns
registry that contains all components.
Todo
put the implementation in the cpp file, (remove inline)

◆ GetResource() [1/2]

template<typename TResource>
TResource & Engine::Core::GetResource ( )
inline

Get a reference of a resource.

Template Parameters
TResourcetype of the resource to get
Returns
reference of the resource
Examples
/home/runner/work/EngineSquared/EngineSquared/src/plugin/sound/src/resource/SoundManager.hpp.

◆ GetResource() [2/2]

template<typename TResource>
const TResource & Engine::Core::GetResource ( ) const
inline

Get a const reference of a resource.

Template Parameters
TResourcetype of the resource to get
Returns
const reference of the resource

◆ GetScheduler() [1/2]

template<CScheduler TScheduler>
TScheduler & Engine::Core::GetScheduler ( )
inline

Get a scheduler from the registry by its type.

Template Parameters
TSchedulerThe type of scheduler to get.
Returns
The scheduler.

◆ GetScheduler() [2/2]

Scheduler::AScheduler & Engine::Core::GetScheduler ( std::type_index id)
inline

Get a scheduler from the registry by its type index.

Parameters
idThe type index of the scheduler to get.
Returns
The scheduler.

◆ HasPlugin() [1/2]

template<CPlugin TPlugin>
bool Engine::Core::HasPlugin ( ) const

Checks if a plugin is present.

Template Parameters
TPluginThe type of the plugin to check for. See Engine::CPlugin.
Returns
true if the plugin is present, false otherwise.

◆ HasPlugin() [2/2]

bool Engine::Core::HasPlugin ( std::type_index type) const

Checks if a plugin of the specified type is present.

Parameters
typeThe type of the plugin to check for.
Returns
true if the plugin is present, false otherwise.

◆ HasResource()

template<typename TResource>
bool Engine::Core::HasResource ( ) const
inline

Check if a resource is registered in the core.

Template Parameters
TResourcetype of the resource to check
Returns
Return true if the resource is registered, false otherwise

◆ IsEntityValid()

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.

Returns
true if the entity is valid, false otherwise.

◆ IsRunning()

bool Engine::Core::IsRunning ( )

Get the running state of the core.

Returns
The running state.

◆ KillEntity()

void Engine::Core::KillEntity ( Engine::Id entity)

Kill an entity. It will remove all components from the entity.

Parameters
entityThe entity to kill.

◆ RegisterResource()

template<typename TResource>
TResource & Engine::Core::RegisterResource ( TResource && resource)
inline

Store a resource instance.

Template Parameters
TResourcetype of the resource to add
Parameters
resourcervalue of the resource to add
Returns
reference of the added resource

◆ RegisterScheduler()

template<CScheduler TScheduler, typename... Args>
TScheduler & Engine::Core::RegisterScheduler ( Args &&... args)
inline

Add a new scheduler to the registry.

Template Parameters
TSchedulerThe type of scheduler to use.
Parameters
argsThe scheduler to add.

◆ RegisterSystem() [1/2]

template<typename... Systems>
decltype(auto) Engine::Core::RegisterSystem ( Systems... systems)
inline

Add one or multiple systems associated to the default scheduler.

Template Parameters
SystemsThe 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.
Parameters
systemsThe systems to add.
Returns
Return the identifiers of the systems added, in the same order as the systems were added.
See also
FunctionUtils::FunctionID.

◆ RegisterSystem() [2/2]

template<CScheduler TScheduler, typename... Systems>
decltype(auto) Engine::Core::RegisterSystem ( Systems... systems)
inline

Add one or multiple systems associated with a specific scheduler.

Template Parameters
TSchedulerThe type of the scheduler to use. It must be derived from AScheduler. You can look at CScheduler
SystemsThe 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.
Parameters
systemsThe systems to add.
Returns
Return the identifiers of the systems added, in the same order as the systems were added.
See also
FunctionUtils::FunctionID.

◆ RegisterSystemWithErrorHandler() [1/2]

template<typename System, typename ErrorCallback>
decltype(auto) Engine::Core::RegisterSystemWithErrorHandler ( System system,
ErrorCallback callback )
inline

Add a system to the default scheduler, associated with a callback that should run if the system fails (throw).

Template Parameters
TSchedulerThe type of scheduler to use.
See also
Engine::CScheduler.
Parameters
systemThe system to add.
callbackThe callback to run if the system fails (throw).
Returns
Return the identifier of the system added. See FunctionUtils::FunctionID.

◆ RegisterSystemWithErrorHandler() [2/2]

template<CScheduler TScheduler, typename System, typename ErrorCallback>
decltype(auto) Engine::Core::RegisterSystemWithErrorHandler ( System system,
ErrorCallback callback )
inline

Add a system to a specific scheduler, associated with a callback that should run if the system fails (throw).

Template Parameters
TSchedulerThe type of scheduler to use. It must be derived from AScheduler. See Engine::CScheduler.
Parameters
systemThe system to add.
callbackThe callback to run if the system fails (throw).
Returns
Return the identifier of the system added. See FunctionUtils::FunctionID.

◆ RemoveDependencyAfter()

template<typename TSchedulerA, typename TSchedulerB>
void Engine::Core::RemoveDependencyAfter ( )
inline

Removes a dependency between two schedulers, ensuring that TSchedulerB is no longer dependent on TSchedulerA.

Template Parameters
TSchedulerAThe type of the first scheduler (the one being depended on).
TSchedulerBThe type of the second scheduler (the one depending on TSchedulerA).
Todo
Move the implementation of this function in the .inl file

◆ RemoveDependencyBefore()

template<typename TSchedulerA, typename TSchedulerB>
void Engine::Core::RemoveDependencyBefore ( )
inline

Removes a dependency between two schedulers, ensuring that TSchedulerA is no longer dependent on TSchedulerB.

Template Parameters
TSchedulerAThe type of the first scheduler (the one depending on TSchedulerB).
TSchedulerBThe type of the second scheduler (the one being depended on).
Todo
Move the implementation of this function in the .inl file

◆ RunCore()

void Engine::Core::RunCore ( )

Execute the core loop, which will run all the schedulers.

◆ RunSystems()

void Engine::Core::RunSystems ( )

Run all the systems once by calling each scheduler.

◆ SetDefaultScheduler() [1/2]

template<CScheduler TScheduler>
void Engine::Core::SetDefaultScheduler ( )
inline

Sets the default scheduler.

Template Parameters
TSchedulerThe type of the scheduler to be set as default. See Engine::CScheduler.
Todo
Move the implementation of this function in the .inl file.

◆ SetDefaultScheduler() [2/2]

void Engine::Core::SetDefaultScheduler ( std::type_index scheduler)
inline

Sets the default scheduler.

Parameters
schedulerThe type index of the scheduler to be set as default.
Note
The scheduler must be present in the core.

◆ SetErrorPolicyForAllSchedulers()

void Engine::Core::SetErrorPolicyForAllSchedulers ( Scheduler::SchedulerErrorPolicy policy)

Sets the error policy for all schedulers.

Parameters
policyThe error policy to set for all schedulers. See Engine::Scheduler::SchedulerErrorPolicy.

◆ SetSchedulerAfter()

template<typename TSchedulerA, typename TSchedulerB>
void Engine::Core::SetSchedulerAfter ( )
inline

Sets the execution order of two schedulers by specifying that one scheduler should execute after another.

Template Parameters
TSchedulerAThe type of the scheduler that should execute first.
TSchedulerBThe type of the scheduler that should execute after TSchedulerA.
Todo
Move the implementation of this function in the .inl file

◆ SetSchedulerBefore()

template<typename TSchedulerA, typename TSchedulerB>
void Engine::Core::SetSchedulerBefore ( )
inline

Sets the execution order of two schedulers, ensuring that TSchedulerA is executed before TSchedulerB.

Template Parameters
TSchedulerAThe type of the scheduler that should execute first.
TSchedulerBThe type of the scheduler that should execute after TSchedulerA.
Todo
Move the implementation of this function in the .inl file

◆ Stop()

void Engine::Core::Stop ( )

Stop the core execution. It will finish the current loop, call shutdown systems if any and stop.

Member Data Documentation

◆ _defaultScheduler

std::type_index Engine::Core::_defaultScheduler = typeid(Engine::Scheduler::Update)
private

The default scheduler type index. It is used when adding systems without specifying a scheduler.

◆ _plugins

std::unordered_map<std::type_index, std::unique_ptr<IPlugin> > Engine::Core::_plugins
private

The plugins added to the core.

◆ _registry

std::unique_ptr<Registry> Engine::Core::_registry
private

The registry that contains all components (and by definition, the entities).

◆ _running

bool Engine::Core::_running = false
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.

◆ _schedulers

Engine::SchedulerContainer Engine::Core::_schedulers
private

The container that contains all the schedulers.

◆ _schedulersToDelete

std::vector<std::type_index> Engine::Core::_schedulersToDelete
private

The list of schedulers to delete at the end of the current loop.


The documentation for this class was generated from the following files: