mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 02:48:12 +02:00
abstraction of recursion through bullet perf stats
This commit is contained in:
parent
0ff91e5926
commit
068d04c58d
2 changed files with 30 additions and 23 deletions
|
@ -10,6 +10,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <PhysicsCollisionGroups.h>
|
#include <PhysicsCollisionGroups.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
@ -328,6 +329,33 @@ void PhysicsEngine::stepSimulation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using CProfileOperator = std::function<void(CProfileIterator*, QString)>;
|
||||||
|
|
||||||
|
CProfileOperator harvestProfile = [](CProfileIterator* profileIterator, QString contextName) {
|
||||||
|
QString childContextName = contextName + QString("/") + QString(profileIterator->Get_Current_Name());
|
||||||
|
uint64_t time = (uint64_t)((btScalar)MSECS_PER_SECOND * profileIterator->Get_Current_Total_Time());
|
||||||
|
PerformanceTimer::addTimerRecord(childContextName, time);
|
||||||
|
};
|
||||||
|
|
||||||
|
void recurseOpOnPerformanceStats(CProfileOperator op, CProfileIterator* profileIterator, QString contextName) {
|
||||||
|
QString parentContextName = contextName + QString("/") + QString(profileIterator->Get_Current_Parent_Name());
|
||||||
|
// get the stats for the children
|
||||||
|
int32_t numChildren = 0;
|
||||||
|
profileIterator->First();
|
||||||
|
while (!profileIterator->Is_Done()) {
|
||||||
|
op(profileIterator, contextName);
|
||||||
|
profileIterator->Next();
|
||||||
|
++numChildren;
|
||||||
|
}
|
||||||
|
// recurse the children
|
||||||
|
for (int32_t i = 0; i < numChildren; ++i) {
|
||||||
|
profileIterator->Enter_Child(i);
|
||||||
|
recurseOpOnPerformanceStats(op, profileIterator, parentContextName);
|
||||||
|
}
|
||||||
|
// retreat back to parent
|
||||||
|
profileIterator->Enter_Parent();
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsEngine::harvestPerformanceStats() {
|
void PhysicsEngine::harvestPerformanceStats() {
|
||||||
// unfortunately the full context names get too long for our stats presentation format
|
// unfortunately the full context names get too long for our stats presentation format
|
||||||
//QString contextName = PerformanceTimer::getContextName(); // TODO: how to show full context name?
|
//QString contextName = PerformanceTimer::getContextName(); // TODO: how to show full context name?
|
||||||
|
@ -340,7 +368,7 @@ void PhysicsEngine::harvestPerformanceStats() {
|
||||||
for (int32_t childIndex = 0; !profileIterator->Is_Done(); ++childIndex) {
|
for (int32_t childIndex = 0; !profileIterator->Is_Done(); ++childIndex) {
|
||||||
if (QString(profileIterator->Get_Current_Name()) == "stepSimulation") {
|
if (QString(profileIterator->Get_Current_Name()) == "stepSimulation") {
|
||||||
profileIterator->Enter_Child(childIndex);
|
profileIterator->Enter_Child(childIndex);
|
||||||
recursivelyHarvestPerformanceStats(profileIterator, contextName);
|
recurseOpOnPerformanceStats(harvestProfile, profileIterator, contextName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
profileIterator->Next();
|
profileIterator->Next();
|
||||||
|
@ -348,27 +376,6 @@ void PhysicsEngine::harvestPerformanceStats() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::recursivelyHarvestPerformanceStats(CProfileIterator* profileIterator, QString contextName) {
|
|
||||||
QString parentContextName = contextName + QString("/") + QString(profileIterator->Get_Current_Parent_Name());
|
|
||||||
// get the stats for the children
|
|
||||||
int32_t numChildren = 0;
|
|
||||||
profileIterator->First();
|
|
||||||
while (!profileIterator->Is_Done()) {
|
|
||||||
QString childContextName = parentContextName + QString("/") + QString(profileIterator->Get_Current_Name());
|
|
||||||
uint64_t time = (uint64_t)((btScalar)MSECS_PER_SECOND * profileIterator->Get_Current_Total_Time());
|
|
||||||
PerformanceTimer::addTimerRecord(childContextName, time);
|
|
||||||
profileIterator->Next();
|
|
||||||
++numChildren;
|
|
||||||
}
|
|
||||||
// recurse the children
|
|
||||||
for (int32_t i = 0; i < numChildren; ++i) {
|
|
||||||
profileIterator->Enter_Child(i);
|
|
||||||
recursivelyHarvestPerformanceStats(profileIterator, contextName);
|
|
||||||
}
|
|
||||||
// retreat back to parent
|
|
||||||
profileIterator->Enter_Parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const btCollisionObject* objectB) {
|
void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const btCollisionObject* objectB) {
|
||||||
BT_PROFILE("ownershipInfection");
|
BT_PROFILE("ownershipInfection");
|
||||||
|
|
||||||
|
@ -515,6 +522,7 @@ const VectorOfMotionStates& PhysicsEngine::getChangedMotionStates() {
|
||||||
void PhysicsEngine::dumpStatsIfNecessary() {
|
void PhysicsEngine::dumpStatsIfNecessary() {
|
||||||
if (_dumpNextStats) {
|
if (_dumpNextStats) {
|
||||||
_dumpNextStats = false;
|
_dumpNextStats = false;
|
||||||
|
CProfileManager::Increment_Frame_Counter();
|
||||||
CProfileManager::dumpAll();
|
CProfileManager::dumpAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,6 @@ public:
|
||||||
private:
|
private:
|
||||||
QList<EntityDynamicPointer> removeDynamicsForBody(btRigidBody* body);
|
QList<EntityDynamicPointer> removeDynamicsForBody(btRigidBody* body);
|
||||||
void addObjectToDynamicsWorld(ObjectMotionState* motionState);
|
void addObjectToDynamicsWorld(ObjectMotionState* motionState);
|
||||||
void recursivelyHarvestPerformanceStats(CProfileIterator* profileIterator, QString contextName);
|
|
||||||
|
|
||||||
/// \brief bump any objects that touch this one, then remove contact info
|
/// \brief bump any objects that touch this one, then remove contact info
|
||||||
void bumpAndPruneContacts(ObjectMotionState* motionState);
|
void bumpAndPruneContacts(ObjectMotionState* motionState);
|
||||||
|
|
Loading…
Reference in a new issue