// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Utility module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #include #include namespace Nz { SkeletonSystem::SkeletonSystem(entt::registry& registry) : m_registry(registry), m_sharedSkeletonConstructObserver(registry, entt::collector.group(entt::exclude)), m_skeletonConstructObserver(registry, entt::collector.group(entt::exclude)) { } SkeletonSystem::~SkeletonSystem() { m_sharedSkeletonConstructObserver.disconnect(); m_skeletonConstructObserver.disconnect(); } void SkeletonSystem::Update(Time /*elapsedTime*/) { m_sharedSkeletonConstructObserver.each([&](entt::entity entity) { NodeComponent& entityNode = m_registry.get(entity); SharedSkeletonComponent& entitySkeleton = m_registry.get(entity); entitySkeleton.SetSkeletonParent(&entityNode); }); m_skeletonConstructObserver.each([&](entt::entity entity) { NodeComponent& entityNode = m_registry.get(entity); SkeletonComponent& entitySkeleton = m_registry.get(entity); // TODO: When attaching for the first time, set the skeleton to the position of the node before attaching the node entityNode.SetParent(entitySkeleton.GetRootNode()); }); // Updated attached skeleton joints (TODO: Only do this if necessary) auto view = m_registry.view(entt::exclude); for (auto entity : view) { auto& sharedSkeletonComponent = view.get(entity); if (sharedSkeletonComponent.IsAttachedSkeletonOutdated()) sharedSkeletonComponent.UpdateAttachedSkeletonJoints(); } } }