Skip to content

Commit 42a83fa

Browse files
committed
- physics: pre-integrate and post-integrate as events
1 parent 52257cd commit 42a83fa

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎shared/physics/eqPhysics_World.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ void CEqPhysicsWorld::ProcessContactPair(eqContactPair& pair)
12251225
//
12261226
//----------------------------------------------------------------------------------------------------
12271227

1228-
void CEqPhysicsWorld::SimulateStep(float deltaTime, int iteration, FNSIMULATECALLBACK preIntegrFunc)
1228+
void CEqPhysicsWorld::SimulateStep(float deltaTime, int iteration)
12291229
{
12301230
if(!m_broadphase)
12311231
return;
@@ -1251,7 +1251,7 @@ void CEqPhysicsWorld::SimulateStep(float deltaTime, int iteration, FNSIMULATECAL
12511251
contr->Update(m_fDt);
12521252
}
12531253
}
1254-
1254+
12551255
m_simMovingMoveables.clear();
12561256
m_simMovingMoveables.reserve(m_moveable.numElem());
12571257

@@ -1288,8 +1288,7 @@ void CEqPhysicsWorld::SimulateStep(float deltaTime, int iteration, FNSIMULATECAL
12881288

12891289
m_fDt = deltaTime;
12901290

1291-
if(preIntegrFunc)
1292-
preIntegrFunc(m_fDt, iteration);
1291+
m_preIntegrateEvt(m_fDt, iteration);
12931292

12941293
if(m_collDetJob)
12951294
{
@@ -1323,6 +1322,8 @@ void CEqPhysicsWorld::SimulateStep(float deltaTime, int iteration, FNSIMULATECAL
13231322
callbacks->PostSimulate(m_fDt);
13241323
}
13251324
}
1325+
1326+
m_postIntegrateEvt(m_fDt, iteration);
13261327

13271328
{
13281329
PROF_EVENT("Constraits apply");

‎shared/physics/eqPhysics_World.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#pragma once
3232
#include "eqPhysics_Defs.h"
3333
#include "core/IEqParallelJobs.h"
34+
#include "ds/event.h"
3435

3536
struct btDispatcherInfo;
3637
class btCollisionWorld;
@@ -48,7 +49,7 @@ class CEqPhysicsBroadphase;
4849
class IEqPhysicsConstraint;
4950
class IEqPhysController;
5051

51-
typedef void (*FNSIMULATECALLBACK)(float fDt, int iterNum);
52+
using PhysIntegrateEvent = Event<void(float delta, int iterNum)>;
5253

5354
//--------------------------------------------------------------------------------------------------------------
5455

@@ -78,6 +79,9 @@ class CEqPhysicsWorld
7879
const eqPhysSurfParam* FindSurfaceParam(const char* name) const;
7980
const eqPhysSurfParam* GetSurfaceParamByID(int id) const;
8081

82+
PhysIntegrateEvent& GetPreIntegrateEvent() { return m_preIntegrateEvt; }
83+
PhysIntegrateEvent& GetPostIntegrateEvent() { return m_postIntegrateEvt; }
84+
8185
void AddToMoveableList( CEqRigidBody* body ); ///< adds object to moveable list
8286
void RemoveFromMoveableList( CEqRigidBody* body );
8387

@@ -144,7 +148,7 @@ class CEqPhysicsWorld
144148
void DebugDrawBodies(int mode);
145149

146150
///< Simulates physics
147-
void SimulateStep( float deltaTime, int iteration, FNSIMULATECALLBACK preIntegrFunc); ///< simulates physics
151+
void SimulateStep( float deltaTime, int iteration); ///< simulates physics
148152

149153

150154
// checks collision (made especially for rays, but could be used in other situations)
@@ -171,6 +175,9 @@ class CEqPhysicsWorld
171175
class PreSimulateJob;
172176
class CollisionDetectionJob;
173177

178+
PhysIntegrateEvent m_preIntegrateEvt{ PP_SL };
179+
PhysIntegrateEvent m_postIntegrateEvt{ PP_SL };
180+
174181
CEqJobManager& m_jobMng;
175182
PreSimulateJob* m_preSimJob{ nullptr };
176183
CollisionDetectionJob* m_collDetJob{ nullptr };

0 commit comments

Comments
 (0)