Add toggle debug display button and config entry

This commit is contained in:
Doyle Thai 2016-08-20 14:18:05 +10:00
parent 6ec92358b2
commit 801107908a
3 changed files with 43 additions and 20 deletions

View File

@ -418,6 +418,17 @@ void debug_drawUi(GameState *state, f32 dt)
} }
/* Render debug info stack */ /* Render debug info stack */
DEBUG_PUSH_STRING("== Controls ==");
DEBUG_PUSH_STRING(" [: Spawn a mob");
DEBUG_PUSH_STRING("<TAB>: Switch UI element");
DEBUG_PUSH_STRING("<ESC>: Close program");
DEBUG_PUSH_STRING("== Config == ");
DEBUG_PUSH_VAR("Toggle World Audio: %d", state->config.playWorldAudio,
"i32");
DEBUG_PUSH_VAR("Toggle Debug Display: %d", state->config.showDebugDisplay,
"i32");
DEBUG_PUSH_STRING("== Hero Properties == "); DEBUG_PUSH_STRING("== Hero Properties == ");
DEBUG_PUSH_VAR("Hero Pos: %06.2f, %06.2f", hero->pos, "v2"); DEBUG_PUSH_VAR("Hero Pos: %06.2f, %06.2f", hero->pos, "v2");
DEBUG_PUSH_VAR("Hero dPos: %06.2f, %06.2f", hero->dPos, "v2"); DEBUG_PUSH_VAR("Hero dPos: %06.2f, %06.2f", hero->dPos, "v2");

View File

@ -129,11 +129,10 @@ INTERNAL void assetInit(GameState *state)
i32 result = i32 result =
asset_loadTTFont(assetManager, arena, "C:/Windows/Fonts/Arialbd.ttf"); asset_loadTTFont(assetManager, arena, "C:/Windows/Fonts/Arialbd.ttf");
if (result) DEBUG_LOG("Font loading failed");
GL_CHECK_ERROR();
#ifdef DENGINE_DEBUG #ifdef DENGINE_DEBUG
if (result) DEBUG_LOG("Font loading failed");
GL_CHECK_ERROR();
DEBUG_LOG("Assets loaded"); DEBUG_LOG("Assets loaded");
#endif #endif
@ -344,6 +343,9 @@ void worldTraveller_gameInit(GameState *state, v2 windowSize)
state->uiState.keyMod = keycode_null; state->uiState.keyMod = keycode_null;
state->uiState.keyChar = keycode_null; state->uiState.keyChar = keycode_null;
state->config.playWorldAudio = FALSE;
state->config.showDebugDisplay = TRUE;
assetInit(state); assetInit(state);
rendererInit(state, windowSize); rendererInit(state, windowSize);
entityInit(state, windowSize); entityInit(state, windowSize);
@ -409,8 +411,8 @@ INTERNAL b32 getKeyStatus(KeyState *key, enum ReadKeyType readType,
break; break;
} }
default: default:
DEBUG_LOG("getKeyStatus() error: Invalid ReadKeyType enum");
#ifdef DENGINE_DEBUG #ifdef DENGINE_DEBUG
DEBUG_LOG("getKeyStatus() error: Invalid ReadKeyType enum");
ASSERT(INVALID_CODE_PATH); ASSERT(INVALID_CODE_PATH);
#endif #endif
break; break;
@ -433,13 +435,6 @@ INTERNAL void parseInput(GameState *state, const f32 dt)
f (t) = (a/2)*t^2 + v*t + p, where p is a constant, old position f (t) = (a/2)*t^2 + v*t + p, where p is a constant, old position
*/ */
#ifdef DENGINE_DEBUG
DEBUG_PUSH_STRING("== Controls ==");
DEBUG_PUSH_STRING(" [: Spawn a mob");
DEBUG_PUSH_STRING("<TAB>: Switch UI element");
DEBUG_PUSH_STRING("<ESC>: Close program");
#endif
World *const world = &state->world[state->currWorldIndex]; World *const world = &state->world[state->currWorldIndex];
Entity *hero = &world->entities[entity_getIndex(world, world->heroId)]; Entity *hero = &world->entities[entity_getIndex(world, world->heroId)];
v2 ddPos = V2(0, 0); v2 ddPos = V2(0, 0);
@ -1246,7 +1241,9 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
// entity, the entity will exist for an additional frame // entity, the entity will exist for an additional frame
case eventtype_entity_died: case eventtype_entity_died:
{ {
#ifdef DEGINE_DEBUG
DEBUG_LOG("Entity died: being deleted"); DEBUG_LOG("Entity died: being deleted");
#endif
if (!event.data) continue; if (!event.data) continue;
Entity *entity = (CAST(Entity *) event.data); Entity *entity = (CAST(Entity *) event.data);
@ -1313,25 +1310,36 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
/* Draw ui */ /* Draw ui */
// TODO(doyle): Bug in font rendering once button reaches 700-800+ pixels // TODO(doyle): Bug in font rendering once button reaches 700-800+ pixels
Rect buttonRectA = {V2(1000, 800), V2(100, 50)}; Rect toggleAudioButtonRect = {V2(1000, 800), V2(100, 50)};
b32 toggleAudioClicked = userInterface_button(
b32 isClicked = userInterface_button(
&state->uiState, &state->arena, assetManager, renderer, font, &state->uiState, &state->arena, assetManager, renderer, font,
state->input, 1, buttonRectA, "Toggle Music"); state->input, 1, toggleAudioButtonRect, "Toggle Music");
if (isClicked) if (toggleAudioClicked)
{ {
state->config.playWorldAudio = ~state->config.playWorldAudio; state->config.playWorldAudio =
(state->config.playWorldAudio == TRUE) ? FALSE : TRUE;
}
Rect toggleDebugButtonRect = {V2(1150, 800), V2(100, 50)};
b32 toggleDebugClicked = userInterface_button(
&state->uiState, &state->arena, assetManager, renderer, font,
state->input, 2, toggleDebugButtonRect, "Toggle Debug Display");
if (toggleDebugClicked)
{
state->config.showDebugDisplay =
(state->config.showDebugDisplay == TRUE) ? FALSE : TRUE;
} }
LOCAL_PERSIST i32 scrollValue = 30; LOCAL_PERSIST i32 scrollValue = 30;
Rect scrollRectA = {V2(1500, 600), V2(16, 255)}; Rect scrollRectA = {V2(1500, 600), V2(16, 255)};
userInterface_scrollBar(&state->uiState, assetManager, renderer, userInterface_scrollBar(&state->uiState, assetManager, renderer,
state->input, 2, scrollRectA, &scrollValue, 160); state->input, 3, scrollRectA, &scrollValue, 160);
LOCAL_PERSIST char fieldString[80] = "Hello world"; LOCAL_PERSIST char fieldString[80] = "Hello world";
userInterface_textField(&state->uiState, &state->arena, assetManager, userInterface_textField(&state->uiState, &state->arena, assetManager,
renderer, font, state->input, 3, V2(1000, 750), renderer, font, state->input, 4, V2(1000, 750),
fieldString); fieldString);
// RESET IMGUI // RESET IMGUI
@ -1406,6 +1414,9 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
#endif #endif
#ifdef DENGINE_DEBUG #ifdef DENGINE_DEBUG
debug_drawUi(state, dt); if (state->config.showDebugDisplay)
{
debug_drawUi(state, dt);
}
#endif #endif
} }

View File

@ -19,6 +19,7 @@ typedef struct Entity Entity;
typedef struct Config typedef struct Config
{ {
b32 playWorldAudio; b32 playWorldAudio;
b32 showDebugDisplay;
} Config; } Config;
typedef struct World typedef struct World