mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 08:38:36 +00:00
launcher, play scripts: review fixes of #3272 (card mask kept out of the F1 file, -Adapter for auto FG, Linux cache and binds, clear-cache race, unreadable binds kept)
merzleckeier's reviews at 02:35, 02:47 and 02:58 and DeadlyChirp's 02:46 note:
1. The AMD/Intel card filter named NoDlss, NoFrameGen and SmoothMotion in
-Chosen, so a real PLAY rewrote leonida-settings.txt without the F1
menu's DLSS, DLSS frame generation and Smooth Motion. The launcher now
passes -CardMask (card_mask) instead; play-d3d12.ps1 hands it over and
play-nvidia.ps1 leaves those settings out of this start only, keeping
them in the menu file (and says so); the menu's FSR stays.
2. play-nvidia.ps1's automatic DLSS frame generation looked at every card:
with -Adapter it now judges the cards whose name holds it (all when none
does), so an AMD card chosen beside an RTX 4070 gets none; the card
mask's NoFrameGen also keeps it off.
3. Clear shader cache on Linux looked under the Windows data folder: it now
uses play-linux.sh's LEONIDA_CACHE_DIR or ${XDG_DATA_HOME:-~/.local/share}
/leonida/cache.
4. After the confirmation, clear_cache asks game_running() again, not only
its own process.
5. Linux PLAY passes the extra variables (the Controls page's binds, the
advanced options, Advanced winning) in play-linux.sh's environment
(`env NAME=value sh play-linux.sh ...`); none were passed before.
6. The Controls page keeps entries it cannot read beside its rows
(split_kbm_binds) and writes them back after them: adding a row no longer
drops a saved list with an unknown entry. Its note called t() with a
`text=` value, which crashed the page as soon as it showed one: the
placeholder is {entries} now, in de/es/fr/pt too.
Tests: test_card_mask_leaves_the_menus_nvidia_values_out_and_in_the_file
(dry runs, a real start with Start-Process stubbed keeping the menu file,
AMD + RTX 4070 with -Adapter each way and with the mask); card_mask and
-CardMask in play_command; LinuxPlayTests; SplitBindsTests with a guard
that no t() call passes text=. Launcher suite OK (1 skip), win launchers
12 OK, docs links, line endings, check_no_game_data. Counter-tests: the
mask ignored, the adapter filter off, the Linux env/cache, split and
card_mask reverted each fail their tests; the guard regex matches the old
source. Real window (isolated APPDATA): the game started during the
confirmation leaves the cache and says close the game first; adding H to
`both:G=Square;vehicle:N=FutureAction` saves G, H and the unknown entry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -102,6 +102,10 @@ param(
|
||||
[string[]]$Typed,
|
||||
# Set by the F1 menu's SAVE AND RESTART: the switches are the last start's again, so the menu's values win.
|
||||
[switch]$MenuRestart,
|
||||
# The switches (this script's names) the card cannot run, from the launcher on an AMD or Intel card: NoDlss,
|
||||
# NoFrameGen, NoSmoothMotion. The F1 menu's values for their settings are left out of this start only, and stay in
|
||||
# the menu file for a later start on an NVIDIA card; NoFrameGen also keeps the automatic DLSS frame generation off.
|
||||
[string[]]$CardMask,
|
||||
[switch]$PrecompileUsed
|
||||
)
|
||||
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
@ -448,8 +452,16 @@ if ($FsrFrameGen) { $settings.LEONIDA_FSR_FRAMEGEN = '1' }
|
||||
# shown. It generates only while the game's window has the focus. -NoFrameGen leaves it off (Smooth Motion then).
|
||||
# Never by itself with ray tracing (software or hardware): turning ray tracing on does not turn frame generation on;
|
||||
# with it, frame generation runs only when asked for (-FrameGen, the F1 menu, LEONIDA_FRAME_GEN), rules below.
|
||||
if (-not $FrameGen -and -not $NoFrameGen -and ($Resolution -or $Lowest) -and -not $RayTracing -and -not $HardwareRT -and $StreamlineDir) {
|
||||
$card = try { (Get-CimInstance Win32_VideoController -ErrorAction Stop | ForEach-Object { $_.Name }) -join ';' } catch { '' }
|
||||
if (-not $FrameGen -and -not $NoFrameGen -and -not (@($CardMask) -contains 'NoFrameGen') -and ($Resolution -or $Lowest) -and -not $RayTracing -and -not $HardwareRT -and $StreamlineDir) {
|
||||
# The card the title runs on: with -Adapter, the cards whose name holds it (any case, as the runtime picks it;
|
||||
# every card when none does), so an AMD card chosen beside an RTX 40 gets no DLSS frame generation (review of
|
||||
# #3272); without it, every card, as before.
|
||||
$cardNames = @(try { Get-CimInstance Win32_VideoController -ErrorAction Stop | ForEach-Object { "$($_.Name)" } } catch { })
|
||||
if ($Adapter) {
|
||||
$picked = @($cardNames | Where-Object { $_.IndexOf($Adapter, [StringComparison]::OrdinalIgnoreCase) -ge 0 })
|
||||
if ($picked.Count) { $cardNames = $picked }
|
||||
}
|
||||
$card = $cardNames -join ';'
|
||||
if ($card -match 'RTX\s*(40|50)\d\d') {
|
||||
$settings.LEONIDA_FRAME_GEN = '2'
|
||||
# Reflex holds the frames shown to 28 a second (14 rendered, 71.4 ms apart), so that the made frames fall
|
||||
@ -626,7 +638,11 @@ $fromLine.LEONIDA_MENU_SMOOTH_MOTION = if ($smooth) { '1' } else { '0' }
|
||||
foreach ($k in $More.Keys) { $fromLine[$k] = "$($More[$k])" }
|
||||
$menu = Read-SettingsFile $menuFile
|
||||
$menuRead = $menu.Count
|
||||
$fromMenu = @(); $replaced = @()
|
||||
# -CardMask: the settings of the switches the card cannot run. The menu's values for them stay in its file and are
|
||||
# not used by this start.
|
||||
$masked = @{}
|
||||
foreach ($name in @($CardMask | Where-Object { $_ })) { foreach ($k in @($switchSettings[$name])) { if ($k) { $masked[$k] = $name } } }
|
||||
$fromMenu = @(); $replaced = @(); $heldBack = @()
|
||||
foreach ($k in @($menu.Keys)) {
|
||||
$v = $menu[$k]
|
||||
if ($chosenNow.ContainsKey($k)) {
|
||||
@ -635,6 +651,7 @@ foreach ($k in @($menu.Keys)) {
|
||||
$menu.Remove($k)
|
||||
continue
|
||||
}
|
||||
if ($masked.ContainsKey($k)) { $heldBack += "$k=$(if ($v) { $v } else { '(unset)' })"; continue }
|
||||
$fromMenu += "$k=$(if ($v) { $v } else { '(unset)' })"
|
||||
if ($k -eq 'LEONIDA_MENU_SMOOTH_MOTION') { $smooth = $v -ne '0'; continue }
|
||||
if ($k -eq 'LEONIDA_MENU_CONSOLE') { if ($v) { $console = $v }; continue }
|
||||
@ -642,6 +659,7 @@ foreach ($k in @($menu.Keys)) {
|
||||
}
|
||||
if ($fromMenu) { Write-Host "F1 menu settings (leonida-settings.txt, for what the command line did not set): $($fromMenu -join ', ')" }
|
||||
if ($replaced) { Write-Host "Command line over the F1 menu's saved values: $($replaced -join ', ')" }
|
||||
if ($heldBack) { Write-Host "F1 menu settings this card cannot run, kept in the menu file but not used now: $($heldBack -join ', ')" }
|
||||
# The menu file keeps the rest as it was; a value the command line set leaves it. If the file cannot be written, this
|
||||
# start still runs with the command line's values and the file stays whole, so nothing saved is lost.
|
||||
if (-not $DryRun -and $menu.Count -ne $menuRead) {
|
||||
|
||||
@ -146,8 +146,10 @@ needs its line in every file, which `tests/test_leonida_launcher.py` checks (sam
|
||||
and Smooth Motion need an NVIDIA RTX card"; FSR stays. PLAY then passes them off (`for_card`: `-NoDlss`, no DLSS
|
||||
mode, no `-FrameGen` multiplier, no `-SmoothMotion`; the options line on Play says so), the two switches are drawn
|
||||
off, and the Resolution stays live (one above the Series S's 1080 lines that a DLSS mode had left out stays out);
|
||||
`-Chosen` names NoDlss, NoFrameGen and SmoothMotion there (`card_chosen`), so the F1 menu's saved DLSS, DLSS frame
|
||||
generation and Smooth Motion do not come back through its file, while its FSR frame generation stays; the saved
|
||||
`-CardMask NoDlss,NoFrameGen,SmoothMotion` goes with it (`card_mask`): play-nvidia.ps1 leaves the F1 menu's saved
|
||||
DLSS, DLSS frame generation and Smooth Motion out of that start only, and its file keeps them for a later start on
|
||||
an NVIDIA card (`-Chosen` would remove them from it); the menu's FSR frame generation stays. With -Adapter naming a
|
||||
card on a PC with several, play-nvidia.ps1's automatic DLSS frame generation judges that card. The saved
|
||||
choices are kept and come back when an NVIDIA card is chosen. Off
|
||||
Windows, or when no card is read, nothing is greyed for the card.
|
||||
On Linux only the game folder and Series X are used.
|
||||
|
||||
@ -81,6 +81,10 @@ param(
|
||||
# Launcher.bat: the switches of this start whose value changed since its last PLAY, comma-separated (`none`).
|
||||
# Only those count as typed for the F1 menu: the launcher passes every option at every start.
|
||||
[string]$Chosen,
|
||||
# Launcher.bat: the switches this card cannot run (an AMD or Intel card: NoDlss, NoFrameGen, SmoothMotion),
|
||||
# comma-separated. play-nvidia.ps1 leaves the F1 menu's values for them out of this start only and keeps them in
|
||||
# its file, for a later start on an NVIDIA card.
|
||||
[string]$CardMask,
|
||||
[switch]$PrecompileUsed
|
||||
)
|
||||
|
||||
@ -131,6 +135,11 @@ $typedHere = if ($PSBoundParameters.ContainsKey('Chosen')) {
|
||||
$launch.Typed = @($typedHere | ForEach-Object {
|
||||
switch ($_) { 'SeriesS' { 'SeriesX' } 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
|
||||
})
|
||||
if ($CardMask) {
|
||||
$launch.CardMask = @($CardMask -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ } | ForEach-Object {
|
||||
switch ($_) { 'SmoothMotion' { 'NoSmoothMotion' } default { $_ } }
|
||||
})
|
||||
}
|
||||
# A called script sets the global exit status. Start fresh for checks that return before launch.
|
||||
$global:LASTEXITCODE = 0
|
||||
& (Join-Path $runtime "scripts\play-nvidia.ps1") @launch
|
||||
|
||||
@ -210,16 +210,19 @@ class ForCardTests(unittest.TestCase):
|
||||
enabled, _ = launcher.settings_rules(values, self.NVIDIA, launch(console="series-s", rt="off"))
|
||||
self.assertFalse(enabled["resolution"]) # with DLSS's mode the script wants it left out
|
||||
|
||||
def test_card_chosen_names_the_menus_nvidia_switches(self) -> None:
|
||||
self.assertEqual(launcher.card_chosen(["Resolution"], self.AMD),
|
||||
["Resolution", "NoDlss", "NoFrameGen", "SmoothMotion"])
|
||||
self.assertEqual(launcher.card_chosen(["NoDlss"], self.AMD), ["NoDlss", "NoFrameGen", "SmoothMotion"])
|
||||
def test_card_mask_names_the_menus_nvidia_switches(self) -> None:
|
||||
self.assertEqual(launcher.card_mask(self.AMD), ["NoDlss", "NoFrameGen", "SmoothMotion"])
|
||||
for card in (self.NVIDIA, self.UNKNOWN):
|
||||
self.assertEqual(launcher.card_chosen(["Resolution"], card), ["Resolution"])
|
||||
# Through play_command: -Chosen carries them.
|
||||
command = launcher.play_command(self.settings(game_dir="D:\\Games"), repo="R", windows=True,
|
||||
chosen=launcher.card_chosen([], self.AMD))
|
||||
self.assertIn("NoDlss,NoFrameGen,SmoothMotion", command)
|
||||
self.assertEqual(launcher.card_mask(card), [])
|
||||
# Through play_command: -CardMask carries them, and -Chosen does not (a name there would remove the menu's
|
||||
# value from its file).
|
||||
command = launcher.play_command(self.settings(game_dir="D:\\Games"), repo="R", windows=True, chosen=[],
|
||||
mask=launcher.card_mask(self.AMD))
|
||||
self.assertEqual(command[command.index("-CardMask") + 1], "NoDlss,NoFrameGen,SmoothMotion")
|
||||
self.assertEqual(command[command.index("-Chosen") + 1], "none")
|
||||
command = launcher.play_command(self.settings(game_dir="D:\\Games"), repo="R", windows=True, chosen=[],
|
||||
mask=launcher.card_mask(self.NVIDIA))
|
||||
self.assertNotIn("-CardMask", command)
|
||||
|
||||
def test_a_resolution_above_series_s_output_stays_out_without_dlss(self) -> None:
|
||||
# Series S with DLSS Quality and a saved 1440 (left out by the mode): on AMD it would come back and stop the
|
||||
@ -714,6 +717,62 @@ class ControlsTests(unittest.TestCase):
|
||||
self.assertEqual(reserved.count("(VK_"), 8)
|
||||
|
||||
|
||||
class LinuxPlayTests(unittest.TestCase):
|
||||
"""Linux PLAY: play-linux.sh gets the Controls page's binds and the advanced options in its environment (the
|
||||
runtime inherits it), Advanced winning; the shader cache is the one play-linux.sh uses (review of #3272)."""
|
||||
|
||||
def test_variables_reach_play_linux(self):
|
||||
settings = launcher.normalise({"game_dir": "/games/gta", "kbm_binds": "both:G=Square",
|
||||
"advanced": "LEONIDA_HW_RT=1"})
|
||||
command = launcher.play_command(settings, repo="/r", windows=False)
|
||||
self.assertEqual(command[0], "env")
|
||||
self.assertIn("LEONIDA_KBM_BINDS=both:G=Square", command)
|
||||
self.assertIn("LEONIDA_HW_RT=1", command)
|
||||
self.assertEqual(command[command.index("sh"):][:2], ["sh", os.path.join("/r", "scripts", "play-linux.sh")])
|
||||
# Advanced wins over the Controls page.
|
||||
settings = launcher.normalise({"game_dir": "/games/gta", "kbm_binds": "both:G=Square",
|
||||
"advanced": "LEONIDA_KBM_BINDS=both:H=Cross"})
|
||||
command = launcher.play_command(settings, repo="/r", windows=False)
|
||||
self.assertIn("LEONIDA_KBM_BINDS=both:H=Cross", command)
|
||||
self.assertNotIn("LEONIDA_KBM_BINDS=both:G=Square", command)
|
||||
# Nothing to pass: the script alone, as before.
|
||||
command = launcher.play_command(launcher.normalise({"game_dir": "/games/gta"}), repo="/r", windows=False)
|
||||
self.assertEqual(command[0], "sh")
|
||||
|
||||
def test_the_linux_cache_is_play_linux_shs(self):
|
||||
settings = launcher.normalise({"data_dir": "/ignored"})
|
||||
self.assertEqual(launcher.shader_cache_dir(settings, windows=False,
|
||||
environ={"XDG_DATA_HOME": "/x", "HOME": "/h"}),
|
||||
os.path.join("/x", "leonida", "cache"))
|
||||
self.assertEqual(launcher.shader_cache_dir(settings, windows=False, environ={"HOME": "/h"}),
|
||||
os.path.join("/h", ".local", "share", "leonida", "cache"))
|
||||
self.assertEqual(launcher.shader_cache_dir(settings, windows=False,
|
||||
environ={"LEONIDA_CACHE_DIR": "/c", "HOME": "/h"}), "/c")
|
||||
self.assertEqual(launcher.shader_cache_dir(settings, windows=True),
|
||||
os.path.join("/ignored", launcher.SHADER_CACHE))
|
||||
script = (Path(launcher.REPO) / "scripts" / "play-linux.sh").read_text(encoding="utf-8")
|
||||
self.assertIn("data=${XDG_DATA_HOME:-$HOME/.local/share}/leonida", script)
|
||||
self.assertIn("LEONIDA_CACHE_DIR=${LEONIDA_CACHE_DIR:-$data/cache}", script)
|
||||
|
||||
|
||||
class SplitBindsTests(unittest.TestCase):
|
||||
"""Entries the Controls page cannot read are kept beside the rows it edits (review of #3272)."""
|
||||
|
||||
def test_no_t_call_passes_text(self):
|
||||
# t(text, **values): a placeholder named {text} made t() fail with two values for `text` (the Controls page
|
||||
# crashed as soon as it showed an entry it cannot read).
|
||||
source = (Path(launcher.__file__)).read_text(encoding="utf-8")
|
||||
self.assertNotRegex(source, r"\bt\((?:[^()]|\([^()]*\))*\btext=")
|
||||
self.assertEqual(launcher.t("Kept as saved (the page cannot read it): {entries}", entries="x:Y=Z"),
|
||||
"Kept as saved (the page cannot read it): x:Y=Z")
|
||||
|
||||
def test_readable_and_kept(self):
|
||||
rows, kept = launcher.split_kbm_binds("both:G=Square;vehicle:N=FutureAction; foot:F1=A ;foot:V=RB")
|
||||
self.assertEqual(rows, [("both", "G", "Square"), ("foot", "V", "RB")])
|
||||
self.assertEqual(kept, ["vehicle:N=FutureAction", "foot:F1=A"])
|
||||
self.assertEqual(launcher.split_kbm_binds(""), ([], []))
|
||||
|
||||
|
||||
class OutputPumpTests(unittest.TestCase):
|
||||
"""Issue #3175: with -Log off the runtime's stderr comes through the pipe, and the window's pump drained the whole
|
||||
queue in one turn with one insert per line, so the window stopped answering clicks while it caught up."""
|
||||
|
||||
@ -323,10 +323,13 @@ Show-Case 'S-auto-none' 8GB @{ Lowest = '1080' }
|
||||
}, result.stdout + result.stderr)
|
||||
|
||||
@unittest.skipUnless(POWERSHELL, "requires PowerShell")
|
||||
def test_card_chosen_switches_drop_the_menus_nvidia_values(self) -> None:
|
||||
"""Without an NVIDIA card the launcher names NoDlss, NoFrameGen and SmoothMotion as chosen (card_chosen, which
|
||||
play-d3d12.ps1 hands over as -Typed, SmoothMotion as NoSmoothMotion): the F1 menu's saved DLSS, DLSS frame
|
||||
generation and Smooth Motion are dropped, its FSR frame generation stays. Without them the menu's win."""
|
||||
def test_card_mask_leaves_the_menus_nvidia_values_out_and_in_the_file(self) -> None:
|
||||
"""Without an NVIDIA card the launcher passes -CardMask NoDlss,NoFrameGen,SmoothMotion (card_mask; play-d3d12.ps1
|
||||
hands SmoothMotion over as NoSmoothMotion): this start runs without the F1 menu's saved DLSS, DLSS frame
|
||||
generation and Smooth Motion, and keeps its FSR frame generation; the menu file keeps all of them, also after a
|
||||
real start (not a dry run), for a later start on an NVIDIA card (review of #3272). Without the mask the menu's
|
||||
win. With -Adapter naming the AMD card of an AMD + RTX 4070 PC, no automatic DLSS frame generation; naming the
|
||||
RTX 4070, the automatic 2x stays."""
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
scripts = root / "scripts"
|
||||
@ -335,6 +338,10 @@ Show-Case 'S-auto-none' 8GB @{ Lowest = '1080' }
|
||||
shutil.copyfile(NVIDIA_LAUNCHER, launcher)
|
||||
executable = root / "synthetic title.exe"
|
||||
executable.touch()
|
||||
diag = root / "target" / "diag"
|
||||
diag.mkdir(parents=True)
|
||||
(diag / "leonida.exe").touch()
|
||||
(diag / "built-with.txt").write_text("diagnostics\n", encoding="utf-8")
|
||||
streamline = root / "streamline"
|
||||
streamline.mkdir()
|
||||
(streamline / "sl.interposer.dll").touch()
|
||||
@ -344,51 +351,85 @@ Show-Case 'S-auto-none' 8GB @{ Lowest = '1080' }
|
||||
(fidelityfx / dll).touch()
|
||||
command = r"""
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$global:cards = @('AMD Radeon RX 9070')
|
||||
function Get-CimInstance {
|
||||
param([string]$ClassName)
|
||||
if ($ClassName -eq 'Win32_VideoController') { return [pscustomobject]@{ Name = 'AMD Radeon RX 9070' } }
|
||||
if ($ClassName -eq 'Win32_VideoController') { return @($global:cards | ForEach-Object { [pscustomobject]@{ Name = $_ } }) }
|
||||
if ($ClassName -ne 'Win32_OperatingSystem') { throw "Unexpected CIM query: $ClassName" }
|
||||
[pscustomobject]@{ BuildNumber = '26100' }
|
||||
}
|
||||
function Show-Case([string]$name, [string]$menu, [string[]]$typed) {
|
||||
Set-Content -LiteralPath (Join-Path $env:TEST_ROOT 'leonida-settings.txt') -Value $menu -Encoding ascii
|
||||
function Start-Process { [pscustomobject]@{ ExitCode = 0; Id = 1; HasExited = $true } }
|
||||
$menuFile = Join-Path $env:TEST_ROOT 'leonida-settings.txt'
|
||||
function Show-Case([string]$name, [string]$menu, [string[]]$mask) {
|
||||
Set-Content -LiteralPath $menuFile -Value $menu -Encoding ascii
|
||||
$lines = & $env:TEST_NVIDIA_LAUNCHER -Exe $env:TEST_NVIDIA_EXE -DryRun -NoDlss -NoSmoothMotion -NoPrecompile `
|
||||
-WindowsBarMB 0 -StreamlineDir $env:TEST_STREAMLINE -Typed $typed
|
||||
-WindowsBarMB 0 -StreamlineDir $env:TEST_STREAMLINE -Typed @() -CardMask $mask
|
||||
foreach ($key in 'LEONIDA_UPSCALE', 'LEONIDA_FRAME_GEN', 'LEONIDA_MENU_SMOOTH_MOTION', 'LEONIDA_FSR_FRAMEGEN') {
|
||||
$v = ($lines | Where-Object { $_ -like "$key=*" }) -replace "^$key=", ''
|
||||
"CASE $name $key=$v"
|
||||
}
|
||||
}
|
||||
$nvidiaMenu = "LEONIDA_UPSCALE=dlss`r`nLEONIDA_FRAME_GEN=2`r`nLEONIDA_MENU_SMOOTH_MOTION=1"
|
||||
Show-Case 'menu-wins' $nvidiaMenu @('NoDlss')
|
||||
Show-Case 'card' $nvidiaMenu @('NoDlss', 'NoFrameGen', 'NoSmoothMotion')
|
||||
Show-Case 'card-fsr' "LEONIDA_FSR_FRAMEGEN=1`r`nLEONIDA_MENU_SMOOTH_MOTION=1" @('NoDlss', 'NoFrameGen', 'NoSmoothMotion')
|
||||
$mask = @('NoDlss', 'NoFrameGen', 'NoSmoothMotion')
|
||||
Show-Case 'menu-wins' $nvidiaMenu @()
|
||||
Show-Case 'card' $nvidiaMenu $mask
|
||||
Show-Case 'card-fsr' "LEONIDA_FSR_FRAMEGEN=1`r`nLEONIDA_MENU_SMOOTH_MOTION=1" $mask
|
||||
# A real start (no -DryRun), the title's launch stubbed: the menu file keeps the masked values.
|
||||
Set-Content -LiteralPath $menuFile -Value "$nvidiaMenu`r`nLEONIDA_FSR_FRAMEGEN=1" -Encoding ascii
|
||||
try {
|
||||
& $env:TEST_NVIDIA_LAUNCHER -Exe $env:TEST_NVIDIA_EXE -NoDlss -NoSmoothMotion -NoPrecompile -WindowsBarMB 0 `
|
||||
-StreamlineDir $env:TEST_STREAMLINE -Typed @() -CardMask $mask *> $null
|
||||
} catch { "START $($_.Exception.Message)" }
|
||||
foreach ($line in (Get-Content -LiteralPath $menuFile)) { if ($line -like 'LEONIDA_*') { "FILE $line" } }
|
||||
# The automatic DLSS frame generation (Series X, -Lowest) follows -Adapter on a mixed PC.
|
||||
$global:cards = @('AMD Radeon RX 7800 XT', 'NVIDIA GeForce RTX 4070')
|
||||
Remove-Item -LiteralPath $menuFile
|
||||
foreach ($case in @(@('mixed-amd', 'AMD Radeon RX 7800 XT'), @('mixed-rtx', 'RTX 4070'), @('mixed-none', ''))) {
|
||||
$extra = @{}; if ($case[1]) { $extra.Adapter = $case[1] }
|
||||
$lines = & $env:TEST_NVIDIA_LAUNCHER -Exe $env:TEST_NVIDIA_EXE -DryRun -NoPrecompile -WindowsBarMB 0 -SeriesX `
|
||||
-Lowest 1080 -StreamlineDir $env:TEST_STREAMLINE -Typed @() @extra
|
||||
"CASE $($case[0]) LEONIDA_FRAME_GEN=$(($lines | Where-Object { $_ -like 'LEONIDA_FRAME_GEN=*' }) -replace '^LEONIDA_FRAME_GEN=', '')"
|
||||
}
|
||||
$lines = & $env:TEST_NVIDIA_LAUNCHER -Exe $env:TEST_NVIDIA_EXE -DryRun -NoPrecompile -WindowsBarMB 0 -SeriesX `
|
||||
-Lowest 1080 -StreamlineDir $env:TEST_STREAMLINE -Typed @() -CardMask $mask
|
||||
"CASE mixed-mask LEONIDA_FRAME_GEN=$(($lines | Where-Object { $_ -like 'LEONIDA_FRAME_GEN=*' }) -replace '^LEONIDA_FRAME_GEN=', '')"
|
||||
"""
|
||||
env = {name: value for name, value in os.environ.items() if not name.upper().startswith("LEONIDA_")}
|
||||
env.update(TEST_NVIDIA_LAUNCHER=str(launcher), TEST_NVIDIA_EXE=str(executable), TEST_ROOT=str(root),
|
||||
TEST_STREAMLINE=str(streamline))
|
||||
result = subprocess.run(
|
||||
[POWERSHELL, "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", command],
|
||||
env=env, capture_output=True, encoding="utf-8", errors="replace", timeout=120,
|
||||
env=env, capture_output=True, encoding="utf-8", errors="replace", timeout=180,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
got = {line.split(" ", 2)[1] + " " + line.split(" ", 2)[2] for line in result.stdout.splitlines()
|
||||
if line.startswith("CASE ")}
|
||||
# The menu's saved frame generation wins when nothing names its switch (Smooth Motion the script keeps
|
||||
# off without an NVIDIA card by itself) ...
|
||||
files = [line[5:] for line in result.stdout.splitlines() if line.startswith("FILE ")]
|
||||
# The menu's saved frame generation wins without the mask ...
|
||||
self.assertIn("menu-wins LEONIDA_FRAME_GEN=2", got, result.stdout)
|
||||
# ... and the card's switches named as chosen drop them; the menu's FSR frame generation stays.
|
||||
# ... with it this start runs without them, the menu's FSR frame generation kept ...
|
||||
for line in ("card LEONIDA_UPSCALE=stretch", "card LEONIDA_FRAME_GEN=", "card LEONIDA_MENU_SMOOTH_MOTION=0",
|
||||
"card-fsr LEONIDA_FSR_FRAMEGEN=1", "card-fsr LEONIDA_MENU_SMOOTH_MOTION=0"):
|
||||
self.assertIn(line, got, result.stdout + result.stderr)
|
||||
# The launcher's names are the script's: each maps (play-d3d12.ps1) to a $switchSettings entry.
|
||||
# ... and a real start leaves every one of them in the menu file.
|
||||
for line in ("LEONIDA_UPSCALE=dlss", "LEONIDA_FRAME_GEN=2", "LEONIDA_MENU_SMOOTH_MOTION=1",
|
||||
"LEONIDA_FSR_FRAMEGEN=1"):
|
||||
self.assertIn(line, files, result.stdout + result.stderr)
|
||||
# Mixed PC: the chosen card decides the automatic DLSS frame generation; the mask keeps it off too.
|
||||
for line in ("mixed-amd LEONIDA_FRAME_GEN=", "mixed-rtx LEONIDA_FRAME_GEN=2", "mixed-none LEONIDA_FRAME_GEN=2",
|
||||
"mixed-mask LEONIDA_FRAME_GEN="):
|
||||
self.assertIn(line, got, result.stdout + result.stderr)
|
||||
# The launcher's names are the script's: each maps (play-d3d12.ps1) to a $switchSettings entry, and
|
||||
# play-d3d12.ps1 hands -CardMask over.
|
||||
import sys
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
import leonida_launcher
|
||||
script = NVIDIA_LAUNCHER.read_text(encoding="utf-8")
|
||||
for name in leonida_launcher.CARD_CHOSEN:
|
||||
for name in leonida_launcher.CARD_MASK:
|
||||
typed = {"SmoothMotion": "NoSmoothMotion"}.get(name, name)
|
||||
self.assertRegex(script, rf"(?m)^\s+{typed} = 'LEONIDA_", name)
|
||||
wrapper = (ROOT / "scripts" / "play-d3d12.ps1").read_text(encoding="utf-8")
|
||||
self.assertIn("$launch.CardMask", wrapper)
|
||||
|
||||
def test_static_quoting_and_no_pause_guards(self) -> None:
|
||||
build_txt = BUILD_BAT.read_text(encoding="utf-8")
|
||||
|
||||
@ -347,7 +347,7 @@
|
||||
"D-pad up": "Steuerkreuz oben",
|
||||
"Default keys": "Standardtasten",
|
||||
"In a vehicle": "Im Fahrzeug",
|
||||
"Kept as saved (the page cannot read it): {text}": "Unverändert behalten (die Seite kann es nicht lesen): {text}",
|
||||
"Kept as saved (the page cannot read it): {entries}": "Unverändert behalten (die Seite kann es nicht lesen): {entries}",
|
||||
"LB (L1)": "LB (L1)",
|
||||
"LEONIDA_KBM_BINDS is also in Settings' advanced options: that one wins at PLAY.": "LEONIDA_KBM_BINDS steht auch in den erweiterten Optionen der Einstellungen: diese gilt bei PLAY.",
|
||||
"LT (L2)": "LT (L2)",
|
||||
|
||||
@ -347,7 +347,7 @@
|
||||
"D-pad up": "Cruceta arriba",
|
||||
"Default keys": "Teclas por defecto",
|
||||
"In a vehicle": "En un vehículo",
|
||||
"Kept as saved (the page cannot read it): {text}": "Se conserva tal cual (la página no puede leerlo): {text}",
|
||||
"Kept as saved (the page cannot read it): {entries}": "Se conserva tal cual (la página no puede leerlo): {entries}",
|
||||
"LB (L1)": "LB (L1)",
|
||||
"LEONIDA_KBM_BINDS is also in Settings' advanced options: that one wins at PLAY.": "LEONIDA_KBM_BINDS también está en las opciones avanzadas de Ajustes: esa es la que cuenta al pulsar PLAY.",
|
||||
"LT (L2)": "LT (L2)",
|
||||
|
||||
@ -347,7 +347,7 @@
|
||||
"D-pad up": "Croix directionnelle haut",
|
||||
"Default keys": "Touches par défaut",
|
||||
"In a vehicle": "En véhicule",
|
||||
"Kept as saved (the page cannot read it): {text}": "Gardé tel quel (la page ne sait pas le lire) : {text}",
|
||||
"Kept as saved (the page cannot read it): {entries}": "Gardé tel quel (la page ne sait pas le lire) : {entries}",
|
||||
"LB (L1)": "LB (L1)",
|
||||
"LEONIDA_KBM_BINDS is also in Settings' advanced options: that one wins at PLAY.": "LEONIDA_KBM_BINDS est aussi dans les options avancées des Réglages : c'est celle-là qui compte à PLAY.",
|
||||
"LT (L2)": "LT (L2)",
|
||||
|
||||
@ -347,7 +347,7 @@
|
||||
"D-pad up": "Direcional para cima",
|
||||
"Default keys": "Teclas padrão",
|
||||
"In a vehicle": "Num veículo",
|
||||
"Kept as saved (the page cannot read it): {text}": "Mantido como salvo (a página não consegue lê-lo): {text}",
|
||||
"Kept as saved (the page cannot read it): {entries}": "Mantido como salvo (a página não consegue lê-lo): {entries}",
|
||||
"LB (L1)": "LB (L1)",
|
||||
"LEONIDA_KBM_BINDS is also in Settings' advanced options: that one wins at PLAY.": "LEONIDA_KBM_BINDS também está nas opções avançadas das Configurações: é essa que vale no PLAY.",
|
||||
"LT (L2)": "LT (L2)",
|
||||
|
||||
@ -217,19 +217,17 @@ def for_card(settings: dict, card: dict) -> dict:
|
||||
|
||||
|
||||
SERIES_S_OUTPUT_LINES = 1080 # play-nvidia.ps1: $outHeight on the Series S profile
|
||||
# The switches whose settings the F1 menu's file also holds and that an AMD or Intel card cannot run (for_card):
|
||||
# named as chosen at every PLAY there, so the script drops the menu's saved DLSS, DLSS frame generation and Smooth
|
||||
# Motion as it drops a value a typed switch replaces ($switchSettings: NoDlss, NoFrameGen, SmoothMotion). FSR frame
|
||||
# generation, the menu's own, stays.
|
||||
CARD_CHOSEN = ("NoDlss", "NoFrameGen", "SmoothMotion")
|
||||
# The switches whose settings the F1 menu's file also holds and that an AMD or Intel card cannot run (for_card),
|
||||
# passed as play-d3d12.ps1's -CardMask: play-nvidia.ps1 leaves the menu's values for them out of this start only and
|
||||
# keeps them in the menu file, for a later start on an NVIDIA card ($switchSettings: NoDlss, NoFrameGen,
|
||||
# NoSmoothMotion). The menu's FSR frame generation stays. They are not named in -Chosen: a switch named there removes
|
||||
# the menu's value from its file (review of #3272: the saved choices were lost after one start on the AMD card).
|
||||
CARD_MASK = ("NoDlss", "NoFrameGen", "SmoothMotion")
|
||||
|
||||
|
||||
def card_chosen(chosen: list[str], card: dict) -> list[str]:
|
||||
"""`chosen` (chosen_switches) for -Chosen on `card`: without an NVIDIA card, CARD_CHOSEN added, so the F1 menu's
|
||||
saved DLSS, DLSS frame generation and Smooth Motion do not come back through the menu file (review of #3272)."""
|
||||
if card.get("nvidia", True):
|
||||
return chosen
|
||||
return list(chosen) + [name for name in CARD_CHOSEN if name not in chosen]
|
||||
def card_mask(card: dict) -> list[str]:
|
||||
"""The -CardMask of a start on `card`: CARD_MASK without an NVIDIA card, nothing otherwise."""
|
||||
return [] if card.get("nvidia", True) else list(CARD_MASK)
|
||||
|
||||
|
||||
def switch_values(args: list[str]) -> dict:
|
||||
@ -386,6 +384,23 @@ def parse_kbm_binds(text: str) -> list[tuple[str, str, str]] | None:
|
||||
return rows
|
||||
|
||||
|
||||
def split_kbm_binds(text: str) -> tuple[list[tuple[str, str, str]], list[str]]:
|
||||
"""The entries of a LEONIDA_KBM_BINDS value the page reads, as rows (parse_kbm_binds's), and the others as they
|
||||
are (an unknown key or action, a reserved key, a newer launcher's): the page edits the rows and writes the others
|
||||
back unchanged after them, so adding a row never loses one (review of #3272)."""
|
||||
rows, kept = [], []
|
||||
for part in (text or "").split(";"):
|
||||
part = part.strip()
|
||||
if not part:
|
||||
continue
|
||||
read = parse_kbm_binds(part)
|
||||
if read:
|
||||
rows.extend(read)
|
||||
else:
|
||||
kept.append(part)
|
||||
return rows, kept
|
||||
|
||||
|
||||
def kbm_binds_text(rows) -> str:
|
||||
"""The LEONIDA_KBM_BINDS value of the rows: `scope:key=action` joined by `;`; rows without a key are left out."""
|
||||
return ";".join(f"{scope}:{key}={action}" for scope, key, action in rows if key and action)
|
||||
@ -655,10 +670,12 @@ def ps_quote(text: str) -> str:
|
||||
|
||||
|
||||
def play_command(settings: dict, repo: str = REPO, windows: bool = WINDOWS, chosen: list[str] | None = None,
|
||||
extra: dict | None = None) -> list[str]:
|
||||
extra: dict | None = None, mask: list[str] | None = None) -> list[str]:
|
||||
"""The command PLAY runs. Raises ValueError when the game folder is not set. With `chosen`, only those switches
|
||||
count as typed for the F1 menu (-Chosen; `none` for none). With variables to pass (extra_variables), the script
|
||||
is started with -Command, since -More takes a hashtable that -File cannot hand over."""
|
||||
count as typed for the F1 menu (-Chosen; `none` for none); `mask` (card_mask) is -CardMask. With variables to pass
|
||||
(extra_variables), the script is started with -Command, since -More takes a hashtable that -File cannot hand
|
||||
over. On Linux the variables go into play-linux.sh's environment (`env NAME=value ...`), which the runtime
|
||||
inherits: the Controls page's binds and the advanced options, as on Windows (review of #3272)."""
|
||||
game = settings["game_dir"].strip()
|
||||
if not game:
|
||||
raise ValueError("Choose the game folder in Settings first.")
|
||||
@ -669,6 +686,8 @@ def play_command(settings: dict, repo: str = REPO, windows: bool = WINDOWS, chos
|
||||
args += ["-Data", settings["data_dir"].strip()]
|
||||
if chosen is not None:
|
||||
args += ["-Chosen", ",".join(chosen) or "none"]
|
||||
if mask:
|
||||
args += ["-CardMask", ",".join(mask)]
|
||||
args += switch_args(settings)
|
||||
more = extra_variables(settings, extra)
|
||||
if not more:
|
||||
@ -681,6 +700,9 @@ def play_command(settings: dict, repo: str = REPO, windows: bool = WINDOWS, chos
|
||||
command = ["sh", os.path.join(repo, "scripts", "play-linux.sh"), os.path.join(game, EXPECTED_EXE)]
|
||||
if settings["series_x"]:
|
||||
command.append("--series-x")
|
||||
more = extra_variables(settings, extra)
|
||||
if more:
|
||||
command = ["env"] + [f"{k}={v}" for k, v in more.items()] + command
|
||||
return command
|
||||
|
||||
|
||||
@ -1682,9 +1704,17 @@ def data_root(settings: dict) -> str:
|
||||
SHADER_CACHE = "cache-2" # scripts/play-d3d12.ps1: LEONIDA_CACHE_DIR = <data>\cache-2 (made again at each start)
|
||||
|
||||
|
||||
def shader_cache_dir(settings: dict) -> str:
|
||||
"""The runtime's cache for PLAY's starts: translated shaders, pipelines, the title's prepared images."""
|
||||
return os.path.join(data_root(settings), SHADER_CACHE)
|
||||
def shader_cache_dir(settings: dict, windows: bool = WINDOWS, environ=None) -> str:
|
||||
"""The runtime's cache for PLAY's starts: translated shaders, pipelines, the title's prepared images. Windows:
|
||||
play-d3d12.ps1's <data>\\cache-2. Linux: play-linux.sh's LEONIDA_CACHE_DIR, by default
|
||||
${XDG_DATA_HOME:-~/.local/share}/leonida/cache (the launcher passes no data folder there; review of #3272)."""
|
||||
if windows:
|
||||
return os.path.join(data_root(settings), SHADER_CACHE)
|
||||
env = os.environ if environ is None else environ
|
||||
if env.get("LEONIDA_CACHE_DIR"):
|
||||
return env["LEONIDA_CACHE_DIR"]
|
||||
data = env.get("XDG_DATA_HOME") or os.path.join(env.get("HOME") or os.path.expanduser("~"), ".local", "share")
|
||||
return os.path.join(data, "leonida", "cache")
|
||||
|
||||
|
||||
def folder_size(path: str) -> int:
|
||||
@ -3337,8 +3367,8 @@ def run_gui() -> int:
|
||||
extra = {"LEONIDA_D3D12_DRED": "1"}
|
||||
args = switch_args(settings)
|
||||
try:
|
||||
command = play_command(settings, extra=extra,
|
||||
chosen=card_chosen(chosen_switches(args, self.settings["last_switches"]), card))
|
||||
command = play_command(settings, extra=extra, mask=card_mask(card),
|
||||
chosen=chosen_switches(args, self.settings["last_switches"]))
|
||||
except ValueError as exc:
|
||||
messagebox.showwarning(t("Play"), str(exc))
|
||||
return
|
||||
@ -4535,10 +4565,11 @@ def run_gui() -> int:
|
||||
self.card_end(mine)
|
||||
if "kbm_binds" not in self.vars:
|
||||
self.vars["kbm_binds"] = tk.StringVar(value=self.settings.get("kbm_binds", ""))
|
||||
rows = parse_kbm_binds(self.vars["kbm_binds"].get())
|
||||
# A saved value the page cannot read (typed by hand, or by a newer launcher) is kept and shown whole.
|
||||
self.kbm_raw = None if rows is not None else self.vars["kbm_binds"].get()
|
||||
self.kbm_rows = [list(r) for r in (rows or [])]
|
||||
rows, kept = split_kbm_binds(self.vars["kbm_binds"].get())
|
||||
# Entries the page cannot read (typed by hand, or by a newer launcher) are kept as they are and shown;
|
||||
# the rows around them stay editable, and saving writes them back after the rows.
|
||||
self.kbm_raw = ";".join(kept) or None
|
||||
self.kbm_rows = [list(r) for r in rows]
|
||||
self.kbm_capturing = None
|
||||
self.render_kbm()
|
||||
|
||||
@ -4548,10 +4579,10 @@ def run_gui() -> int:
|
||||
for child in frame.winfo_children():
|
||||
child.destroy()
|
||||
if self.kbm_raw is not None:
|
||||
tk.Label(frame, text=t("Kept as saved (the page cannot read it): {text}", text=self.kbm_raw),
|
||||
tk.Label(frame, text=t("Kept as saved (the page cannot read it): {entries}", entries=self.kbm_raw),
|
||||
bg=PANEL, fg=WARN, font=("Segoe UI", 9), anchor="w", justify="left",
|
||||
wraplength=px(560), padx=0).grid(row=0, column=0, columnspan=5, sticky="ew")
|
||||
elif not self.kbm_rows:
|
||||
if self.kbm_raw is None and not self.kbm_rows:
|
||||
tk.Label(frame, text=t("No binds of your own: the default keys."), bg=PANEL, fg=FAINT,
|
||||
font=("Segoe UI", 9), anchor="w", padx=0).grid(row=0, column=0, columnspan=5, sticky="ew")
|
||||
labels = [t(label) for _name, label in KBM_ACTIONS]
|
||||
@ -4581,8 +4612,8 @@ def run_gui() -> int:
|
||||
|
||||
def kbm_store(self):
|
||||
"""Writes the rows to kbm_binds and saves the settings (the page has no Save button)."""
|
||||
if self.kbm_raw is None:
|
||||
self.vars["kbm_binds"].set(kbm_binds_text(r[:3] for r in self.kbm_rows))
|
||||
self.vars["kbm_binds"].set(";".join(p for p in (kbm_binds_text(r[:3] for r in self.kbm_rows),
|
||||
self.kbm_raw or "") if p))
|
||||
self.collect_settings()
|
||||
try:
|
||||
save_settings(self.settings)
|
||||
@ -4596,7 +4627,6 @@ def run_gui() -> int:
|
||||
self.kbm_store()
|
||||
|
||||
def kbm_add(self):
|
||||
self.kbm_raw = None
|
||||
self.kbm_rows = [r[:3] for r in self.kbm_rows] + [["both", "", "Square"]]
|
||||
self.render_kbm()
|
||||
self.kbm_capture(len(self.kbm_rows) - 1)
|
||||
@ -4725,7 +4755,9 @@ def run_gui() -> int:
|
||||
"again, which takes a while (longer with Precompile every pipeline).\n\nYour saves are not "
|
||||
"touched.\n\nContinue?", path=path, size=size_text(folder_size(path))), icon="warning"):
|
||||
return
|
||||
done, message = clear_shader_cache(self.settings, running=lambda: self.process is not None)
|
||||
# The game may have been started (here or elsewhere) while the dialog was open: asked again now.
|
||||
done, message = clear_shader_cache(self.settings,
|
||||
running=lambda: self.process is not None or game_running())
|
||||
(messagebox.showinfo if done else messagebox.showwarning)(t("Clear shader cache"), message)
|
||||
|
||||
def run_tool(self, name, what, state):
|
||||
|
||||
Reference in New Issue
Block a user