Skip to content

Commit

Permalink
eeaf332d: dngSceneViewer: use consoleGraphicalPresets
Browse files Browse the repository at this point in the history
  • Loading branch information
NicSavichev committed Dec 17, 2024
1 parent 0f2e51d commit e2dce2d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 228 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
low {
graphics {
shadowsQuality:t="low"
dynamicShadowsQuality:t="low"
giAlgorithm:t="medium"
giAlgorithmQuality:r=0.5
skiesQuality:t="medium"
aoQuality:t="low"
ssrQuality:t="low"
ssssQuality:t="low"
anisotropy:i=4
cloudsQuality:t="default"
volumeFogQuality:t="close"
fxTarget:t="lowres"
groundDisplacementQuality:i=1
tsrQuality:i=1
}
video {
antiAliasingMode:i=3
temporalUpsamplingRatio:r=50
}
}

medium {
graphics {
shadowsQuality:t="low"
dynamicShadowsQuality:t="low"
giAlgorithm:t="high"
giAlgorithmQuality:r=0.2
skiesQuality:t="medium"
aoQuality:t="medium"
ssrQuality:t="medium"
ssssQuality:t="low"
anisotropy:i=8
cloudsQuality:t="default"
volumeFogQuality:t="far"
fxTarget:t="highres"
groundDisplacementQuality:i=2
tsrQuality:i=0
}
video {
antiAliasingMode:i=3
temporalUpsamplingRatio:r=100
}
}

ultra {
graphics {
shadowsQuality:t="high"
dynamicShadowsQuality:t="high"
giAlgorithm:t="high"
giAlgorithmQuality:r=0.75
skiesQuality:t="high"
aoQuality:t="high"
ssrQuality:t="high"
ssssQuality:t="high"
anisotropy:i=16
cloudsQuality:t="volumetric"
volumeFogQuality:t="close"
fxTarget:t="hires"
groundDisplacementQuality:i=2
tsrQuality:i=1
}
video {
antiAliasingMode:i=3
temporalUpsamplingRatio:r=100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ unitedVdata.dynModel {
canRebuild:b=yes
}

consoleGraphicalPresets {
include "_graphics_presets.blk"
}

__allow_force_apply_all:b=no
__allowedConfigOverrides{
launchCnt:i=0
Expand Down
106 changes: 37 additions & 69 deletions samples/dngSceneViewer/prog/scripts/ui/settings/graphics_options.nut
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from "%scripts/ui/ui_library.nut" import *
from "dagor.system" import dgs_get_settings

let ecs = require("%dngscripts/ecs.nut")

let { showWarning } = require("%scripts/ui/widgets/msgbox.nut")
let { hardPersistWatched } = require("%sqstd/globalState.nut")
let { get_setting_by_blk_path, set_setting_by_blk_path, set_setting_by_blk_path_and_save, save_changed_settings } = require("settings")
let { get_setting_by_blk_path, set_setting_by_blk_path_and_save, save_changed_settings } = require("settings")
let { apply_video_settings } = require("videomode")
let { mkCombo } = require("%scripts/ui/widgets/simpleComponents.nut")
let { mkSettingsOption } = require("options_lib.nut")

let presets = ["low", "medium", "ultra"]
let presets = []
foreach (block in (dgs_get_settings()?["consoleGraphicalPresets"] ?? {}))
presets.append(block.getBlockName())

let allowCustomSettingsQuery = ecs.SqQuery("allowCustomSettingsQuery", {comps_rw=[["settings_override__useCustomSettings", ecs.TYPE_BOOL], ["settings_override__graphicsSettings", ecs.TYPE_OBJECT]]})
let setCustomSetting = function(blkPath, v) {
Expand All @@ -21,50 +22,11 @@ let setCustomSetting = function(blkPath, v) {
}
let getCustomSetting = @(blkPath) allowCustomSettingsQuery.perform(@(_, comp) comp["settings_override__graphicsSettings"][blkPath])

let mapOptionsByPresetTable = {
["graphics/shadowsQuality"] = ["low","low", "high"],
["graphics/dynamicShadowsQuality"] = ["low", "low", "high"],
["graphics/giAlgorithm"] = ["medium","high", "high"],
["graphics/giAlgorithmQuality"] = [0.5,0.2,0.75],
["graphics/skiesQuality"] = ["medium","medium", "high"],
["graphics/aoQuality"] = ["low","medium","high"],
["graphics/ssrQuality"] = ["low","medium","high"],
["graphics/ssssQuality"] = ["low", "low", "high"],
["graphics/anisotropy"] = [4, 8, 16],
["graphics/cloudsQuality"] = ["default", "default", "volumetric"],
["graphics/volumeFogQuality"] = ["close", "close", "far"],
["graphics/fxTarget"] = ["lowres","medres", "highres"],
["graphics/groundDisplacementQuality"] = [1, 2, 2],
["video/antiAliasingMode"] = [3, 3, 3],
["video/temporalUpsamplingRatio"] = [50.0, 100.0, 100.0],
}
let optionsRequireRestart = {
["graphics/texquality"] = true
}

let mapOptionsByPreset = {}
foreach (i, presetName in presets){
let preset = {}
mapOptionsByPreset[presetName] <- preset
foreach (opt, perPreset in mapOptionsByPresetTable) {
let blkPath = type(opt)=="string" ? opt : opt.blkPath
preset[blkPath] <- perPreset[i]
}
}

function showMsgboxOfRestart(){
showWarning("Restart required to apply some changes")
}

function optionCtor(opt) {
let var = opt?.var ?? Watched(opt.defVal)
let needRestart = opt?.restart ?? false
let set = opt?.setValue ?? @(v) var.set(v)
let setValue = function(v) {
set(v)
let setValue = opt?.setValue ?? function(v) {
var.set(v)
set_setting_by_blk_path_and_save(opt.blkPath, v)
if (needRestart)
showMsgboxOfRestart()
}
return mkSettingsOption(opt.name, opt.widgetCtor(opt.__merge({var, setValue})))
}
Expand Down Expand Up @@ -104,33 +66,39 @@ let postfxOpts = [
})


const graphicsPresetBlkPath = "graphics/preset"
let graphicsPreset = hardPersistWatched("graphicsPreset", get_setting_by_blk_path(graphicsPresetBlkPath) ?? "ultra")
const graphicsPresetBlkPath = "graphics/consolePreset"
let graphicsPreset = Watched(get_setting_by_blk_path(graphicsPresetBlkPath) ?? "ultra")

function mkGraphicsPresetUpdate(checkRestart=true){
return function graphicsPresetUpdate(presetName) {
assert(presetName in mapOptionsByPreset, @() $"unknownPreset: '{presetName}', supported = {", ".join(presets)}")
let selectedPreset = mapOptionsByPreset[presetName]
let changedSettings = []
let prevPreset = mapOptionsByPreset?[graphicsPreset.get()] ?? mapOptionsByPreset["ultra"]
graphicsPreset.set(presetName)
set_setting_by_blk_path_and_save(graphicsPresetBlkPath, presetName)
local needRestart = false
foreach (blkpath, value in selectedPreset) {
set_setting_by_blk_path(blkpath, value)
if (prevPreset[blkpath] != value) {
changedSettings.append(blkpath)
if (blkpath in optionsRequireRestart)
needRestart = true
}
function getVideoSettings(){
let res = {graphics={}, video={}}
let settings = dgs_get_settings()
foreach (k, r in res){
foreach (opt, val in (settings?[k] ?? {}))
r[opt] <- val
}
return res
}
function graphicsPresetUpdate(presetName) {
let changedSettings = []
let prev = getVideoSettings()
graphicsPreset.set(presetName)
set_setting_by_blk_path_and_save(graphicsPresetBlkPath, presetName)
save_changed_settings([graphicsPresetBlkPath])
let new = getVideoSettings()
foreach (r, v in prev) {
foreach (opt, val in v)
if (val != new[r]?[opt])
changedSettings.append($"{r}/{opt}")
}
foreach (r, v in new) {
foreach (opt, val in v) {
let optKey = $"{r}/{opt}"
if (val != prev[r]?[opt] && optKey not in changedSettings)
changedSettings.append(optKey)
}
save_changed_settings(changedSettings)
apply_video_settings(changedSettings)
if (checkRestart && needRestart)
showMsgboxOfRestart()
}
apply_video_settings(changedSettings)
}
let graphicsPresetUpdate = mkGraphicsPresetUpdate()

let optPreset = optionCtor({
name = "Quality Preset"
Expand All @@ -156,6 +124,6 @@ let graphicsOptions = [optPreset].extend(postfxOpts)//, optDriver]
return {
graphicsOptions
graphicsPresetUpdate
graphicsPresetApply = @() mkGraphicsPresetUpdate(false)(graphicsPreset.get())
graphicsPresetApply = @() graphicsPresetUpdate(get_setting_by_blk_path(graphicsPresetBlkPath))
optDriver
}
3 changes: 0 additions & 3 deletions samples/dngSceneViewer/prog/scripts/ui/ui.nut
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ let inspectorToggle = require("%darg/helpers/inspector.nut")
let { exit_game } =require("app")
let { showGameMenu, gameMenu } = require("game_menu.nut")
let { showSettingsMenu, settingsMenuUi } = require("settings/main_settings.nut")
let { graphicsPresetApply } = require("settings/graphics_options.nut")

graphicsPresetApply()

let eventHandlers = freeze({
["Global.Screenshot"] = @(...) take_screenshot(),
Expand Down
156 changes: 0 additions & 156 deletions samples/dngSceneViewer/prog/scripts/ui/widgets/msgbox.nut

This file was deleted.

0 comments on commit e2dce2d

Please sign in to comment.