Sdk: Add automatic system update
Former-commit-id: ce129cc945e7373ac5b9f48960894712d66b097a
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Ndk
|
||||
Requires<ListenerComponent, NodeComponent>();
|
||||
}
|
||||
|
||||
void ListenerSystem::Update(float elapsedTime)
|
||||
void ListenerSystem::OnUpdate(float elapsedTime)
|
||||
{
|
||||
NazaraUnused(elapsedTime);
|
||||
|
||||
|
||||
@@ -22,7 +22,21 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
void PhysicsSystem::Update(float elapsedTime)
|
||||
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
{
|
||||
// Si l'entité ne vient pas d'être ajoutée au système, il est possible qu'elle fasse partie du mauvais tableau
|
||||
if (!justAdded)
|
||||
{
|
||||
// On prend le tableau inverse de celui dont l'entité devrait faire partie
|
||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
|
||||
entities.Remove(entity);
|
||||
}
|
||||
|
||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
|
||||
entities.Insert(entity);
|
||||
}
|
||||
|
||||
void PhysicsSystem::OnUpdate(float elapsedTime)
|
||||
{
|
||||
m_world.Step(elapsedTime);
|
||||
|
||||
@@ -75,19 +89,5 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
{
|
||||
// Si l'entité ne vient pas d'être ajoutée au système, il est possible qu'elle fasse partie du mauvais tableau
|
||||
if (!justAdded)
|
||||
{
|
||||
// On prend le tableau inverse de celui dont l'entité devrait faire partie
|
||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
|
||||
entities.Remove(entity);
|
||||
}
|
||||
|
||||
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
|
||||
entities.Insert(entity);
|
||||
}
|
||||
|
||||
SystemIndex PhysicsSystem::systemIndex;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,38 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
void RenderSystem::Update(float elapsedTime)
|
||||
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||
{
|
||||
m_cameras.Remove(entity);
|
||||
m_drawables.Remove(entity);
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
{
|
||||
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
|
||||
{
|
||||
m_cameras.Insert(entity);
|
||||
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
|
||||
{
|
||||
return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer();
|
||||
});
|
||||
}
|
||||
else
|
||||
m_cameras.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
||||
m_drawables.Insert(entity);
|
||||
else
|
||||
m_drawables.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||
m_lights.Insert(entity);
|
||||
else
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnUpdate(float elapsedTime)
|
||||
{
|
||||
for (const Ndk::EntityHandle& camera : m_cameras)
|
||||
{
|
||||
@@ -52,36 +83,5 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||
{
|
||||
m_cameras.Remove(entity);
|
||||
m_drawables.Remove(entity);
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
{
|
||||
if (entity->HasComponent<CameraComponent>() && entity->HasComponent<NodeComponent>())
|
||||
{
|
||||
m_cameras.Insert(entity);
|
||||
std::sort(m_cameras.begin(), m_cameras.end(), [](const EntityHandle& handle1, const EntityHandle& handle2)
|
||||
{
|
||||
return handle1->GetComponent<CameraComponent>().GetLayer() < handle2->GetComponent<CameraComponent>().GetLayer();
|
||||
});
|
||||
}
|
||||
else
|
||||
m_cameras.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
||||
m_drawables.Insert(entity);
|
||||
else
|
||||
m_drawables.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||
m_lights.Insert(entity);
|
||||
else
|
||||
m_lights.Remove(entity);
|
||||
}
|
||||
|
||||
SystemIndex RenderSystem::systemIndex;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Ndk
|
||||
Excludes<PhysicsComponent>();
|
||||
}
|
||||
|
||||
void VelocitySystem::Update(float elapsedTime)
|
||||
void VelocitySystem::OnUpdate(float elapsedTime)
|
||||
{
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user