From cd6c7e188a4a974a8642d51db6dbf12826668551 Mon Sep 17 00:00:00 2001 From: Irlan <-> Date: Thu, 26 Apr 2018 23:51:20 -0300 Subject: [PATCH] initialize time-step statistics in a world; rename profile function --- examples/hello_world/main.cpp | 6 +++--- examples/testbed/framework/profiler.h | 2 ++ examples/testbed/framework/test.cpp | 29 +++++-------------------- include/bounce/common/settings.h | 19 +++++++--------- src/bounce/dynamics/world.cpp | 31 +++++++++++++++++++++++++-- 5 files changed, 47 insertions(+), 40 deletions(-) diff --git a/examples/hello_world/main.cpp b/examples/hello_world/main.cpp index 2760e6d..88d0594 100644 --- a/examples/hello_world/main.cpp +++ b/examples/hello_world/main.cpp @@ -19,13 +19,13 @@ #include // We don't care for a profiler. This definition does nothing. -bool b3PushProfileScope(const char* name) +void b3BeginProfileScope(const char* name) { - return false; + } // We don't care for a profiler. This definition does nothing. -void b3PopProfileScope() +void b3EndProfileScope() { } diff --git a/examples/testbed/framework/profiler.h b/examples/testbed/framework/profiler.h index 79dd23a..f5c2d8b 100644 --- a/examples/testbed/framework/profiler.h +++ b/examples/testbed/framework/profiler.h @@ -61,6 +61,8 @@ public: // Add a profiler event to the queue. // Return true if the even has been added to the event queue // or false if the queue is full. + // You can control the maximum number of profiler events using + // MAX_PROFILER_EVENTS. bool PushEvent(const char* name); // Remove the top profiler event. diff --git a/examples/testbed/framework/test.cpp b/examples/testbed/framework/test.cpp index c3602c7..4bceb6c 100644 --- a/examples/testbed/framework/test.cpp +++ b/examples/testbed/framework/test.cpp @@ -21,30 +21,24 @@ #include extern u32 b3_allocCalls, b3_maxAllocCalls; +extern u32 b3_convexCalls, b3_convexCacheHits; extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; extern bool b3_convexCache; -extern u32 b3_convexCalls, b3_convexCacheHits; -bool b3PushProfileScope(const char* name) +void b3BeginProfileScope(const char* name) { - return g_profiler->PushEvent(name); + g_profiler->PushEvent(name); } -void b3PopProfileScope() +void b3EndProfileScope() { g_profiler->PopEvent(); } Test::Test() : m_bodyDragger(&m_bodyRay, &m_world) { - b3_allocCalls = 0; - b3_gjkCalls = 0; - b3_gjkIters = 0; - b3_gjkMaxIters = 0; - b3_convexCache = g_testSettings->convexCache; - b3_convexCalls = 0; - b3_convexCacheHits = 0; b3Draw_draw = g_draw; + b3_convexCache = g_testSettings->convexCache; m_world.SetContactListener(this); @@ -58,25 +52,12 @@ Test::Test() : m_bodyDragger(&m_bodyRay, &m_world) Test::~Test() { - b3_allocCalls = 0; - b3_gjkCalls = 0; - b3_gjkIters = 0; - b3_gjkMaxIters = 0; - b3_convexCache = false; - b3_convexCalls = 0; - b3_convexCacheHits = 0; b3Draw_draw = nullptr; } void Test::Step() { - b3_allocCalls = 0; - b3_gjkCalls = 0; - b3_gjkIters = 0; - b3_gjkMaxIters = 0; b3_convexCache = g_testSettings->convexCache; - b3_convexCalls = 0; - b3_convexCacheHits = 0; // Step float32 dt = g_testSettings->inv_hertz; diff --git a/include/bounce/common/settings.h b/include/bounce/common/settings.h index b665914..7aeba36 100644 --- a/include/bounce/common/settings.h +++ b/include/bounce/common/settings.h @@ -143,28 +143,25 @@ void b3Free(void* block); // from this software. void b3Log(const char* string, ...); -// You should implement this function to use your own profiler. -bool b3PushProfileScope(const char* name); +// You should implement this function to listen when a profile scope is opened. +void b3BeginProfileScope(const char* name); -// You should implement this function to use your own profiler. -void b3PopProfileScope(); +// You must implement this function if you have implemented b3BeginProfileScope. +// Implement this function to listen when a profile scope is closed. +void b3EndProfileScope(); +// struct b3ProfileScope { b3ProfileScope(const char* name) { - b = b3PushProfileScope(name); + b3BeginProfileScope(name); } ~b3ProfileScope() { - if (b) - { - b3PopProfileScope(); - } + b3EndProfileScope(); } -private: - bool b; }; // The current version this software. diff --git a/src/bounce/dynamics/world.cpp b/src/bounce/dynamics/world.cpp index 2b57ab7..a0e940a 100644 --- a/src/bounce/dynamics/world.cpp +++ b/src/bounce/dynamics/world.cpp @@ -25,14 +25,24 @@ #include #include -extern u32 b3_allocCalls; -extern u32 b3_maxAllocCalls; +extern u32 b3_allocCalls, b3_maxAllocCalls; +extern u32 b3_convexCalls, b3_convexCacheHits; +extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; +extern bool b3_convexCache; b3World::b3World() : m_bodyBlocks(sizeof(b3Body)) { b3_allocCalls = 0; b3_maxAllocCalls = 0; + + b3_gjkCalls = 0; + b3_gjkIters = 0; + b3_convexCalls = 0; + b3_convexCacheHits = 0; + + b3_convexCache = true; + m_flags = e_clearForcesFlag; m_sleeping = false; m_warmStarting = true; @@ -49,8 +59,15 @@ b3World::~b3World() b->DestroyJoints(); b = b->m_next; } + b3_allocCalls = 0; b3_maxAllocCalls = 0; + + b3_gjkCalls = 0; + b3_gjkIters = 0; + + b3_convexCalls = 0; + b3_convexCacheHits = 0; } void b3World::SetSleeping(bool flag) @@ -98,6 +115,16 @@ void b3World::Step(float32 dt, u32 velocityIterations, u32 positionIterations) { B3_PROFILE("Step"); + // Clear statistics + b3_allocCalls = 0; + + b3_convexCalls = 0; + b3_convexCacheHits = 0; + + b3_gjkCalls = 0; + b3_gjkIters = 0; + b3_gjkMaxIters = 0; + if (m_flags & e_shapeAddedFlag) { // If new shapes were added new contacts might be created.