wasm app
This commit is contained in:
@@ -264,11 +264,9 @@ type_t type__app_event_t = { type_kind_struct, s8_const_lit("app_event_t"), size
|
||||
{.name = s8_const_lit("shift"), .type = &type__b8, .offset = offsetof(app_event_t, shift)},
|
||||
{.name = s8_const_lit("alt"), .type = &type__b8, .offset = offsetof(app_event_t, alt)},
|
||||
{.name = s8_const_lit("meta"), .type = &type__b8, .offset = offsetof(app_event_t, meta)},
|
||||
{.name = s8_const_lit("time"), .type = &type__f64, .offset = offsetof(app_event_t, time)},
|
||||
{.name = s8_const_lit("delta_time"), .type = &type__f64, .offset = offsetof(app_event_t, delta_time)},
|
||||
{.name = s8_const_lit("dpr"), .type = &type__f64, .offset = offsetof(app_event_t, dpr)},
|
||||
{.name = s8_const_lit("window_size"), .type = &type__v2f64_t, .offset = offsetof(app_event_t, window_size)},
|
||||
{.name = s8_const_lit("mouse_pos"), .type = &type__v2f64_t, .offset = offsetof(app_event_t, mouse_pos)},
|
||||
},
|
||||
.count = 14,
|
||||
.count = 12,
|
||||
};
|
||||
@@ -102,8 +102,6 @@ struct app_event_t {
|
||||
b8 shift;
|
||||
b8 alt;
|
||||
b8 meta;
|
||||
f64 time;
|
||||
f64 delta_time;
|
||||
f64 dpr;
|
||||
v2f64_t window_size;
|
||||
v2f64_t mouse_pos;
|
||||
|
||||
@@ -162,10 +162,10 @@ void meta_app(ma_arena_t *arena) {
|
||||
app_event_kind_t kind;
|
||||
|
||||
// data present only during events
|
||||
app_mouse_button_t mouse_button;
|
||||
app_key_t key;
|
||||
s8_t text;
|
||||
v3f64_t mouse_wheel_delta;
|
||||
app_mouse_button_t mouse_button; // @mouse_down @mouse_up
|
||||
app_key_t key; // @key_down @key_up
|
||||
s8_t text; // @text
|
||||
v3f64_t mouse_wheel_delta; // @mouse_wheel
|
||||
|
||||
// always present data
|
||||
b8 ctrl;
|
||||
@@ -173,9 +173,6 @@ void meta_app(ma_arena_t *arena) {
|
||||
b8 alt;
|
||||
b8 meta;
|
||||
|
||||
f64 time;
|
||||
f64 delta_time;
|
||||
|
||||
f64 dpr;
|
||||
v2f64_t window_size;
|
||||
v2f64_t mouse_pos;
|
||||
|
||||
@@ -1,13 +1,51 @@
|
||||
/*
|
||||
|
||||
.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
|
||||
|
||||
void app_update(app_event_t *events, i32 event_count) {
|
||||
loop (events) update(it);
|
||||
|
||||
{
|
||||
app_event_t *ev = events + event_count - 1;
|
||||
f64 delta_time = app_anim_get_delta_time();
|
||||
f64 time = app_anim_get_time();
|
||||
animate(ev, delta_time, time);
|
||||
render(ev);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
glb_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13};
|
||||
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;
|
||||
|
||||
glb f64 wasm_dpr;
|
||||
glb ma_arena_t *wasm_input_text_arena;
|
||||
glb STACK(app_event_t, 64) wasm_events;
|
||||
glb b32 wasm_event_failed_to_queue;
|
||||
glb f64 wasm_last_time = 0;
|
||||
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;
|
||||
|
||||
global f64 wasm_delta_time;
|
||||
global f64 wasm_time;
|
||||
global f64 wasm_last_time_milliseconds;
|
||||
global f64 wasm_app_init_time_milliseconds;
|
||||
|
||||
typedef struct wasm_cached_t wasm_cached_t;
|
||||
struct wasm_cached_t {
|
||||
@@ -141,10 +179,12 @@ 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) {
|
||||
f64 delta_time = (time - wasm_last_time);
|
||||
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
|
||||
fn_wasm_export void wasm_update(f64 width, f64 height, f64 dpr) {
|
||||
wasm_time = os_get_milliseconds();
|
||||
wasm_delta_time = wasm_time - wasm_last_time_milliseconds;
|
||||
|
||||
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
|
||||
wasm_dpr = dpr;
|
||||
|
||||
if (wasm_events.len == 0) {
|
||||
wasm_add_event((app_event_t){
|
||||
@@ -160,15 +200,12 @@ fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
|
||||
for (i32 i = 0; i < wasm_events.len; i += 1) {
|
||||
wasm_events.data[i].dpr = dpr;
|
||||
wasm_events.data[i].window_size = window_size;
|
||||
wasm_events.data[i].time = time;
|
||||
wasm_events.data[i].delta_time = delta_time;
|
||||
}
|
||||
wasm_dpr = dpr;
|
||||
|
||||
app_update(wasm_events.data, wasm_events.len);
|
||||
|
||||
wasm_events.len = 0;
|
||||
wasm_last_time = time;
|
||||
wasm_last_time_milliseconds = wasm_time;
|
||||
ma_set0(wasm_input_text_arena);
|
||||
}
|
||||
|
||||
@@ -176,4 +213,13 @@ 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();
|
||||
}
|
||||
|
||||
fn f64 app_get_anim_time(void) {
|
||||
return wasm_time;
|
||||
}
|
||||
|
||||
fn f64 app_get_anim_delta_time(void) {
|
||||
return wasm_delta_time;
|
||||
}
|
||||
Reference in New Issue
Block a user