From 25c73af11451f95ca1f9e4fb1b198bf10ab89c66 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Thu, 19 Dec 2019 11:09:51 +1100 Subject: [PATCH] Implemented shortcut keys to cycle between debug_vars locations and to toggle it on and off --- src/game/debug_vars.c | 54 ++++++++++++++++++++++++++----------------- src/game/debug_vars.h | 6 +++++ src/game/game.c | 2 ++ src/game/input.c | 36 ++++++++++++++++------------- todo.txt | 6 ++--- tools/setup_env.bat | 2 +- 6 files changed, 65 insertions(+), 41 deletions(-) diff --git a/src/game/debug_vars.c b/src/game/debug_vars.c index f6c8b72..3d2e12b 100755 --- a/src/game/debug_vars.c +++ b/src/game/debug_vars.c @@ -10,8 +10,13 @@ static void debug_vars_clear(struct Debug_Vars* debug_vars); void debug_vars_init(struct Debug_Vars* debug_vars) { - debug_vars->visible = true; - debug_vars->location = DVL_TOP_RIGHT; + debug_vars->visible = true; + 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++) { @@ -47,45 +52,46 @@ void debug_vars_post_update(struct Debug_Vars* debug_vars) if(!debug_vars->visible) return; - const int row_height = 12; - const int window_width = 400, window_height = 700; - int window_x = 0, window_y = 0; - int display_width = 0, display_height = 0; - struct Game_State* game_state = game_state_get(); - struct Gui* gui = game_state->gui; - struct nk_context* context = &gui->context; + int window_x = 0; + int window_y = 0; + int display_width = 0; + int display_height = 0; + struct Game_State* game_state = game_state_get(); + struct Gui* gui = game_state->gui; + struct nk_context* context = &gui->context; + window_get_drawable_size(game_state->window, &display_width, &display_height); int window_flags = NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR; switch(debug_vars->location) { case DVL_TOP_RIGHT: - window_x = display_width - window_width; + window_x = display_width - debug_vars->window_width; window_y = 0; break; case DVL_BOTTOM_RIGHT: - window_x = display_width - window_width; - window_y = display_height - window_height; + window_x = display_width - debug_vars->window_width; + window_y = display_height - debug_vars->window_height; break; case DVL_BOTTOM_LEFT: window_x = 0; - window_y = display_height - window_height; + window_y = display_height - debug_vars->window_height; break; case DVL_TOP_LEFT: window_x = 0; window_y = 0; break; case DVL_FREE: - window_x = (display_width / 2) - (window_width / 2); - window_y = (display_height / 2) - (window_height / 2); + window_x = (display_width / 2) - (debug_vars->window_width / 2); + window_y = (display_height / 2) - (debug_vars->window_height / 2); window_flags &= ~(NK_WINDOW_BACKGROUND & NK_WINDOW_NO_INPUT); break; } nk_byte previous_opacity = context->style.window.background.a; 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 value_flags = NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_CENTERED; 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) { 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_image_color(context, nk_image_id(texture_get_texture_handle(variable->value.val_int)), nk_rgb_f(1.f, 1.f, 1.f)); break; 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_button_color(context, nk_rgb_fv(&variable->value.val_vec3)); break; 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_button_color(context, nk_rgba_fv(&variable->value.val_vec4)); break; 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, "Unsupported Type", value_flags); break; @@ -252,3 +258,9 @@ void debug_vars_show_color_rgba(const char* name, const vec4* value) variant_assign_vec4(&temp_var, value); 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; +} diff --git a/src/game/debug_vars.h b/src/game/debug_vars.h index 7397a29..f772d88 100755 --- a/src/game/debug_vars.h +++ b/src/game/debug_vars.h @@ -27,6 +27,11 @@ struct Debug_Vars { bool visible; 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 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_location_set(struct Debug_Vars* debug_vars, int location); 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_int(const char* name, int value); diff --git a/src/game/game.c b/src/game/game.c index a1ae54b..b0f251f 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -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_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("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(game_state->game_mode == GAME_MODE_EDITOR) diff --git a/src/game/input.c b/src/game/input.c index 5704783..e0a4197 100755 --- a/src/game/input.c +++ b/src/game/input.c @@ -28,21 +28,23 @@ void input_init(void) key_bindings = hashmap_new(); /* Default keys for fallback */ - 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 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 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 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_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 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 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 win_max_keys = {KEY_F12, KMOD_NONE, KEY_NONE, 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 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 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 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_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 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 console_toggle_keys = {KEY_TILDE, 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 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_Backward", backward_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("Editor_Toggle", editor_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); if(!input_keybinds_load("keybindings.symtres", DIRT_USER)) diff --git a/todo.txt b/todo.txt index 063e1ad..9692148 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,4 @@ Todo: - - Shortcut key to toggle debug variable display and cycle locations - - Move debug vars display settings to debug_vars struct - Command history in console - Add editor undo for transformation operations - Decide how to handle scale when checking sphere-ray intersection @@ -365,4 +363,6 @@ Done: * Debug Vars viewbale from game and editor * Console Command to display debug vars * Console command to set the location of debug vars location - * Brought back debug variable display in editor and allow showing colours, textures etc \ No newline at end of file + * 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 \ No newline at end of file diff --git a/tools/setup_env.bat b/tools/setup_env.bat index 186b081..1295f29 100644 --- a/tools/setup_env.bat +++ b/tools/setup_env.bat @@ -5,4 +5,4 @@ subst W: %CD%\.. call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 cls set path=W:\tools;%path% rem - +call launch_vs.bat