diff --git a/ChangeLog.md b/ChangeLog.md index 329f1200e..ebfa04b97 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -64,6 +64,7 @@ Nazara Engine: - ⚠️ LuaInstance no longer load all lua libraries on construction, this is done in the new LoadLibraries method which allows you to excludes some libraries - Clock::Restart now returns the elapsed microseconds since construction or last Restart call - Add PhysWorld2D::[Get|Set]IterationCount to control how many iterations chipmunk will perform per step. +- Add PhysWorld2D::UseSpatialHash to use spatial hashing instead of bounding box trees, which may speedup simulation in some cases. Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Physics2D/PhysWorld2D.hpp b/include/Nazara/Physics2D/PhysWorld2D.hpp index 00d64bc4d..9762a8309 100644 --- a/include/Nazara/Physics2D/PhysWorld2D.hpp +++ b/include/Nazara/Physics2D/PhysWorld2D.hpp @@ -75,6 +75,8 @@ namespace Nz void Step(float timestep); + void UseSpatialHash(float cellSize, std::size_t entityCount); + PhysWorld2D& operator=(const PhysWorld2D&) = delete; PhysWorld2D& operator=(PhysWorld2D&&) = delete; ///TODO diff --git a/src/Nazara/Physics2D/PhysWorld2D.cpp b/src/Nazara/Physics2D/PhysWorld2D.cpp index c4b296e5c..205ec20f9 100644 --- a/src/Nazara/Physics2D/PhysWorld2D.cpp +++ b/src/Nazara/Physics2D/PhysWorld2D.cpp @@ -322,6 +322,11 @@ namespace Nz } } + void PhysWorld2D::UseSpatialHash(float cellSize, std::size_t entityCount) + { + cpSpaceUseSpatialHash(m_handle, cpFloat(cellSize), int(entityCount)); + } + void PhysWorld2D::InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks) { auto it = m_callbacks.emplace(handler, std::make_unique(callbacks)).first;