Skip to content

Commit

Permalink
Close #69 : drawはrequestAnimationFrameに載せないとgetImagedataが遅くなる
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaowl committed Sep 16, 2019
1 parent e212824 commit 022698e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wasm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ async function main() {

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

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

0 comments on commit 022698e

Please sign in to comment.