Update debug data architecture and methods
This commit is contained in:
parent
ea50aeb44e
commit
1f364f7024
@ -122,6 +122,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\AssetManager.c" />
|
||||
<ClCompile Include="src\Common.c" />
|
||||
<ClCompile Include="src\Debug.c" />
|
||||
<ClCompile Include="src\dengine.c" />
|
||||
<ClCompile Include="src\Platform.c" />
|
||||
<ClCompile Include="src\Renderer.c" />
|
||||
@ -137,6 +138,7 @@
|
||||
<None Include="data\shaders\sprite.vert.glsl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\Dengine\Debug.h" />
|
||||
<ClInclude Include="src\include\Dengine\Platform.h" />
|
||||
<ClInclude Include="src\include\Dengine\AssetManager.h" />
|
||||
<ClInclude Include="src\include\Dengine\Common.h" />
|
||||
|
@ -42,6 +42,9 @@
|
||||
<ClCompile Include="src\Common.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Debug.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="data\shaders\default.vert.glsl" />
|
||||
@ -83,5 +86,8 @@
|
||||
<ClInclude Include="src\include\Dengine\Platform.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\Dengine\Debug.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
//#define WT_RENDER_FONT_FILE
|
||||
#ifdef WT_RENDER_FONT_FILE
|
||||
@ -20,7 +21,7 @@ Texture *asset_getTexture(AssetManager *assetManager, const enum TexList type)
|
||||
if (type < texlist_count)
|
||||
return &assetManager->textures[type];
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(INVALID_CODE_PATH);
|
||||
#endif
|
||||
|
||||
@ -32,7 +33,7 @@ TexAtlas *asset_getTextureAtlas(AssetManager *assetManager, const enum TexList t
|
||||
if (type < texlist_count)
|
||||
return &assetManager->texAtlas[type];
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(INVALID_CODE_PATH);
|
||||
#endif
|
||||
return NULL;
|
||||
@ -67,7 +68,7 @@ Shader *asset_getShader(AssetManager *assetManager, const enum ShaderList type)
|
||||
if (type < shaderlist_count)
|
||||
return &assetManager->shaders[type];
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(INVALID_CODE_PATH);
|
||||
#endif
|
||||
return NULL;
|
||||
@ -214,7 +215,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
||||
if (width > largestGlyphDimension.w)
|
||||
largestGlyphDimension.w = width;
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
if ((largestGlyphDimension.h - CAST(i32)targetFontHeight) >= 50)
|
||||
{
|
||||
printf(
|
||||
@ -237,7 +238,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
||||
font->maxSize = largestGlyphDimension;
|
||||
i32 glyphsPerRow = (MAX_TEXTURE_SIZE / font->maxSize.w);
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
i32 glyphsPerCol = MAX_TEXTURE_SIZE / font->maxSize.h;
|
||||
if ((glyphsPerRow * glyphsPerCol) <= numGlyphs)
|
||||
{
|
||||
@ -278,7 +279,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath)
|
||||
if (verticalPixelsBlitted == 0)
|
||||
{
|
||||
TexAtlas *fontAtlas = &assetManager->texAtlas[texlist_font];
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(activeGlyph.codepoint < ARRAY_COUNT(fontAtlas->texRect));
|
||||
#endif
|
||||
|
||||
|
13
src/Common.c
13
src/Common.c
@ -6,3 +6,16 @@ i32 common_strlen(const char *const string)
|
||||
while (string[result]) result++;
|
||||
return result;
|
||||
}
|
||||
|
||||
i32 common_strcmp(const char *a, const char *b)
|
||||
{
|
||||
while (*a == *b)
|
||||
{
|
||||
if (!*a)
|
||||
return 0;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
return ((*a < *b) ? -1 : 1);
|
||||
}
|
||||
|
78
src/Debug.c
Normal file
78
src/Debug.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
DebugState GLOBAL_debugState;
|
||||
|
||||
void debug_init()
|
||||
{
|
||||
GLOBAL_debugState.numDebugStrings = 0;
|
||||
GLOBAL_debugState.stringUpdateTimer = 0.0f;
|
||||
GLOBAL_debugState.stringUpdateRate = 0.15f;
|
||||
|
||||
GLOBAL_debugState.stringLineGap = -1;
|
||||
}
|
||||
|
||||
void debug_pushString(char *formatString, void *data, char *dataType)
|
||||
{
|
||||
if (GLOBAL_debugState.stringUpdateTimer <= 0)
|
||||
{
|
||||
i32 numDebugStrings = GLOBAL_debugState.numDebugStrings;
|
||||
if (common_strcmp(dataType, "v2") == 0)
|
||||
{
|
||||
v2 val = *(CAST(v2 *) data);
|
||||
snprintf(GLOBAL_debugState.debugStrings[numDebugStrings],
|
||||
ARRAY_COUNT(GLOBAL_debugState.debugStrings[0]),
|
||||
formatString, val.x, val.y);
|
||||
}
|
||||
else if (common_strcmp(dataType, "i32") == 0)
|
||||
{
|
||||
i32 val = *(CAST(i32 *) data);
|
||||
snprintf(GLOBAL_debugState.debugStrings[numDebugStrings],
|
||||
ARRAY_COUNT(GLOBAL_debugState.debugStrings[0]),
|
||||
formatString, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(INVALID_CODE_PATH);
|
||||
}
|
||||
GLOBAL_debugState.numDebugStrings++;
|
||||
}
|
||||
}
|
||||
|
||||
void debug_stringUpdateAndRender(Renderer *renderer, Font *font, f32 dt)
|
||||
{
|
||||
if (GLOBAL_debugState.stringLineGap == -1)
|
||||
{
|
||||
GLOBAL_debugState.stringLineGap =
|
||||
1.1f * asset_getVFontSpacing(font->metrics);
|
||||
GLOBAL_debugState.initialStringPos =
|
||||
V2(0.0f,
|
||||
(renderer->size.y - 1.8f * GLOBAL_debugState.stringLineGap));
|
||||
GLOBAL_debugState.stringPos = GLOBAL_debugState.initialStringPos;
|
||||
}
|
||||
|
||||
for (i32 i = 0; i < GLOBAL_debugState.numDebugStrings; i++)
|
||||
{
|
||||
f32 rotate = 0;
|
||||
v4 color = V4(0, 0, 0, 1);
|
||||
renderer_string(renderer, font, GLOBAL_debugState.debugStrings[i],
|
||||
GLOBAL_debugState.stringPos, rotate, color);
|
||||
GLOBAL_debugState.stringPos.y -=
|
||||
(0.9f * GLOBAL_debugState.stringLineGap);
|
||||
}
|
||||
|
||||
if (GLOBAL_debugState.stringUpdateTimer <= 0)
|
||||
{
|
||||
GLOBAL_debugState.stringUpdateTimer =
|
||||
GLOBAL_debugState.stringUpdateRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
GLOBAL_debugState.stringUpdateTimer -= dt;
|
||||
if (GLOBAL_debugState.stringUpdateTimer <= 0)
|
||||
{
|
||||
GLOBAL_debugState.numDebugStrings = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLOBAL_debugState.stringPos = GLOBAL_debugState.initialStringPos;
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
|
||||
#define RENDER_BOUNDING_BOX FALSE
|
||||
|
||||
DebugRenderer debugRenderer = {0};
|
||||
|
||||
INTERNAL void updateBufferObject(Renderer *const renderer,
|
||||
RenderQuad *const quads, const i32 numQuads)
|
||||
{
|
||||
@ -61,25 +59,6 @@ void renderer_string(Renderer *const renderer, Font *const font,
|
||||
|
||||
}
|
||||
|
||||
void renderer_debugString(Renderer *const renderer, Font *const font,
|
||||
const char *const string)
|
||||
{
|
||||
/* Intialise debug object */
|
||||
if (!debugRenderer.init)
|
||||
{
|
||||
debugRenderer.stringPos =
|
||||
V2(0.0f, renderer->size.y -
|
||||
(1.8f * asset_getVFontSpacing(font->metrics)));
|
||||
debugRenderer.init = TRUE;
|
||||
}
|
||||
|
||||
f32 rotate = 0;
|
||||
v4 color = V4(0, 0, 0, 1);
|
||||
renderer_string(renderer, font, string, debugRenderer.stringPos, rotate,
|
||||
color);
|
||||
debugRenderer.stringPos.y -= (0.9f * asset_getVFontSpacing(font->metrics));
|
||||
}
|
||||
|
||||
void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity, f32 dt, f32 rotate,
|
||||
v4 color)
|
||||
{
|
||||
@ -159,6 +138,10 @@ void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v4 color,
|
||||
|
||||
glBindVertexArray(renderer->vao);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, renderer->numVertexesInVbo);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
#endif
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
|
@ -39,8 +39,8 @@ Texture genTexture(const GLuint width, const GLuint height,
|
||||
tex.internalFormat = GL_RGBA;
|
||||
tex.wrapS = GL_REPEAT;
|
||||
tex.wrapT = GL_REPEAT;
|
||||
tex.filterMinification = GL_LINEAR;
|
||||
tex.filterMagnification = GL_LINEAR;
|
||||
tex.filterMinification = GL_NEAREST;
|
||||
tex.filterMagnification = GL_NEAREST;
|
||||
|
||||
glGenTextures(1, &tex.id);
|
||||
glCheckError();
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Math.h"
|
||||
#include "Dengine/Debug.h"
|
||||
#include "WorldTraveller/WorldTraveller.h"
|
||||
|
||||
//TODO(doyle): This is temporary! Maybe abstract into our platform layer, or
|
||||
@ -11,7 +11,7 @@ INTERNAL Entity *addEntity(World *world, v2 pos, v2 size,
|
||||
Texture *tex, b32 collides)
|
||||
{
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(tex && world);
|
||||
ASSERT(world->freeEntityIndex < world->maxEntities);
|
||||
ASSERT(type < entitytype_count);
|
||||
@ -34,7 +34,7 @@ INTERNAL Entity *addEntity(World *world, v2 pos, v2 size,
|
||||
INTERNAL void addAnim(Entity *entity, v4 *rects, i32 numRects, f32 duration)
|
||||
{
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(rects && numRects >= 0)
|
||||
ASSERT(entity->freeAnimIndex < ARRAY_COUNT(entity->anim));
|
||||
#endif
|
||||
@ -102,8 +102,10 @@ void worldTraveller_gameInit(GameState *state, v2i windowSize)
|
||||
TexAtlas *terrainAtlas =
|
||||
asset_getTextureAtlas(assetManager, texlist_terrain);
|
||||
f32 atlasTileSize = 128.0f;
|
||||
const i32 texSize = 1024;
|
||||
v2 texOrigin = V2(0, CAST(f32)(texSize - 128));
|
||||
terrainAtlas->texRect[terraincoords_ground] =
|
||||
V4(384.0f, 512.0f, 384.0f + atlasTileSize, 512.0f + atlasTileSize);
|
||||
V4(texOrigin.x, texOrigin.y, texOrigin.x + atlasTileSize, texOrigin.y - atlasTileSize);
|
||||
|
||||
asset_loadShaderFiles(assetManager, "data/shaders/sprite.vert.glsl",
|
||||
"data/shaders/sprite.frag.glsl", shaderlist_sprite);
|
||||
@ -144,7 +146,7 @@ void worldTraveller_gameInit(GameState *state, v2i windowSize)
|
||||
{
|
||||
for (i32 x = 0; x < worldDimensionInTiles.x; x++)
|
||||
{
|
||||
#ifdef WT_DEBUG
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(worldDimensionInTiles.x * worldDimensionInTiles.y <
|
||||
world->maxEntities);
|
||||
#endif
|
||||
@ -415,36 +417,12 @@ void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt)
|
||||
// TODO(doyle): Clean up lines
|
||||
// Renderer::~Renderer() { glDeleteVertexArrays(1, &this->quadVAO); }
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
LOCAL_PERSIST f32 debugUpdateCounter = 0.0f;
|
||||
LOCAL_PERSIST char debugStrings[256][64] = {0};
|
||||
LOCAL_PERSIST i32 numDebugStrings = 0;
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
Font *font = &assetManager->font;
|
||||
if (debugUpdateCounter <= 0)
|
||||
{
|
||||
numDebugStrings = 0;
|
||||
Entity *const hero = &world->entities[world->heroIndex];
|
||||
snprintf(debugStrings[0], ARRAY_COUNT(debugStrings[0]),
|
||||
"Hero Pos: %06.2f,%06.2f", hero->pos.x, hero->pos.y);
|
||||
numDebugStrings++;
|
||||
|
||||
snprintf(debugStrings[1], ARRAY_COUNT(debugStrings[1]),
|
||||
"Hero dPos: %06.2f,%06.2f", hero->dPos.x, hero->dPos.y);
|
||||
numDebugStrings++;
|
||||
|
||||
snprintf(debugStrings[2], ARRAY_COUNT(debugStrings[2]),
|
||||
"FreeEntityIndex: %d", world->freeEntityIndex);
|
||||
numDebugStrings++;
|
||||
|
||||
const f32 debugUpdateRate = 0.15f;
|
||||
debugUpdateCounter = debugUpdateRate;
|
||||
}
|
||||
|
||||
for (i32 i = 0; i < numDebugStrings; i++)
|
||||
renderer_debugString(&state->renderer, font, debugStrings[i]);
|
||||
|
||||
debugUpdateCounter -= dt;
|
||||
debugRenderer.init = FALSE;
|
||||
Entity *hero = &world->entities[world->heroIndex];
|
||||
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_stringUpdateAndRender(&state->renderer, font, dt);
|
||||
#endif
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Renderer.h"
|
||||
#include "Dengine/Math.h"
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
#include "WorldTraveller/WorldTraveller.h"
|
||||
|
||||
@ -75,6 +76,10 @@ int main()
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
debug_init();
|
||||
#endif
|
||||
|
||||
GameState worldTraveller = {0};
|
||||
worldTraveller_gameInit(&worldTraveller, frameBufferSize);
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define WT_DEBUG
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
@ -26,10 +24,9 @@ typedef double f64;
|
||||
#define CAST(type) (type)
|
||||
#define ASSERT(expr) if(!(expr)) { *(int *)0 = 0; }
|
||||
|
||||
#define DENGINE_DEBUG
|
||||
|
||||
i32 common_strlen(const char *const string);
|
||||
|
||||
#ifdef WT_DEBUG
|
||||
#define INVALID_CODE_PATH TRUE
|
||||
#endif
|
||||
i32 common_strcmp(const char *a, const char *b);
|
||||
|
||||
#endif
|
||||
|
35
src/include/Dengine/Debug.h
Normal file
35
src/include/Dengine/Debug.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef DENGINE_DEBUG_H
|
||||
#define DENGINE_DEBUG_H
|
||||
|
||||
#include "Dengine/Renderer.h"
|
||||
|
||||
#define INVALID_CODE_PATH TRUE
|
||||
#define DEBUG_PUSH_STRING(formatString, data, type) \
|
||||
debug_pushString(formatString, CAST(void *) data, type)
|
||||
|
||||
enum DebugCallCount
|
||||
{
|
||||
debugcallcount_drawArrays,
|
||||
debugcallcount_num,
|
||||
};
|
||||
|
||||
typedef struct DebugState
|
||||
{
|
||||
/* Debug strings rendered in top left corner */
|
||||
char debugStrings[256][64];
|
||||
i32 numDebugStrings;
|
||||
f32 stringUpdateTimer;
|
||||
f32 stringUpdateRate;
|
||||
|
||||
v2 initialStringPos;
|
||||
v2 stringPos;
|
||||
|
||||
f32 stringLineGap;
|
||||
} DebugState;
|
||||
|
||||
extern DebugState GLOBAL_debugState;
|
||||
|
||||
void debug_init();
|
||||
void debug_pushString(char *formatString, void *data, char *dataType);
|
||||
void debug_stringUpdateAndRender(Renderer *renderer, Font *font, f32 dt);
|
||||
#endif
|
@ -14,32 +14,14 @@ typedef struct Renderer
|
||||
v2 size;
|
||||
} Renderer;
|
||||
|
||||
typedef struct DebugRenderer
|
||||
{
|
||||
b32 init;
|
||||
v2 stringPos;
|
||||
|
||||
} DebugRenderer;
|
||||
|
||||
typedef struct RenderQuad
|
||||
{
|
||||
v4 vertex[4];
|
||||
} RenderQuad;
|
||||
|
||||
extern DebugRenderer debugRenderer;
|
||||
|
||||
#if 0
|
||||
void renderer_backgroundTiles(Renderer *const renderer, const v2 tileSize,
|
||||
World *const world, TexAtlas *const atlasTexture,
|
||||
Texture *const tex);
|
||||
#endif
|
||||
|
||||
void renderer_string(Renderer *const renderer, Font *const font,
|
||||
const char *const string, v2 pos, f32 rotate, v4 color);
|
||||
|
||||
void renderer_debugString(Renderer *const renderer, Font *const font,
|
||||
const char *const string);
|
||||
|
||||
void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
|
||||
f32 dt, f32 rotate, v4 color);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef DENGINE_TEXTURE_H
|
||||
#define DENGINE_TEXTURE_H
|
||||
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
#include "Dengine/Common.h"
|
||||
|
||||
#define TARGET_TEXTURE_SIZE 1024
|
||||
#define TARGET_BYTES_PER_PIXEL 4
|
||||
|
Loading…
Reference in New Issue
Block a user