a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 41cb2b17212684ba86d8199409793903cb5e9594
parent 046a2e5bd704e91fb1f1d65ef927845991a5d057
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Mon,  1 Jul 2019 17:17:47 -0700

Take actual dt into account

Diffstat:
Msrc/platform_wasm.c | 8++++----
Msrc/platform_wasm_loader.js | 3++-
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -32,7 +32,7 @@ global_variable i32 g_height = PLATFORM_SCR_HEIGHT; // TODO: replace with allocator global_variable char g_mem_buffer[1000] = {0}; global_variable i32 g_mem_buffer_i = 0; -global_variable u32 time = 0; +global_variable u32 previous_time = 0; i32 str_length(const char *str) { @@ -72,10 +72,10 @@ bool init(i32 num_wasm_memory_pages) return init_successful; } -void render(void) +void render(f64 current_time) { - // TODO: measure dt - game_input.dt = 16; + game_input.dt = current_time - previous_time; + previous_time = current_time; game_update_and_render(&game_memory, &game_input, (v2u) {g_width, g_height}); } diff --git a/src/platform_wasm_loader.js b/src/platform_wasm_loader.js @@ -218,7 +218,8 @@ function canvas_resize() { console.log("resize: (" + w_pixels + ", " + h_pixels + ")"); } function canvas_render() { - exports['render'](); + let timestamp_in_ms = performance.now(); + exports['render'](timestamp_in_ms); window.requestAnimationFrame(canvas_render); } function file_load(name) {