diff --git a/src/core/core_ctx.h b/src/core/core_ctx.h index 92e2d60..257a2ad 100644 --- a/src/core/core_ctx.h +++ b/src/core/core_ctx.h @@ -17,6 +17,5 @@ gb_thread thread_ctx_t tcx = { .log = { .break_on_fatal = true, .log_proc = default_log_proc, - .flags = log_flag_file_path, } }; diff --git a/src/core/core_lexer.c b/src/core/core_lexer.c index 674fc33..92df061 100644 --- a/src/core/core_lexer.c +++ b/src/core/core_lexer.c @@ -1,7 +1,5 @@ -const i32 module_lex = 1; - #define lex_error(TOKEN, STRING) do {\ - errorf(module_lex, STRING);\ + errorf(STRING);\ TOKEN->kind = lex_kind_error;\ TOKEN->string = s8_lit(STRING);\ } while (0) diff --git a/src/core/core_log.c b/src/core/core_log.c index 9562275..dc5d66a 100644 --- a/src/core/core_log.c +++ b/src/core/core_log.c @@ -1,51 +1,32 @@ -fn char *log_level_str(log_level_t level) { +fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...) { + ma_temp_t scratch = ma_begin_scratch(); + S8_FMT(scratch.arena, str, string); + tcx.log.log_proc(level, file_and_line, string); + ma_end_scratch(scratch); +} + +fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string) { + ma_temp_t scratch = ma_begin_scratch(); + switch(level) { - case log_level_debug: return "DEBUG"; - case log_level_info: return "INFO"; - case log_level_warning: return "WARN"; - case log_level_error: return "ERROR"; - case log_level_fatal: return "FATAL"; - default: return "INVALID"; - } -} - -fn void log_base(i32 module, log_level_t level, s8_t file_and_line, s8_t string) { - tcx.log.log_proc((log_event_t){module, level, file_and_line, string}); -} - -fn void log_basef(i32 module, log_level_t level, s8_t file_and_line, const char *str, ...) { - ma_temp_t scratch = ma_begin_scratch(); - S8_FMT(scratch.arena, str, str8); - log_base(module, level, file_and_line, str8); - ma_end_scratch(scratch); -} - -fn void default_log_proc(log_event_t ev) { - ma_temp_t scratch = ma_begin_scratch(); - sb8_t *sb = sb8_serial_begin(scratch.arena); - if (tcx.log.flags & log_flag_level) { - sb8_printf(sb, "%-5s ", log_level_str(ev.level)); - } - if (tcx.log.flags & log_flag_file_path) { - sb8_printf(sb, "%S: ", ev.file_and_line); - } - - sb8_printf(sb, "%S\n", ev.string); - s8_t result = sb8_serial_end(scratch.arena, sb); - - if (ev.level != log_level_fatal) { - os_console_log(result.str); - } else { - os_error_box(result.str); - #if PLATFORM_WASM - debug_break(); - #else - if (tcx.log.break_on_fatal) { - debug_break(); - } else { - exit(1); - } - #endif + case log_level_debug: + case log_level_info: { + os_console_log(s8_printf(scratch.arena, "%S\n", string).str); + } break; + case log_level_warning: { + os_console_log(s8_printf(scratch.arena, "%S: warning: %S\n", file_and_line, string).str); + if (tcx.log.break_on_warning) debug_break(); + } break; + case log_level_error: { + os_console_log(s8_printf(scratch.arena, "%S: error: %S\n", file_and_line, string).str); + if (tcx.log.break_on_error) debug_break(); + } break; + case log_level_fatal: { + os_error_box(s8_printf(scratch.arena, "%S: fatal error: %S\n", file_and_line, string).str); + if (tcx.log.break_on_fatal) debug_break(); + exit(1); + } break; + default_is_invalid; } ma_end_scratch(scratch); diff --git a/src/core/core_log.h b/src/core/core_log.h index a3d4ba1..1e8bc6b 100644 --- a/src/core/core_log.h +++ b/src/core/core_log.h @@ -16,15 +16,6 @@ ** ** */ -const i32 module_null = 0; - -typedef enum { - log_flag_null = 0, - log_flag_level = 1, - log_flag_file_path = 8, - log_flag_all = log_flag_level | log_flag_file_path, -} log_flag_t; - typedef enum { // AFTER_CHANGING: modify type_info and log_level_str log_level_debug, log_level_info, @@ -33,34 +24,27 @@ typedef enum { // AFTER_CHANGING: modify type_info and log_level_str log_level_fatal, } log_level_t; -typedef struct log_event_t log_event_t; -struct log_event_t { - i32 module; - log_level_t level; - s8_t file_and_line; - s8_t string; -}; - typedef struct logger_t logger_t; struct logger_t { - void (*log_proc)(log_event_t); + void (*log_proc)(log_level_t level, s8_t file_and_line, s8_t string); void *user_data; - log_flag_t flags; - b32 break_on_fatal; + b8 break_on_fatal; + b8 break_on_error; + b8 break_on_warning; }; /////////////////////////////// // main api -#define debugf(...) log_basef(module_null, log_level_debug, S8_FILE_AND_LINE, __VA_ARGS__) -#define errorf(MODULE, ...) log_basef(MODULE, log_level_error, S8_FILE_AND_LINE, __VA_ARGS__) -#define fatalf(...) (log_basef(module_null, log_level_fatal, S8_FILE_AND_LINE, __VA_ARGS__), 0) +#define debugf(...) log_basef(log_level_debug, S8_FILE_AND_LINE, __VA_ARGS__) +#define errorf(...) log_basef(log_level_error, S8_FILE_AND_LINE, __VA_ARGS__) +#define fatalf(...) (log_basef(log_level_fatal, S8_FILE_AND_LINE, __VA_ARGS__), 0) -fn void default_log_proc(log_event_t ev); +fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string); +fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...); -#define program_version "---" #if PLATFORM_DEBUG_ASSERT -#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": internal program error! assertion failed: " #x ", program version: " program_version "\n"), debug_break())) +#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": assertion failed: " #x "\n"), debug_break())) #else #define assert(x) (void)(x) #endif @@ -69,132 +53,3 @@ fn void default_log_proc(log_event_t ev); #define default_is_invalid default: assert(!"invalid default case") #define else_is_invalid else { assert(!"else was not expected to be executed!"); } - - -fn void log_base(i32 module, log_level_t level, s8_t file_and_line, s8_t string); -fn void log_basef(i32 module, log_level_t level, s8_t file_and_line, const char *str, ...); - - - -/* - -Seems like there are 2 logging categories: -1. Logging in a graphical program where you have control over how logs are displayed -2. Logging in a console program where you dump shit into conso - - -DESIGN ANALYSIS - -/////////////////////////////// -// rxi log.c api: -// > 22:54:32 INFO src/memes/memes.c:65: message - -log_trace(const char *fmt, ...); -log_debug(const char *fmt, ...); -log_info(const char *fmt, ...); -log_warn(const char *fmt, ...); -log_error(const char *fmt, ...); -log_fatal(const char *fmt, ...); - - -log_set_quiet(bool enable) -log_set_level(level) -log_add_fp(file, level) -log_add_callback(func, user_data, level) -log_set_lock(lock_func, void *user_data) - -/////////////////////////////// -// odin log package - -Logger_Proc :: #type proc(data: rawptr, level: Level, - text: string, options: Options, location := #caller_location); - -Logger :: struct { - procedure: Logger_Proc, - data: rawptr, - lowest_level: Level, - options: Logger_Options, -} - -Option :: enum { - Level, - Date, - Time, - Short_File_Path, - Long_File_Path, - Line, - Procedure, - Terminal_Color -} - -Logger_Level :: enum { - Debug = 0, - Info = 10, - Warning = 20, - Error = 30, - Fatal = 40, -} - -debugf() -infof() -warnf() -errorf() -fatalf() - -panic() -panicf() - -assert() -assertf() - -/////////////////////////////// -// raddebugger log - -Log { arena, LogScope *top_scope } (stack of LogScopes) -LogScope { LogScope *next, pos in arena to pop, StringList[LogMsgKinds] } -LogScopeResult { String[LogMsgKinds] } - - -internal Log *log_alloc(void); -internal void log_release(Log *log); -internal void log_select( - -internal void log_scope_begin(void); -internal LogScopeResult log_scope_end(Arena *are - - -#define log_info(s) log_msg(LogMsgKind_Info, (s)) -#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__) -#define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) -#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__) - -#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) -#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) - -{ - log_scope_begin(); - - log_infof("user2ctrl_msg:{kind:\"%S\"}\n", ctrl_string_from_msg_kind(msg->kind)); - LogInfoNamedBlockF("dmn_event") - { - log_infof("kind: %S\n", dmn_event_kind_string_table[ev->kind]); - log_infof("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]); - log_infof("process: [%I64u]\n", ev->process.u64[0]); - log_infof("thread: [%I64u]\n", ev->thread.u64[0]); - log_infof("module: [%I64u]\n", ev->module.u64[0]); - log_infof("arch: %S\n", string_from_arch(ev->arch)); - log_infof("address: 0x%I64x\n", ev->address); - log_infof("string: \"%S\"\n", ev->string); - log_infof("ip_vaddr: 0x%I64x\n", ev->instruction_pointer); - } - - - LogScopeResult log = log_scope_end(scratch.arena); - ctrl_thread__flush_info_log(log.strings[LogMsgKind_Info]); - if(log.strings[LogMsgKind_UserError].size != 0) - { - Show to user - } -} - -*/ \ No newline at end of file diff --git a/src/core/core_math.h b/src/core/core_math.h index 15290d4..c366e75 100644 --- a/src/core/core_math.h +++ b/src/core/core_math.h @@ -205,9 +205,9 @@ union r3i64_t { #define rgba_macro_const(r, g, b, a) { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f } -gb_read_only v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255); -gb_read_only v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255); -gb_read_only v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255); -gb_read_only v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255); -gb_read_only v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255); -gb_read_only v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255); +gb v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255); +gb v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255); +gb v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255); +gb v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255); +gb v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255); +gb v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255); diff --git a/src/core/core_type_info.h b/src/core/core_type_info.h index 4fbc8f2..27d76d5 100644 --- a/src/core/core_type_info.h +++ b/src/core/core_type_info.h @@ -59,6 +59,7 @@ struct mt_tweak_t { }; #define mt_embed_file(name, path) #define mt_tweak_f32(name, default, min, max) +#define mt_tweak_color(name, ...) #define mt_tweak_b32(name, default) // diff --git a/src/ui/ui.c b/src/ui/ui.c index 96d82a7..cdd59f9 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -610,6 +610,12 @@ fn void ui_demo_update(app_frame_t *frame) { } } else_is_invalid; } + ui_serial_subtype(&primary_color_global, type(v4f32_t), s8_lit("primary_color_global")); + ui_serial_subtype(&secondary_color_global, type(v4f32_t), s8_lit("secondary_color_global")); + ui_serial_subtype(&accent1_color_global, type(v4f32_t), s8_lit("accent1_color_global")); + ui_serial_subtype(&accent2_color_global, type(v4f32_t), s8_lit("accent2_color_global")); + ui_serial_subtype(&white_color_global, type(v4f32_t), s8_lit("white_color_global")); + ui_serial_subtype(&black_color_global, type(v4f32_t), s8_lit("black_color_global")); ui_serial_type(&ui_test_event, type(app_event_t)); ui_expander("app_event_t") { for (int i = 0; i < 2; i += 1) { diff --git a/src/wasm_app/wasm_app.meta.c b/src/wasm_app/wasm_app.meta.c index 51e7d67..0767bff 100644 --- a/src/wasm_app/wasm_app.meta.c +++ b/src/wasm_app/wasm_app.meta.c @@ -65,6 +65,22 @@ void mt_wasm_app(ma_arena_t *arena) { matched = true; } + if (par->at->inside_macro == false && parser_matchi(par, s8_lit("mt_tweak_color"))) { + cg_tweak_t *tweak = ma_push_type(arena, cg_tweak_t); + tweak->type = type(v4f32_t); + tweak->min = s8_lit("0.0f"); + tweak->max = s8_lit("1.0f"); + parser_expect(par, lex_kind_open_paren); + tweak->name = parser_expect(par, lex_kind_ident)->string; + parser_expect(par, lex_kind_comma); + tweak->value = parser_next(par)->string; + while (par->at->kind != lex_kind_close_paren && par->at->kind != lex_kind_eof) parser_next(par); + lex_t *end = parser_expect(par, lex_kind_close_paren); + tweak->value.len = (i64)(end->str - tweak->value.str); + SLLQ_APPEND(first_tweak, last_tweak, tweak); + matched = true; + } + if (!matched) { parser_next(par); }