w32 wait for events

This commit is contained in:
krzosa
2025-01-04 11:24:01 +01:00
parent dcd1266477
commit 489c8c413e
2 changed files with 15 additions and 19 deletions

View File

@@ -4,7 +4,7 @@
.sleeps properly when nothing is happening
.replayable (that is you can serialize all the events, replay them back and get the same results)
..rendering and update decoupled
..animations probably then should be in the rendering part
..animations probably should be in the rendering part
void app_update(app_event_t *events, i32 event_count) {
update_result_t *state = NULL; // contains event
@@ -23,17 +23,6 @@ void app_update(app_event_t *events, i32 event_count) {
}
}
while (true) {
app_event_t *events = NULL;
if (animating) {
events = poll_events(); // non-blocking
} else {
events = wait_for_events(); // blocking
}
app_update(events, event_count);
SwapBuffers(); // vsync block
}
*/
gb_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13};
@@ -176,7 +165,7 @@ fn_wasm_export void wasm_key_up(char *key, b32 ctrl, b32 shift, b32 alt, b32 met
}
}
fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
fn_wasm_export b32 wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
wasm_time = time;
wasm_delta_time = wasm_time - wasm_last_time;
@@ -199,11 +188,13 @@ fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
ev->window_size = window_size;
}
app_update(wasm_event_list);
b32 animating = app_update(wasm_event_list);
ma_set0(tcx.temp);
zero_struct(&wasm_event_list);
wasm_last_time = wasm_time;
return animating;
}
fn_wasm_export void wasm_init(void) {

View File

@@ -165,11 +165,17 @@ fn LRESULT CALLBACK w32_window_proc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lp
return 0;
}
app_event_list_t w32_get_events(ma_arena_t *arena) {
app_event_list_t w32_get_events(ma_arena_t *arena, b32 wait) {
w32_event_arena = arena;
memory_zero(&w32_event_list, sizeof(w32_event_list));
zero_struct(&w32_event_list);
MSG msg;
if (wait) {
GetMessageW(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
@@ -342,7 +348,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
u64 missed_frames = 0;
u64 frame = 0;
for (;;) {
app_event_list_t event_list = w32_get_events(tcx.temp);
app_event_list_t event_list = w32_get_events(tcx.temp, false);
for (app_event_t *ev = event_list.first; ev; ev = ev->next) {
if (ev->kind == app_event_kind_key_down && ev->key == app_key_escape) {
@@ -363,11 +369,10 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
// w32_present_canvas(&canvas);
ma_set0(tcx.temp);
///////////////////////////////
// end of frame timings
ma_set0(tcx.temp);
f64 time_update_partial = os_seconds_now() - time_frame_start;
time_update = time_update_partial;
if (time_update < time_delta) {