From a5884a2e07b85d669d58f1862dce871192302ede Mon Sep 17 00:00:00 2001 From: Iain Mckay Date: Wed, 15 Dec 2021 20:52:58 +0100 Subject: [PATCH] Fixing Linux build --- Source/Engine/Physics/PhysicsScene.cpp | 51 ++++++++++++++------------ Source/Engine/Physics/PhysicsScene.h | 6 +-- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/Source/Engine/Physics/PhysicsScene.cpp b/Source/Engine/Physics/PhysicsScene.cpp index fcc935b51..7b5520c0a 100644 --- a/Source/Engine/Physics/PhysicsScene.cpp +++ b/Source/Engine/Physics/PhysicsScene.cpp @@ -2,6 +2,7 @@ #include "PhysicsScene.h" #include "PhysicsSettings.h" #include "PhysicsStepper.h" +#include "SimulationEventCallback.h" #include "Utilities.h" #include "Actors/IPhysicsActor.h" @@ -101,6 +102,8 @@ private: PxCpuDispatcher* CpuDispatcher; PxControllerManager* ControllerManager; PxSimulationFilterShader PhysXDefaultFilterShader = PxDefaultSimulationFilterShader; + SimulationEventCallback EventsCallback; + CriticalSection FlushLocker; Array NewActors; Array DeadActors; @@ -138,7 +141,7 @@ PhysicsScene::PhysicsScene(const String& name, const PhysicsSettings& settings) sceneDesc.flags |= PxSceneFlag::eENABLE_CCD; if (settings.EnableAdaptiveForce) sceneDesc.flags |= PxSceneFlag::eADAPTIVE_FORCE; - sceneDesc.simulationEventCallback = &mEventsCallback; + sceneDesc.simulationEventCallback = &mPhysxImpl->EventsCallback; sceneDesc.filterShader = FilterShader; sceneDesc.bounceThresholdVelocity = settings.BounceThresholdVelocity; if (sceneDesc.cpuDispatcher == nullptr) @@ -284,7 +287,7 @@ void PhysicsScene::Simulate(float dt) mIsDuringSimulation = true; if (mStepper->advance(mPhysxImpl->Scene, dt, mScratchMemory, SCRATCH_BLOCK_SIZE) == false) return; - mEventsCallback.Clear(); + mPhysxImpl->EventsCallback.Clear(); mLastDeltaTime = dt; // TODO: move this call after rendering done @@ -618,10 +621,10 @@ void PhysicsScene::CollectResults() { PROFILE_CPU_NAMED("Physics.SendEvents"); - mEventsCallback.CollectResults(); - mEventsCallback.SendTriggerEvents(); - mEventsCallback.SendCollisionEvents(); - mEventsCallback.SendJointEvents(); + mPhysxImpl->EventsCallback.CollectResults(); + mPhysxImpl->EventsCallback.SendTriggerEvents(); + mPhysxImpl->EventsCallback.SendCollisionEvents(); + mPhysxImpl->EventsCallback.SendJointEvents(); } // End @@ -635,7 +638,7 @@ void PhysicsScene::FlushRequests() 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 @@ -671,7 +674,7 @@ void PhysicsScene::FlushRequests() { for (int32 i = 0; i < mPhysxImpl->DeadColliders.Count(); i++) { - mEventsCallback.OnColliderRemoved(mPhysxImpl->DeadColliders[i]); + mPhysxImpl->EventsCallback.OnColliderRemoved(mPhysxImpl->DeadColliders[i]); } mPhysxImpl->DeadColliders.Clear(); } @@ -680,7 +683,7 @@ void PhysicsScene::FlushRequests() { for (int32 i = 0; i < mPhysxImpl->DeadJoints.Count(); i++) { - mEventsCallback.OnJointRemoved(mPhysxImpl->DeadJoints[i]); + mPhysxImpl->EventsCallback.OnJointRemoved(mPhysxImpl->DeadJoints[i]); } mPhysxImpl->DeadJoints.Clear(); } @@ -702,32 +705,32 @@ void PhysicsScene::FlushRequests() } mPhysxImpl->DeadObjects.Clear(); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::RemoveMaterial(PxMaterial* material) { ASSERT(material); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); mPhysxImpl->DeadMaterials.Add(material); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::RemoveObject(PxBase* obj) { ASSERT(obj); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); mPhysxImpl->DeadObjects.Add(obj); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::AddActor(PxActor* actor) { ASSERT(actor); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); if (IsInMainThread()) { GetScene()->addActor(*actor); @@ -736,14 +739,14 @@ void PhysicsScene::AddActor(PxActor* actor) { mPhysxImpl->NewActors.Add(actor); } - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::AddActor(PxRigidDynamic* actor, bool putToSleep) { ASSERT(actor); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); if (IsInMainThread()) { GetScene()->addActor(*actor); @@ -756,7 +759,7 @@ void PhysicsScene::AddActor(PxRigidDynamic* actor, bool putToSleep) if (putToSleep) mPhysxImpl->Actions.Add({ ActionType::Sleep, actor }); } - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::UnlinkActor(PxActor* actor) @@ -774,27 +777,27 @@ void PhysicsScene::RemoveActor(PxActor* actor) // Unlink ref to flax object actor->userData = nullptr; - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); mPhysxImpl->DeadActors.Add(actor); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::RemoveCollider(PhysicsColliderActor* collider) { ASSERT(collider); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); mPhysxImpl->DeadColliders.Add(collider); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } void PhysicsScene::RemoveJoint(Joint* joint) { ASSERT(joint); - mFlushLocker.Lock(); + mPhysxImpl->FlushLocker.Lock(); mPhysxImpl->DeadJoints.Add(joint); - mFlushLocker.Unlock(); + mPhysxImpl->FlushLocker.Unlock(); } PxControllerManager* PhysicsScene::GetControllerManager() diff --git a/Source/Engine/Physics/PhysicsScene.h b/Source/Engine/Physics/PhysicsScene.h index fa0e0303d..b4a3c7d8d 100644 --- a/Source/Engine/Physics/PhysicsScene.h +++ b/Source/Engine/Physics/PhysicsScene.h @@ -1,6 +1,5 @@ #pragma once -#include "Engine/Physics/SimulationEventCallback.h" #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Core/Math/Vector3.h" @@ -12,6 +11,7 @@ class WheeledVehicle; #endif struct ActionData; +struct RayCastHit; class FixedStepper; class PhysicsSettings; class PhysicsColliderActor; @@ -519,14 +519,10 @@ public: private: String mName; bool mAutoSimulation = true; - SimulationEventCallback mEventsCallback; - void* mScratchMemory = nullptr; FixedStepper* mStepper = nullptr; float mLastDeltaTime = 0.0f; bool mIsDuringSimulation = false; - CriticalSection mFlushLocker; - PhysicsScenePhysX* mPhysxImpl; };