Rework EnTT integration

- Update EnTT to 3.11.1
- Moved EnTT wrapper to EnTTWorld, inheriting EntityWorld
- AppEntitySystemComponent can now handles multiple EntityWorld
- Headers relying on EnTT are now automatically included if NAZARA_ENTT is defined
- Renamed SystemGraph to EnttSystemGraph (as it depends on it for now)
This commit is contained in:
SirLynix
2023-01-28 18:16:10 +01:00
committed by Jérôme Leclercq
parent d5f281a768
commit 97fa4d98be
52 changed files with 361 additions and 191 deletions

View File

@@ -10,25 +10,19 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ApplicationComponent.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Systems/SystemGraph.hpp>
#include <Nazara/Core/EntityWorld.hpp>
namespace Nz
{
class NAZARA_CORE_API AppEntitySystemComponent : public ApplicationComponent
{
public:
inline AppEntitySystemComponent(ApplicationBase& app);
using ApplicationComponent::ApplicationComponent;
AppEntitySystemComponent(const AppEntitySystemComponent&) = delete;
AppEntitySystemComponent(AppEntitySystemComponent&&) = delete;
~AppEntitySystemComponent() = default;
template<typename T, typename... Args> T& AddSystem(Args&&... args);
entt::handle CreateEntity();
entt::registry& GetRegistry();
const entt::registry& GetRegistry() const;
template<typename T> T& GetSystem() const;
template<typename T, typename... Args> T& AddWorld(Args&&... args);
void Update(Time elapsedTime) override;
@@ -36,8 +30,7 @@ namespace Nz
AppEntitySystemComponent& operator=(AppEntitySystemComponent&&) = delete;
private:
entt::registry m_registry;
SystemGraph m_systemGraph;
std::vector<std::unique_ptr<EntityWorld>> m_worlds;
};
}

View File

@@ -7,37 +7,10 @@
namespace Nz
{
inline AppEntitySystemComponent::AppEntitySystemComponent(ApplicationBase& app) :
ApplicationComponent(app),
m_systemGraph(m_registry)
{
}
template<typename T, typename... Args>
T& AppEntitySystemComponent::AddSystem(Args&&... args)
T& AppEntitySystemComponent::AddWorld(Args&&... args)
{
return m_systemGraph.AddSystem<T>(std::forward<Args>(args)...);
}
inline entt::handle AppEntitySystemComponent::CreateEntity()
{
return entt::handle(m_registry, m_registry.create());
}
inline entt::registry& AppEntitySystemComponent::GetRegistry()
{
return m_registry;
}
inline const entt::registry& AppEntitySystemComponent::GetRegistry() const
{
return m_registry;
}
template<typename T>
T& AppEntitySystemComponent::GetSystem() const
{
return m_systemGraph.GetSystem<T>();
return static_cast<T&>(*m_worlds.emplace_back(std::make_unique<T>(std::forward<Args>(args)...)));
}
}

View File

@@ -3,7 +3,7 @@
/*
Nazara Engine - Core module
Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_ENTITYWORLD_HPP
#define NAZARA_CORE_ENTITYWORLD_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Time.hpp>
namespace Nz
{
class NAZARA_CORE_API EntityWorld
{
public:
EntityWorld() = default;
EntityWorld(const EntityWorld&) = default;
EntityWorld(EntityWorld&&) = default;
virtual ~EntityWorld();
virtual void Update(Time elapsedTime) = 0;
EntityWorld& operator=(const EntityWorld&) = default;
EntityWorld& operator=(EntityWorld&&) = default;
};
}
#include <Nazara/Core/EntityWorld.inl>
#endif // NAZARA_CORE_ENTITYWORLD_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/EntityWorld.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -4,8 +4,8 @@
#pragma once
#ifndef NAZARA_CORE_SYSTEMS_SYSTEMGRAPH_HPP
#define NAZARA_CORE_SYSTEMS_SYSTEMGRAPH_HPP
#ifndef NAZARA_CORE_ENTTSYSTEMGRAPH_HPP
#define NAZARA_CORE_ENTTSYSTEMGRAPH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
@@ -18,13 +18,13 @@
namespace Nz
{
class NAZARA_CORE_API SystemGraph
class NAZARA_CORE_API EnttSystemGraph
{
public:
inline SystemGraph(entt::registry& registry);
SystemGraph(const SystemGraph&) = delete;
SystemGraph(SystemGraph&&) = delete;
~SystemGraph() = default;
inline EnttSystemGraph(entt::registry& registry);
EnttSystemGraph(const EnttSystemGraph&) = delete;
EnttSystemGraph(EnttSystemGraph&&) = delete;
~EnttSystemGraph() = default;
template<typename T, typename... Args> T& AddSystem(Args&&... args);
@@ -33,8 +33,8 @@ namespace Nz
void Update();
void Update(Time elapsedTime);
SystemGraph& operator=(const SystemGraph&) = delete;
SystemGraph& operator=(SystemGraph&&) = delete;
EnttSystemGraph& operator=(const EnttSystemGraph&) = delete;
EnttSystemGraph& operator=(EnttSystemGraph&&) = delete;
private:
struct NAZARA_CORE_API NodeBase
@@ -65,6 +65,6 @@ namespace Nz
};
}
#include <Nazara/Core/Systems/SystemGraph.inl>
#include <Nazara/Core/EnttSystemGraph.inl>
#endif // NAZARA_CORE_SYSTEMS_SYSTEMGRAPH_HPP
#endif // NAZARA_CORE_ENTTSYSTEMGRAPH_HPP

View File

@@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Systems/SystemGraph.hpp>
#include <Nazara/Core/EnttSystemGraph.hpp>
#include <Nazara/Core/Error.hpp>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
@@ -12,44 +12,44 @@ namespace Nz
namespace Detail
{
template<typename, typename = void>
struct SystemGraphAllowConcurrent : std::bool_constant<true> {};
struct EnttSystemGraphAllowConcurrent : std::bool_constant<true> {};
template<typename T>
struct SystemGraphAllowConcurrent<T, std::void_t<decltype(T::AllowConcurrent)>> : std::bool_constant<T::AllowConcurrent> {};
struct EnttSystemGraphAllowConcurrent<T, std::void_t<decltype(T::AllowConcurrent)>> : std::bool_constant<T::AllowConcurrent> {};
template<typename, typename = void>
struct SystemGraphExecutionOrder : std::integral_constant<Int64, 0> {};
struct EnttSystemGraphExecutionOrder : std::integral_constant<Int64, 0> {};
template<typename T>
struct SystemGraphExecutionOrder<T, std::void_t<decltype(T::ExecutionOrder)>> : std::integral_constant<Int64, T::ExecutionOrder> {};
struct EnttSystemGraphExecutionOrder<T, std::void_t<decltype(T::ExecutionOrder)>> : std::integral_constant<Int64, T::ExecutionOrder> {};
}
template<typename T>
template<typename... Args>
SystemGraph::Node<T>::Node(Args&&... args) :
EnttSystemGraph::Node<T>::Node(Args&&... args) :
system(std::forward<Args>(args)...)
{
}
template<typename T>
void SystemGraph::Node<T>::Update(Time elapsedTime)
void EnttSystemGraph::Node<T>::Update(Time elapsedTime)
{
system.Update(elapsedTime);
}
inline SystemGraph::SystemGraph(entt::registry& registry) :
inline EnttSystemGraph::EnttSystemGraph(entt::registry& registry) :
m_registry(registry),
m_systemOrderUpdated(true)
{
}
template<typename T, typename... Args>
T& SystemGraph::AddSystem(Args&&... args)
T& EnttSystemGraph::AddSystem(Args&&... args)
{
NazaraAssert(m_systemToNodes.find(entt::type_hash<T>()) == m_systemToNodes.end(), "this system already exists");
auto nodePtr = std::make_unique<Node<T>>(m_registry, std::forward<Args>(args)...);
nodePtr->executionOrder = Detail::SystemGraphExecutionOrder<T>();
nodePtr->executionOrder = Detail::EnttSystemGraphExecutionOrder<T>();
T& system = nodePtr->system;
@@ -63,7 +63,7 @@ namespace Nz
}
template<typename T>
T& SystemGraph::GetSystem() const
T& EnttSystemGraph::GetSystem() const
{
auto it = m_systemToNodes.find(entt::type_hash<T>());
if (it == m_systemToNodes.end())

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_ENTTWORLD_HPP
#define NAZARA_CORE_ENTTWORLD_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ApplicationComponent.hpp>
#include <Nazara/Core/EntityWorld.hpp>
#include <Nazara/Core/EnttSystemGraph.hpp>
namespace Nz
{
class NAZARA_CORE_API EnttWorld : public EntityWorld
{
public:
EnttWorld();
EnttWorld(const EnttWorld&) = default;
EnttWorld(EnttWorld&&) = default;
~EnttWorld() = default;
template<typename T, typename... Args> T& AddSystem(Args&&... args);
entt::handle CreateEntity();
entt::registry& GetRegistry();
const entt::registry& GetRegistry() const;
template<typename T> T& GetSystem() const;
void Update(Time elapsedTime) override;
operator entt::registry&();
operator const entt::registry&() const;
EnttWorld& operator=(const EnttWorld&) = delete;
EnttWorld& operator=(EnttWorld&&) = delete;
private:
entt::registry m_registry;
EnttSystemGraph m_systemGraph;
};
}
#include <Nazara/Core/EnttWorld.inl>
#endif // NAZARA_CORE_ENTTWORLD_HPP

View File

@@ -0,0 +1,53 @@
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/EnttWorld.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
inline EnttWorld::EnttWorld() :
m_systemGraph(m_registry)
{
}
template<typename T, typename... Args>
T& EnttWorld::AddSystem(Args&&... args)
{
return m_systemGraph.AddSystem<T>(std::forward<Args>(args)...);
}
inline entt::handle EnttWorld::CreateEntity()
{
return entt::handle(m_registry, m_registry.create());
}
inline entt::registry& EnttWorld::GetRegistry()
{
return m_registry;
}
inline const entt::registry& EnttWorld::GetRegistry() const
{
return m_registry;
}
template<typename T>
T& EnttWorld::GetSystem() const
{
return m_systemGraph.GetSystem<T>();
}
inline EnttWorld::operator entt::registry&()
{
return m_registry;
}
inline EnttWorld::operator const entt::registry&() const
{
return m_registry;
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -3,7 +3,7 @@
/*
Nazara Engine - Core module
Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -30,6 +30,5 @@
#define NAZARA_CORE_SYSTEMS_HPP
#include <Nazara/Core/Systems/LifetimeSystem.hpp>
#include <Nazara/Core/Systems/SystemGraph.hpp>
#endif // NAZARA_CORE_SYSTEMS_HPP