|
@@ -9,6 +9,10 @@
|
|
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
|
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
|
#include <Jolt/Core/JobSystemThreadPool.h>
|
|
#include <Jolt/Core/JobSystemThreadPool.h>
|
|
#include <Jolt/Core/TempAllocator.h>
|
|
#include <Jolt/Core/TempAllocator.h>
|
|
|
|
+#include <Jolt/Core/StreamWrapper.h>
|
|
|
|
+#ifdef JPH_DEBUG_RENDERER
|
|
|
|
+ #include <Jolt/Renderer/DebugRendererRecorder.h>
|
|
|
|
+#endif
|
|
|
|
|
|
PhysicsTestContext::PhysicsTestContext(float inDeltaTime, int inCollisionSteps, int inWorkerThreads, uint inMaxBodies, uint inMaxBodyPairs, uint inMaxContactConstraints) :
|
|
PhysicsTestContext::PhysicsTestContext(float inDeltaTime, int inCollisionSteps, int inWorkerThreads, uint inMaxBodies, uint inMaxBodyPairs, uint inMaxContactConstraints) :
|
|
#ifdef JPH_DISABLE_TEMP_ALLOCATOR
|
|
#ifdef JPH_DISABLE_TEMP_ALLOCATOR
|
|
@@ -27,6 +31,11 @@ PhysicsTestContext::PhysicsTestContext(float inDeltaTime, int inCollisionSteps,
|
|
|
|
|
|
PhysicsTestContext::~PhysicsTestContext()
|
|
PhysicsTestContext::~PhysicsTestContext()
|
|
{
|
|
{
|
|
|
|
+#ifdef JPH_DEBUG_RENDERER
|
|
|
|
+ delete mDebugRenderer;
|
|
|
|
+ delete mStreamWrapper;
|
|
|
|
+ delete mStream;
|
|
|
|
+#endif // JPH_DEBUG_RENDERER
|
|
delete mSystem;
|
|
delete mSystem;
|
|
delete mJobSystem;
|
|
delete mJobSystem;
|
|
delete mTempAllocator;
|
|
delete mTempAllocator;
|
|
@@ -77,6 +86,23 @@ Body &PhysicsTestContext::CreateSphere(RVec3Arg inPosition, float inRadius, EMot
|
|
return CreateBody(new SphereShapeSettings(inRadius), inPosition, Quat::sIdentity(), inMotionType, inMotionQuality, inLayer, inActivation);
|
|
return CreateBody(new SphereShapeSettings(inRadius), inPosition, Quat::sIdentity(), inMotionType, inMotionQuality, inLayer, inActivation);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+EPhysicsUpdateError PhysicsTestContext::SimulateSingleStep()
|
|
|
|
+{
|
|
|
|
+ EPhysicsUpdateError errors = mSystem->Update(mDeltaTime, mCollisionSteps, mTempAllocator, mJobSystem);
|
|
|
|
+#ifndef JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
+ JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
|
|
|
|
+#endif // JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
+#ifdef JPH_DEBUG_RENDERER
|
|
|
|
+ if (mDebugRenderer != nullptr)
|
|
|
|
+ {
|
|
|
|
+ mSystem->DrawBodies(BodyManager::DrawSettings(), mDebugRenderer);
|
|
|
|
+ mSystem->DrawConstraints(mDebugRenderer);
|
|
|
|
+ mDebugRenderer->EndFrame();
|
|
|
|
+ }
|
|
|
|
+#endif // JPH_DEBUG_RENDERER
|
|
|
|
+ return errors;
|
|
|
|
+}
|
|
|
|
+
|
|
EPhysicsUpdateError PhysicsTestContext::Simulate(float inTotalTime, function<void()> inPreStepCallback)
|
|
EPhysicsUpdateError PhysicsTestContext::Simulate(float inTotalTime, function<void()> inPreStepCallback)
|
|
{
|
|
{
|
|
EPhysicsUpdateError errors = EPhysicsUpdateError::None;
|
|
EPhysicsUpdateError errors = EPhysicsUpdateError::None;
|
|
@@ -84,25 +110,13 @@ EPhysicsUpdateError PhysicsTestContext::Simulate(float inTotalTime, function<voi
|
|
const int cNumSteps = int(round(inTotalTime / mDeltaTime));
|
|
const int cNumSteps = int(round(inTotalTime / mDeltaTime));
|
|
for (int s = 0; s < cNumSteps; ++s)
|
|
for (int s = 0; s < cNumSteps; ++s)
|
|
{
|
|
{
|
|
- inPreStepCallback();
|
|
|
|
- errors |= mSystem->Update(mDeltaTime, mCollisionSteps, mTempAllocator, mJobSystem);
|
|
|
|
- #ifndef JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
- JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
|
|
|
|
- #endif // JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
|
|
+ inPreStepCallback();
|
|
|
|
+ errors |= SimulateSingleStep();
|
|
}
|
|
}
|
|
|
|
|
|
return errors;
|
|
return errors;
|
|
}
|
|
}
|
|
|
|
|
|
-EPhysicsUpdateError PhysicsTestContext::SimulateSingleStep()
|
|
|
|
-{
|
|
|
|
- EPhysicsUpdateError errors = mSystem->Update(mDeltaTime, mCollisionSteps, mTempAllocator, mJobSystem);
|
|
|
|
-#ifndef JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
- JPH_ASSERT(static_cast<TempAllocatorImpl *>(mTempAllocator)->IsEmpty());
|
|
|
|
-#endif // JPH_DISABLE_TEMP_ALLOCATOR
|
|
|
|
- return errors;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
RVec3 PhysicsTestContext::PredictPosition(RVec3Arg inPosition, Vec3Arg inVelocity, Vec3Arg inAcceleration, float inTotalTime) const
|
|
RVec3 PhysicsTestContext::PredictPosition(RVec3Arg inPosition, Vec3Arg inVelocity, Vec3Arg inAcceleration, float inTotalTime) const
|
|
{
|
|
{
|
|
// Integrate position using a Symplectic Euler step (just like the PhysicsSystem)
|
|
// Integrate position using a Symplectic Euler step (just like the PhysicsSystem)
|
|
@@ -137,3 +151,23 @@ Quat PhysicsTestContext::PredictOrientation(QuatArg inRotation, Vec3Arg inAngula
|
|
}
|
|
}
|
|
return rot;
|
|
return rot;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+#ifdef JPH_DEBUG_RENDERER
|
|
|
|
+
|
|
|
|
+void PhysicsTestContext::RecordDebugOutput(const char *inFileName)
|
|
|
|
+{
|
|
|
|
+ mStream = new ofstream;
|
|
|
|
+ mStream->open(inFileName, ofstream::out | ofstream::binary | ofstream::trunc);
|
|
|
|
+ if (mStream->is_open())
|
|
|
|
+ {
|
|
|
|
+ mStreamWrapper = new StreamOutWrapper(*mStream);
|
|
|
|
+ mDebugRenderer = new DebugRendererRecorder(*mStreamWrapper);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ delete mStream;
|
|
|
|
+ mStream = nullptr;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#endif // JPH_DEBUG_RENDERER
|