make published tick id atomic
This commit is contained in:
parent
3b0cdfd1f4
commit
ba7769fba9
@ -8,6 +8,7 @@
|
|||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "scratch.h"
|
#include "scratch.h"
|
||||||
|
#include "atomic.h"
|
||||||
|
|
||||||
GLOBAL struct {
|
GLOBAL struct {
|
||||||
b32 shutdown;
|
b32 shutdown;
|
||||||
@ -22,6 +23,7 @@ GLOBAL struct {
|
|||||||
/* Game thread output */
|
/* Game thread output */
|
||||||
struct sys_mutex published_tick_mutex;
|
struct sys_mutex published_tick_mutex;
|
||||||
struct world published_tick;
|
struct world published_tick;
|
||||||
|
struct atomic_u64 published_tick_id;
|
||||||
} L = { 0 }, DEBUG_LVAR(L_game);
|
} L = { 0 }, DEBUG_LVAR(L_game);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -66,6 +68,7 @@ INTERNAL void publish_game_tick(void)
|
|||||||
sys_mutex_lock(&L.published_tick_mutex);
|
sys_mutex_lock(&L.published_tick_mutex);
|
||||||
{
|
{
|
||||||
world_copy_replace(&L.published_tick, &L.world);
|
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);
|
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)
|
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)
|
void game_push_cmds(struct game_cmd_array cmd_array)
|
||||||
|
|||||||
@ -59,6 +59,8 @@ struct win32_window {
|
|||||||
* their pre-minimized values) */
|
* their pre-minimized values) */
|
||||||
i32 x, y, width, height;
|
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;
|
u32 cursor_set_flags;
|
||||||
struct v2 cursor_set_position;
|
struct v2 cursor_set_position;
|
||||||
struct rect cursor_clip_bounds;
|
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
|
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);
|
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);
|
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)
|
struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -169,8 +169,11 @@ INLINE void sync_flag_wait(struct sync_flag *sf)
|
|||||||
__prof;
|
__prof;
|
||||||
while (atomic_i32_eval(&sf->flag) == 0) {
|
while (atomic_i32_eval(&sf->flag) == 0) {
|
||||||
sys_mutex_lock(&sf->mutex);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user