From 54ecddad2f6c90fd11be5619267be9b722418514 Mon Sep 17 00:00:00 2001 From: Doyle Thai Date: Sat, 9 Jul 2016 20:59:54 +1000 Subject: [PATCH] Add function call counting to debug infrastructure --- src/Debug.c | 5 +++++ src/Renderer.c | 2 ++ src/WorldTraveller.c | 5 +++++ src/include/Dengine/Debug.h | 14 ++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/Debug.c b/src/Debug.c index 51f8be1..7345cdd 100644 --- a/src/Debug.c +++ b/src/Debug.c @@ -1,4 +1,5 @@ #include "Dengine/Debug.h" +#include DebugState GLOBAL_debugState; @@ -9,6 +10,9 @@ void debug_init() GLOBAL_debugState.stringUpdateRate = 0.15f; GLOBAL_debugState.stringLineGap = -1; + + GLOBAL_debugState.callCount = + CAST(i32 *) calloc(debugcallcount_num, sizeof(i32)); } void debug_pushString(char *formatString, void *data, char *dataType) @@ -76,3 +80,4 @@ void debug_stringUpdateAndRender(Renderer *renderer, Font *font, f32 dt) GLOBAL_debugState.stringPos = GLOBAL_debugState.initialStringPos; } + diff --git a/src/Renderer.c b/src/Renderer.c index f59b322..dc50db4 100644 --- a/src/Renderer.c +++ b/src/Renderer.c @@ -1,6 +1,7 @@ #include "Dengine/Platform.h" #include "Dengine/OpenGL.h" #include "Dengine/Renderer.h" +#include "Dengine/Debug.h" #define RENDER_BOUNDING_BOX FALSE @@ -140,6 +141,7 @@ void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v4 color, glDrawArrays(GL_TRIANGLE_STRIP, 0, renderer->numVertexesInVbo); #ifdef DENGINE_DEBUG + debug_callCountIncrement(debugcallcount_drawArrays); #endif glBindVertexArray(0); diff --git a/src/WorldTraveller.c b/src/WorldTraveller.c index c356eb6..a558ae4 100644 --- a/src/WorldTraveller.c +++ b/src/WorldTraveller.c @@ -423,6 +423,11 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt) DEBUG_PUSH_STRING("Hero Pos: %06.2f, %06.2f", &hero->pos, "v2"); DEBUG_PUSH_STRING("Hero dPos: %06.2f, %06.2f", &hero->dPos, "v2"); DEBUG_PUSH_STRING("FreeEntityIndex: %d", &world->freeEntityIndex, "i32"); + + DEBUG_PUSH_STRING("glDrawArray Calls: %d", + &GLOBAL_debugState.callCount[debugcallcount_drawArrays], + "i32"); debug_stringUpdateAndRender(&state->renderer, font, dt); + debug_clearCallCounter(); #endif } diff --git a/src/include/Dengine/Debug.h b/src/include/Dengine/Debug.h index 0f1cd00..ed4e3b8 100644 --- a/src/include/Dengine/Debug.h +++ b/src/include/Dengine/Debug.h @@ -15,6 +15,7 @@ enum DebugCallCount typedef struct DebugState { + i32 *callCount; /* Debug strings rendered in top left corner */ char debugStrings[256][64]; i32 numDebugStrings; @@ -29,7 +30,20 @@ typedef struct DebugState extern DebugState GLOBAL_debugState; +inline void debug_callCountIncrement(i32 id) +{ + ASSERT(id < debugcallcount_num); + GLOBAL_debugState.callCount[id]++; +} + +inline void debug_clearCallCounter() +{ + for (i32 i = 0; i < debugcallcount_num; i++) + GLOBAL_debugState.callCount[i] = 0; +} + void debug_init(); void debug_pushString(char *formatString, void *data, char *dataType); void debug_stringUpdateAndRender(Renderer *renderer, Font *font, f32 dt); + #endif