SDK/PhysicsComponent2D: Add node synchronization

This commit is contained in:
Lynix
2018-10-24 20:38:20 +02:00
parent a292e47673
commit 2c0c8ef0a0
4 changed files with 54 additions and 11 deletions

View File

@@ -147,16 +147,21 @@ namespace Ndk
void PhysicsSystem2D::OnEntityValidation(Entity* entity, bool justAdded)
{
// It's possible our entity got revalidated because of the addition/removal of a PhysicsComponent3D
if (!justAdded)
if (entity->HasComponent<PhysicsComponent2D>())
{
// We take the opposite array from which the entity should belong to
auto& entities = (entity->HasComponent<PhysicsComponent2D>()) ? m_staticObjects : m_dynamicObjects;
entities.Remove(entity);
}
if (entity->GetComponent<PhysicsComponent2D>().IsNodeSynchronizationEnabled())
m_dynamicObjects.Insert(entity);
else
m_dynamicObjects.Remove(entity);
auto& entities = (entity->HasComponent<PhysicsComponent2D>()) ? m_dynamicObjects : m_staticObjects;
entities.Insert(entity);
m_staticObjects.Remove(entity);
}
else
{
m_dynamicObjects.Remove(entity);
m_staticObjects.Insert(entity);
}
if (!m_physWorld)
CreatePhysWorld();