win32_app
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
/*
|
||||
|
||||
.doesn't miss events (always processes all key strokes and buttons etc.)
|
||||
.replayable / deterministic (that is you can serialize all the events, replay them back and get the same results)
|
||||
..rendering and update decoupled
|
||||
.sleeps properly when nothing is happening
|
||||
.animations probably then should be in the rendering part
|
||||
.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
|
||||
|
||||
void app_update(app_event_t *events, i32 event_count) {
|
||||
loop (events) update(it);
|
||||
update_result_t *state = NULL; // contains event
|
||||
loop (events) {
|
||||
state = update(it);
|
||||
}
|
||||
|
||||
{
|
||||
app_event_t *ev = events + event_count - 1;
|
||||
app_event_t *ev = state->ev;
|
||||
|
||||
|
||||
f64 delta_time = app_anim_get_delta_time();
|
||||
f64 time = app_anim_get_time();
|
||||
animate(ev, delta_time, time);
|
||||
render(ev);
|
||||
animate(state, delta_time, time);
|
||||
render(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +42,10 @@ glb_wasm_export i32 wasm_temp_buff1_len = 127;
|
||||
glb_wasm_export char wasm_temp_buff2[128] = {[127] = 0x13};
|
||||
glb_wasm_export i32 wasm_temp_buff2_len = 127;
|
||||
|
||||
global f64 wasm_dpr;
|
||||
global ma_arena_t *wasm_input_text_arena;
|
||||
global STACK(app_event_t, 64) wasm_events;
|
||||
global b32 wasm_event_failed_to_queue;
|
||||
// @todo: event list
|
||||
global f64 wasm_dpr;
|
||||
global STACK(app_event_t, 256) wasm_events;
|
||||
global b32 wasm_event_failed_to_queue;
|
||||
|
||||
global f64 wasm_delta_time;
|
||||
global f64 wasm_time;
|
||||
@@ -53,7 +58,7 @@ struct wasm_cached_t {
|
||||
b8 ctrl, alt, meta, shift;
|
||||
} wasm_cached;
|
||||
|
||||
fn void app_update(app_event_t *events, i32 event_count);
|
||||
fn void app_update(void);
|
||||
fn void app_init(void);
|
||||
|
||||
fn void wasm_add_event(app_event_t event) {
|
||||
@@ -147,7 +152,7 @@ fn_wasm_export void wasm_key_down(char *key, b32 ctrl, b32 shift, b32 alt, b32 m
|
||||
return;
|
||||
}
|
||||
|
||||
s8_t text = s8_copy(wasm_input_text_arena, key8);
|
||||
s8_t text = s8_copy(tcx.temp, key8);
|
||||
wasm_add_event((app_event_t){
|
||||
.kind = app_event_kind_text,
|
||||
.mouse_pos = wasm_cached.mouse_pos,
|
||||
@@ -180,7 +185,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 width, f64 height, f64 dpr) {
|
||||
wasm_time = os_get_milliseconds();
|
||||
wasm_time = os_milliseconds_now();
|
||||
wasm_delta_time = wasm_time - wasm_last_time_milliseconds;
|
||||
|
||||
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
|
||||
@@ -202,18 +207,32 @@ fn_wasm_export void wasm_update(f64 width, f64 height, f64 dpr) {
|
||||
wasm_events.data[i].window_size = window_size;
|
||||
}
|
||||
|
||||
app_update(wasm_events.data, wasm_events.len);
|
||||
app_update();
|
||||
|
||||
wasm_events.len = 0;
|
||||
wasm_last_time_milliseconds = wasm_time;
|
||||
ma_set0(wasm_input_text_arena);
|
||||
}
|
||||
|
||||
fn_wasm_export void wasm_init(void) {
|
||||
core_init();
|
||||
wasm_input_text_arena = ma_push_arena(&tcx.perm, kib(1));
|
||||
app_init();
|
||||
wasm_app_init_time_milliseconds = os_get_milliseconds();
|
||||
wasm_app_init_time_milliseconds = os_milliseconds_now();
|
||||
}
|
||||
|
||||
fn app_event_t *app_iterate_events(void) {
|
||||
return wasm_events.data;
|
||||
}
|
||||
|
||||
fn b32 app_is_event_valid(app_event_t *event) {
|
||||
return event < (wasm_events.data + wasm_events.len);
|
||||
}
|
||||
|
||||
fn void app_next_event(app_event_t **event) {
|
||||
event[0] += 1;
|
||||
}
|
||||
|
||||
fn app_event_t *app_get_last_event(void) {
|
||||
return wasm_events.data + wasm_events.len - 1;
|
||||
}
|
||||
|
||||
fn f64 app_get_anim_time(void) {
|
||||
|
||||
Reference in New Issue
Block a user