Fixing Linux build
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include "PhysicsScene.h"
|
#include "PhysicsScene.h"
|
||||||
#include "PhysicsSettings.h"
|
#include "PhysicsSettings.h"
|
||||||
#include "PhysicsStepper.h"
|
#include "PhysicsStepper.h"
|
||||||
|
#include "SimulationEventCallback.h"
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
|
|
||||||
#include "Actors/IPhysicsActor.h"
|
#include "Actors/IPhysicsActor.h"
|
||||||
@@ -101,6 +102,8 @@ private:
|
|||||||
PxCpuDispatcher* CpuDispatcher;
|
PxCpuDispatcher* CpuDispatcher;
|
||||||
PxControllerManager* ControllerManager;
|
PxControllerManager* ControllerManager;
|
||||||
PxSimulationFilterShader PhysXDefaultFilterShader = PxDefaultSimulationFilterShader;
|
PxSimulationFilterShader PhysXDefaultFilterShader = PxDefaultSimulationFilterShader;
|
||||||
|
SimulationEventCallback EventsCallback;
|
||||||
|
CriticalSection FlushLocker;
|
||||||
|
|
||||||
Array<PxActor*> NewActors;
|
Array<PxActor*> NewActors;
|
||||||
Array<PxActor*> DeadActors;
|
Array<PxActor*> DeadActors;
|
||||||
@@ -138,7 +141,7 @@ PhysicsScene::PhysicsScene(const String& name, const PhysicsSettings& settings)
|
|||||||
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD;
|
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD;
|
||||||
if (settings.EnableAdaptiveForce)
|
if (settings.EnableAdaptiveForce)
|
||||||
sceneDesc.flags |= PxSceneFlag::eADAPTIVE_FORCE;
|
sceneDesc.flags |= PxSceneFlag::eADAPTIVE_FORCE;
|
||||||
sceneDesc.simulationEventCallback = &mEventsCallback;
|
sceneDesc.simulationEventCallback = &mPhysxImpl->EventsCallback;
|
||||||
sceneDesc.filterShader = FilterShader;
|
sceneDesc.filterShader = FilterShader;
|
||||||
sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity;
|
sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity;
|
||||||
if (sceneDesc.cpuDispatcher == nullptr)
|
if (sceneDesc.cpuDispatcher == nullptr)
|
||||||
@@ -284,7 +287,7 @@ void PhysicsScene::Simulate(float dt)
|
|||||||
mIsDuringSimulation = true;
|
mIsDuringSimulation = true;
|
||||||
if (mStepper->advance(mPhysxImpl->Scene, dt, mScratchMemory, SCRATCH_BLOCK_SIZE) == false)
|
if (mStepper->advance(mPhysxImpl->Scene, dt, mScratchMemory, SCRATCH_BLOCK_SIZE) == false)
|
||||||
return;
|
return;
|
||||||
mEventsCallback.Clear();
|
mPhysxImpl->EventsCallback.Clear();
|
||||||
mLastDeltaTime = dt;
|
mLastDeltaTime = dt;
|
||||||
|
|
||||||
// TODO: move this call after rendering done
|
// TODO: move this call after rendering done
|
||||||
@@ -618,10 +621,10 @@ void PhysicsScene::CollectResults()
|
|||||||
{
|
{
|
||||||
PROFILE_CPU_NAMED("Physics.SendEvents");
|
PROFILE_CPU_NAMED("Physics.SendEvents");
|
||||||
|
|
||||||
mEventsCallback.CollectResults();
|
mPhysxImpl->EventsCallback.CollectResults();
|
||||||
mEventsCallback.SendTriggerEvents();
|
mPhysxImpl->EventsCallback.SendTriggerEvents();
|
||||||
mEventsCallback.SendCollisionEvents();
|
mPhysxImpl->EventsCallback.SendCollisionEvents();
|
||||||
mEventsCallback.SendJointEvents();
|
mPhysxImpl->EventsCallback.SendJointEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// End
|
// End
|
||||||
@@ -635,7 +638,7 @@ void PhysicsScene::FlushRequests()
|
|||||||
|
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
|
|
||||||
// Note: this does not handle case when actor is removed and added to the scene at the same time
|
// Note: this does not handle case when actor is removed and added to the scene at the same time
|
||||||
|
|
||||||
@@ -671,7 +674,7 @@ void PhysicsScene::FlushRequests()
|
|||||||
{
|
{
|
||||||
for (int32 i = 0; i < mPhysxImpl->DeadColliders.Count(); i++)
|
for (int32 i = 0; i < mPhysxImpl->DeadColliders.Count(); i++)
|
||||||
{
|
{
|
||||||
mEventsCallback.OnColliderRemoved(mPhysxImpl->DeadColliders[i]);
|
mPhysxImpl->EventsCallback.OnColliderRemoved(mPhysxImpl->DeadColliders[i]);
|
||||||
}
|
}
|
||||||
mPhysxImpl->DeadColliders.Clear();
|
mPhysxImpl->DeadColliders.Clear();
|
||||||
}
|
}
|
||||||
@@ -680,7 +683,7 @@ void PhysicsScene::FlushRequests()
|
|||||||
{
|
{
|
||||||
for (int32 i = 0; i < mPhysxImpl->DeadJoints.Count(); i++)
|
for (int32 i = 0; i < mPhysxImpl->DeadJoints.Count(); i++)
|
||||||
{
|
{
|
||||||
mEventsCallback.OnJointRemoved(mPhysxImpl->DeadJoints[i]);
|
mPhysxImpl->EventsCallback.OnJointRemoved(mPhysxImpl->DeadJoints[i]);
|
||||||
}
|
}
|
||||||
mPhysxImpl->DeadJoints.Clear();
|
mPhysxImpl->DeadJoints.Clear();
|
||||||
}
|
}
|
||||||
@@ -702,32 +705,32 @@ void PhysicsScene::FlushRequests()
|
|||||||
}
|
}
|
||||||
mPhysxImpl->DeadObjects.Clear();
|
mPhysxImpl->DeadObjects.Clear();
|
||||||
|
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::RemoveMaterial(PxMaterial* material)
|
void PhysicsScene::RemoveMaterial(PxMaterial* material)
|
||||||
{
|
{
|
||||||
ASSERT(material);
|
ASSERT(material);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
mPhysxImpl->DeadMaterials.Add(material);
|
mPhysxImpl->DeadMaterials.Add(material);
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::RemoveObject(PxBase* obj)
|
void PhysicsScene::RemoveObject(PxBase* obj)
|
||||||
{
|
{
|
||||||
ASSERT(obj);
|
ASSERT(obj);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
mPhysxImpl->DeadObjects.Add(obj);
|
mPhysxImpl->DeadObjects.Add(obj);
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::AddActor(PxActor* actor)
|
void PhysicsScene::AddActor(PxActor* actor)
|
||||||
{
|
{
|
||||||
ASSERT(actor);
|
ASSERT(actor);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
if (IsInMainThread())
|
if (IsInMainThread())
|
||||||
{
|
{
|
||||||
GetScene()->addActor(*actor);
|
GetScene()->addActor(*actor);
|
||||||
@@ -736,14 +739,14 @@ void PhysicsScene::AddActor(PxActor* actor)
|
|||||||
{
|
{
|
||||||
mPhysxImpl->NewActors.Add(actor);
|
mPhysxImpl->NewActors.Add(actor);
|
||||||
}
|
}
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::AddActor(PxRigidDynamic* actor, bool putToSleep)
|
void PhysicsScene::AddActor(PxRigidDynamic* actor, bool putToSleep)
|
||||||
{
|
{
|
||||||
ASSERT(actor);
|
ASSERT(actor);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
if (IsInMainThread())
|
if (IsInMainThread())
|
||||||
{
|
{
|
||||||
GetScene()->addActor(*actor);
|
GetScene()->addActor(*actor);
|
||||||
@@ -756,7 +759,7 @@ void PhysicsScene::AddActor(PxRigidDynamic* actor, bool putToSleep)
|
|||||||
if (putToSleep)
|
if (putToSleep)
|
||||||
mPhysxImpl->Actions.Add({ ActionType::Sleep, actor });
|
mPhysxImpl->Actions.Add({ ActionType::Sleep, actor });
|
||||||
}
|
}
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::UnlinkActor(PxActor* actor)
|
void PhysicsScene::UnlinkActor(PxActor* actor)
|
||||||
@@ -774,27 +777,27 @@ void PhysicsScene::RemoveActor(PxActor* actor)
|
|||||||
// Unlink ref to flax object
|
// Unlink ref to flax object
|
||||||
actor->userData = nullptr;
|
actor->userData = nullptr;
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
mPhysxImpl->DeadActors.Add(actor);
|
mPhysxImpl->DeadActors.Add(actor);
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::RemoveCollider(PhysicsColliderActor* collider)
|
void PhysicsScene::RemoveCollider(PhysicsColliderActor* collider)
|
||||||
{
|
{
|
||||||
ASSERT(collider);
|
ASSERT(collider);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
mPhysxImpl->DeadColliders.Add(collider);
|
mPhysxImpl->DeadColliders.Add(collider);
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsScene::RemoveJoint(Joint* joint)
|
void PhysicsScene::RemoveJoint(Joint* joint)
|
||||||
{
|
{
|
||||||
ASSERT(joint);
|
ASSERT(joint);
|
||||||
|
|
||||||
mFlushLocker.Lock();
|
mPhysxImpl->FlushLocker.Lock();
|
||||||
mPhysxImpl->DeadJoints.Add(joint);
|
mPhysxImpl->DeadJoints.Add(joint);
|
||||||
mFlushLocker.Unlock();
|
mPhysxImpl->FlushLocker.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
PxControllerManager* PhysicsScene::GetControllerManager()
|
PxControllerManager* PhysicsScene::GetControllerManager()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Engine/Physics/SimulationEventCallback.h"
|
|
||||||
#include "Engine/Scripting/ScriptingObject.h"
|
#include "Engine/Scripting/ScriptingObject.h"
|
||||||
#include "Engine/Scripting/ScriptingType.h"
|
#include "Engine/Scripting/ScriptingType.h"
|
||||||
#include "Engine/Core/Math/Vector3.h"
|
#include "Engine/Core/Math/Vector3.h"
|
||||||
@@ -12,6 +11,7 @@ class WheeledVehicle;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ActionData;
|
struct ActionData;
|
||||||
|
struct RayCastHit;
|
||||||
class FixedStepper;
|
class FixedStepper;
|
||||||
class PhysicsSettings;
|
class PhysicsSettings;
|
||||||
class PhysicsColliderActor;
|
class PhysicsColliderActor;
|
||||||
@@ -519,14 +519,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
String mName;
|
String mName;
|
||||||
bool mAutoSimulation = true;
|
bool mAutoSimulation = true;
|
||||||
SimulationEventCallback mEventsCallback;
|
|
||||||
|
|
||||||
void* mScratchMemory = nullptr;
|
void* mScratchMemory = nullptr;
|
||||||
FixedStepper* mStepper = nullptr;
|
FixedStepper* mStepper = nullptr;
|
||||||
float mLastDeltaTime = 0.0f;
|
float mLastDeltaTime = 0.0f;
|
||||||
bool mIsDuringSimulation = false;
|
bool mIsDuringSimulation = false;
|
||||||
|
|
||||||
CriticalSection mFlushLocker;
|
|
||||||
|
|
||||||
PhysicsScenePhysX* mPhysxImpl;
|
PhysicsScenePhysX* mPhysxImpl;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user