Physics3D: Use pool for rigid bodies (+ sort them to improve cache)
This commit is contained in:
committed by
Jérôme Leclercq
parent
899739cdce
commit
5ee25e9621
@@ -12,18 +12,26 @@
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
class btDynamicsWorld;
|
||||
class btRigidBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RigidBody3D;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysWorld3D
|
||||
{
|
||||
friend RigidBody3D;
|
||||
|
||||
public:
|
||||
struct RaycastHit;
|
||||
|
||||
PhysWorld3D();
|
||||
PhysWorld3D(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D(PhysWorld3D&& ph) noexcept;
|
||||
PhysWorld3D(PhysWorld3D&& ph) = delete;
|
||||
~PhysWorld3D();
|
||||
|
||||
btDynamicsWorld* GetDynamicsWorld();
|
||||
@@ -38,9 +46,20 @@ namespace Nz
|
||||
void Step(Time timestep);
|
||||
|
||||
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) noexcept;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) = delete;
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
float fraction;
|
||||
RigidBody3D* hitBody;
|
||||
Vector3f hitPosition;
|
||||
Vector3f hitNormal;
|
||||
};
|
||||
|
||||
private:
|
||||
btRigidBody* AddRigidBody(std::size_t& rigidBodyIndex, FunctionRef<void(btRigidBody* body)> constructor);
|
||||
void RemoveRigidBody(btRigidBody* rigidBody, std::size_t rigidBodyIndex);
|
||||
|
||||
struct BulletWorld;
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
|
||||
@@ -78,7 +78,8 @@ namespace Nz
|
||||
|
||||
private:
|
||||
std::shared_ptr<Collider3D> m_geom;
|
||||
std::unique_ptr<btRigidBody> m_body;
|
||||
std::size_t m_bodyPoolIndex;
|
||||
btRigidBody* m_body;
|
||||
PhysWorld3D* m_world;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
||||
Reference in New Issue
Block a user