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

View file

@ -3,6 +3,7 @@ import modInfo from "@/data/modInfo.json";
import Decimal, { DecimalSource } from "@/util/bignum"; import Decimal, { DecimalSource } from "@/util/bignum";
import { layers } from "./layers"; import { layers } from "./layers";
import player from "./player"; import player from "./player";
import settings from "./settings";
import state from "./state"; import state from "./state";
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
@ -107,6 +108,8 @@ function updateLayers(diff: DecimalSource) {
}); });
} }
let intervalID: number | null = null;
function update() { function update() {
const now = Date.now(); const now = Date.now();
let diff: DecimalSource = (now - player.time) / 1e3; let diff: DecimalSource = (now - player.time) / 1e3;
@ -169,8 +172,22 @@ function update() {
updateLayers(diff); updateLayers(diff);
player.justLoaded = false; 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 { 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, showTPS: true,
msDisplay: MilestoneDisplay.All, msDisplay: MilestoneDisplay.All,
hideChallenges: false, hideChallenges: false,
theme: Themes.Nordic theme: Themes.Nordic,
unthrottled: false
}); });
const settingsHandler: ProxyHandler<Record<string, any>> = { const settingsHandler: ProxyHandler<Record<string, any>> = {

View file

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