diff --git a/build_file.c b/build_file.c index 32afd59..a4bdb94 100644 --- a/build_file.c +++ b/build_file.c @@ -134,19 +134,19 @@ void generate_math_code(ma_arena_t *arena) { } int main(int argc, char **argv) { - core_init(); + os_core_init(); int ok = 0; SRC_SearchPaths.include_path = (char*[]){OS_GetAbsolutePath(&Perm, s8("../src")).str}; SRC_SearchPaths.include_path_count = 1; cache_init(&Perm, s8("cache_build_file")); - generate_math_code(tcx->temp); - generate_ui_code(tcx->temp); - generate_app_code(tcx->temp); - generate_prototype_code(tcx->temp); - generate_render_code(tcx->temp); - generate_testing_code(tcx->temp); + generate_math_code(&tcx->temp); + generate_ui_code(&tcx->temp); + generate_app_code(&tcx->temp); + generate_prototype_code(&tcx->temp); + generate_render_code(&tcx->temp); + generate_testing_code(&tcx->temp); b32 run_win32_app_base_target = true; b32 run_testing_target = true; diff --git a/src/app/app_wasm.c b/src/app/app_wasm.c index 8b24fcf..4a94961 100644 --- a/src/app/app_wasm.c +++ b/src/app/app_wasm.c @@ -155,5 +155,5 @@ fn_wasm_export b32 wasm_update(f64 time, f32 width, f32 height, f32 dpr) { } fn_wasm_export void wasm_init(void) { - core_init(); + os_core_init(); } diff --git a/src/app/app_win32.c b/src/app/app_win32.c index 1323577..b1e916b 100644 --- a/src/app/app_win32.c +++ b/src/app/app_win32.c @@ -307,12 +307,12 @@ fn void w32_try_reloading_library(w32_library_t *lib, app_frame_t frame) { u64 random_value = get_random_u64(&lib->seed); s8_t base_name = s8_chop_last_period(lib->dll_name); - s8_t new_dll_name = s8_printf(tcx->temp, "%S_temp_%u.dll", base_name, random_value); + s8_t new_dll_name = s8_printf(&tcx->temp, "%S_temp_%u.dll", base_name, random_value); b32 ok = os_copy(lib->dll_name, new_dll_name, true); if (!ok) debugf("failed to copy from %S to %S", lib->dll_name, new_dll_name); - s8_t pdb_name = s8_printf(tcx->temp, "%S.pdb", base_name); - s8_t new_pdb_name = s8_printf(tcx->temp, "%S_temp_%u.pdb", base_name, random_value); + s8_t pdb_name = s8_printf(&tcx->temp, "%S.pdb", base_name); + s8_t new_pdb_name = s8_printf(&tcx->temp, "%S_temp_%u.pdb", base_name, random_value); ok = os_copy(pdb_name, new_pdb_name, true); if (!ok) debugf("failed to copy from %S to %S", pdb_name, new_pdb_name); @@ -343,7 +343,7 @@ end_of_lib_load:; } int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { - core_init(); + os_core_init(); // Delete temporary dll files { @@ -487,7 +487,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n for (;;) { app_frame_t frame = {0}; - b32 waited = w32_get_events(tcx->temp, &frame, wait_for_events); + b32 waited = w32_get_events(&tcx->temp, &frame, wait_for_events); if (waited) { frame.delta = 0.00001; } @@ -526,7 +526,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n SwapBuffers(w32_dc); - ma_set0(tcx->temp); + ma_set0(&tcx->temp); /////////////////////////////// // end of frame timings diff --git a/src/core/core_ctx.c b/src/core/core_ctx.c index 0343140..f0540ac 100644 --- a/src/core/core_ctx.c +++ b/src/core/core_ctx.c @@ -1,19 +1,5 @@ -gb_thread thread_ctx_t global_thread_context = { - .log = { - .break_on_fatal = true, - .break_on_error = true, - .break_on_warning = true, - .print_file_and_line = true, - .log_proc = default_log_proc, - } -}; gb_thread thread_ctx_t *tcx; -fn void core_init(void) { - tcx = &global_thread_context; - os_core_init(); -} - fn void *ma_arena_alo_proc(alo_t alo, alokind_t kind, void *ptr, size_t size) { ma_arena_t *ma = alo.object; if (kind == alokind_alloc) { @@ -39,3 +25,4 @@ fn void dealloc(alo_t alo, void *ptr) { fn void *alloc_size(alo_t alo, size_t size) { return alo.proc(alo, alokind_alloc, NULL, size); } + diff --git a/src/core/core_ctx.h b/src/core/core_ctx.h index a0268c9..fa71eb8 100644 --- a/src/core/core_ctx.h +++ b/src/core/core_ctx.h @@ -1,7 +1,7 @@ typedef struct thread_ctx_t thread_ctx_t; struct thread_ctx_t { ma_arena_t scratch[3]; - ma_arena_t *temp; // application specific arena + ma_arena_t temp; // application specific arena // I probably want to discourage using it implicitly like: tcx.perm, instead just pass it around // to functions that allocate pernament memory. temp and scratch very nicely create reusable code @@ -13,6 +13,7 @@ struct thread_ctx_t { void *rn_ctx; void *ui_ctx; void *te_ctx; + void *user_ctx; logger_t log; int thread_index; diff --git a/src/core/core_platform.h b/src/core/core_platform.h index afd17d7..de3e1d8 100644 --- a/src/core/core_platform.h +++ b/src/core/core_platform.h @@ -6,4 +6,4 @@ fn b32 os_vmem_commit(void *p, usize size); fn b32 os_vmem_release(void *p); fn b32 os_vmem_decommit(void *p, usize size); -fn void core_init(void); // required in wasm \ No newline at end of file +fn void os_core_init(void); \ No newline at end of file diff --git a/src/core/core_platform_unix.c b/src/core/core_platform_unix.c index 44b79fc..b1122c4 100644 --- a/src/core/core_platform_unix.c +++ b/src/core/core_platform_unix.c @@ -54,8 +54,18 @@ fn void os_unix_register_crash_handler() { sigaction(SIGABRT, &sa, NULL); } -fn void os_core_init(void) { - tcx->temp = ma_create(ma_default_reserve_size); - ma_init(&tcx->perm, ma_default_reserve_size); +fn void os_core_small_init(ma_arena_t *arena) { + tcx = ma_push_type(arena, thread_ctx_t); + tcx->log.break_on_error = true; + tcx->log.break_on_fatal = true; + tcx->log.break_on_warning = true; + tcx->log.print_file_and_line = true; + tcx->log.log_proc = default_log_proc; os_unix_register_crash_handler(); +} + +fn void os_core_init(void) { + ma_arena_t perm = {0}; + os_core_small_init(&perm); + tcx->perm = perm; } \ No newline at end of file diff --git a/src/core/core_platform_wasm.c b/src/core/core_platform_wasm.c index b0b43f4..5f5f762 100644 --- a/src/core/core_platform_wasm.c +++ b/src/core/core_platform_wasm.c @@ -40,18 +40,27 @@ fn f64 os_parse_float(char *str) { return wasm_parse_float((isize)str, str_len((char *)str)); } +fn void os_core_small_init(ma_arena_t *arena) { + tcx = ma_push_type(arena, thread_ctx_t); + tcx->log.break_on_error = true; + tcx->log.break_on_fatal = true; + tcx->log.break_on_warning = true; + tcx->log.print_file_and_line = true; + tcx->log.log_proc = default_log_proc; +} + fn void os_core_init(void) { + ma_arena_t perm = {0}; isize page_size = kib(64); isize page_count = __builtin_wasm_memory_size(0); u8 *memory = (u8 *)&__heap_base; usize memory_size = page_count * (page_size) - (isize)memory; - tcx->perm.data = memory; - tcx->perm.commit = tcx->perm.reserve = memory_size; - - ma_arena_t *perm = &tcx->perm; + perm.data = memory; + perm.commit = perm.reserve = memory_size; + os_core_small_init(&perm); + tcx->perm = perm; + tcx->temp = ma_push_arena(&perm, mib(2)); ma_push_arena_ex(&tcx->perm, &tcx->scratch[0], mib(1)); ma_push_arena_ex(&tcx->perm, &tcx->scratch[1], kib(256)); ma_push_arena_ex(&tcx->perm, &tcx->scratch[2], kib(64)); - - tcx->temp = ma_push_arena(perm, mib(2)); } \ No newline at end of file diff --git a/src/core/core_platform_win32.c b/src/core/core_platform_win32.c index 2a3d0d4..98aa910 100644 --- a/src/core/core_platform_win32.c +++ b/src/core/core_platform_win32.c @@ -45,8 +45,18 @@ fn void os_win32_register_crash_handler() { signal(SIGABRT, os_win32_crash_handler); } -fn void os_core_init(void) { - tcx->temp = ma_create(ma_default_reserve_size); - ma_init(&tcx->perm, ma_default_reserve_size); +fn void os_core_small_init(ma_arena_t *arena) { + tcx = ma_push_type(arena, thread_ctx_t); + tcx->log.break_on_error = true; + tcx->log.break_on_fatal = true; + tcx->log.break_on_warning = true; + tcx->log.print_file_and_line = true; + tcx->log.log_proc = default_log_proc; os_win32_register_crash_handler(); -} \ No newline at end of file +} + +fn void os_core_init(void) { + ma_arena_t perm = {0}; + os_core_small_init(&perm); + tcx->perm = perm; +} diff --git a/src/os/os_win32.c b/src/os/os_win32.c index e9cc392..0473761 100644 --- a/src/os/os_win32.c +++ b/src/os/os_win32.c @@ -358,7 +358,7 @@ fn i32 os_thread_join(os_thread_t *thread) { // @todo: // This will probably create 16 arenas or more XD // fn i32 os__thread_log(void *data) { -// core_init(); +// os_core_init(); // debugf("testing"); // return 0; // } diff --git a/src/prototype/main.c b/src/prototype/main.c index f9e150a..c66f000 100644 --- a/src/prototype/main.c +++ b/src/prototype/main.c @@ -12,6 +12,13 @@ #include "transcript_browser.c" #include "prototype.gen.c" +// @todo: how to pack the data so it's available on wasm? +// @todo: cursor doesn't change when hovering on text +// @todo: copy paste +// @todo: selecting and writing is bugged +// @todo: make it possible without executable +// https://drive.proton.me/urls/F9X0GWGH38#t7MaKdLbvOfN + fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { tcx = thread_ctx; if (frame->first_event->kind == app_event_kind_init) { @@ -23,17 +30,19 @@ fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { rn_init(&tcx->perm, font_size, frame->dpr); ui_init(&tcx->perm); - global_res = ma_push_type(&tcx->perm, res_t); - res_init(global_res); - res_add_folder(global_res, s8("D:/videos/jiang")); - // res_add_folder(global_res, s8("D:/tools")); + tcx->user_ctx = (void *)ma_push_type(&tcx->perm, res_t); + res_init(tcx->user_ctx); + + res_t *res = tcx->user_ctx; + res_report(res, "type in the path to folder with videos and press enter, for me it would be: D:/videos/jiang"); return true; } else if (frame->first_event->kind == app_event_kind_reload) { ui_reload(); rn_reload(); - + res_unload(tcx->user_ctx); return true; } else if (frame->first_event->kind == app_event_kind_unload) { + res_unload(tcx->user_ctx); return true; } @@ -45,3 +54,7 @@ fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { transcript_browser_update(frame, tweak_table, lengthof(tweak_table)); return true; } + +/* +Answering one of your things. Maybe I went too much into idealism with that formulation, there are many solutions to the puzzle and they will differ by place, culture but you always need some kind of new elite, it would be a bit nicer if they gained support from actual hard work, communication, education etc. Back in the day you would do that for example by building the national, communal spirit through literature and poetry targetting peasentry, proletariatt. Today you have new digital media like youtube where you can reach big audiences, this seems to work pretty nicely in my country currently and it has a basis in historical polish ideas, "work at the base" where in one of the classics there is fantasy staged that polish nation is an organic unity where every part has to function and it is the responsibility of polish new elite to go down to the people learn about their circumstances, educate them, give them tools to overcome their circumstances because they will be the foundation of a new country. The interesting part is that the new elite has to be high on romanticism, always looking beyond. The assumption is they will be hated for it by everyone: the townspeople, the corrupt aristocracy who are all self-interested, divided and don't care about the nation as a unity. In the end the truly talented will be marginalized. The book ends with a sad, miserable ending where the main hero kills himself but leaves a note that not everything of him will die. +*/ \ No newline at end of file diff --git a/src/prototype/prototype.gen.c b/src/prototype/prototype.gen.c index e304e93..4e9c88d 100644 --- a/src/prototype/prototype.gen.c +++ b/src/prototype/prototype.gen.c @@ -13,5 +13,4 @@ void run_all_tests(void) { test_array(); ui_test_text_replace(); buffer16_test(); - testing_out_things(); }// run_all_tests() diff --git a/src/prototype/transcript_browser.c b/src/prototype/transcript_browser.c index 479f93f..25f332f 100644 --- a/src/prototype/transcript_browser.c +++ b/src/prototype/transcript_browser.c @@ -1,6 +1,5 @@ /////////////////////////////// // work queue - #define FN_WORK(name) void name(void *data) typedef FN_WORK(work_queue_callback_t); @@ -11,7 +10,8 @@ typedef struct { typedef struct work_queue_t work_queue_t; struct work_queue_t { - i32 thread_count; + b32 running; + i32 thread_count; work_queue_entry_t entries[1024]; i64 volatile index_to_write; i64 volatile index_to_read; @@ -22,8 +22,9 @@ struct work_queue_t { typedef struct thread_startup_info_t thread_startup_info_t; struct thread_startup_info_t { - u32 thread_id; - i32 thread_index; + u32 thread_id; + i32 thread_index; + ma_arena_t *arena; work_queue_t *queue; }; @@ -69,17 +70,18 @@ fn b8 work_queue_try_doing_work(work_queue_t *wq) { fn DWORD WINAPI work_queue_thread_entry(LPVOID param) { thread_startup_info_t *ti = (thread_startup_info_t *)param; - tcx = &global_thread_context; - os_win32_register_crash_handler(); + os_core_small_init(ti->arena); tcx->thread_index = ti->thread_index; - for (;;) { + for (;ti->queue->running;) { if (work_queue_try_doing_work(ti->queue)) { WaitForSingleObject(ti->queue->semaphore, INFINITE); } } + ExitThread(0); } fn void work_queue_init(work_queue_t *queue, thread_startup_info_t *info, u32 thread_count) { + queue->running = true; queue->thread_count = thread_count; queue->index_to_read = 0; queue->index_to_write = 0; @@ -90,6 +92,7 @@ fn void work_queue_init(work_queue_t *queue, thread_startup_info_t *info, u32 th for (u32 i = 0; i < thread_count; i++) { thread_startup_info_t *ti = info + i; + ti->arena = &tcx->perm; ti->thread_index = i; ti->queue = queue; @@ -112,6 +115,11 @@ fn void work_queue_wait(work_queue_t *wq) { } } +fn void work_queue_stop(work_queue_t *wq) { + wq->running = false; + work_queue_wait(wq); +} + /////////////////////////////// // process typedef struct process_t process_t; @@ -199,6 +207,7 @@ struct srt_entry_t { u16 hour, minute, second; s8_t string; s8_t filepath; + i32 filepath_index; }; typedef array(srt_entry_t) array_srt_entry_t; @@ -281,8 +290,16 @@ struct res_t { #define res_report(res, ...) (mutex_lock((res)->log_mutex), array_add(&(res)->error_messages, s8_printf(&(res)->misc_arena, __VA_ARGS__)), mutex_unlock((res)->log_mutex)) -fn void res_init(res_t *res) { +fn void res_unload(res_t *res) { + work_queue_stop(&res->work_queue); +} + +fn void res_reload(res_t *res) { work_queue_init(&res->work_queue, res->thread_info, lengthof(res->thread_info)); +} + +fn void res_init(res_t *res) { + res_reload(res); ma_init(&res->text_arena, ma_default_reserve_size); ma_init(&res->node_arena, ma_default_reserve_size); ma_init(&res->misc_arena, ma_default_reserve_size); @@ -301,7 +318,7 @@ fn s8_t srt_find_matching_video(s8_t filename) { } char *ext[] = {"mp4", "webm", "mkv"}; for (i32 i = 0; i < lengthof(ext); i += 1) { - s8_t video = s8_printf(tcx->temp, "%S.%s", no_srt, ext[i]); + s8_t video = s8_printf(&tcx->temp, "%S.%s", no_srt, ext[i]); if (os_exists(video)) { return video; } @@ -317,7 +334,7 @@ FN_WORK(res_parse_thread) { pair->res->mapping_entries.alo = malo(&pair->res->node_arena); for (i64 i = 0; i < srt.len; i += 1) { srt_entry_t it = srt.data[i]; - it.filepath = s8_copy(&pair->res->misc_arena, it.filepath); + it.filepath = s8_copy(&pair->res->node_arena, it.filepath); it.string = s8_copy(&pair->res->text_arena, it.string); it.string.str[it.string.len] = ' '; array_add(&pair->res->mapping_entries, it); @@ -345,7 +362,6 @@ fn void res_add_folder(res_t *res, s8_t folder) { if (!s8_ends_with(iter->abs, s8(".srt"))) { continue; } - // @leak res_parse_work_t *work = ma_push_type(&res->misc_arena, res_parse_work_t); work->srt = iter->abs; work->res = res; @@ -420,13 +436,7 @@ fn array_s8_t res_search_get(ma_arena_t *arena, res_t *res) { return copy; } -res_t *global_res = NULL; -// @todo @core make temp arena normal pointer in ctx, dont init on win32 etc. -// @todo @core make it sure that not too much arenas are initialized for threads // @todo @ui scrolling when focused button goes out of screen -fn_test void testing_out_things(void) { - -} /////////////////////////////// // update @@ -435,7 +445,7 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i ui_begin_frame(frame); rn_begin_frame(frame); - res_t *res = global_res; + res_t *res = (res_t *)tcx->user_ctx; for (app_event_t *ev = frame->first_event; ev; ev = ev->next) { ui_begin_build(UILOC, ev, window_rect_from_frame(frame)); @@ -485,7 +495,7 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i uintptr_t begin_region = (uintptr_t)res->text_arena.data; uintptr_t end_region = (uintptr_t)res->text_arena.data + res->text_arena.len; - u64 chars_per_line = (i64)(frame->window_size.x) / (i64)ui_dm(1) - strlen(res->search_prompt) * 2; + u64 chars_per_line = (i64)(frame->window_size.x) / (i64)ui_dm(1); u64 begin = (uintptr_t)(it.str - chars_per_line / 2); u64 end = (uintptr_t)(it.str + it.len + chars_per_line / 2); @@ -504,6 +514,35 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i ui_box_t *box = ui_box(.string = string, .flags = {.draw_rect = true, .draw_text = true, .keyboard_nav = true}); ui_signal_t sig = ui_signal_from_box(box); if (sig.clicked && matches.data != res->error_messages.data) { + + + // { + // s8_t text = s8_make(res->text_arena.data, res->text_arena.len); + // sb8_t *sb = sb8_serial_begin(scratch.arena); + // sb8_printf(sb, "s8_t the_text_itself = s8(\"%S\");\n", text); + // sb8_printf(sb, "s8_t the_filenames[] = {\n"); + // array_srt_entry_t entries = res->mapping_entries; + // i32 idx = 0; + // for (i64 i = 1; i < entries.len; i += 1) { + // srt_entry_t *prev_it = entries.data + i - 1; + // srt_entry_t *it = entries.data + i; + // if (!s8_are_equal(it->filepath, prev_it->filepath)) { + // sb8_printf(sb, "s8(\"%S\"),\n", s8_chop_last_period(s8_chop_last_period(s8_skip_to_last_slash(it->filepath)))); + // idx += 1; + // } + // it->filepath_index = idx; + // } + // sb8_printf(sb, "};\n"); + // sb8_printf(sb, "srt_entry_t all_the_entries[] = {\n"); + // for (i64 i = 0; i < entries.len; i += 1) { + // srt_entry_t *it = entries.data + i; + // sb8_printf(sb, "{%u, %u, %u, %u, %u, %d},\n", it->hour, it-> minute, it->second, (it->string.str - text.str), it->string.len, it->filepath_index); + // } + // sb8_printf(sb, "};\n"); + // s8_t text_entries = sb8_serial_end(scratch.arena, sb); + // os_write(s8("entries.inc"), text_entries); + // } + srt_entry_t *entry = res_find_entry(res, middle); s8_t video = srt_find_matching_video(entry->filepath); if (video.len == 0) { @@ -514,7 +553,6 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i if (video.str[i] == '/') video.str[i] = '\\'; } s8_t cmd = s8_printf(scratch.arena, "\"C:/Program Files/VideoLAN/VLC/vlc.exe\" --start-time %d \"%S\"", seconds, video); - debugf("%S\n", cmd); process_run(cmd); } } @@ -532,6 +570,12 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i res_search_start(res); set_focus = true; } + if (text_input_sig.text_commit) { + if (os_is_abs(res->search_text_input.string)) { + res_add_folder(res, res->search_text_input.string); + ui_text_clear(&res->search_text_input); + } + } assert(res->error_messages.cap == 10000); assert(res->search_matches.cap == 10000000); @@ -545,4 +589,4 @@ fn void transcript_browser_update(app_frame_t *frame, mt_tweak_t *tweak_table, i ui_draw(); rn_end(); ui_end_frame(); -} \ No newline at end of file +} diff --git a/src/render/render.c b/src/render/render.c index c239933..923ff4e 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -10,7 +10,7 @@ #define STBTT_acos(x) (f64_acos(x)) #define STBTT_fabs(x) (f64_abs(x)) #define STBTT_assert(x) assert(x) -#define STBTT_malloc(x,u) (ma_push_size(tcx->temp, x)) +#define STBTT_malloc(x,u) (ma_push_size(&tcx->temp, x)) #define STBTT_free(x,u) #define STBTT_strlen(x) (str_len(x)) #define STBTT_memcpy memory_copy diff --git a/src/render/render_basic.c b/src/render/render_basic.c index 44fc8fb..95b0a20 100644 --- a/src/render/render_basic.c +++ b/src/render/render_basic.c @@ -8,7 +8,7 @@ fn rn_cmd_t *rn_get_cmd(rn_cmd_kind_t kind) { rn_cmd_t *result = rn->last_cmd; if (alloc_new) { - result = ma_push_type(tcx->temp, rn_cmd_t); + result = ma_push_type(&tcx->temp, rn_cmd_t); result->kind = kind; SLLQ_APPEND(rn->first_cmd, rn->last_cmd, result); @@ -115,7 +115,7 @@ fn v2f32_t rn_draw_string(rn_font_t *font, v2f32_t pos, v4f32_t color, s8_t stri } fn v2f32_t rn_draw_stringf(rn_font_t *font, v2f32_t pos, v4f32_t color, char *str, ...) { - S8_FMT(tcx->temp, str, result); + S8_FMT(&tcx->temp, str, result); return rn_draw_string(font, pos, color, result); } diff --git a/src/testing/testing_main.c b/src/testing/testing_main.c index 3e16d73..9070ad9 100644 --- a/src/testing/testing_main.c +++ b/src/testing/testing_main.c @@ -11,12 +11,12 @@ fn void os_test(void) { os_date_t local_time = os_local_time(); os_date_t universal_time = os_universal_time(); unused(universal_time); unused(local_time); - // debugf("OS local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time)); + // debugf("OS local_time = %S | universal_time = %S", os_format_date(&tcx->temp, local_time), os_format_date(&tcx->temp, universal_time)); - s8_t exe_dir = os_exe_dir(tcx->temp); + s8_t exe_dir = os_exe_dir(&tcx->temp); assert(exe_dir.str[exe_dir.len - 1] == '/'); - s8_t exe = os_exe(tcx->temp); - s8_t cwd = os_cwd(tcx->temp); + s8_t exe = os_exe(&tcx->temp); + s8_t cwd = os_cwd(&tcx->temp); assert(cwd.str[cwd.len - 1] == '/'); assert(os_is_dir(exe_dir)); assert(os_is_file(exe)); @@ -30,7 +30,7 @@ fn void os_test(void) { assert(!os_is_abs(s8("../path/"))); // debugf("OS paths %S %S %S", exe_dir, exe, cwd); - s8_t file = os_read(tcx->temp, s8("../.gitignore")); + s8_t file = os_read(&tcx->temp, s8("../.gitignore")); assert(file.str != 0); assert(file.len != 0); @@ -140,7 +140,7 @@ fn void test_s8(void) { } int main() { - core_init(); + os_core_init(); run_tests(); test_s8(); os_test(); diff --git a/src/ui/ui.c b/src/ui/ui.c index 7e6be3d..b8c63c4 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -39,7 +39,7 @@ fn ui_caret_t ui_carets(i32 x) { } fn s8_t ui_tprint_loc(ui_code_loc_t loc) { - return s8_printf(tcx->temp, "%s(%d)", loc.file, loc.line); + return s8_printf(&tcx->temp, "%s(%d)", loc.file, loc.line); } fn s8_t ui_get_display_string(s8_t string) { @@ -106,7 +106,7 @@ fn ui_id_t ui_id(s8_t string) { } fn ui_id_t ui_idf(char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); return ui_id(string); } @@ -598,7 +598,7 @@ fn ui_signal_t ui__text_input(ui_code_loc_t loc, ui_text_input_t *ti, ui_box_fla #define ui_button(...) ui__button(UILOC, __VA_ARGS__) fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); ui_box_t *box = ui_box(.loc = loc, .string = string, .flags = { .draw_border = true, .draw_rect = true, .draw_text = true, .keyboard_nav = true }); ui_signal_t signal = ui_signal_from_box(box); return signal; @@ -606,7 +606,7 @@ fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) { #define ui_radio_button(...) ui__radio_button(UILOC, __VA_ARGS__) fn ui_signal_t ui__radio_button(ui_code_loc_t loc, i32 *value, i32 value_clicked, char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); ui_box_t *box = ui_box(.loc = loc, .string = string, .flags = { .draw_border = true, .draw_rect = true, .draw_text = true, .keyboard_nav = true }); ui_signal_t signal = ui_signal_from_box(box); if (signal.clicked) *value = value_clicked; @@ -616,7 +616,7 @@ fn ui_signal_t ui__radio_button(ui_code_loc_t loc, i32 *value, i32 value_clicked #define ui_label_button(...) ui__label_button(UILOC, __VA_ARGS__) fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); ui_box_t *box = ui_box(.loc = loc, .string = string, .flags = {.draw_text = true, .keyboard_nav = true}); ui_signal_t signal = ui_signal_from_box(box); return signal; @@ -624,7 +624,7 @@ fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) { #define ui_label(...) ui__label(UILOC, __VA_ARGS__) fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); ui_box_t *box = ui_box(.loc = loc, .string = string, .flags = {.draw_text = true}); return box; } @@ -649,7 +649,7 @@ fn void ui_tree_table_pop_expandable(void) { ui_pop_id(); } fn ui_signal_t ui_tree_table_push_expandable(ui_code_loc_t loc, char *str, ...) { - S8_FMT(tcx->temp, str, string); + S8_FMT(&tcx->temp, str, string); ui_id_t id = ui_id(ui_get_hash_string(string)); ui_push_id(id); ui_tree_table_begin(loc); @@ -668,8 +668,8 @@ fn ui_signal_t ui_tree_table_push_expandable(ui_code_loc_t loc, char *str, ...) if (button.clicked == false) { ui_tree_table_pop_expandable(); } - if ( button.box->expanded) button.box->string = s8_printf(tcx->temp, "* %S", button.box->string); - if (!button.box->expanded) button.box->string = s8_printf(tcx->temp, "> %S", button.box->string); + if ( button.box->expanded) button.box->string = s8_printf(&tcx->temp, "* %S", button.box->string); + if (!button.box->expanded) button.box->string = s8_printf(&tcx->temp, "> %S", button.box->string); return button; } diff --git a/src/ui/ui.gen.c b/src/ui/ui.gen.c index 1f98ff2..5d0771f 100644 --- a/src/ui/ui.gen.c +++ b/src/ui/ui.gen.c @@ -46,63 +46,63 @@ ui_color_table[ui_color_scroller] = ui_color_table[ui_color_text]; ui_color_table[ui_color_scroller_hot] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.7f, 1.0f}); ui_color_table[ui_color_scroller_active] = v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.2f, 0.5f, 1.0f}); } -fn void ui_push_id(ui_id_t v) { ui_id_node_t *n = ma_push_type(tcx->temp, ui_id_node_t); n->value = v; SLLS_PUSH(ui->id_stack, n); } +fn void ui_push_id(ui_id_t v) { ui_id_node_t *n = ma_push_type(&tcx->temp, ui_id_node_t); n->value = v; SLLS_PUSH(ui->id_stack, n); } fn void ui_pop_id(void) { SLLS_POP(ui->id_stack); } fn ui_id_t ui_top_id(void) { return ui->id_stack->value; } #define ui_set_id(x) defer_block(ui_push_id(x), ui_pop_id()) -fn void ui_push_lop(ui_lop_t v) { ui_lop_node_t *n = ma_push_type(tcx->temp, ui_lop_node_t); n->value = v; SLLS_PUSH(ui->lop_stack, n); } +fn void ui_push_lop(ui_lop_t v) { ui_lop_node_t *n = ma_push_type(&tcx->temp, ui_lop_node_t); n->value = v; SLLS_PUSH(ui->lop_stack, n); } fn void ui_pop_lop(void) { SLLS_POP(ui->lop_stack); } fn ui_lop_t ui_top_lop(void) { return ui->lop_stack->value; } #define ui_set_lop(x) defer_block(ui_push_lop(x), ui_pop_lop()) -fn void ui_push_border_thickness(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->border_thickness_stack, n); } +fn void ui_push_border_thickness(f32 v) { ui_f32_node_t *n = ma_push_type(&tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->border_thickness_stack, n); } fn void ui_pop_border_thickness(void) { SLLS_POP(ui->border_thickness_stack); } fn f32 ui_top_border_thickness(void) { return ui->border_thickness_stack->value; } #define ui_set_border_thickness(x) defer_block(ui_push_border_thickness(x), ui_pop_border_thickness()) -fn void ui_push_text_align(ui_text_align_t v) { ui_text_align_node_t *n = ma_push_type(tcx->temp, ui_text_align_node_t); n->value = v; SLLS_PUSH(ui->text_align_stack, n); } +fn void ui_push_text_align(ui_text_align_t v) { ui_text_align_node_t *n = ma_push_type(&tcx->temp, ui_text_align_node_t); n->value = v; SLLS_PUSH(ui->text_align_stack, n); } fn void ui_pop_text_align(void) { SLLS_POP(ui->text_align_stack); } fn ui_text_align_t ui_top_text_align(void) { return ui->text_align_stack->value; } #define ui_set_text_align(x) defer_block(ui_push_text_align(x), ui_pop_text_align()) -fn void ui_push_required_size(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_size_stack, n); } +fn void ui_push_required_size(f32 v) { ui_f32_node_t *n = ma_push_type(&tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_size_stack, n); } fn void ui_pop_required_size(void) { SLLS_POP(ui->required_size_stack); } fn f32 ui_top_required_size(void) { return ui->required_size_stack->value; } #define ui_set_required_size(x) defer_block(ui_push_required_size(x), ui_pop_required_size()) -fn void ui_push_padding(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->padding_stack, n); } +fn void ui_push_padding(f32 v) { ui_f32_node_t *n = ma_push_type(&tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->padding_stack, n); } fn void ui_pop_padding(void) { SLLS_POP(ui->padding_stack); } fn f32 ui_top_padding(void) { return ui->padding_stack->value; } #define ui_set_padding(x) defer_block(ui_push_padding(x), ui_pop_padding()) -fn void ui_push_string_pos_offset(f32 v) { ui_f32_node_t *n = ma_push_type(tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->string_pos_offset_stack, n); } +fn void ui_push_string_pos_offset(f32 v) { ui_f32_node_t *n = ma_push_type(&tcx->temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->string_pos_offset_stack, n); } fn void ui_pop_string_pos_offset(void) { SLLS_POP(ui->string_pos_offset_stack); } fn f32 ui_top_string_pos_offset(void) { return ui->string_pos_offset_stack->value; } #define ui_set_string_pos_offset(x) defer_block(ui_push_string_pos_offset(x), ui_pop_string_pos_offset()) -fn void ui_push_rect(r2f32_t v) { ui_r2f32_node_t *n = ma_push_type(tcx->temp, ui_r2f32_node_t); n->value = v; SLLS_PUSH(ui->rect_stack, n); } +fn void ui_push_rect(r2f32_t v) { ui_r2f32_node_t *n = ma_push_type(&tcx->temp, ui_r2f32_node_t); n->value = v; SLLS_PUSH(ui->rect_stack, n); } fn void ui_pop_rect(void) { SLLS_POP(ui->rect_stack); } fn r2f32_t ui_top_rect(void) { return ui->rect_stack->value; } #define ui_set_rect(x) defer_block(ui_push_rect(x), ui_pop_rect()) -fn void ui_push_background_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->background_color_stack, n); } +fn void ui_push_background_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->background_color_stack, n); } fn void ui_pop_background_color(void) { SLLS_POP(ui->background_color_stack); } fn v4f32_t ui_top_background_color(void) { return ui->background_color_stack->value; } #define ui_set_background_color(x) defer_block(ui_push_background_color(x), ui_pop_background_color()) -fn void ui_push_bg_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_hot_color_stack, n); } +fn void ui_push_bg_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_hot_color_stack, n); } fn void ui_pop_bg_hot_color(void) { SLLS_POP(ui->bg_hot_color_stack); } fn v4f32_t ui_top_bg_hot_color(void) { return ui->bg_hot_color_stack->value; } #define ui_set_bg_hot_color(x) defer_block(ui_push_bg_hot_color(x), ui_pop_bg_hot_color()) -fn void ui_push_bg_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_active_color_stack, n); } +fn void ui_push_bg_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->bg_active_color_stack, n); } fn void ui_pop_bg_active_color(void) { SLLS_POP(ui->bg_active_color_stack); } fn v4f32_t ui_top_bg_active_color(void) { return ui->bg_active_color_stack->value; } #define ui_set_bg_active_color(x) defer_block(ui_push_bg_active_color(x), ui_pop_bg_active_color()) -fn void ui_push_border_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->border_color_stack, n); } +fn void ui_push_border_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->border_color_stack, n); } fn void ui_pop_border_color(void) { SLLS_POP(ui->border_color_stack); } fn v4f32_t ui_top_border_color(void) { return ui->border_color_stack->value; } #define ui_set_border_color(x) defer_block(ui_push_border_color(x), ui_pop_border_color()) -fn void ui_push_text_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_color_stack, n); } +fn void ui_push_text_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_color_stack, n); } fn void ui_pop_text_color(void) { SLLS_POP(ui->text_color_stack); } fn v4f32_t ui_top_text_color(void) { return ui->text_color_stack->value; } #define ui_set_text_color(x) defer_block(ui_push_text_color(x), ui_pop_text_color()) -fn void ui_push_text_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_hot_color_stack, n); } +fn void ui_push_text_hot_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_hot_color_stack, n); } fn void ui_pop_text_hot_color(void) { SLLS_POP(ui->text_hot_color_stack); } fn v4f32_t ui_top_text_hot_color(void) { return ui->text_hot_color_stack->value; } #define ui_set_text_hot_color(x) defer_block(ui_push_text_hot_color(x), ui_pop_text_hot_color()) -fn void ui_push_text_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_active_color_stack, n); } +fn void ui_push_text_active_color(v4f32_t v) { ui_v4f32_node_t *n = ma_push_type(&tcx->temp, ui_v4f32_node_t); n->value = v; SLLS_PUSH(ui->text_active_color_stack, n); } fn void ui_pop_text_active_color(void) { SLLS_POP(ui->text_active_color_stack); } fn v4f32_t ui_top_text_active_color(void) { return ui->text_active_color_stack->value; } #define ui_set_text_active_color(x) defer_block(ui_push_text_active_color(x), ui_pop_text_active_color()) diff --git a/src/ui/ui.h b/src/ui/ui.h index 9597558..f051de5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -70,6 +70,13 @@ struct ui_text_input_t { ui_caret_t caret; }; +// typedef struct ui_styled_string_t ui_styled_string_t; +// struct ui_styled_string_t { +// ui_styled_string_t *next; +// s8_t string; +// v4f32_t color; +// }; + typedef struct ui_box_t ui_box_t; typedef void ui_custom_draw_t(ui_box_t *); diff --git a/src/ui/ui.meta.c b/src/ui/ui.meta.c index aeae74f..280842c 100644 --- a/src/ui/ui.meta.c +++ b/src/ui/ui.meta.c @@ -102,7 +102,7 @@ fn void mt_ui_stacks(ma_arena_t *arena, sb8_t *c, sb8_t *h) { /////////////////////////////// // generate stack functions for (ast_t *it = table->first; it; it = it->next) { - mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx->temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n" + mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(&tcx->temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n" "fn void ui_pop_@name(void) { SLLS_POP(ui->@stack); }\n" "fn @type ui_top_@name(void) { return ui->@stack->value; }\n" "#define ui_set_@name(x) defer_block(ui_push_@name(x), ui_pop_@name())\n");