-
Notifications
You must be signed in to change notification settings - Fork 61
DPR: Quality Presets and Recommended Preset #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ariesninjadev
wants to merge
16
commits into
dev
Choose a base branch
from
aries/1781/quality-presets
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+340
−71
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ef849bf
Graphics presets and auto selection
ariesninjadev 257e87a
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev 8a7236b
fix: postc
ariesninjadev b8c35d3
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev 06370ad
cleanup with helper
ariesninjadev 0e8b4b4
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev ca22cec
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev 0951bc9
auto-optimize button
ariesninjadev 2675327
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev b8d1f9b
chore: cleanup
ariesninjadev f3762b0
Merge remote-tracking branch 'refs/remotes/origin/aries/1781/quality-…
ariesninjadev 69c4a16
Merge branch 'dev' into aries/1781/quality-presets
ariesninjadev 81e7ccf
Stateful checkboxes
ariesninjadev 9083160
Merge remote-tracking branch 'origin/dev' into aries/1781/quality-pre…
ariesninjadev 4009b82
fix: state update / visual issues
ariesninjadev d310a5d
chore: formatting
ariesninjadev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import PreferencesSystem from "@/systems/preferences/PreferencesSystem" | ||
import { globalAddToast } from "@/ui/components/GlobalUIControls" | ||
|
||
export type GraphicsPreset = "Fast" | "Balanced" | "Fancy" | ||
|
||
export const GRAPHICS_PRESETS: Record< | ||
GraphicsPreset, | ||
{ | ||
lightIntensity: number | ||
fancyShadows: boolean | ||
maxFar: number | ||
cascades: number | ||
shadowMapSize: number | ||
antiAliasing: boolean | ||
} | ||
> = { | ||
Fast: { | ||
lightIntensity: 3, | ||
fancyShadows: false, | ||
maxFar: 20, | ||
cascades: 3, | ||
shadowMapSize: 0, | ||
antiAliasing: false, | ||
}, | ||
Balanced: { | ||
lightIntensity: 5, | ||
fancyShadows: true, | ||
maxFar: 30, | ||
cascades: 4, | ||
shadowMapSize: 2048, | ||
antiAliasing: false, | ||
}, | ||
Fancy: { | ||
lightIntensity: 8, | ||
fancyShadows: true, | ||
maxFar: 40, | ||
cascades: 6, | ||
shadowMapSize: 8192, | ||
antiAliasing: true, | ||
}, | ||
} | ||
|
||
export const isMobileDevice = (): boolean => { | ||
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) | ||
} | ||
|
||
export const isLowEndDevice = (): boolean => { | ||
if (isMobileDevice()) return true | ||
|
||
const memory = | ||
typeof navigator !== "undefined" && "deviceMemory" in navigator | ||
? (navigator as Navigator & { deviceMemory?: number }).deviceMemory | ||
: undefined | ||
if (memory !== undefined && memory <= 4) return true // 4GB or less RAM | ||
|
||
const cores = navigator.hardwareConcurrency | ||
if (cores && cores <= 2) return true // 2 cores or less | ||
|
||
const userAgent = navigator.userAgent.toLowerCase() | ||
if (userAgent.includes("android") && (userAgent.includes("lite") || userAgent.includes("go"))) return true | ||
|
||
return false | ||
} | ||
|
||
export const autoOptimizeGraphics = (toastType: "long" | "short" | "none" = "none"): GraphicsPreset => { | ||
if (isLowEndDevice()) { | ||
if (toastType === "long") { | ||
globalAddToast?.( | ||
"info", | ||
"Graphics Optimized", | ||
"We've set your graphics to 'Fast' mode for optimal performance on your device. You can change this in Graphics Settings." | ||
) | ||
} else if (toastType === "short") { | ||
globalAddToast?.("info", "Success", "Auto-optimized graphics to 'Fast'.") | ||
} | ||
return "Fast" | ||
} else { | ||
if (toastType === "long") { | ||
globalAddToast?.( | ||
"info", | ||
"Graphics Optimized", | ||
"We've set your graphics to 'Balanced' mode for optimal performance on your device. You can change this in Graphics Settings." | ||
) | ||
} else if (toastType === "short") { | ||
globalAddToast?.("info", "Success", "Auto-optimized graphics to 'Balanced'.") | ||
} | ||
return "Balanced" | ||
} | ||
} | ||
|
||
export const applyInitialGraphicsSettings = (): void => { | ||
// Check if graphics optimization has already been applied | ||
const optimizationApplied = PreferencesSystem.getGlobalPreference("GraphicsOptimizationApplied") | ||
|
||
// If optimization hasn't been applied yet and device should use fast mode, apply fast settings | ||
if (!optimizationApplied) { | ||
const presetToApply = autoOptimizeGraphics("long") | ||
const settings = GRAPHICS_PRESETS[presetToApply] | ||
PreferencesSystem.getGraphicsPreferences().lightIntensity = settings.lightIntensity | ||
PreferencesSystem.getGraphicsPreferences().fancyShadows = settings.fancyShadows | ||
PreferencesSystem.getGraphicsPreferences().maxFar = settings.maxFar | ||
PreferencesSystem.getGraphicsPreferences().cascades = settings.cascades | ||
PreferencesSystem.getGraphicsPreferences().shadowMapSize = settings.shadowMapSize | ||
PreferencesSystem.getGraphicsPreferences().antiAliasing = settings.antiAliasing | ||
|
||
// Mark that optimization has been applied | ||
PreferencesSystem.setGlobalPreference("GraphicsOptimizationApplied", true) | ||
PreferencesSystem.savePreferences() | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.