Re-implemented and improved debug vars that can display different types of numerical and graphical data without needing any slots

dev
Shariq Shah 6 years ago
parent 115873b586
commit 42a25e0499
  1. 28
      src/game/console.c
  2. 254
      src/game/debug_vars.c
  3. 50
      src/game/debug_vars.h
  4. 141
      src/game/editor.c
  5. 10
      src/game/editor.h
  6. 6
      src/game/game.c
  7. 1
      src/game/game.h
  8. 2
      src/game/geometry.h
  9. 5
      src/game/player.c
  10. 5
      src/game/renderer.c
  11. 11
      todo.txt

@ -5,6 +5,7 @@
#include "../system/platform.h" #include "../system/platform.h"
#include "scene.h" #include "scene.h"
#include "entity.h" #include "entity.h"
#include "debug_vars.h"
#include "../system/file_io.h" #include "../system/file_io.h"
#include <assert.h> #include <assert.h>
@ -20,6 +21,8 @@ static void console_command_scene_save(struct Console* console, const char* comm
static void console_command_scene_load(struct Console* console, const char* command); static void console_command_scene_load(struct Console* console, const char* command);
static void console_command_entity_save(struct Console* console, const char* command); static void console_command_entity_save(struct Console* console, const char* command);
static void console_command_entity_load(struct Console* console, const char* command); static void console_command_entity_load(struct Console* console, const char* command);
static void console_command_debug_vars_toggle(struct Console* console, const char* command);
static void console_command_debug_vars_location_set(struct Console* console, const char* command);
static void console_command_help(struct Console* console, const char* command); static void console_command_help(struct Console* console, const char* command);
void console_init(struct Console* console) void console_init(struct Console* console)
@ -51,6 +54,8 @@ void console_init(struct Console* console)
hashmap_ptr_set(console->console_commands, "scene_load", &console_command_scene_load); hashmap_ptr_set(console->console_commands, "scene_load", &console_command_scene_load);
hashmap_ptr_set(console->console_commands, "entity_save", &console_command_entity_save); hashmap_ptr_set(console->console_commands, "entity_save", &console_command_entity_save);
hashmap_ptr_set(console->console_commands, "entity_load", &console_command_entity_load); hashmap_ptr_set(console->console_commands, "entity_load", &console_command_entity_load);
hashmap_ptr_set(console->console_commands, "debug_vars_toggle", &console_command_debug_vars_toggle);
hashmap_ptr_set(console->console_commands, "debug_vars_location", &console_command_debug_vars_location_set);
hashmap_ptr_set(console->console_commands, "help", &console_command_help); hashmap_ptr_set(console->console_commands, "help", &console_command_help);
} }
@ -127,7 +132,7 @@ void console_update(struct Console* console, struct Gui* gui_state, float dt)
void console_destroy(struct Console* console) void console_destroy(struct Console* console)
{ {
hashmap_free(console->console_commands);
} }
int console_filter(const struct nk_text_edit *box, nk_rune unicode) int console_filter(const struct nk_text_edit *box, nk_rune unicode)
@ -284,3 +289,24 @@ void console_command_scene_empty(struct Console* console, const char* command)
scene_post_update(scene); scene_post_update(scene);
scene_init(scene); scene_init(scene);
} }
void console_command_debug_vars_toggle(struct Console* console, const char* command)
{
struct Debug_Vars* debug_vars = game_state_get()->debug_vars;
debug_vars->visible = !debug_vars->visible;
}
void console_command_debug_vars_location_set(struct Console* console, const char* command)
{
struct Debug_Vars* debug_vars = game_state_get()->debug_vars;
int location = debug_vars->location;
int params_read = sscanf(command, "%d", &location);
if(params_read != 1)
{
log_warning("Invalid parameters for command");
log_warning("Usage: debug_vars_location [Location 0-4]");
return;
}
debug_vars_location_set(debug_vars, location);
}

@ -0,0 +1,254 @@
#include "debug_vars.h"
#include "event.h"
#include "game.h"
#include "gui.h"
#include "../system/platform.h"
#include "texture.h"
#include <string.h>
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;
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++)
{
memset(&debug_vars->numeric_vars[i].name[0], '\0', MAX_DEBUG_VAR_NAME);
variant_init_empty(&debug_vars->numeric_vars[i]);
}
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_TEXTURES; i++)
{
memset(&debug_vars->texture_vars[i].name[0], '\0', MAX_DEBUG_VAR_NAME);
variant_init_empty(&debug_vars->texture_vars[i]);
}
}
void debug_vars_cleanup(struct Debug_Vars* debug_vars)
{
debug_vars->visible = false;
debug_vars_clear(debug_vars);
}
void debug_vars_location_set(struct Debug_Vars* debug_vars, int location)
{
if(location < 0 || location >= DVL_MAX)
{
log_error("debug_vars:location_set", "Invalid location. Valid values are from 0-4");
return;
}
debug_vars->location = location;
}
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;
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_y = 0;
break;
case DVL_BOTTOM_RIGHT:
window_x = display_width - window_width;
window_y = display_height - window_height;
break;
case DVL_BOTTOM_LEFT:
window_x = 0;
window_y = display_height - 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_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))
{
nk_layout_row_dynamic(context, 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++)
{
struct Debug_Variable* variable = &debug_vars->numeric_vars[i];
if(variable->value.type == VT_NONE)
continue;
switch(variable->value.type)
{
case VT_INT:
nk_label(context, &variable->name[0], name_flags);
nk_labelf(context, value_flags, "%d", variable->value.val_int);
break;
case VT_FLOAT:
nk_label(context, &variable->name[0], name_flags);
nk_labelf(context, value_flags, "%.3f", variable->value.val_float);
break;
case VT_VEC2:
nk_label(context, &variable->name[0], name_flags);
nk_labelf(context, value_flags, "%.3f %.3f", variable->value.val_vec2.x, variable->value.val_vec2.y);
break;
case VT_VEC3:
nk_label(context, &variable->name[0], name_flags);
nk_labelf(context, value_flags, "%.3f %.3f %.3f", variable->value.val_vec3.x, variable->value.val_vec3.y, variable->value.val_vec3.z);
break;
case VT_VEC4:
nk_label(context, &variable->name[0], name_flags);
nk_labelf(context, value_flags, "%.3f %.3f %.3f %.3f", variable->value.val_vec4.x, variable->value.val_vec4.y, variable->value.val_vec4.z, variable->value.val_vec4.w);
break;
default:
nk_label(context, &variable->name[0], name_flags);
nk_label(context, "Unsupported Type", value_flags);
break;
}
}
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_TEXTURES; i++)
{
struct Debug_Variable* variable = &debug_vars->texture_vars[i];
if(variable->value.type == VT_NONE)
continue;
switch(variable->value.type)
{
case VT_INT: // Texture
nk_layout_row_dynamic(context, 200, 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_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_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_label(context, &variable->name[0], name_flags);
nk_label(context, "Unsupported Type", value_flags);
break;
}
}
nk_end(context);
}
context->style.window.fixed_background.data.color.a = 255;
debug_vars_clear(debug_vars);
}
void debug_vars_clear(struct Debug_Vars* debug_vars)
{
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_NUMERIC; i++)
{
memset(&debug_vars->numeric_vars[i].name[0], '\0', MAX_DEBUG_VAR_NAME);
variant_free(&debug_vars->numeric_vars[i].value);
}
for(int i = 0; i < MAX_DEBUG_VARS_PER_FRAME_TEXTURES; i++)
{
memset(&debug_vars->texture_vars[i].name[0], '\0', MAX_DEBUG_VAR_NAME);
variant_free(&debug_vars->texture_vars[i].value);
}
}
void debug_vars_show(const char* name, const struct Variant* value, bool is_numeric)
{
struct Debug_Vars* debug_vars = game_state_get()->debug_vars;
if(!debug_vars->visible)
return;
struct Debug_Variable* vars_array = is_numeric ? &debug_vars->numeric_vars[0] : &debug_vars->texture_vars[0];
int array_length = is_numeric ? MAX_DEBUG_VARS_PER_FRAME_NUMERIC : MAX_DEBUG_VARS_PER_FRAME_TEXTURES;
for(int i = 0; i < array_length; i++)
{
struct Debug_Variable* variable = &vars_array[i];
if(variable->value.type == VT_NONE)
{
strncpy(&variable->name[0], name, MAX_DEBUG_VAR_NAME);
variant_copy(&variable->value, value);
return;
}
}
log_warning("%s Debug Vars Full", is_numeric ? "Numeric" : "Texture");
}
void debug_vars_show_int(const char* name, int value)
{
struct Variant temp_var;
variant_assign_int(&temp_var, value);
debug_vars_show(name, &temp_var, true);
}
void debug_vars_show_float(const char* name, float value)
{
struct Variant temp_var;
variant_assign_float(&temp_var, value);
debug_vars_show(name, &temp_var, true);
}
void debug_vars_show_texture(const char* name, int texture_index)
{
struct Variant temp_var;
variant_assign_int(&temp_var, texture_index);
debug_vars_show(name, &temp_var, false);
}
void debug_vars_show_vec3(const char* name, const vec3* value)
{
struct Variant temp_var;
variant_assign_vec3(&temp_var, value);
debug_vars_show(name, &temp_var, true);
}
void debug_vars_show_vec2(const char* name, const vec3* value)
{
struct Variant temp_var;
variant_assign_vec2(&temp_var, value);
debug_vars_show(name, &temp_var, true);
}
void debug_vars_show_vec4(const char* name, const vec3* value)
{
struct Variant temp_var;
variant_assign_vec4(&temp_var, value);
debug_vars_show(name, &temp_var, true);
}
void debug_vars_show_color_rgb(const char* name, const vec3* value)
{
struct Variant temp_var;
variant_assign_vec3(&temp_var, value);
debug_vars_show(name, &temp_var, false);
}
void debug_vars_show_color_rgba(const char* name, const vec4* value)
{
struct Variant temp_var;
variant_assign_vec4(&temp_var, value);
debug_vars_show(name, &temp_var, false);
}

@ -0,0 +1,50 @@
#ifndef DEBUG_VARS_H
#define DEBUG_VARS_H
#include "../common/variant.h"
#define MAX_DEBUG_VAR_NAME 64
#define MAX_DEBUG_VARS_PER_FRAME_NUMERIC 64
#define MAX_DEBUG_VARS_PER_FRAME_TEXTURES 8
struct Debug_Variable
{
char name[MAX_DEBUG_VAR_NAME];
struct Variant value;
};
enum Debug_Variables_Location
{
DVL_TOP_LEFT = 0,
DVL_TOP_RIGHT,
DVL_BOTTOM_LEFT,
DVL_BOTTOM_RIGHT,
DVL_FREE,
DVL_MAX
};
struct Debug_Vars
{
bool visible;
int location;
struct Debug_Variable numeric_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC];
struct Debug_Variable texture_vars[MAX_DEBUG_VARS_PER_FRAME_NUMERIC];
};
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_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_float(const char* name, float value);
void debug_vars_show_texture(const char* name, int texture_index);
void debug_vars_show_vec3(const char* name, const vec3* value);
void debug_vars_show_vec2(const char* name, const vec3* value);
void debug_vars_show_vec4(const char* name, const vec3* value);
void debug_vars_show_color_rgb(const char* name, const vec3* value);
void debug_vars_show_color_rgba(const char* name, const vec4* value);
#endif

@ -30,6 +30,7 @@
#include "geometry.h" #include "geometry.h"
#include "gui.h" #include "gui.h"
#include "console.h" #include "console.h"
#include "debug_vars.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -39,12 +40,6 @@
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
struct Debug_Variable
{
struct Variant data;
char* name;
};
enum Editor_Tool enum Editor_Tool
{ {
EDITOR_TOOL_NORMAL = 0, EDITOR_TOOL_NORMAL = 0,
@ -65,13 +60,11 @@ enum Editor_Axis
EDITOR_AXIS_YZ, EDITOR_AXIS_YZ,
}; };
static struct Debug_Variable* debug_vars_list = NULL; static int window_flags = NK_WINDOW_BORDER |
static int* empty_indices = NULL; NK_WINDOW_CLOSABLE |
static int window_flags = NK_WINDOW_BORDER | NK_WINDOW_MOVABLE |
NK_WINDOW_CLOSABLE | NK_WINDOW_SCROLL_AUTO_HIDE |
NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE;
NK_WINDOW_SCROLL_AUTO_HIDE |
NK_WINDOW_SCALABLE;
static void editor_on_mousebutton_press(const struct Event* event); static void editor_on_mousebutton_press(const struct Event* event);
static void editor_on_mousebutton_release(const struct Event* event); static void editor_on_mousebutton_release(const struct Event* event);
@ -94,7 +87,6 @@ static bool editor_widget_v3(struct nk_context* context,
int row_height); int row_height);
static void editor_window_scene_heirarchy(struct nk_context* context, struct Editor* editor, struct Game_State* game_state); static void editor_window_scene_heirarchy(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
static void editor_window_debug_variables(struct nk_context* context, struct Editor* editor);
static void editor_window_property_inspector(struct nk_context* context, struct Editor* editor, struct Game_State* game_state); static void editor_window_property_inspector(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
static void editor_window_renderer_settings(struct nk_context* context, struct Editor* editor, struct Game_State* game_state); static void editor_window_renderer_settings(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
static void editor_window_settings_editor(struct nk_context* context, struct Editor* editor, struct Game_State* game_state); static void editor_window_settings_editor(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
@ -107,7 +99,6 @@ void editor_init(struct Editor* editor)
{ {
editor->window_settings_renderer = 0; editor->window_settings_renderer = 0;
editor->window_settings_editor = 0; editor->window_settings_editor = 0;
editor->window_debug_variables = 0;
editor->window_property_inspector = 0; editor->window_property_inspector = 0;
editor->window_scene_heirarchy = 0; editor->window_scene_heirarchy = 0;
editor->camera_looking_around = 0; editor->camera_looking_around = 0;
@ -147,9 +138,6 @@ void editor_init(struct Editor* editor)
vec4_fill(&editor->axis_color_z, 0.47, 0.67, 0.89, 0.8f); vec4_fill(&editor->axis_color_z, 0.47, 0.67, 0.89, 0.8f);
vec3_fill(&editor->tool_scale_amount, 1.f, 1.f, 1.f); vec3_fill(&editor->tool_scale_amount, 1.f, 1.f, 1.f);
debug_vars_list = array_new(struct Debug_Variable);
empty_indices = array_new(int);
struct Event_Manager* event_manager = game_state_get()->event_manager; struct Event_Manager* event_manager = game_state_get()->event_manager;
event_manager_subscribe(event_manager, EVT_MOUSEBUTTON_PRESSED, &editor_on_mousebutton_press); event_manager_subscribe(event_manager, EVT_MOUSEBUTTON_PRESSED, &editor_on_mousebutton_press);
event_manager_subscribe(event_manager, EVT_MOUSEBUTTON_RELEASED, &editor_on_mousebutton_release); event_manager_subscribe(event_manager, EVT_MOUSEBUTTON_RELEASED, &editor_on_mousebutton_release);
@ -333,79 +321,6 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
} }
} }
int editor_debugvar_slot_create(const char* name, int value_type)
{
int index = -1;
struct Debug_Variable* debug_var = NULL;
if(array_len(empty_indices) > 0)
{
index = *array_get_last(empty_indices, int);
array_pop(empty_indices);
debug_var = &debug_vars_list[index];
}
else
{
debug_var = array_grow(debug_vars_list, struct Debug_Variable);
index = array_len(debug_vars_list) - 1;
}
debug_var->name = str_new(name);
debug_var->data.type = value_type;
return index;
}
void editor_debugvar_slot_remove(int index)
{
assert(index > -1 && index < array_len(debug_vars_list));
struct Debug_Variable* debug_var = &debug_vars_list[index];
variant_free(&debug_var->data);
if(debug_var->name) free(debug_var->name);
debug_var->name = NULL;
debug_var->data.type = VT_NONE;
}
void editor_debugvar_slot_set_float(int index, float value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_float(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_int(int index, int value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_int(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_double(int index, double value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_double(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_vec2(int index, vec2* value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_vec2(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_vec3(int index, vec3* value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_vec3(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_vec4(int index, vec4* value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_vec4(&debug_vars_list[index].data, value);
}
void editor_debugvar_slot_set_quat(int index, quat* value)
{
assert(index > -1 && index < array_len(debug_vars_list));
variant_assign_quat(&debug_vars_list[index].data, value);
}
void editor_update(struct Editor* editor, float dt) void editor_update(struct Editor* editor, float dt)
{ {
editor_camera_update(editor, dt); editor_camera_update(editor, dt);
@ -449,10 +364,14 @@ void editor_update(struct Editor* editor, float dt)
nk_layout_row_push(context, 0.05f); nk_layout_row_push(context, 0.05f);
if(nk_menu_begin_label(context, "Windows", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE, nk_vec2(180, 100))) if(nk_menu_begin_label(context, "Windows", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE, nk_vec2(180, 100)))
{ {
struct Debug_Vars* debug_vars = game_state->debug_vars;
int debug_vars_visible = debug_vars->visible;
nk_layout_row_dynamic(context, row_height, 1); nk_layout_row_dynamic(context, row_height, 1);
nk_checkbox_label(context, "Scene Heirarchy", &editor->window_scene_heirarchy); nk_checkbox_label(context, "Scene Heirarchy", &editor->window_scene_heirarchy);
nk_checkbox_label(context, "Property Inspector", &editor->window_property_inspector); nk_checkbox_label(context, "Property Inspector", &editor->window_property_inspector);
nk_checkbox_label(context, "Debug Variables", &editor->window_debug_variables); nk_checkbox_label(context, "Debug Variables", &debug_vars_visible);
if(debug_vars_visible != (int)debug_vars->visible)
debug_vars->visible = (bool)debug_vars_visible;
nk_menu_end(context); nk_menu_end(context);
} }
@ -648,7 +567,6 @@ void editor_update(struct Editor* editor, float dt)
nk_end(context); nk_end(context);
if(editor->window_scene_heirarchy) editor_window_scene_heirarchy(context, editor, game_state); if(editor->window_scene_heirarchy) editor_window_scene_heirarchy(context, editor, game_state);
if(editor->window_debug_variables) editor_window_debug_variables(context, editor);
if(editor->window_property_inspector) editor_window_property_inspector(context, editor, game_state); if(editor->window_property_inspector) editor_window_property_inspector(context, editor, game_state);
if(editor->window_settings_renderer) editor_window_renderer_settings(context, editor, game_state); if(editor->window_settings_renderer) editor_window_renderer_settings(context, editor, game_state);
if(editor->window_settings_editor) editor_window_settings_editor(context, editor, game_state); if(editor->window_settings_editor) editor_window_settings_editor(context, editor, game_state);
@ -1406,6 +1324,9 @@ void editor_camera_update(struct Editor* editor, float dt)
//log_message("Position : %s", tostr_vec3(&transform->position)); //log_message("Position : %s", tostr_vec3(&transform->position));
} }
} }
debug_vars_show_texture("Editor Cam Depth", editor_camera->depth_tex);
debug_vars_show_color_rgba("Editor Cam Clear Color", &editor_camera->clear_color);
} }
void editor_widget_color_combov3(struct nk_context* context, vec3* color, int width, int height) void editor_widget_color_combov3(struct nk_context* context, vec3* color, int width, int height)
@ -1491,12 +1412,6 @@ void editor_cleanup(struct Editor* editor)
event_manager_unsubscribe(event_manager, EVT_MOUSEMOTION, &editor_on_mousemotion); event_manager_unsubscribe(event_manager, EVT_MOUSEMOTION, &editor_on_mousemotion);
event_manager_unsubscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press); event_manager_unsubscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press);
event_manager_unsubscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release); event_manager_unsubscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release);
for(int i = 0; i < array_len(debug_vars_list); i++)
editor_debugvar_slot_remove(i);
array_free(debug_vars_list);
array_free(empty_indices);
} }
@ -1565,34 +1480,6 @@ void editor_window_scene_heirarchy(struct nk_context* context, struct Editor* ed
nk_end(context); nk_end(context);
} }
void editor_window_debug_variables(struct nk_context* context, struct Editor* editor)
{
if(nk_begin(context, "Debug Variables", nk_recti(0, 500, 300, 400), window_flags))
{
static char variant_str[MAX_VARIANT_STR_LEN] = { '\0' };
nk_layout_row_dynamic(context, 250, 1);
if(nk_group_begin(context, "Name", NK_WINDOW_SCROLL_AUTO_HIDE))
{
for(int i = 0; i < array_len(debug_vars_list); i++)
{
struct Debug_Variable* debug_var = &debug_vars_list[i];
if(debug_var->data.type == VT_NONE) continue;
nk_layout_row_dynamic(context, 20, 2);
nk_label(context, debug_var->name, NK_TEXT_ALIGN_LEFT);
variant_to_str(&debug_var->data, variant_str, MAX_VARIANT_STR_LEN);
nk_label(context, variant_str, NK_TEXT_ALIGN_RIGHT);
memset(variant_str, '\0', MAX_VARIANT_STR_LEN);
}
nk_group_end(context);
}
}
else
{
editor->window_debug_variables = false;
}
nk_end(context);
}
void editor_window_property_inspector(struct nk_context* context, struct Editor* editor, struct Game_State* game_state) void editor_window_property_inspector(struct nk_context* context, struct Editor* editor, struct Game_State* game_state)
{ {
int win_width = 0, win_height = 0; int win_width = 0, win_height = 0;

@ -15,7 +15,6 @@ struct Editor
int window_settings_editor; int window_settings_editor;
int window_scene_heirarchy; int window_scene_heirarchy;
int window_property_inspector; int window_property_inspector;
int window_debug_variables;
int camera_looking_around; int camera_looking_around;
struct Entity* selected_entity; struct Entity* selected_entity;
struct Static_Mesh* cursor_entity; struct Static_Mesh* cursor_entity;
@ -61,14 +60,5 @@ void editor_init_entities(struct Editor* editor);
void editor_render(struct Editor* editor_state, struct Camera* active_camera); void editor_render(struct Editor* editor_state, struct Camera* active_camera);
void editor_update(struct Editor* editor_state, float dt); void editor_update(struct Editor* editor_state, float dt);
void editor_cleanup(struct Editor* editor_state); void editor_cleanup(struct Editor* editor_state);
int editor_debugvar_slot_create(const char* name, int value_type);
void editor_debugvar_slot_remove(int index);
void editor_debugvar_slot_set_float(int index, float value);
void editor_debugvar_slot_set_int(int index, int value);
void editor_debugvar_slot_set_double(int index, double value);
void editor_debugvar_slot_set_vec2(int index, vec2* value);
void editor_debugvar_slot_set_vec3(int index, vec3* value);
void editor_debugvar_slot_set_vec4(int index, vec4* value);
void editor_debugvar_slot_set_quat(int index, quat* value);
#endif #endif

@ -32,6 +32,7 @@
#include "../common/variant.h" #include "../common/variant.h"
#include "../system/physics.h" #include "../system/physics.h"
#include "../system/platform.h" #include "../system/platform.h"
#include "debug_vars.h"
#include "im_render.h" #include "im_render.h"
#include "event.h" #include "event.h"
@ -78,6 +79,7 @@ bool game_init(struct Window* window, struct Hashmap* cvars)
game_state->gui = calloc(1, sizeof(*game_state->gui)); game_state->gui = calloc(1, sizeof(*game_state->gui));
game_state->event_manager = calloc(1, sizeof(*game_state->event_manager)); game_state->event_manager = calloc(1, sizeof(*game_state->event_manager));
game_state->sound = calloc(1, sizeof(*game_state->sound)); game_state->sound = calloc(1, sizeof(*game_state->sound));
game_state->debug_vars = calloc(1, sizeof(*game_state->debug_vars));
log_message_callback_set(game_on_log_message); log_message_callback_set(game_on_log_message);
log_warning_callback_set(game_on_log_warning); log_warning_callback_set(game_on_log_warning);
@ -107,6 +109,7 @@ bool game_init(struct Window* window, struct Hashmap* cvars)
//physics_body_set_moved_callback(entity_rigidbody_on_move); //physics_body_set_moved_callback(entity_rigidbody_on_move);
//physics_body_set_collision_callback(entity_rigidbody_on_collision); //physics_body_set_collision_callback(entity_rigidbody_on_collision);
sound_init(game_state->sound); sound_init(game_state->sound);
debug_vars_init(game_state->debug_vars);
renderer_init(game_state->renderer); renderer_init(game_state->renderer);
scene_init(game_state->scene); scene_init(game_state->scene);
@ -575,6 +578,7 @@ void game_post_update(float dt)
input_post_update(); input_post_update();
scene_post_update(game_state->scene); scene_post_update(game_state->scene);
sound_update_3d(game_state->sound); sound_update_3d(game_state->sound);
debug_vars_post_update(game_state->debug_vars);
} }
void game_debug_gui(float dt) void game_debug_gui(float dt)
@ -1918,6 +1922,7 @@ void game_cleanup(void)
shader_cleanup(); shader_cleanup();
sound_cleanup(game_state->sound); sound_cleanup(game_state->sound);
//physics_cleanup(); //physics_cleanup();
debug_vars_cleanup(game_state->debug_vars);
event_manager_cleanup(game_state->event_manager); event_manager_cleanup(game_state->event_manager);
free(game_state->editor); free(game_state->editor);
@ -1927,6 +1932,7 @@ void game_cleanup(void)
free(game_state->event_manager); free(game_state->event_manager);
free(game_state->gui); free(game_state->gui);
free(game_state->sound); free(game_state->sound);
free(game_state->debug_vars);
} }
free(game_state); free(game_state);
game_state = NULL; game_state = NULL;

@ -34,6 +34,7 @@ struct Game_State
struct Editor* editor; struct Editor* editor;
struct Hashmap* cvars; struct Hashmap* cvars;
struct Sound* sound; struct Sound* sound;
struct Debug_Vars* debug_vars;
}; };

@ -46,7 +46,7 @@ int geom_create_from_file(const char* name);
int geom_find(const char* filename); int geom_find(const char* filename);
void geom_remove(int index); void geom_remove(int index);
void geom_cleanup(void); void geom_cleanup(void);
void geom_render(int index, enum Geometry_Draw_Mode); void geom_render(int index, enum Geometry_Draw_Mode draw_mode);
void geom_bounding_volume_generate(int index); void geom_bounding_volume_generate(int index);
void geom_bounding_volume_generate_all(void); void geom_bounding_volume_generate_all(void);
struct Geometry* geom_get(int index); struct Geometry* geom_get(int index);

@ -11,6 +11,7 @@
#include "../system/config_vars.h" #include "../system/config_vars.h"
#include "../system/platform.h" #include "../system/platform.h"
#include "game.h" #include "game.h"
#include "debug_vars.h"
void player_init(struct Player* player, struct Scene* scene) void player_init(struct Player* player, struct Scene* scene)
{ {
@ -141,4 +142,8 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
struct Raycast_Result ray_result; struct Raycast_Result ray_result;
scene_ray_intersect(scene, &ray, &ray_result); scene_ray_intersect(scene, &ray, &ray_result);
} }
debug_vars_show_vec3("Player Position", &player->base.transform.position);
debug_vars_show_texture("Player Camera Render", player->camera_node->render_tex);
debug_vars_show_texture("Player Camera Depth", player->camera_node->depth_tex);
} }

@ -25,6 +25,7 @@
#include "../system/config_vars.h" #include "../system/config_vars.h"
#include "scene.h" #include "scene.h"
#include "event.h" #include "event.h"
#include "debug_vars.h"
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -311,6 +312,10 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene)
} }
shader_unbind(); shader_unbind();
} }
debug_vars_show_int("Rendered", renderer->num_rendered);
debug_vars_show_int("Culled", renderer->num_culled);
debug_vars_show_int("Num Indices", renderer->num_indices);
//editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered); //editor_debugvar_slot_set_int(renderer->num_rendered_slot, renderer->num_rendered);
//editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled); //editor_debugvar_slot_set_int(renderer->num_culled_slot, renderer->num_culled);
//editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices); //editor_debugvar_slot_set_int(renderer->num_indices_slot, renderer->num_indices);

@ -1,5 +1,9 @@
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
- Add editor undo for transformation operations - Add editor undo for transformation operations
- Decide how to handle scale when checking sphere-ray intersection
- Add material export for blender exporter? - Add material export for blender exporter?
- Fix crash when exiting from fullscreen mode - Fix crash when exiting from fullscreen mode
- Allow renaming scene objects in editor - Allow renaming scene objects in editor
@ -7,8 +11,6 @@ Todo:
- Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update - Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update
- Add config file reloading and fire event that notifies potential listeners to update values from the new config file - Add config file reloading and fire event that notifies potential listeners to update values from the new config file
- Command to reload entities only - Command to reload entities only
- Command history in console
- Bring back debug variable display in editor and allow showing colours, textures etc
- Serialize player, camera properties to file - Serialize player, camera properties to file
- Multisampled buffers to bring back aa - Multisampled buffers to bring back aa
- Implement behaviour that avoids writing normal entities that do not have children or parent to file to avoid inconsistencies when loading them - Implement behaviour that avoids writing normal entities that do not have children or parent to file to avoid inconsistencies when loading them
@ -134,6 +136,7 @@ Bugs:
- Fix delete in editor not working when the cursor is hovering over scene hierarchy window - Fix delete in editor not working when the cursor is hovering over scene hierarchy window
- Investigate memory leaks caused by nuklear or opengl related operations in gui_update - Investigate memory leaks caused by nuklear or opengl related operations in gui_update
- Fix weird rotational bug when rotation resets or inverts after 180 degrees - Fix weird rotational bug when rotation resets or inverts after 180 degrees
- Fix crash if player's mesh is deleted in editor
Done: Done:
* Input * Input
@ -359,3 +362,7 @@ Done:
* Fix hierarchical transforms not working in editor mode * Fix hierarchical transforms not working in editor mode
* Better, slightly accurate picking * Better, slightly accurate picking
* Removed flickering from selection in editor * Removed flickering from selection in editor
* 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
Loading…
Cancel
Save