mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
we now handle the frame timing in C, audio for me is now VERY stable
This commit is contained in:
parent
1a9d5901cc
commit
10ee738f88
|
@ -8,7 +8,6 @@ import {
|
||||||
import mGBA, { mGBAEmulator } from "./vendor/mgba";
|
import mGBA, { mGBAEmulator } from "./vendor/mgba";
|
||||||
import { GbaKey, KeyBindings } from "./bindings";
|
import { GbaKey, KeyBindings } from "./bindings";
|
||||||
import { styled } from "styled-components";
|
import { styled } from "styled-components";
|
||||||
import { useFrameSkip } from "./useFrameSkip.hook";
|
|
||||||
import { useController } from "./useController.hook";
|
import { useController } from "./useController.hook";
|
||||||
import { useLocalStorage } from "./useLocalStorage.hook";
|
import { useLocalStorage } from "./useLocalStorage.hook";
|
||||||
|
|
||||||
|
@ -148,7 +147,6 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
||||||
};
|
};
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
useFrameSkip(mgbaModule);
|
|
||||||
useController(mgbaModule);
|
useController(mgbaModule);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
import { MutableRefObject, useEffect } from "react";
|
|
||||||
import { mGBAEmulator } from "./vendor/mgba";
|
|
||||||
|
|
||||||
export function useFrameSkip(
|
|
||||||
mgbaModule: MutableRefObject<mGBAEmulator | undefined>
|
|
||||||
) {
|
|
||||||
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]);
|
|
||||||
}
|
|
|
@ -10,10 +10,10 @@ ENV BUILD_DIR=build-wasm
|
||||||
|
|
||||||
WORKDIR /
|
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
|
RUN mkdir /mgba/build-wasm
|
||||||
WORKDIR /mgba/build-wasm
|
WORKDIR /mgba/build-wasm
|
||||||
RUN git checkout 27dede256b6de36303a87d0886f81505a0f30c28
|
RUN git checkout 26a2701cef6fcad47c67559fcb7892004f8d489c
|
||||||
|
|
||||||
|
|
||||||
RUN emcmake cmake .. && make install DESTDIR=install
|
RUN emcmake cmake .. && make install DESTDIR=install
|
||||||
|
|
Loading…
Reference in a new issue