diff --git a/src/ase.c b/src/ase.c index c502e787..f87984e9 100644 --- a/src/ase.c +++ b/src/ase.c @@ -70,11 +70,11 @@ struct huffman { struct huffman_entry *entries; }; -GLOBAL READONLY const u32 g_hclen_order[] = { +GLOBAL READONLY u32 g_hclen_order[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; -GLOBAL READONLY const struct huffman_entry g_length_table[] = { +GLOBAL READONLY struct huffman_entry g_length_table[] = { {3, 0}, /* 257 */ {4, 0}, /* 258 */ {5, 0}, /* 259 */ @@ -106,7 +106,7 @@ GLOBAL READONLY const struct huffman_entry g_length_table[] = { {258, 0}, /* 285 */ }; -GLOBAL READONLY const struct huffman_entry g_dist_table[] = { +GLOBAL READONLY struct huffman_entry g_dist_table[] = { {1, 0}, /* 0 */ {2, 0}, /* 1 */ {3, 0}, /* 2 */ @@ -139,7 +139,7 @@ GLOBAL READONLY const struct huffman_entry g_dist_table[] = { {24577, 13}, /* 29 */ }; -GLOBAL READONLY const u32 g_fixed_bl_counts[][2] = { +GLOBAL READONLY u32 g_fixed_bl_counts[][2] = { {143, 8}, {255, 9}, {279, 7}, diff --git a/src/font.c b/src/font.c index 91122dfd..bd0d48e4 100644 --- a/src/font.c +++ b/src/font.c @@ -78,7 +78,7 @@ INTERNAL void font_task_params_release(struct font_task_params *p) * Load * ========================== */ -INTERNAL void font_load_asset_task(void *vparams) +INTERNAL WORK_TASK_FUNC_DEF(font_load_asset_task, vparams) { __prof; struct font_task_params *params = (struct font_task_params *)vparams; diff --git a/src/game.c b/src/game.c index c3456207..5474e1b1 100644 --- a/src/game.c +++ b/src/game.c @@ -543,7 +543,7 @@ INTERNAL void game_update(void) * Startup * ========================== */ -INTERNAL void game_thread_entry_point(void *arg) +INTERNAL SYS_THREAD_FUNC_DEF(game_thread_entry_point, arg) { (UNUSED)arg; sys_timestamp_t last_frame_ts = 0; diff --git a/src/log.h b/src/log.h index 84a4f53f..f774fb85 100644 --- a/src/log.h +++ b/src/log.h @@ -46,7 +46,7 @@ struct log_event { i32 line; }; -typedef void(log_event_callback_func)(struct log_event); +typedef void (log_event_callback_func)(struct log_event); void log_register_callback(log_event_callback_func *func); diff --git a/src/playback_wasapi.c b/src/playback_wasapi.c index 8b08e601..3c780b43 100644 --- a/src/playback_wasapi.c +++ b/src/playback_wasapi.c @@ -204,7 +204,7 @@ INTERNAL void wasapi_update_end(struct wasapi_buffer *wspbuf, struct mixed_pcm_f * Startup * ========================== */ -INTERNAL void playback_thread_entry_point(void *arg) +INTERNAL SYS_THREAD_FUNC_DEF(playback_thread_entry_point, arg) { (UNUSED)arg; diff --git a/src/sheet.c b/src/sheet.c index b1aa47de..0a1a939e 100644 --- a/src/sheet.c +++ b/src/sheet.c @@ -134,7 +134,7 @@ INTERNAL struct sheet sheet_default(struct arena *arena) * Load * ========================== */ -INTERNAL void sheet_load_asset_task(void *vparams) +INTERNAL WORK_TASK_FUNC_DEF(sheet_load_asset_task, vparams) { __prof; struct sheet_task_params *params = (struct sheet_task_params *)vparams; diff --git a/src/sound.c b/src/sound.c index 3fffa8fb..b6a9e606 100644 --- a/src/sound.c +++ b/src/sound.c @@ -76,7 +76,7 @@ INTERNAL void sound_task_params_release(struct sound_task_params *p) * Load * ========================== */ -INTERNAL void sound_load_asset_task(void *vparams) +INTERNAL WORK_TASK_FUNC_DEF(sound_load_asset_task, vparams) { __prof; struct sound_task_params *params = (struct sound_task_params *)vparams; diff --git a/src/string.c b/src/string.c index da533339..42ad2a1a 100644 --- a/src/string.c +++ b/src/string.c @@ -159,8 +159,19 @@ struct string string_copy(struct arena *arena, struct string src) return str; } +struct string string_copy_buff(struct buffer buff, struct string src) +{ + u64 len = min_u64(buff.size, src.len); + struct string str = { + .len = len, + .text = buff.data + }; + MEMCPY(str.text, src.text, src.len); + return str; +} + /* TODO: Benchmark performance of appending each character while calculating size here */ -// //struct string string_cpy_cstr(struct arena *arena, char *cstr) +// //struct string string_copy_cstr(struct arena *arena, char *cstr) // //{ // // u8 *final_text = arena_next(arena); // // char *c = cstr; diff --git a/src/string.h b/src/string.h index 1d162f72..366b07c5 100644 --- a/src/string.h +++ b/src/string.h @@ -21,6 +21,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision); * ========================== */ struct string string_copy(struct arena *arena, struct string src); +struct string string_copy_buff(struct buffer buff, struct string src); struct string string_from_cstr(char *cstr); struct string string_from_cstr_len(char *cstr, u64 len); struct string string_repeat(struct arena *arena, struct string src, u64 count); diff --git a/src/sys.h b/src/sys.h index 413b303c..965cc30e 100644 --- a/src/sys.h +++ b/src/sys.h @@ -250,7 +250,9 @@ enum sys_window_flags { SYS_WINDOW_FLAG_SHOWING = 0x02 }; -typedef void (sys_window_event_callback_func)(struct sys_event event); + +#define SYS_WINDOW_EVENT_CALLBACK_DEF(name, arg_name) void name(struct sys_event arg_name) +typedef SYS_WINDOW_EVENT_CALLBACK_DEF(sys_window_event_callback, event); /* sys_window_update_settings should be used when altering settings values */ struct sys_window_settings { @@ -274,8 +276,8 @@ struct sys_window { struct sys_window sys_window_alloc(void); void sys_window_release(struct sys_window *sys_window); -void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func); -void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func); +void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback *func); +void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback *func); void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings); struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window); @@ -394,7 +396,8 @@ struct worker_context *sys_thread_get_worker_context(void); #define SYS_THREAD_STACK_SIZE MEGABYTE(1) -typedef void (sys_thread_func)(void *data); +#define SYS_THREAD_FUNC_DEF(name, arg_name) void name(void *arg_name) +typedef SYS_THREAD_FUNC_DEF(sys_thread_func, data); struct sys_thread { u64 handle; diff --git a/src/sys_win32.c b/src/sys_win32.c index 15ea5d35..44bc1ef3 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -67,7 +67,7 @@ struct win32_window { struct sys_thread event_thread; struct sys_mutex event_callbacks_mutex; - sys_window_event_callback_func *event_callbacks[SYS_WINDOW_EVENT_LISTENERS_MAX]; + sys_window_event_callback *event_callbacks[SYS_WINDOW_EVENT_LISTENERS_MAX]; u64 event_callbacks_count; struct win32_window *next_free; @@ -1008,7 +1008,7 @@ void sys_window_release(struct sys_window *sys_window) win32_window_release(window); } -void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func) +void sys_window_register_event_callback(struct sys_window *sys_window, sys_window_event_callback *func) { struct win32_window *window = (struct win32_window *)sys_window->handle; @@ -1023,14 +1023,14 @@ void sys_window_register_event_callback(struct sys_window *sys_window, sys_windo sys_mutex_unlock(&window->event_callbacks_mutex); } -void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback_func *func) +void sys_window_unregister_event_callback(struct sys_window *sys_window, sys_window_event_callback *func) { struct win32_window *window = (struct win32_window *)sys_window->handle; sys_mutex_lock(&window->event_callbacks_mutex); { u64 count = window->event_callbacks_count; - sys_window_event_callback_func *last = count > 0 ? window->event_callbacks[count - 1] : NULL; + sys_window_event_callback *last = count > 0 ? window->event_callbacks[count - 1] : NULL; for (u64 i = 0; i < window->event_callbacks_count; ++i) { if (window->event_callbacks[i] == func) { @@ -1373,6 +1373,7 @@ void sys_semaphore_wait(struct sys_semaphore *semaphore) void sys_semaphore_signal(struct sys_semaphore *semaphore, u32 count) { __prof; + /* FIXME: Implicit mutex release means mutex debug owner info becomes invalid? */ ReleaseSemaphore((HANDLE)semaphore->handle, count, NULL); } diff --git a/src/texture.c b/src/texture.c index e5be3334..c66ec49c 100644 --- a/src/texture.c +++ b/src/texture.c @@ -121,7 +121,7 @@ INTERNAL struct image_rgba generate_purple_black_image(struct arena *arena, u32 * Load * ========================== */ -INTERNAL void texture_load_asset_task(void *vparams) +INTERNAL WORK_TASK_FUNC_DEF(texture_load_asset_task, vparams) { __prof; struct texture_task_params *params = (struct texture_task_params *)vparams; diff --git a/src/user.c b/src/user.c index dcf7746d..1949dc46 100644 --- a/src/user.c +++ b/src/user.c @@ -111,7 +111,7 @@ INTERNAL struct sys_event_array pop_sys_events(struct arena *arena) return array; } -INTERNAL void window_event_callback(struct sys_event event) +INTERNAL SYS_WINDOW_EVENT_CALLBACK_DEF(window_event_callback, event) { sys_mutex_lock(&L.sys_events_mutex); { @@ -1026,7 +1026,7 @@ INTERNAL void user_update(void) * Startup * ========================== */ -INTERNAL void user_thread_entry_point(void *arg) +INTERNAL SYS_THREAD_FUNC_DEF(user_thread_entry_point, arg) { (UNUSED)arg; diff --git a/src/work.h b/src/work.h index 6a3a8bfa..68f37fb8 100644 --- a/src/work.h +++ b/src/work.h @@ -14,7 +14,8 @@ enum work_priority { NUM_WORK_PRIORITIES }; -typedef void (work_task_func)(void *data); +#define WORK_TASK_FUNC_DEF(name, arg_name) void name(void *arg_name) +typedef WORK_TASK_FUNC_DEF(work_task_func, data); struct work; struct work_task;