Skip to content

Commit c4644c9

Browse files
Maximum quality settings [AARD-1928] (#1186)
Co-authored-by: Brandon Pacewic <92102436+BrandonPacewic@users.noreply.github.com> Co-authored-by: Zach Rutman <92497727+rutmanz@users.noreply.github.com>
2 parents be20321 + b3241a8 commit c4644c9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import WorldSystem from "@/systems/WorldSystem.ts"
2+
import { Global_AddToast, Global_OpenPanel } from "@/components/GlobalUIControls.ts"
3+
import World from "@/systems/World.ts"
4+
import PreferencesSystem from "@/systems/preferences/PreferencesSystem.ts"
5+
6+
export class PerformanceMonitoringSystem extends WorldSystem {
7+
isCritical: boolean = false
8+
activeCount: number = 0
9+
antiCount: number = 0
10+
lastTime = performance.now()
11+
constructor() {
12+
super()
13+
setInterval(() => {
14+
this.Reset()
15+
}, 15000)
16+
}
17+
public Update(_: number) {
18+
const time = performance.now() - this.lastTime
19+
const newIsCritical = time > 150
20+
if (newIsCritical == this.isCritical) {
21+
this.activeCount++
22+
} else {
23+
this.antiCount++
24+
if (this.antiCount <= 10 || this.antiCount <= 0.5 * this.activeCount) return
25+
26+
this.isCritical = newIsCritical
27+
const oldActive = this.activeCount
28+
this.activeCount = this.antiCount
29+
this.antiCount = oldActive
30+
if (this.isCritical) {
31+
PreferencesSystem.resetGraphicsPreferences()
32+
World.SceneRenderer.changeCSMSettings(PreferencesSystem.getGraphicsPreferences())
33+
Global_OpenPanel?.("graphics-settings")
34+
Global_AddToast?.("warning", "Performance Issues Detected", "Reverting to simple graphics")
35+
}
36+
}
37+
38+
this.lastTime = performance.now()
39+
}
40+
41+
public Reset() {
42+
this.activeCount = 0
43+
this.antiCount = 0
44+
}
45+
46+
public Destroy() {}
47+
}

fission/src/systems/World.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SimulationSystem from "./simulation/SimulationSystem"
66
import InputSystem from "./input/InputSystem"
77
import AnalyticsSystem, { AccumTimes } from "./analytics/AnalyticsSystem"
88
import DragModeSystem from "./scene/DragModeSystem"
9+
import { PerformanceMonitoringSystem } from "@/systems/PerformanceMonitor.ts"
910

1011
class World {
1112
private static _isAlive: boolean = false
@@ -18,6 +19,7 @@ class World {
1819
private static _inputSystem: InputSystem
1920
private static _analyticsSystem: AnalyticsSystem | undefined = undefined
2021
private static _dragModeSystem: DragModeSystem
22+
private static _performanceMonitorSystem: PerformanceMonitoringSystem
2123

2224
private static _accumTimes: AccumTimes = {
2325
frames: 0,
@@ -77,6 +79,7 @@ class World {
7779
World._simulationSystem = new SimulationSystem()
7880
World._inputSystem = new InputSystem()
7981
World._dragModeSystem = new DragModeSystem()
82+
World._performanceMonitorSystem = new PerformanceMonitoringSystem()
8083
try {
8184
World._analyticsSystem = new AnalyticsSystem()
8285
} catch (_) {
@@ -95,6 +98,7 @@ class World {
9598
World._inputSystem.Destroy()
9699
World._dragModeSystem.Destroy()
97100

101+
World._performanceMonitorSystem.Destroy()
98102
World._analyticsSystem?.Destroy()
99103
}
100104

@@ -112,6 +116,7 @@ class World {
112116
})
113117

114118
World._analyticsSystem?.Update(this._currentDeltaT)
119+
World._performanceMonitorSystem?.Update(this._currentDeltaT)
115120
}
116121

117122
public static get currentDeltaT(): number {

fission/src/systems/preferences/PreferencesSystem.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ class PreferencesSystem {
199199
return graphicsPrefs
200200
}
201201

202+
/** Resets simulation quality preferences to default values */
203+
public static resetGraphicsPreferences() {
204+
this._preferences[GraphicsPreferenceKey] = DefaultGraphicsPreferences()
205+
this.savePreferences()
206+
}
207+
202208
/** Loads all preferences from local storage. */
203209
public static loadPreferences() {
204210
const loadedPrefs = window.localStorage.getItem(this._localStorageKey)

0 commit comments

Comments
 (0)