Add function call counting to debug infrastructure

This commit is contained in:
Doyle Thai 2016-07-09 20:59:54 +10:00
parent 1f364f7024
commit 54ecddad2f
4 changed files with 26 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "Dengine/Debug.h"
#include <stdlib.h>
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;
}

View File

@ -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);

View File

@ -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
}

View File

@ -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