use macros for typedef'd function definitions

This commit is contained in:
jacob 2024-03-28 11:46:43 -05:00
parent 6122905949
commit 508c77abfd
14 changed files with 40 additions and 23 deletions

View File

@ -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},

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;