Implemented shortcut keys to cycle between debug_vars locations and to toggle it on and off

dev
Shariq Shah 6 years ago
parent 42a25e0499
commit 25c73af114
  1. 54
      src/game/debug_vars.c
  2. 6
      src/game/debug_vars.h
  3. 2
      src/game/game.c
  4. 36
      src/game/input.c
  5. 6
      todo.txt
  6. 2
      tools/setup_env.bat

@ -10,8 +10,13 @@ static void debug_vars_clear(struct Debug_Vars* debug_vars);
void debug_vars_init(struct Debug_Vars* debug_vars) void debug_vars_init(struct Debug_Vars* debug_vars)
{ {
debug_vars->visible = true; debug_vars->visible = true;
debug_vars->location = DVL_TOP_RIGHT; debug_vars->location = DVL_TOP_RIGHT;
debug_vars->window_width = 300;
debug_vars->window_height = 500;
debug_vars->row_height = 14;
debug_vars->row_height_color = 16;
debug_vars->row_height_texture = 200;
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++) for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++)
{ {
@ -47,45 +52,46 @@ void debug_vars_post_update(struct Debug_Vars* debug_vars)
if(!debug_vars->visible) if(!debug_vars->visible)
return; return;
const int row_height = 12; int window_x = 0;
const int window_width = 400, window_height = 700; int window_y = 0;
int window_x = 0, window_y = 0; int display_width = 0;
int display_width = 0, display_height = 0; int display_height = 0;
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
struct Gui* gui = game_state->gui; struct Gui* gui = game_state->gui;
struct nk_context* context = &gui->context; struct nk_context* context = &gui->context;
window_get_drawable_size(game_state->window, &display_width, &display_height); window_get_drawable_size(game_state->window, &display_width, &display_height);
int window_flags = NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR; int window_flags = NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR;
switch(debug_vars->location) switch(debug_vars->location)
{ {
case DVL_TOP_RIGHT: case DVL_TOP_RIGHT:
window_x = display_width - window_width; window_x = display_width - debug_vars->window_width;
window_y = 0; window_y = 0;
break; break;
case DVL_BOTTOM_RIGHT: case DVL_BOTTOM_RIGHT:
window_x = display_width - window_width; window_x = display_width - debug_vars->window_width;
window_y = display_height - window_height; window_y = display_height - debug_vars->window_height;
break; break;
case DVL_BOTTOM_LEFT: case DVL_BOTTOM_LEFT:
window_x = 0; window_x = 0;
window_y = display_height - window_height; window_y = display_height - debug_vars->window_height;
break; break;
case DVL_TOP_LEFT: case DVL_TOP_LEFT:
window_x = 0; window_x = 0;
window_y = 0; window_y = 0;
break; break;
case DVL_FREE: case DVL_FREE:
window_x = (display_width / 2) - (window_width / 2); window_x = (display_width / 2) - (debug_vars->window_width / 2);
window_y = (display_height / 2) - (window_height / 2); window_y = (display_height / 2) - (debug_vars->window_height / 2);
window_flags &= ~(NK_WINDOW_BACKGROUND & NK_WINDOW_NO_INPUT); window_flags &= ~(NK_WINDOW_BACKGROUND & NK_WINDOW_NO_INPUT);
break; break;
} }
nk_byte previous_opacity = context->style.window.background.a; nk_byte previous_opacity = context->style.window.background.a;
context->style.window.fixed_background.data.color.a = 100; context->style.window.fixed_background.data.color.a = 100;
if(nk_begin(context, "Debug Variables", nk_recti(window_x, window_y, window_width, window_height), window_flags)) if(nk_begin(context, "Debug Variables", nk_recti(window_x, window_y, debug_vars->window_width, debug_vars->window_height), window_flags))
{ {
nk_layout_row_dynamic(context, row_height, 2); nk_layout_row_dynamic(context, debug_vars->row_height, 2);
int name_flags = NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED; int name_flags = NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED;
int value_flags = NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_CENTERED; int value_flags = NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_CENTERED;
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++) for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++)
@ -132,22 +138,22 @@ void debug_vars_post_update(struct Debug_Vars* debug_vars)
switch(variable->value.type) switch(variable->value.type)
{ {
case VT_INT: // Texture case VT_INT: // Texture
nk_layout_row_dynamic(context, 200, 2); nk_layout_row_dynamic(context, debug_vars->row_height_texture, 2);
nk_label(context, &variable->name[0], name_flags); nk_label(context, &variable->name[0], name_flags);
nk_image_color(context, nk_image_id(texture_get_texture_handle(variable->value.val_int)), nk_rgb_f(1.f, 1.f, 1.f)); nk_image_color(context, nk_image_id(texture_get_texture_handle(variable->value.val_int)), nk_rgb_f(1.f, 1.f, 1.f));
break; break;
case VT_VEC3: // Color RGB case VT_VEC3: // Color RGB
nk_layout_row_dynamic(context, 20, 2); nk_layout_row_dynamic(context, debug_vars->row_height_color, 2);
nk_label(context, &variable->name[0], name_flags); nk_label(context, &variable->name[0], name_flags);
nk_button_color(context, nk_rgb_fv(&variable->value.val_vec3)); nk_button_color(context, nk_rgb_fv(&variable->value.val_vec3));
break; break;
case VT_VEC4: // Color RGBA case VT_VEC4: // Color RGBA
nk_layout_row_dynamic(context, 20, 2); nk_layout_row_dynamic(context, debug_vars->row_height_color, 2);
nk_label(context, &variable->name[0], name_flags); nk_label(context, &variable->name[0], name_flags);
nk_button_color(context, nk_rgba_fv(&variable->value.val_vec4)); nk_button_color(context, nk_rgba_fv(&variable->value.val_vec4));
break; break;
default: default:
nk_layout_row_dynamic(context, row_height, 2); nk_layout_row_dynamic(context, debug_vars->row_height, 2);
nk_label(context, &variable->name[0], name_flags); nk_label(context, &variable->name[0], name_flags);
nk_label(context, "Unsupported Type", value_flags); nk_label(context, "Unsupported Type", value_flags);
break; break;
@ -252,3 +258,9 @@ void debug_vars_show_color_rgba(const char* name, const vec4* value)
variant_assign_vec4(&temp_var, value); variant_assign_vec4(&temp_var, value);
debug_vars_show(name, &temp_var, false); debug_vars_show(name, &temp_var, false);
} }
void debug_vars_cycle_location(struct Debug_Vars* debug_vars)
{
if(++debug_vars->location >= DVL_MAX)
debug_vars->location = 0;
}

@ -27,6 +27,11 @@ struct Debug_Vars
{ {
bool visible; bool visible;
int location; int location;
int window_width;
int window_height;
int row_height;
int row_height_color;
int row_height_texture;
struct Debug_Variable numeric_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC]; struct Debug_Variable numeric_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC];
struct Debug_Variable texture_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC]; struct Debug_Variable texture_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC];
}; };
@ -35,6 +40,7 @@ void debug_vars_init(struct Debug_Vars* debug_vars);
void debug_vars_cleanup(struct Debug_Vars* debug_vars); void debug_vars_cleanup(struct Debug_Vars* debug_vars);
void debug_vars_location_set(struct Debug_Vars* debug_vars, int location); void debug_vars_location_set(struct Debug_Vars* debug_vars, int location);
void debug_vars_post_update(struct Debug_Vars* debug_vars); void debug_vars_post_update(struct Debug_Vars* debug_vars);
void debug_vars_cycle_location(struct Debug_Vars* debug_vars);
void debug_vars_show(const char* name, const struct Variant* value, bool is_numeric); void debug_vars_show(const char* name, const struct Variant* value, bool is_numeric);
void debug_vars_show_int(const char* name, int value); void debug_vars_show_int(const char* name, int value);

@ -541,6 +541,8 @@ void game_update(float dt, bool* window_should_close)
if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, true); if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, true);
if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, false); if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, false);
if(input_map_state_get("Console_Toggle", KS_RELEASED)) console_toggle(game_state->console); if(input_map_state_get("Console_Toggle", KS_RELEASED)) console_toggle(game_state->console);
if(input_map_state_get("Debug_Vars_Toggle", KS_RELEASED)) game_state->debug_vars->visible = !game_state->debug_vars->visible;
if(input_map_state_get("Debug_Vars_Cycle", KS_RELEASED)) debug_vars_cycle_location(game_state->debug_vars);
if(input_map_state_get("Editor_Toggle", KS_RELEASED)) if(input_map_state_get("Editor_Toggle", KS_RELEASED))
{ {
if(game_state->game_mode == GAME_MODE_EDITOR) if(game_state->game_mode == GAME_MODE_EDITOR)

@ -28,21 +28,23 @@ void input_init(void)
key_bindings = hashmap_new(); key_bindings = hashmap_new();
/* Default keys for fallback */ /* Default keys for fallback */
struct Key_Binding forward_keys = {KEY_W, KMOD_NONE, KEY_UP, KMOD_NONE, KS_INACTIVE}; struct Key_Binding forward_keys = {KEY_W, KMOD_NONE, KEY_UP, KMOD_NONE, KS_INACTIVE};
struct Key_Binding backward_keys = {KEY_S, KMOD_NONE, KEY_DOWN, KMOD_NONE, KS_INACTIVE}; struct Key_Binding backward_keys = {KEY_S, KMOD_NONE, KEY_DOWN, KMOD_NONE, KS_INACTIVE};
struct Key_Binding up_keys = {KEY_Q, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding up_keys = {KEY_Q, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding down_keys = {KEY_E, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding down_keys = {KEY_E, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding left_keys = {KEY_A, KMOD_NONE, KEY_LEFT, KMOD_NONE, KS_INACTIVE}; struct Key_Binding left_keys = {KEY_A, KMOD_NONE, KEY_LEFT, KMOD_NONE, KS_INACTIVE};
struct Key_Binding right_keys = {KEY_D, KMOD_NONE, KEY_RIGHT, KMOD_NONE, KS_INACTIVE}; struct Key_Binding right_keys = {KEY_D, KMOD_NONE, KEY_RIGHT, KMOD_NONE, KS_INACTIVE};
struct Key_Binding turn_right_keys = {KEY_L, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding turn_right_keys = {KEY_L, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding turn_left_keys = {KEY_H, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding turn_left_keys = {KEY_H, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding turn_up_keys = {KEY_K, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding turn_up_keys = {KEY_K, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding turn_down_keys = {KEY_J, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding turn_down_keys = {KEY_J, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding sprint_keys = {KEY_LSHIFT, KMOD_NONE, KEY_RSHIFT, KMOD_NONE, KS_INACTIVE}; struct Key_Binding sprint_keys = {KEY_LSHIFT, KMOD_NONE, KEY_RSHIFT, KMOD_NONE, KS_INACTIVE};
struct Key_Binding editor_toggle_keys = {KEY_F1, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding editor_toggle_keys = {KEY_F1, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding console_toggle_keys = {KEY_TILDE, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding console_toggle_keys = {KEY_TILDE, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding win_fullscr_keys = {KEY_F11, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding debug_vars_toggle_keys = {KEY_F2, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding win_max_keys = {KEY_F12, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE}; struct Key_Binding debug_vars_cycle_keys = {KEY_F3, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding win_fullscreen_keys = {KEY_F11, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
struct Key_Binding win_max_keys = {KEY_F12, KMOD_NONE, KEY_NONE, KMOD_NONE, KS_INACTIVE};
input_map_create("Move_Forward", forward_keys); input_map_create("Move_Forward", forward_keys);
input_map_create("Move_Backward", backward_keys); input_map_create("Move_Backward", backward_keys);
input_map_create("Move_Up", up_keys); input_map_create("Move_Up", up_keys);
@ -56,7 +58,9 @@ void input_init(void)
input_map_create("Sprint", sprint_keys); input_map_create("Sprint", sprint_keys);
input_map_create("Editor_Toggle", editor_toggle_keys); input_map_create("Editor_Toggle", editor_toggle_keys);
input_map_create("Console_Toggle", console_toggle_keys); input_map_create("Console_Toggle", console_toggle_keys);
input_map_create("Window_Fullscreen", win_fullscr_keys); input_map_create("Debug_Vars_Toggle", debug_vars_toggle_keys);
input_map_create("Debug_Vars_Cycle", debug_vars_cycle_keys);
input_map_create("Window_Fullscreen", win_fullscreen_keys);
input_map_create("Window_Maximize", win_max_keys); input_map_create("Window_Maximize", win_max_keys);
if(!input_keybinds_load("keybindings.symtres", DIRT_USER)) if(!input_keybinds_load("keybindings.symtres", DIRT_USER))

@ -1,6 +1,4 @@
Todo: Todo:
- Shortcut key to toggle debug variable display and cycle locations
- Move debug vars display settings to debug_vars struct
- Command history in console - Command history in console
- Add editor undo for transformation operations - Add editor undo for transformation operations
- Decide how to handle scale when checking sphere-ray intersection - Decide how to handle scale when checking sphere-ray intersection
@ -365,4 +363,6 @@ Done:
* Debug Vars viewbale from game and editor * Debug Vars viewbale from game and editor
* Console Command to display debug vars * Console Command to display debug vars
* Console command to set the location of debug vars location * Console command to set the location of debug vars location
* Brought back debug variable display in editor and allow showing colours, textures etc * Brought back debug variable display in editor and allow showing colours, textures etc
* Shortcut key to toggle debug variable display and cycle locations
* Move debug vars display settings to debug_vars struct

@ -5,4 +5,4 @@ subst W: %CD%\..
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
cls cls
set path=W:\tools;%path% rem set path=W:\tools;%path% rem
call launch_vs.bat

Loading…
Cancel
Save