debug & time logs in console
This commit is contained in:
parent
751472eb86
commit
53d03f1684
@ -156,7 +156,7 @@ INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams)
|
|||||||
|
|
||||||
font_task_params_release(params);
|
font_task_params_release(params);
|
||||||
|
|
||||||
logf_success("Finished loading font \"%F\" (point size %F) in %F seconds", FMT_STR(path), FMT_FLOAT((f64)point_size), FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)));
|
logf_success("Loaded font \"%F\" (point size %F) in %F seconds", FMT_STR(path), FMT_FLOAT((f64)point_size), FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)));
|
||||||
asset_cache_mark_ready(asset, font);
|
asset_cache_mark_ready(asset, font);
|
||||||
|
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
|
|||||||
@ -134,7 +134,7 @@ INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams)
|
|||||||
sound->pcm.samples = samples;
|
sound->pcm.samples = samples;
|
||||||
MEMCPY(sound->pcm.samples, decoded.pcm.samples, decoded.pcm.count * sizeof(*decoded.pcm.samples));
|
MEMCPY(sound->pcm.samples, decoded.pcm.samples, decoded.pcm.count * sizeof(*decoded.pcm.samples));
|
||||||
|
|
||||||
logf_success("Finished loading sound \"%F\" in %F seconds", FMT_STR(path), FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)));
|
logf_success("Loaded sound \"%F\" in %F seconds", FMT_STR(path), FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)));
|
||||||
asset_cache_mark_ready(asset, sound);
|
asset_cache_mark_ready(asset, sound);
|
||||||
} else {
|
} else {
|
||||||
logf_error("Error loading sound \"%F\": %F", FMT_STR(path), FMT_STR(error_msg));
|
logf_error("Error loading sound \"%F\": %F", FMT_STR(path), FMT_STR(error_msg));
|
||||||
|
|||||||
@ -397,7 +397,7 @@ INTERNAL void cache_entry_load_texture(struct cache_ref ref, struct sprite_tag t
|
|||||||
atomic_u64_eval_add_u64(&G.cache.memory_usage, e->memory_usage);
|
atomic_u64_eval_add_u64(&G.cache.memory_usage, e->memory_usage);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
logf_success("Finished loading sprite texture [%F] \"%F\" in %F seconds (cache size: %F bytes).",
|
logf_success("Loaded sprite texture [%F] \"%F\" in %F seconds (cache size: %F bytes).",
|
||||||
FMT_HEX(e->hash.v),
|
FMT_HEX(e->hash.v),
|
||||||
FMT_STR(path),
|
FMT_STR(path),
|
||||||
FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)),
|
FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)),
|
||||||
@ -718,7 +718,7 @@ INTERNAL void cache_entry_load_sheet(struct cache_ref ref, struct sprite_tag tag
|
|||||||
atomic_u64_eval_add_u64(&G.cache.memory_usage, e->memory_usage);
|
atomic_u64_eval_add_u64(&G.cache.memory_usage, e->memory_usage);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
logf_success("Finished loading sprite sheet [%F] \"%F\" in %F seconds (cache size: %F bytes).",
|
logf_success("Loaded sprite sheet [%F] \"%F\" in %F seconds (cache size: %F bytes).",
|
||||||
FMT_HEX(e->hash.v),
|
FMT_HEX(e->hash.v),
|
||||||
FMT_STR(path),
|
FMT_STR(path),
|
||||||
FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)),
|
FMT_FLOAT(SECONDS_FROM_NS(sys_time_ns() - start_ns)),
|
||||||
|
|||||||
61
src/user.c
61
src/user.c
@ -40,7 +40,7 @@ struct second_stat {
|
|||||||
struct console_log {
|
struct console_log {
|
||||||
struct string msg;
|
struct string msg;
|
||||||
i32 level;
|
i32 level;
|
||||||
i32 index;
|
i32 color_index;
|
||||||
struct sys_datetime datetime;
|
struct sys_datetime datetime;
|
||||||
i64 time_ns;
|
i64 time_ns;
|
||||||
struct rect bounds;
|
struct rect bounds;
|
||||||
@ -97,7 +97,9 @@ GLOBAL struct {
|
|||||||
struct arena console_logs_arena;
|
struct arena console_logs_arena;
|
||||||
struct console_log *first_console_log;
|
struct console_log *first_console_log;
|
||||||
struct console_log *last_console_log;
|
struct console_log *last_console_log;
|
||||||
|
i32 console_log_color_indices[LOG_LEVEL_COUNT];
|
||||||
f32 console_logs_height;
|
f32 console_logs_height;
|
||||||
|
b32 debug_console;
|
||||||
|
|
||||||
/* Window -> user */
|
/* Window -> user */
|
||||||
struct sys_mutex sys_events_mutex;
|
struct sys_mutex sys_events_mutex;
|
||||||
@ -177,7 +179,8 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = {
|
|||||||
[SYS_BTN_Q] = USER_BIND_KIND_DEBUG_FOLLOW,
|
[SYS_BTN_Q] = USER_BIND_KIND_DEBUG_FOLLOW,
|
||||||
[SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE,
|
[SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE,
|
||||||
[SYS_BTN_F2] = USER_BIND_KIND_DEBUG_CAMERA,
|
[SYS_BTN_F2] = USER_BIND_KIND_DEBUG_CAMERA,
|
||||||
[SYS_BTN_GRAVE_ACCENT] = USER_BIND_KIND_DEBUG_DRAW,
|
[SYS_BTN_F3] = USER_BIND_KIND_DEBUG_DRAW,
|
||||||
|
[SYS_BTN_GRAVE_ACCENT] = USER_BIND_KIND_DEBUG_CONSOLE,
|
||||||
[SYS_BTN_F11] = USER_BIND_KIND_FULLSCREEN,
|
[SYS_BTN_F11] = USER_BIND_KIND_FULLSCREEN,
|
||||||
[SYS_BTN_MWHEELUP] = USER_BIND_KIND_ZOOM_IN,
|
[SYS_BTN_MWHEELUP] = USER_BIND_KIND_ZOOM_IN,
|
||||||
[SYS_BTN_MWHEELDOWN] = USER_BIND_KIND_ZOOM_OUT,
|
[SYS_BTN_MWHEELDOWN] = USER_BIND_KIND_ZOOM_OUT,
|
||||||
@ -259,7 +262,7 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
|
|||||||
G.backbuffer_cmd_buffer = gpu_cmd_buffer_alloc();
|
G.backbuffer_cmd_buffer = gpu_cmd_buffer_alloc();
|
||||||
|
|
||||||
//log_register_callback(debug_console_log_callback, LOG_LEVEL_SUCCESS);
|
//log_register_callback(debug_console_log_callback, LOG_LEVEL_SUCCESS);
|
||||||
log_register_callback(debug_console_log_callback, LOG_LEVEL_INFO);
|
log_register_callback(debug_console_log_callback, LOG_LEVEL_DEBUG);
|
||||||
G.console_logs_mutex = sys_mutex_alloc();
|
G.console_logs_mutex = sys_mutex_alloc();
|
||||||
G.console_logs_arena = arena_alloc(GIGABYTE(64));
|
G.console_logs_arena = arena_alloc(GIGABYTE(64));
|
||||||
|
|
||||||
@ -476,7 +479,10 @@ INTERNAL LOG_EVENT_CALLBACK_FUNC_DEF(debug_console_log_callback, log)
|
|||||||
if (G.last_console_log) {
|
if (G.last_console_log) {
|
||||||
G.last_console_log->next = clog;
|
G.last_console_log->next = clog;
|
||||||
clog->prev = G.last_console_log;
|
clog->prev = G.last_console_log;
|
||||||
clog->index = G.last_console_log->index + 1;
|
/* Alternating color index between logs of same level */
|
||||||
|
i32 *color_index = &G.console_log_color_indices[log.level];
|
||||||
|
clog->color_index = *color_index;
|
||||||
|
*color_index = 1 - *color_index;
|
||||||
} else {
|
} else {
|
||||||
G.first_console_log = clog;
|
G.first_console_log = clog;
|
||||||
}
|
}
|
||||||
@ -494,10 +500,21 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
|||||||
f32 fade_curve = 0.5;
|
f32 fade_curve = 0.5;
|
||||||
f32 spacing = 0;
|
f32 spacing = 0;
|
||||||
f32 bg_margin = 5;
|
f32 bg_margin = 5;
|
||||||
|
|
||||||
|
LOCAL_PERSIST u32 colors[LOG_LEVEL_COUNT][2] = ZI;
|
||||||
|
MEMSET(colors, 0xFF, sizeof(colors));
|
||||||
|
#if 1
|
||||||
|
colors[LOG_LEVEL_DEBUG][0] = RGB_F(0.4, 0.1, 0.4); colors[LOG_LEVEL_DEBUG][1] = RGB_F(0.5, 0.2, 0.5);
|
||||||
|
colors[LOG_LEVEL_INFO][0] = RGB_F(0.4, 0.4, 0.4); colors[LOG_LEVEL_INFO][1] = RGB_F(0.5, 0.5, 0.5);
|
||||||
|
colors[LOG_LEVEL_SUCCESS][0] = RGB_F(0.1, 0.3, 0.1); colors[LOG_LEVEL_SUCCESS][1] = RGB_F(0.2, 0.4, 0.2);
|
||||||
|
colors[LOG_LEVEL_WARNING][0] = RGB_F(0.4, 0.4, 0.1); colors[LOG_LEVEL_WARNING][1] = RGB_F(0.5, 0.5, 0.2);
|
||||||
|
colors[LOG_LEVEL_ERROR][0] = RGB_F(0.4, 0.1, 0.1); colors[LOG_LEVEL_ERROR][1] = RGB_F(0.5, 0.2, 0.2);
|
||||||
|
#else
|
||||||
u32 info_colors[2] = { RGB_F(0.4, 0.4, 0.4), RGB_F(0.5, 0.5, 0.5) };
|
u32 info_colors[2] = { RGB_F(0.4, 0.4, 0.4), RGB_F(0.5, 0.5, 0.5) };
|
||||||
u32 success_colors[2] = { RGB_F(0.1, 0.3, 0.1), RGB_F(0.2, 0.4, 0.2) };
|
u32 success_colors[2] = { RGB_F(0.1, 0.3, 0.1), RGB_F(0.2, 0.4, 0.2) };
|
||||||
u32 warning_colors[2] = { RGB_F(0.4, 0.4, 0.1), RGB_F(0.5, 0.5, 0.2) };
|
u32 warning_colors[2] = { RGB_F(0.4, 0.4, 0.1), RGB_F(0.5, 0.5, 0.2) };
|
||||||
u32 error_colors[2] = { RGB_F(0.4, 0.1, 0.1), RGB_F(0.5, 0.2, 0.2) };
|
u32 error_colors[2] = { RGB_F(0.4, 0.1, 0.1), RGB_F(0.5, 0.2, 0.2) };
|
||||||
|
#endif
|
||||||
|
|
||||||
struct v2 draw_pos = desired_start_pos;
|
struct v2 draw_pos = desired_start_pos;
|
||||||
f32 bounds_top = F32_INFINITY;
|
f32 bounds_top = F32_INFINITY;
|
||||||
@ -522,18 +539,23 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
|
|||||||
if (draw_pos.y > -desired_start_pos.y && opacity > 0) {
|
if (draw_pos.y > -desired_start_pos.y && opacity > 0) {
|
||||||
if (log->level <= level) {
|
if (log->level <= level) {
|
||||||
/* Draw background */
|
/* Draw background */
|
||||||
u32 color_index = log->index & 1; /* Alternate colors for greater distinction between logs */
|
u32 color = colors[log->level][log->color_index];
|
||||||
u32 color = info_colors[color_index];
|
|
||||||
switch (log->level) {
|
|
||||||
default: break;
|
|
||||||
case LOG_LEVEL_ERROR: color = error_colors[color_index]; break;
|
|
||||||
case LOG_LEVEL_WARNING: color = warning_colors[color_index]; break;
|
|
||||||
case LOG_LEVEL_SUCCESS: color = success_colors[color_index]; break;
|
|
||||||
}
|
|
||||||
draw_quad(G.ui_cmd_buffer, quad_from_rect(log->bounds), ALPHA_F(color, opacity));
|
draw_quad(G.ui_cmd_buffer, quad_from_rect(log->bounds), ALPHA_F(color, opacity));
|
||||||
|
|
||||||
/* Draw text */
|
/* Draw text */
|
||||||
struct string text = log->msg;
|
struct string text = log->msg;
|
||||||
|
if (!minimized) {
|
||||||
|
struct sys_datetime datetime = log->datetime;
|
||||||
|
text = string_format(
|
||||||
|
scratch.arena,
|
||||||
|
LIT("[%F:%F:%F.%F] %F"),
|
||||||
|
FMT_UINT_Z(datetime.hour, 2),
|
||||||
|
FMT_UINT_Z(datetime.minute, 2),
|
||||||
|
FMT_UINT_Z(datetime.second, 2),
|
||||||
|
FMT_UINT_Z(datetime.milliseconds, 3),
|
||||||
|
FMT_STR(text));
|
||||||
|
}
|
||||||
|
|
||||||
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA_F(COLOR_WHITE, opacity), .str = text);
|
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA_F(COLOR_WHITE, opacity), .str = text);
|
||||||
struct rect bounds = draw_text(G.ui_cmd_buffer, params);
|
struct rect bounds = draw_text(G.ui_cmd_buffer, params);
|
||||||
|
|
||||||
@ -838,6 +860,10 @@ INTERNAL void user_update(void)
|
|||||||
G.debug_draw = !G.debug_draw;
|
G.debug_draw = !G.debug_draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (G.bind_states[USER_BIND_KIND_DEBUG_CONSOLE].num_presses > 0) {
|
||||||
|
G.debug_console = !G.debug_console;
|
||||||
|
}
|
||||||
|
|
||||||
if (G.bind_states[USER_BIND_KIND_DEBUG_CAMERA].num_presses > 0) {
|
if (G.bind_states[USER_BIND_KIND_DEBUG_CAMERA].num_presses > 0) {
|
||||||
G.debug_camera = !G.debug_camera;
|
G.debug_camera = !G.debug_camera;
|
||||||
}
|
}
|
||||||
@ -1904,9 +1930,6 @@ INTERNAL void user_update(void)
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
if (G.debug_draw) {
|
if (G.debug_draw) {
|
||||||
//struct v2 pos = V2(0, 500);
|
|
||||||
//struct v2 pos = V2(10, G.ui_size.y - 20);
|
|
||||||
struct v2 pos = V2(0, G.ui_size.y);
|
|
||||||
struct font *font = font_load_async(LIT("fonts/fixedsys.ttf"), 12.0f);
|
struct font *font = font_load_async(LIT("fonts/fixedsys.ttf"), 12.0f);
|
||||||
if (font) {
|
if (font) {
|
||||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||||
@ -2003,15 +2026,17 @@ INTERNAL void user_update(void)
|
|||||||
//draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
|
//draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
|
||||||
//draw_text(G.ui_cmd_buffer, font, pos, text);
|
//draw_text(G.ui_cmd_buffer, font, pos, text);
|
||||||
|
|
||||||
draw_text(G.ui_cmd_buffer, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = COLOR_WHITE));
|
struct v2 pos = V2(10, G.ui_size.y);
|
||||||
|
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
|
||||||
|
draw_text(G.ui_cmd_buffer, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
|
||||||
arena_temp_end(temp);
|
arena_temp_end(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
#if DEVELOPER
|
#if DEVELOPER
|
||||||
b32 console_minimized = !G.debug_draw;
|
b32 console_minimized = !G.debug_console;
|
||||||
i32 console_level = LOG_LEVEL_DEBUG;
|
i32 console_level = console_minimized ? LOG_LEVEL_SUCCESS: LOG_LEVEL_DEBUG;
|
||||||
draw_debug_console(console_level, console_minimized);
|
draw_debug_console(console_level, console_minimized);
|
||||||
#else
|
#else
|
||||||
if (G.debug_draw) {
|
if (G.debug_draw) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ enum user_bind_kind {
|
|||||||
USER_BIND_KIND_DEBUG_WALLS,
|
USER_BIND_KIND_DEBUG_WALLS,
|
||||||
USER_BIND_KIND_DEBUG_FOLLOW,
|
USER_BIND_KIND_DEBUG_FOLLOW,
|
||||||
USER_BIND_KIND_DEBUG_DRAW,
|
USER_BIND_KIND_DEBUG_DRAW,
|
||||||
|
USER_BIND_KIND_DEBUG_CONSOLE,
|
||||||
USER_BIND_KIND_DEBUG_CAMERA,
|
USER_BIND_KIND_DEBUG_CAMERA,
|
||||||
USER_BIND_KIND_DEBUG_PAUSE,
|
USER_BIND_KIND_DEBUG_PAUSE,
|
||||||
USER_BIND_KIND_DEBUG_STEP,
|
USER_BIND_KIND_DEBUG_STEP,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user