Core: Add DisabledComponent (to temporary disable an entity)
This commit is contained in:
parent
c69397707e
commit
bbbd3f88c1
|
|
@ -29,6 +29,7 @@
|
||||||
#ifndef NAZARA_CORE_COMPONENTS_HPP
|
#ifndef NAZARA_CORE_COMPONENTS_HPP
|
||||||
#define NAZARA_CORE_COMPONENTS_HPP
|
#define NAZARA_CORE_COMPONENTS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
||||||
|
|
||||||
#endif // NAZARA_CORE_COMPONENTS_HPP
|
#endif // NAZARA_CORE_COMPONENTS_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 <NazaraUtils/Prerequisites.hpp>
|
||||||
|
#include <Nazara/Core/Time.hpp>
|
||||||
|
#include <Nazara/Utility/Config.hpp>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -53,6 +53,7 @@ namespace Nz
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnCameraDestroy(entt::registry& registry, entt::entity entity);
|
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 OnGraphicsDestroy(entt::registry& registry, entt::entity entity);
|
||||||
void OnLightDestroy(entt::registry& registry, entt::entity entity);
|
void OnLightDestroy(entt::registry& registry, entt::entity entity);
|
||||||
void OnNodeDestroy(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_sharedSkeletonConstructObserver;
|
||||||
entt::observer m_skeletonConstructObserver;
|
entt::observer m_skeletonConstructObserver;
|
||||||
entt::scoped_connection m_cameraDestroyConnection;
|
entt::scoped_connection m_cameraDestroyConnection;
|
||||||
|
entt::scoped_connection m_disabledConstructedConnection;
|
||||||
|
entt::scoped_connection m_disabledDestroyConnection;
|
||||||
entt::scoped_connection m_graphicsDestroyConnection;
|
entt::scoped_connection m_graphicsDestroyConnection;
|
||||||
entt::scoped_connection m_lightDestroyConnection;
|
entt::scoped_connection m_lightDestroyConnection;
|
||||||
entt::scoped_connection m_nodeDestroyConnection;
|
entt::scoped_connection m_nodeDestroyConnection;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.hpp>
|
#include <Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
||||||
|
|
@ -102,7 +103,7 @@ namespace Nz
|
||||||
// TODO: Only replicate active entities
|
// TODO: Only replicate active entities
|
||||||
m_activeObjectCount = 0;
|
m_activeObjectCount = 0;
|
||||||
|
|
||||||
auto view = m_registry.view<NodeComponent, const BulletRigidBody3DComponent>();
|
auto view = m_registry.view<NodeComponent, const BulletRigidBody3DComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto entity : view)
|
for (auto entity : view)
|
||||||
{
|
{
|
||||||
auto& rigidBodyComponent = view.get<const BulletRigidBody3DComponent>(entity);
|
auto& rigidBodyComponent = view.get<const BulletRigidBody3DComponent>(entity);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -49,7 +50,7 @@ namespace Nz
|
||||||
m_physWorld.Step(elapsedTime);
|
m_physWorld.Step(elapsedTime);
|
||||||
|
|
||||||
// Replicate rigid body position to their node components
|
// Replicate rigid body position to their node components
|
||||||
auto view = m_registry.view<NodeComponent, const ChipmunkRigidBody2DComponent>();
|
auto view = m_registry.view<NodeComponent, const ChipmunkRigidBody2DComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto [entity, nodeComponent, rigidBodyComponent] : view.each())
|
for (auto [entity, nodeComponent, rigidBodyComponent] : view.each())
|
||||||
{
|
{
|
||||||
if (rigidBodyComponent.IsSleeping())
|
if (rigidBodyComponent.IsSleeping())
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Core/Systems/LifetimeSystem.hpp>
|
#include <Nazara/Core/Systems/LifetimeSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
||||||
#include <Nazara/Core/Debug.hpp>
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -10,7 +11,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
void LifetimeSystem::Update(Time elapsedTime)
|
void LifetimeSystem::Update(Time elapsedTime)
|
||||||
{
|
{
|
||||||
auto view = m_registry.view<LifetimeComponent>();
|
auto view = m_registry.view<LifetimeComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto [entity, lifetimeComponent] : view.each())
|
for (auto [entity, lifetimeComponent] : view.each())
|
||||||
{
|
{
|
||||||
lifetimeComponent.DecreaseLifetime(elapsedTime);
|
lifetimeComponent.DecreaseLifetime(elapsedTime);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
|
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Graphics/ForwardFramePipeline.hpp>
|
#include <Nazara/Graphics/ForwardFramePipeline.hpp>
|
||||||
#include <Nazara/Graphics/ViewerInstance.hpp>
|
#include <Nazara/Graphics/ViewerInstance.hpp>
|
||||||
#include <Nazara/Graphics/WorldInstance.hpp>
|
#include <Nazara/Graphics/WorldInstance.hpp>
|
||||||
|
|
@ -21,16 +22,17 @@ namespace Nz
|
||||||
{
|
{
|
||||||
RenderSystem::RenderSystem(entt::registry& registry) :
|
RenderSystem::RenderSystem(entt::registry& registry) :
|
||||||
m_registry(registry),
|
m_registry(registry),
|
||||||
m_cameraConstructObserver(registry, entt::collector.group<CameraComponent, NodeComponent>()),
|
m_cameraConstructObserver(registry, entt::collector.group<CameraComponent, NodeComponent>(entt::exclude<DisabledComponent>)),
|
||||||
m_graphicsConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent>()),
|
m_graphicsConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent>(entt::exclude<DisabledComponent>)),
|
||||||
m_lightConstructObserver(registry, entt::collector.group<LightComponent, NodeComponent>()),
|
m_lightConstructObserver(registry, entt::collector.group<LightComponent, NodeComponent>(entt::exclude<DisabledComponent>)),
|
||||||
m_sharedSkeletonConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent, SharedSkeletonComponent>(entt::exclude<SkeletonComponent>)),
|
m_sharedSkeletonConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent, SharedSkeletonComponent>(entt::exclude<DisabledComponent, SkeletonComponent>)),
|
||||||
m_skeletonConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent, SkeletonComponent>(entt::exclude<SharedSkeletonComponent>)),
|
m_skeletonConstructObserver(registry, entt::collector.group<GraphicsComponent, NodeComponent, SkeletonComponent>(entt::exclude<DisabledComponent, SharedSkeletonComponent>)),
|
||||||
m_cameraEntityPool(8),
|
m_cameraEntityPool(8),
|
||||||
m_graphicsEntityPool(1024),
|
m_graphicsEntityPool(1024),
|
||||||
m_lightEntityPool(32)
|
m_lightEntityPool(32)
|
||||||
{
|
{
|
||||||
m_cameraDestroyConnection = registry.on_destroy<CameraComponent>().connect<&RenderSystem::OnCameraDestroy>(this);
|
m_cameraDestroyConnection = registry.on_destroy<CameraComponent>().connect<&RenderSystem::OnCameraDestroy>(this);
|
||||||
|
m_disabledConstructedConnection = registry.on_construct<DisabledComponent>().connect<&RenderSystem::OnDisabledConstructed>(this);
|
||||||
m_graphicsDestroyConnection = registry.on_destroy<GraphicsComponent>().connect<&RenderSystem::OnGraphicsDestroy>(this);
|
m_graphicsDestroyConnection = registry.on_destroy<GraphicsComponent>().connect<&RenderSystem::OnGraphicsDestroy>(this);
|
||||||
m_lightDestroyConnection = registry.on_destroy<LightComponent>().connect<&RenderSystem::OnLightDestroy>(this);
|
m_lightDestroyConnection = registry.on_destroy<LightComponent>().connect<&RenderSystem::OnLightDestroy>(this);
|
||||||
m_nodeDestroyConnection = registry.on_destroy<NodeComponent>().connect<&RenderSystem::OnNodeDestroy>(this);
|
m_nodeDestroyConnection = registry.on_destroy<NodeComponent>().connect<&RenderSystem::OnNodeDestroy>(this);
|
||||||
|
|
@ -89,6 +91,12 @@ namespace Nz
|
||||||
m_cameraEntityPool.Free(cameraEntity->poolIndex);
|
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)
|
void RenderSystem::OnGraphicsDestroy([[maybe_unused]] entt::registry& registry, entt::entity entity)
|
||||||
{
|
{
|
||||||
assert(&m_registry == ®istry);
|
assert(&m_registry == ®istry);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.hpp>
|
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||||
|
|
@ -102,7 +103,7 @@ namespace Nz
|
||||||
Time t2 = GetElapsedNanoseconds();
|
Time t2 = GetElapsedNanoseconds();
|
||||||
|
|
||||||
// Replicate active rigid body position to their node components
|
// Replicate active rigid body position to their node components
|
||||||
auto view = m_registry.view<NodeComponent, const JoltRigidBody3DComponent>();
|
auto view = m_registry.view<NodeComponent, const JoltRigidBody3DComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto entity : view)
|
for (auto entity : view)
|
||||||
{
|
{
|
||||||
auto& rigidBodyComponent = view.get<const JoltRigidBody3DComponent>(entity);
|
auto& rigidBodyComponent = view.get<const JoltRigidBody3DComponent>(entity);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Utility/Systems/SkeletonSystem.hpp>
|
#include <Nazara/Utility/Systems/SkeletonSystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/SharedSkeletonComponent.hpp>
|
#include <Nazara/Utility/Components/SharedSkeletonComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/SkeletonComponent.hpp>
|
#include <Nazara/Utility/Components/SkeletonComponent.hpp>
|
||||||
|
|
@ -43,7 +44,7 @@ namespace Nz
|
||||||
});
|
});
|
||||||
|
|
||||||
// Updated attached skeleton joints (TODO: Only do this if necessary)
|
// Updated attached skeleton joints (TODO: Only do this if necessary)
|
||||||
auto view = m_registry.view<NodeComponent, SharedSkeletonComponent>();
|
auto view = m_registry.view<NodeComponent, SharedSkeletonComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto entity : view)
|
for (auto entity : view)
|
||||||
{
|
{
|
||||||
auto& sharedSkeletonComponent = view.get<SharedSkeletonComponent>(entity);
|
auto& sharedSkeletonComponent = view.get<SharedSkeletonComponent>(entity);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Utility/Systems/VelocitySystem.hpp>
|
#include <Nazara/Utility/Systems/VelocitySystem.hpp>
|
||||||
|
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
#include <Nazara/Utility/Components/VelocityComponent.hpp>
|
#include <Nazara/Utility/Components/VelocityComponent.hpp>
|
||||||
#include <Nazara/Utility/Debug.hpp>
|
#include <Nazara/Utility/Debug.hpp>
|
||||||
|
|
@ -13,7 +14,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
float delta = elapsedTime.AsSeconds();
|
float delta = elapsedTime.AsSeconds();
|
||||||
|
|
||||||
auto view = m_registry.view<NodeComponent, VelocityComponent>();
|
auto view = m_registry.view<NodeComponent, VelocityComponent>(entt::exclude<DisabledComponent>);
|
||||||
for (auto [entity, nodeComponent, velocityComponent] : view.each())
|
for (auto [entity, nodeComponent, velocityComponent] : view.each())
|
||||||
{
|
{
|
||||||
NazaraUnused(entity);
|
NazaraUnused(entity);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue