// Copyright (C) 2022 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 #include namespace Nz { namespace Detail { template struct SystemGraphAllowConcurrent : std::bool_constant {}; template struct SystemGraphAllowConcurrent> : std::bool_constant {}; template struct SystemGraphExecutionOrder : std::integral_constant {}; template struct SystemGraphExecutionOrder> : std::integral_constant {}; } template template SystemGraph::Node::Node(Args&&... args) : system(std::forward(args)...) { } template void SystemGraph::Node::Update(Time elapsedTime) { system.Update(elapsedTime); } inline SystemGraph::SystemGraph(entt::registry& registry) : m_registry(registry), m_systemOrderUpdated(true) { } template T& SystemGraph::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::SystemGraphExecutionOrder(); 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& SystemGraph::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