a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 937a77ad4e34865b3030f3ee6cd4a8b328fdeb1d
parent 51cb312527969d63ebfcc22319583498d00c317f
Author: amin <dev@aminmesbah.com>
Date:   Tue,  2 Jul 2019 00:17:47 +0000

Take actual dt into account

FossilOrigin-Name: 85cf61e5c109b56a924135f21e5374f6f731c0b6e0d6e52652187a9b7b431c39
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) {