diff --git a/src/game.c b/src/game.c index 86b11cbf..9b970ccb 100644 --- a/src/game.c +++ b/src/game.c @@ -8,6 +8,7 @@ #include "mixer.h" #include "math.h" #include "scratch.h" +#include "atomic.h" GLOBAL struct { b32 shutdown; @@ -22,6 +23,7 @@ GLOBAL struct { /* Game thread output */ struct sys_mutex published_tick_mutex; struct world published_tick; + struct atomic_u64 published_tick_id; } L = { 0 }, DEBUG_LVAR(L_game); /* ========================== * @@ -66,6 +68,7 @@ INTERNAL void publish_game_tick(void) sys_mutex_lock(&L.published_tick_mutex); { world_copy_replace(&L.published_tick, &L.world); + atomic_u64_eval_exchange(&L.published_tick_id, L.published_tick.tick_id); } sys_mutex_unlock(&L.published_tick_mutex); } @@ -577,7 +580,7 @@ void game_get_latest_tick(struct world *dest) u64 game_get_latest_tick_id(void) { - return L.published_tick.tick_id; + return atomic_u64_eval(&L.published_tick_id); } void game_push_cmds(struct game_cmd_array cmd_array) diff --git a/src/sys_win32.c b/src/sys_win32.c index ea9f15be..86b647c5 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -59,6 +59,8 @@ struct win32_window { * their pre-minimized values) */ i32 x, y, width, height; + /* FIXME: Use a cmd buffer for updating cursor (and maybe also settings). + * Current setup means cursor_set calls can be applied out of order */ u32 cursor_set_flags; struct v2 cursor_set_position; struct rect cursor_clip_bounds; @@ -767,25 +769,6 @@ INTERNAL void win32_update_window_from_settings(struct win32_window *window, str SWP_NOZORDER | SWP_NOOWNERZORDER ); -#if 0 - if (settings->flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED) { - ShowWindow(hwnd, SW_SHOWMAXIMIZED); - window->flags |= SYS_WINDOW_FLAG_SHOWING; - } - - if (settings->flags & SYS_WINDOW_SETTINGS_FLAG_MINIMIZED) { - ShowWindow(hwnd, SW_MINIMIZE); - window->flags |= SYS_WINDOW_FLAG_SHOWING; - } - - if (!(window->flags & SYS_WINDOW_FLAG_SHOWING)) { - /* Open window for first time */ - ShowWindow(hwnd, SW_NORMAL); - window->flags |= SYS_WINDOW_FLAG_SHOWING; - } - - BringWindowToTop(hwnd); -#endif SetWindowTextA(hwnd, settings->title); } @@ -1052,7 +1035,7 @@ void sys_window_update_settings(struct sys_window *sys_window, struct sys_window sys_rw_mutex_unlock_exclusive(&window->settings_rw_mutex); } -/* TODO: Lock settings mutex for these functions */ +/* FIXME: Lock settings mutex for these functions */ struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window) { diff --git a/src/util.h b/src/util.h index 2e611450..575fd3c8 100644 --- a/src/util.h +++ b/src/util.h @@ -169,7 +169,10 @@ INLINE void sync_flag_wait(struct sync_flag *sf) __prof; while (atomic_i32_eval(&sf->flag) == 0) { sys_mutex_lock(&sf->mutex); - sys_condition_variable_wait(&sf->cv, &sf->mutex); + { + sys_condition_variable_wait(&sf->cv, &sf->mutex); + } + sys_mutex_unlock(&sf->mutex); } }