From 10ee738f88bc6e020174febef5e1b821d00ffa91 Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 1 Oct 2024 18:36:53 +0100 Subject: [PATCH] we now handle the frame timing in C, audio for me is now VERY stable --- website/agb/src/components/mgba/mgba.tsx | 2 - .../src/components/mgba/useFrameSkip.hook.ts | 50 ------------------- website/mgba-wasm/BuildMgbaWasm | 4 +- 3 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 website/agb/src/components/mgba/useFrameSkip.hook.ts diff --git a/website/agb/src/components/mgba/mgba.tsx b/website/agb/src/components/mgba/mgba.tsx index 002acb91..2f02ab85 100644 --- a/website/agb/src/components/mgba/mgba.tsx +++ b/website/agb/src/components/mgba/mgba.tsx @@ -8,7 +8,6 @@ import { import mGBA, { mGBAEmulator } from "./vendor/mgba"; import { GbaKey, KeyBindings } from "./bindings"; import { styled } from "styled-components"; -import { useFrameSkip } from "./useFrameSkip.hook"; import { useController } from "./useController.hook"; import { useLocalStorage } from "./useLocalStorage.hook"; @@ -148,7 +147,6 @@ export const Mgba = forwardRef( }; }, [state]); - useFrameSkip(mgbaModule); useController(mgbaModule); useEffect(() => { diff --git a/website/agb/src/components/mgba/useFrameSkip.hook.ts b/website/agb/src/components/mgba/useFrameSkip.hook.ts deleted file mode 100644 index c6999ff3..00000000 --- a/website/agb/src/components/mgba/useFrameSkip.hook.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { MutableRefObject, useEffect } from "react"; -import { mGBAEmulator } from "./vendor/mgba"; - -export function useFrameSkip( - mgbaModule: MutableRefObject -) { - useEffect(() => { - let previous: number | undefined = undefined; - let stopped = false; - let smoothedFrameTime = 60; - - let totalTime = 0; - let paused = false; - - function raf(time: DOMHighResTimeStamp) { - if (previous) { - const delta = time - previous; - - smoothedFrameTime = (smoothedFrameTime * 3 + delta) / 4; - - const smoothedFrameRate = Math.round(1 / (smoothedFrameTime / 1000)); - - totalTime += 1 / smoothedFrameRate; - - if (totalTime >= 1 / 60) { - totalTime -= 1 / 60; - if (paused) { - mgbaModule.current?.resumeGame(); - paused = false; - } - } else { - if (!paused) { - mgbaModule.current?.pauseGame(); - paused = true; - } - } - } - previous = time; - - if (!stopped) { - window.requestAnimationFrame(raf); - } - } - - window.requestAnimationFrame(raf); - return () => { - stopped = true; - }; - }, [mgbaModule]); -} diff --git a/website/mgba-wasm/BuildMgbaWasm b/website/mgba-wasm/BuildMgbaWasm index ba308ed3..61f4eda5 100644 --- a/website/mgba-wasm/BuildMgbaWasm +++ b/website/mgba-wasm/BuildMgbaWasm @@ -10,10 +10,10 @@ ENV BUILD_DIR=build-wasm WORKDIR / -RUN git clone https://github.com/thenick775/mgba.git --filter=tree:0 -b feature/wasm +RUN git clone https://github.com/corwinkuiper/mgba.git --filter=tree:0 -b wasm RUN mkdir /mgba/build-wasm WORKDIR /mgba/build-wasm -RUN git checkout 27dede256b6de36303a87d0886f81505a0f30c28 +RUN git checkout 26a2701cef6fcad47c67559fcb7892004f8d489c RUN emcmake cmake .. && make install DESTDIR=install