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:
committed by
Jérôme Leclercq
parent
d5f281a768
commit
97fa4d98be
@@ -1,70 +0,0 @@
|
||||
// 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_SYSTEMS_SYSTEMGRAPH_HPP
|
||||
#define NAZARA_CORE_SYSTEMS_SYSTEMGRAPH_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Utils/MovablePtr.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SystemGraph
|
||||
{
|
||||
public:
|
||||
inline SystemGraph(entt::registry& registry);
|
||||
SystemGraph(const SystemGraph&) = delete;
|
||||
SystemGraph(SystemGraph&&) = delete;
|
||||
~SystemGraph() = default;
|
||||
|
||||
template<typename T, typename... Args> T& AddSystem(Args&&... args);
|
||||
|
||||
template<typename T> T& GetSystem() const;
|
||||
|
||||
void Update();
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
SystemGraph& operator=(const SystemGraph&) = delete;
|
||||
SystemGraph& operator=(SystemGraph&&) = delete;
|
||||
|
||||
private:
|
||||
struct NAZARA_CORE_API NodeBase
|
||||
{
|
||||
virtual ~NodeBase();
|
||||
|
||||
virtual void Update(Time elapsedTime) = 0;
|
||||
|
||||
Int64 executionOrder;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Node : NodeBase
|
||||
{
|
||||
template<typename... Args> Node(Args&&... args);
|
||||
|
||||
void Update(Time elapsedTime) override;
|
||||
|
||||
T system;
|
||||
};
|
||||
|
||||
std::unordered_map<entt::id_type, std::size_t /*nodeIndex*/> m_systemToNodes;
|
||||
std::vector<NodeBase*> m_orderedNodes;
|
||||
std::vector<std::unique_ptr<NodeBase>> m_nodes;
|
||||
entt::registry& m_registry;
|
||||
Nz::HighPrecisionClock m_clock;
|
||||
bool m_systemOrderUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Systems/SystemGraph.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SYSTEMS_SYSTEMGRAPH_HPP
|
||||
@@ -1,77 +0,0 @@
|
||||
// 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/Systems/SystemGraph.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
template<typename, typename = void>
|
||||
struct SystemGraphAllowConcurrent : std::bool_constant<true> {};
|
||||
|
||||
template<typename T>
|
||||
struct SystemGraphAllowConcurrent<T, std::void_t<decltype(T::AllowConcurrent)>> : std::bool_constant<T::AllowConcurrent> {};
|
||||
|
||||
template<typename, typename = void>
|
||||
struct SystemGraphExecutionOrder : std::integral_constant<Int64, 0> {};
|
||||
|
||||
template<typename T>
|
||||
struct SystemGraphExecutionOrder<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) :
|
||||
system(std::forward<Args>(args)...)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SystemGraph::Node<T>::Update(Time elapsedTime)
|
||||
{
|
||||
system.Update(elapsedTime);
|
||||
}
|
||||
|
||||
inline SystemGraph::SystemGraph(entt::registry& registry) :
|
||||
m_registry(registry),
|
||||
m_systemOrderUpdated(true)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T& SystemGraph::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>();
|
||||
|
||||
T& system = nodePtr->system;
|
||||
|
||||
std::size_t nodeIndex = m_nodes.size();
|
||||
|
||||
m_nodes.emplace_back(std::move(nodePtr));
|
||||
m_systemToNodes.emplace(entt::type_hash<T>(), nodeIndex);
|
||||
m_systemOrderUpdated = false;
|
||||
|
||||
return system;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& SystemGraph::GetSystem() const
|
||||
{
|
||||
auto it = m_systemToNodes.find(entt::type_hash<T>());
|
||||
if (it == m_systemToNodes.end())
|
||||
throw std::runtime_error("this system is not part of the graph");
|
||||
|
||||
auto& node = static_cast<Node<T>&>(*m_nodes[it->second]);
|
||||
return node.system;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user