From d53ab1dff399a3811256a937685cfc67af2a6cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Mon, 27 Feb 2023 22:01:25 +0000 Subject: [PATCH] feat: new high performance timers from emukit --- frontends/web/ts/gb.ts | 14 +++++++------- node_modules/emukit | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) create mode 160000 node_modules/emukit diff --git a/frontends/web/ts/gb.ts b/frontends/web/ts/gb.ts index f376320f..3dec704e 100644 --- a/frontends/web/ts/gb.ts +++ b/frontends/web/ts/gb.ts @@ -105,7 +105,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { private paused = false; private nextTickTime = 0; private fps = 0; - private frameStart: number = new Date().getTime(); + private frameStart: number = EmulatorBase.now(); private frameCount = 0; private paletteIndex = 0; private storeCycles: number = LOGIC_HZ * STORE_RATE; @@ -163,7 +163,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { // obtains the current time, this value is going // to be used to compute the need for tick computation - let currentTime = new Date().getTime(); + let currentTime = EmulatorBase.now(); try { pending = this.tick( @@ -214,7 +214,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { // calculates the amount of time until the next draw operation // this is the amount of time that is going to be pending - currentTime = new Date().getTime(); + currentTime = EmulatorBase.now(); const pendingTime = Math.max(this.nextTickTime - currentTime, 0); // waits a little bit for the next frame to be draw, @@ -284,7 +284,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { // has been reached calculates the number of FPS and // flushes the value to the screen if (this.frameCount >= this.visualFrequency * FPS_SAMPLE_RATE) { - const currentTime = new Date().getTime(); + const currentTime = EmulatorBase.now(); const deltaTime = (currentTime - this.frameStart) / 1000; const fps = Math.round(this.frameCount / deltaTime); this.fps = fps; @@ -604,7 +604,7 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { resume() { this.paused = false; - this.nextTickTime = new Date().getTime(); + this.nextTickTime = EmulatorBase.now(); } reset() { @@ -638,11 +638,11 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { let cycles = 0; this.pause(); try { - const initial = Date.now(); + const initial = EmulatorBase.now(); for (let i = 0; i < count; i++) { cycles += this.gameBoy?.clock() ?? 0; } - const delta = (Date.now() - initial) / 1000; + const delta = (EmulatorBase.now() - initial) / 1000; const frequency_mhz = cycles / delta / 1000 / 1000; return { delta: delta, diff --git a/node_modules/emukit b/node_modules/emukit new file mode 160000 index 00000000..b246b0d8 --- /dev/null +++ b/node_modules/emukit @@ -0,0 +1 @@ +Subproject commit b246b0d87d0ce2d891677369c8e4f6b7b4d13ca5 -- GitLab