Skip to content

Commit

Permalink
Ref #69 fpsは直ったけど時折フリーズする
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaowl committed Sep 16, 2019
1 parent 792f266 commit e212824
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions wasm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ async function main() {

// FPS制御とか
const emulateFps = 60;
const drawFps = 30;
const emulateInterval = 1000.0 / emulateFps;
let isEmulateEnable = false;

// Animation Frame Firedには依存せずに実行する
function emulate_loop() {
setTimeout(() => {
requestAnimationFrame(emulate_loop);
if (isEmulateEnable) {
emu.step_line();
}
}, 1000.0 / emulateFps);
const start = new Date().getMilliseconds();
if (isEmulateEnable) {
emu.step_line();
draw();
}
const diffTime = emulateInterval - ((new Date().getMilliseconds()) - start);
// めちゃはやだったら待たせるし、間に合ってなければ即
const sleepTime = diffTime < 0 ? 0 : diffTime;
setTimeout(emulate_loop, sleepTime);
}
// Animation Frame Firedに同期してcanvasだけ書き換える
function draw_loop() {
setTimeout(() => {
requestAnimationFrame(draw_loop);
draw();
}, 1000.0 / drawFps);
if (isEmulateEnable) {
}
requestAnimationFrame(draw_loop);
}

emulate_loop();
draw_loop();
// draw_loop();

function release_key(key) {
if (isEmulateEnable) {
Expand Down

0 comments on commit e212824

Please sign in to comment.