initialize time-step statistics in a world; rename profile function

This commit is contained in:
Irlan 2018-04-26 23:51:20 -03:00
parent 16d351ecac
commit cd6c7e188a
5 changed files with 47 additions and 40 deletions

View File

@ -19,13 +19,13 @@
#include <bounce\bounce.h> #include <bounce\bounce.h>
// We don't care for a profiler. This definition does nothing. // 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. // We don't care for a profiler. This definition does nothing.
void b3PopProfileScope() void b3EndProfileScope()
{ {
} }

View File

@ -61,6 +61,8 @@ public:
// Add a profiler event to the queue. // Add a profiler event to the queue.
// Return true if the even has been added to the event queue // Return true if the even has been added to the event queue
// or false if the queue is full. // 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); bool PushEvent(const char* name);
// Remove the top profiler event. // Remove the top profiler event.

View File

@ -21,30 +21,24 @@
#include <imgui/imgui.h> #include <imgui/imgui.h>
extern u32 b3_allocCalls, b3_maxAllocCalls; extern u32 b3_allocCalls, b3_maxAllocCalls;
extern u32 b3_convexCalls, b3_convexCacheHits;
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters; extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
extern bool b3_convexCache; 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(); g_profiler->PopEvent();
} }
Test::Test() : m_bodyDragger(&m_bodyRay, &m_world) 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; b3Draw_draw = g_draw;
b3_convexCache = g_testSettings->convexCache;
m_world.SetContactListener(this); m_world.SetContactListener(this);
@ -58,25 +52,12 @@ Test::Test() : m_bodyDragger(&m_bodyRay, &m_world)
Test::~Test() 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; b3Draw_draw = nullptr;
} }
void Test::Step() void Test::Step()
{ {
b3_allocCalls = 0;
b3_gjkCalls = 0;
b3_gjkIters = 0;
b3_gjkMaxIters = 0;
b3_convexCache = g_testSettings->convexCache; b3_convexCache = g_testSettings->convexCache;
b3_convexCalls = 0;
b3_convexCacheHits = 0;
// Step // Step
float32 dt = g_testSettings->inv_hertz; float32 dt = g_testSettings->inv_hertz;

View File

@ -143,28 +143,25 @@ void b3Free(void* block);
// from this software. // from this software.
void b3Log(const char* string, ...); void b3Log(const char* string, ...);
// You should implement this function to use your own profiler. // You should implement this function to listen when a profile scope is opened.
bool b3PushProfileScope(const char* name); void b3BeginProfileScope(const char* name);
// You should implement this function to use your own profiler. // You must implement this function if you have implemented b3BeginProfileScope.
void b3PopProfileScope(); // Implement this function to listen when a profile scope is closed.
void b3EndProfileScope();
//
struct b3ProfileScope struct b3ProfileScope
{ {
b3ProfileScope(const char* name) b3ProfileScope(const char* name)
{ {
b = b3PushProfileScope(name); b3BeginProfileScope(name);
} }
~b3ProfileScope() ~b3ProfileScope()
{ {
if (b) b3EndProfileScope();
{
b3PopProfileScope();
} }
}
private:
bool b;
}; };
// The current version this software. // The current version this software.

View File

@ -25,14 +25,24 @@
#include <bounce/dynamics/joints/joint.h> #include <bounce/dynamics/joints/joint.h>
#include <bounce/dynamics/time_step.h> #include <bounce/dynamics/time_step.h>
extern u32 b3_allocCalls; extern u32 b3_allocCalls, b3_maxAllocCalls;
extern u32 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)) b3World::b3World() : m_bodyBlocks(sizeof(b3Body))
{ {
b3_allocCalls = 0; b3_allocCalls = 0;
b3_maxAllocCalls = 0; b3_maxAllocCalls = 0;
b3_gjkCalls = 0;
b3_gjkIters = 0;
b3_convexCalls = 0;
b3_convexCacheHits = 0;
b3_convexCache = true;
m_flags = e_clearForcesFlag; m_flags = e_clearForcesFlag;
m_sleeping = false; m_sleeping = false;
m_warmStarting = true; m_warmStarting = true;
@ -49,8 +59,15 @@ b3World::~b3World()
b->DestroyJoints(); b->DestroyJoints();
b = b->m_next; b = b->m_next;
} }
b3_allocCalls = 0; b3_allocCalls = 0;
b3_maxAllocCalls = 0; b3_maxAllocCalls = 0;
b3_gjkCalls = 0;
b3_gjkIters = 0;
b3_convexCalls = 0;
b3_convexCacheHits = 0;
} }
void b3World::SetSleeping(bool flag) void b3World::SetSleeping(bool flag)
@ -98,6 +115,16 @@ void b3World::Step(float32 dt, u32 velocityIterations, u32 positionIterations)
{ {
B3_PROFILE("Step"); 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 (m_flags & e_shapeAddedFlag)
{ {
// If new shapes were added new contacts might be created. // If new shapes were added new contacts might be created.