Added unthrottled setting

This commit is contained in:
thepaperpilot 2021-09-05 19:13:56 -05:00
parent c617737788
commit 2eeb96a66f
4 changed files with 27 additions and 3 deletions

View file

@ -26,6 +26,11 @@
:value="hideChallenges"
@change="toggleSettingsOption('hideChallenges')"
/>
<Toggle
title="Unthrottled"
:value="unthrottled"
@change="toggleSettingsOption('unthrottled')"
/>
<Toggle
title="Offline Production<tooltip display='Save-specific'>*</tooltip>"
:value="offlineProd"
@ -75,7 +80,7 @@ export default defineComponent({
};
},
computed: {
...mapSettings(["showTPS", "hideChallenges", "theme", "msDisplay"]),
...mapSettings(["showTPS", "hideChallenges", "theme", "msDisplay", "unthrottled"]),
...mapPlayer(["autosave", "offlineProd"]),
paused() {
return player.devSpeed === 0;

View file

@ -3,6 +3,7 @@ import modInfo from "@/data/modInfo.json";
import Decimal, { DecimalSource } from "@/util/bignum";
import { layers } from "./layers";
import player from "./player";
import settings from "./settings";
import state from "./state";
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
@ -107,6 +108,8 @@ function updateLayers(diff: DecimalSource) {
});
}
let intervalID: number | null = null;
function update() {
const now = Date.now();
let diff: DecimalSource = (now - player.time) / 1e3;
@ -169,8 +172,22 @@ function update() {
updateLayers(diff);
player.justLoaded = false;
if (settings.unthrottled) {
requestAnimationFrame(update);
if (intervalID != null) {
clearInterval(intervalID);
intervalID = null;
}
} else if (intervalID == null) {
intervalID = setInterval(update, 50);
}
}
export default function startGameLoop(): void {
setInterval(update, 50);
if (settings.unthrottled) {
requestAnimationFrame(update);
} else {
intervalID = setInterval(update, 50);
}
}

View file

@ -12,7 +12,8 @@ const state = reactive<Settings>({
showTPS: true,
msDisplay: MilestoneDisplay.All,
hideChallenges: false,
theme: Themes.Nordic
theme: Themes.Nordic,
unthrottled: false
});
const settingsHandler: ProxyHandler<Record<string, any>> = {

View file

@ -9,5 +9,6 @@ export interface Settings {
msDisplay: MilestoneDisplay;
hideChallenges: boolean;
theme: Themes;
unthrottled: boolean;
[index: string]: unknown;
}