Sdk/PhysicsSystem: Fix GetWorld() not initializing the internal world
This commit is contained in:
parent
debf87e739
commit
01cd9b220f
|
|
@ -27,12 +27,13 @@ namespace Ndk
|
||||||
static SystemIndex systemIndex;
|
static SystemIndex systemIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CreatePhysWorld() const;
|
||||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||||
void OnUpdate(float elapsedTime) override;
|
void OnUpdate(float elapsedTime) override;
|
||||||
|
|
||||||
EntityList m_dynamicObjects;
|
EntityList m_dynamicObjects;
|
||||||
EntityList m_staticObjects;
|
EntityList m_staticObjects;
|
||||||
std::unique_ptr<Nz::PhysWorld> m_world; ///TODO: std::optional (Should I make a Nz::Optional class?)
|
mutable std::unique_ptr<Nz::PhysWorld> m_world; ///TODO: std::optional (Should I make a Nz::Optional class?)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ namespace Ndk
|
||||||
|
|
||||||
inline Nz::PhysWorld& PhysicsSystem::GetWorld()
|
inline Nz::PhysWorld& PhysicsSystem::GetWorld()
|
||||||
{
|
{
|
||||||
|
if (!m_world)
|
||||||
|
CreatePhysWorld();
|
||||||
|
|
||||||
return *m_world;
|
return *m_world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,6 +24,9 @@ namespace Ndk
|
||||||
|
|
||||||
inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const
|
inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const
|
||||||
{
|
{
|
||||||
|
if (!m_world)
|
||||||
|
CreatePhysWorld();
|
||||||
|
|
||||||
return *m_world;
|
return *m_world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,13 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsSystem::CreatePhysWorld() const
|
||||||
|
{
|
||||||
|
NazaraAssert(!m_world, "Physics world should not be created twice");
|
||||||
|
|
||||||
|
m_world = std::make_unique<Nz::PhysWorld>();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Operation to perform when entity is validated for the system
|
* \brief Operation to perform when entity is validated for the system
|
||||||
*
|
*
|
||||||
|
|
@ -62,7 +69,7 @@ namespace Ndk
|
||||||
entities.Insert(entity);
|
entities.Insert(entity);
|
||||||
|
|
||||||
if (!m_world)
|
if (!m_world)
|
||||||
m_world = std::make_unique<Nz::PhysWorld>();
|
CreatePhysWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue