// 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 #include #include namespace Nz { namespace Detail { template struct EnttSystemGraphAllowConcurrent : std::bool_constant {}; template struct EnttSystemGraphAllowConcurrent> : std::bool_constant {}; template struct EnttSystemGraphExecutionOrder : std::integral_constant {}; template struct EnttSystemGraphExecutionOrder> : std::integral_constant {}; } template template EnttSystemGraph::Node::Node(Args&&... args) : system(std::forward(args)...) { } template void EnttSystemGraph::Node::Update(Time elapsedTime) { system.Update(elapsedTime); } inline EnttSystemGraph::EnttSystemGraph(entt::registry& registry) : m_registry(registry), m_systemOrderUpdated(true) { } template T& EnttSystemGraph::AddSystem(Args&&... args) { NazaraAssert(m_systemToNodes.find(entt::type_hash()) == m_systemToNodes.end(), "this system already exists"); auto nodePtr = std::make_unique>(m_registry, std::forward(args)...); nodePtr->executionOrder = Detail::EnttSystemGraphExecutionOrder(); T& system = nodePtr->system; std::size_t nodeIndex = m_nodes.size(); m_nodes.emplace_back(std::move(nodePtr)); m_systemToNodes.emplace(entt::type_hash(), nodeIndex); m_systemOrderUpdated = false; return system; } template T& EnttSystemGraph::GetSystem() const { auto it = m_systemToNodes.find(entt::type_hash()); if (it == m_systemToNodes.end()) throw std::runtime_error("this system is not part of the graph"); auto& node = static_cast&>(*m_nodes[it->second]); return node.system; } } #include