From 732e6a47ded496cd224e1cfadc2106b04dcf6859 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 3 Oct 2025 02:05:42 +0200 Subject: checkpoint --- code/platform.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'code/platform.js') diff --git a/code/platform.js b/code/platform.js index fda3a49..163b0ad 100644 --- a/code/platform.js +++ b/code/platform.js @@ -2,7 +2,6 @@ var HEAPU8; //- Helper functions - function ReadHeapString(ptr, length) { if (length === 0 || !ptr) return ''; @@ -101,24 +100,19 @@ async function main() }; //- Game loop - var prev = null; - function frame(timestamp) + let prev = 0; + let timestamp = 0; + let update_hz = 30; + while(true) { - var dt = (timestamp - prev)*0.001; + let dt = (timestamp - prev)*0.001; prev = timestamp; - // TODO(luca): How to get this??? - var update_hz = 30; - instance.exports.RenderGradient(width, height, bytes_per_pixel, 1/update_hz, mouse_down, mouse_x, mouse_y); + instance.exports.UpdateAndRender(width, height, bytes_per_pixel, 1/update_hz, mouse_down, mouse_x, mouse_y); ctx.putImageData(image, 0, 0); - window.requestAnimationFrame(frame); - } - window.requestAnimationFrame((timestamp) => { - prev = timestamp; - window.requestAnimationFrame(frame); - }); + await new Promise(requestAnimationFrame); + } } - window.onload = main; -- cgit v1.2.3-70-g09d2