diff --git a/include/Nazara/Core/Components.hpp b/include/Nazara/Core/Components.hpp index 31f616fc8..d144f9cd9 100644 --- a/include/Nazara/Core/Components.hpp +++ b/include/Nazara/Core/Components.hpp @@ -29,6 +29,7 @@ #ifndef NAZARA_CORE_COMPONENTS_HPP #define NAZARA_CORE_COMPONENTS_HPP +#include #include #endif // NAZARA_CORE_COMPONENTS_HPP diff --git a/include/Nazara/Core/Components/DisabledComponent.hpp b/include/Nazara/Core/Components/DisabledComponent.hpp new file mode 100644 index 000000000..01cd6847a --- /dev/null +++ b/include/Nazara/Core/Components/DisabledComponent.hpp @@ -0,0 +1,29 @@ +// 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_COMPONENTS_DISABLEDCOMPONENT_HPP +#define NAZARA_CORE_COMPONENTS_DISABLEDCOMPONENT_HPP + +#include +#include +#include + +namespace Nz +{ + class DisabledComponent + { + public: + DisabledComponent() = default; + DisabledComponent(const DisabledComponent&) = default; + DisabledComponent(DisabledComponent&&) = default; + ~DisabledComponent() = default; + + DisabledComponent& operator=(const DisabledComponent&) = default; + DisabledComponent& operator=(DisabledComponent&&) = default; + }; +} + +#endif // NAZARA_CORE_COMPONENTS_DISABLEDCOMPONENT_HPP diff --git a/include/Nazara/Graphics/Systems/RenderSystem.hpp b/include/Nazara/Graphics/Systems/RenderSystem.hpp index 0d00135db..5a7c7ae3b 100644 --- a/include/Nazara/Graphics/Systems/RenderSystem.hpp +++ b/include/Nazara/Graphics/Systems/RenderSystem.hpp @@ -53,6 +53,7 @@ namespace Nz private: void OnCameraDestroy(entt::registry& registry, entt::entity entity); + void OnDisabledConstructed(entt::registry& registry, entt::entity entity); void OnGraphicsDestroy(entt::registry& registry, entt::entity entity); void OnLightDestroy(entt::registry& registry, entt::entity entity); void OnNodeDestroy(entt::registry& registry, entt::entity entity); @@ -116,6 +117,8 @@ namespace Nz entt::observer m_sharedSkeletonConstructObserver; entt::observer m_skeletonConstructObserver; entt::scoped_connection m_cameraDestroyConnection; + entt::scoped_connection m_disabledConstructedConnection; + entt::scoped_connection m_disabledDestroyConnection; entt::scoped_connection m_graphicsDestroyConnection; entt::scoped_connection m_lightDestroyConnection; entt::scoped_connection m_nodeDestroyConnection; diff --git a/src/Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.cpp b/src/Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.cpp index d373d79b1..ef531e8a7 100644 --- a/src/Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.cpp +++ b/src/Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -102,7 +103,7 @@ namespace Nz // TODO: Only replicate active entities m_activeObjectCount = 0; - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto entity : view) { auto& rigidBodyComponent = view.get(entity); diff --git a/src/Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.cpp b/src/Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.cpp index 2d1dcca4e..faa7d89ca 100644 --- a/src/Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.cpp +++ b/src/Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include @@ -49,7 +50,7 @@ namespace Nz m_physWorld.Step(elapsedTime); // Replicate rigid body position to their node components - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto [entity, nodeComponent, rigidBodyComponent] : view.each()) { if (rigidBodyComponent.IsSleeping()) diff --git a/src/Nazara/Core/Systems/LifetimeSystem.cpp b/src/Nazara/Core/Systems/LifetimeSystem.cpp index bbc0d1649..9a52b483d 100644 --- a/src/Nazara/Core/Systems/LifetimeSystem.cpp +++ b/src/Nazara/Core/Systems/LifetimeSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include @@ -10,7 +11,7 @@ namespace Nz { void LifetimeSystem::Update(Time elapsedTime) { - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto [entity, lifetimeComponent] : view.each()) { lifetimeComponent.DecreaseLifetime(elapsedTime); diff --git a/src/Nazara/Graphics/Systems/RenderSystem.cpp b/src/Nazara/Graphics/Systems/RenderSystem.cpp index 03218e77e..aa2dddbeb 100644 --- a/src/Nazara/Graphics/Systems/RenderSystem.cpp +++ b/src/Nazara/Graphics/Systems/RenderSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -21,16 +22,17 @@ namespace Nz { RenderSystem::RenderSystem(entt::registry& registry) : m_registry(registry), - m_cameraConstructObserver(registry, entt::collector.group()), - m_graphicsConstructObserver(registry, entt::collector.group()), - m_lightConstructObserver(registry, entt::collector.group()), - m_sharedSkeletonConstructObserver(registry, entt::collector.group(entt::exclude)), - m_skeletonConstructObserver(registry, entt::collector.group(entt::exclude)), + m_cameraConstructObserver(registry, entt::collector.group(entt::exclude)), + m_graphicsConstructObserver(registry, entt::collector.group(entt::exclude)), + m_lightConstructObserver(registry, entt::collector.group(entt::exclude)), + m_sharedSkeletonConstructObserver(registry, entt::collector.group(entt::exclude)), + m_skeletonConstructObserver(registry, entt::collector.group(entt::exclude)), m_cameraEntityPool(8), m_graphicsEntityPool(1024), m_lightEntityPool(32) { m_cameraDestroyConnection = registry.on_destroy().connect<&RenderSystem::OnCameraDestroy>(this); + m_disabledConstructedConnection = registry.on_construct().connect<&RenderSystem::OnDisabledConstructed>(this); m_graphicsDestroyConnection = registry.on_destroy().connect<&RenderSystem::OnGraphicsDestroy>(this); m_lightDestroyConnection = registry.on_destroy().connect<&RenderSystem::OnLightDestroy>(this); m_nodeDestroyConnection = registry.on_destroy().connect<&RenderSystem::OnNodeDestroy>(this); @@ -89,6 +91,12 @@ namespace Nz m_cameraEntityPool.Free(cameraEntity->poolIndex); } + void RenderSystem::OnDisabledConstructed(entt::registry& registry, entt::entity entity) + { + // This is essentially the same + OnNodeDestroy(registry, entity); + } + void RenderSystem::OnGraphicsDestroy([[maybe_unused]] entt::registry& registry, entt::entity entity) { assert(&m_registry == ®istry); diff --git a/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp b/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp index 8ffe2d11a..f254cac45 100644 --- a/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp +++ b/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -102,7 +103,7 @@ namespace Nz Time t2 = GetElapsedNanoseconds(); // Replicate active rigid body position to their node components - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto entity : view) { auto& rigidBodyComponent = view.get(entity); diff --git a/src/Nazara/Utility/Systems/SkeletonSystem.cpp b/src/Nazara/Utility/Systems/SkeletonSystem.cpp index 8663cddbc..859096655 100644 --- a/src/Nazara/Utility/Systems/SkeletonSystem.cpp +++ b/src/Nazara/Utility/Systems/SkeletonSystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -43,7 +44,7 @@ namespace Nz }); // Updated attached skeleton joints (TODO: Only do this if necessary) - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto entity : view) { auto& sharedSkeletonComponent = view.get(entity); diff --git a/src/Nazara/Utility/Systems/VelocitySystem.cpp b/src/Nazara/Utility/Systems/VelocitySystem.cpp index e0ae97a79..0aeb3d817 100644 --- a/src/Nazara/Utility/Systems/VelocitySystem.cpp +++ b/src/Nazara/Utility/Systems/VelocitySystem.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -13,7 +14,7 @@ namespace Nz { float delta = elapsedTime.AsSeconds(); - auto view = m_registry.view(); + auto view = m_registry.view(entt::exclude); for (auto [entity, nodeComponent, velocityComponent] : view.each()) { NazaraUnused(entity);