Read low_end_gpu's and shader_carry's off words the same in the low-end mode and in make_game.py as in the game's other readers.

The review of the commit that taught nx2navi.ini's readers off, false and no found three readers it left behind. cfg.c
lowend_of reads low_end_gpu through raw_get, which skips switch_word, and still took anything but "0" as on: with
"low_end_gpu = off" cfg_get, cfg_bool and the menu said off while cfg_low_end_active() was 1, so the mode's defaults
and its LOWEND_ONLY keys stayed in effect, and F-7's check, which now accepts the word, logged nothing. lowend_of now
takes the value through switch_of as cfg_bool does: 0 and the off words are off, anything else set is on (an
environment value "0 ; x" stays on, as cfg_bool reads it). tools/make_game.py read the file on its own too:
shader_carry took only "0" as off and kept a comment in the value, so with "shader_carry = off" or "shader_carry = 0 ;
note" an update skipped the full shader preparation and left the shaders to a game that no longer carries them over;
guest_opt_ini took low_end_gpu as on for anything but "" and "0". shader_carry now reads the switch as the game does
(the environment wins over the file and is taken as written, the file's last line with a value wins, a comment after
a blank is cut unless the value is in double quotes, make_game.py ini_choice, and 0, off, false and no in any case are
off); guest_opt_ini keeps its cut and takes the same words as off.

tests/cfg_parse_check gains a lowend case (low_end_gpu = Off, = 0 ; note and = yes from the file, FALSE and "0 ; x"
from the environment; two of them fail on the old lowend_of), and launcher_test's MakeGameTest two tests of
shader_carry's and guest_opt_ini's reading, which fail on the old make_game.py. cfg_rows_check reports 0 problems, and
the -Wall compile of cfg.c shows no warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:35:01 -05:00
parent b6709da852
commit 8c9011d56f
5 changed files with 103 additions and 15 deletions

View File

@@ -852,11 +852,13 @@ static int lowend_only(const char *key) {
return 0;
}
static int lowend = -1;
// Read through raw_get, which skips switch_word, so the words are taken here as cfg_bool takes them: "low_end_gpu =
// off" is off for the mode as for the menu and cfg_get, and any value that is not 0 or one of the off words is on.
static int lowend_of(void) {
int p = __atomic_load_n(&lowend, __ATOMIC_ACQUIRE);
if (p >= 0) return p;
const char *set = raw_get(PREFIX "LOW_END_GPU");
p = set && *set && strcmp(set, "0") != 0;
p = set && *set && switch_of(set) != 0;
__atomic_store_n(&lowend, p, __ATOMIC_RELEASE);
return p;
}

View File

@@ -5,6 +5,8 @@
// full cfg_load on the file, then two cfg_set of keys the file does not have
// read cfg_load on the file and cfg_init's check of the environment; then what cfg_get, cfg_bool and cfg_int give
// for a list of keys
// lowend cfg_load on the file and cfg_init; then whether the low-end mode is on (cfg.c lowend_of, which reads its
// switch apart from cfg_get), what cfg_bool gives for its switch and what one of the mode's keys reads
// norow cfg_int and cfg_double of a key without a row whose value (the environment's) does not parse
#include <stdarg.h>
#include <stdint.h>
@@ -101,6 +103,14 @@ int main(int argc, char **argv) {
}
return 0;
}
if (!strcmp(argv[1], "lowend")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
cfg_init();
const char *mesh = cfg_get("NX2NAVI_MESH_EMULATION");
printf("got: low_end %d bool %d mesh_emulation '%s'\n", cfg_low_end_active(), cfg_bool("NX2NAVI_LOW_END_GPU"),
mesh ? mesh : "(unset)");
return 0;
}
if (!strcmp(argv[1], "norow")) {
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
printf("got: cfg_int %d cfg_double %g\n", cfg_int("NX2NAVI_NO_ROW_CHECK"), cfg_double("NX2NAVI_NO_ROW_CHECK"));

View File

@@ -7,6 +7,8 @@ for what it links with. What the readers get and what the log says about the val
it is part of the value; at most 16 lines, then a count;
- switches written as words (cfg.c switch_word, cfg_bool): false, off and no in any case read as 0 and true, on and
yes as 1 through cfg_get, cfg_bool and cfg_int, from the file and from the environment, with no line about them;
the low-end mode's switch (cfg.c lowend_of, read apart from cfg_get) takes the same words, so "low_end_gpu = off"
leaves the mode and its keys off;
- values outside their rows' sets (cfg.c check_value): a 0|1 switch with another value, a number outside its range, a
word that is none of the menu's choices, each named with its line; none for a file whose values fit, nor for a list
with numbers in it (the menu's presets); at most 16 lines, then a count;
@@ -185,6 +187,17 @@ def main():
'a file with 601 keys: one line at load from line 513 on', out)
check(rc == 0 and len(set_lines) == 1 and 'VK_PRESENT is not kept' in set_lines[0],
'two menu changes past a full table: one line', out)
# the low-end mode's switch, read apart from cfg_get (cfg.c lowend_of): the same words as cfg_bool, from the file
# and from the environment; the mode is decided once per process, so each value is its own run
for text, extra, want in (
('low_end_gpu = Off\n', None, "low_end 0 bool 0 mesh_emulation '(unset)'"),
('low_end_gpu = 0 ; note\n', None, "low_end 0 bool 0 mesh_emulation '(unset)'"),
('low_end_gpu = yes\n', None, "low_end 1 bool 1 mesh_emulation '1'"),
('; nothing\n', {'NX2NAVI_LOW_END_GPU': 'FALSE'}, "low_end 0 bool 0 mesh_emulation '(unset)'"),
('; nothing\n', {'NX2NAVI_LOW_END_GPU': '0 ; x'}, "low_end 1 bool 1 mesh_emulation '1'")):
rc, out = run(exe, env, 'lowend', text, work, extra)
what = text.strip() if extra is None else f"the environment's {extra['NX2NAVI_LOW_END_GPU']!r}"
check(rc == 0 and f'got: {want}' in out, f'low end: {what}: {want}', out)
rc, out = run(exe, env, 'norow', CLEAN, work, {'NX2NAVI_NO_ROW_CHECK': 'abc'})
check(rc == 0 and 'got: cfg_int 0 cfg_double 0' in out, 'cfg_int of a set, unparsable key without a row: 0', out)
print(f'cfg_parse_check: {"FAILED" if bad else "ok"}')

View File

@@ -2904,6 +2904,47 @@ class MakeGameTest(Tmp):
(out / 'nx2navi.ini').write_text('[performance]\nNX2NAVI_SHADER_CARRY = "0"\n')
self.assertFalse(self.mg.shader_carry(out))
def test_shader_carry_reads_the_switch_as_the_game(self):
"""shader_carry reads NX2NAVI_SHADER_CARRY as runtime/cfg.c does: 0, off, false and no in any case are off, a
comment after a blank is cut unless the value is in double quotes, the file's last line with a value wins and
the environment wins over the file. A line the game reads as off and this as on would skip a preparation the
game does not make up for."""
out = self.tmp / 'game'
(out / 'shader-cache').mkdir(parents=True)
(out / 'shader-prepared.bin').write_bytes(b'x')
(out / 'shader-cache' / 'identities.txt').write_text('# translators\n' + 'ab' * 32 + '\n')
ini = out / 'nx2navi.ini'
env = {k: v for k, v in os.environ.items() if k.upper() != 'NX2NAVI_SHADER_CARRY'}
with mock.patch.dict(os.environ, env, clear=True):
for text, carry in (('shader_carry = off\n', False), ('shader_carry = FALSE\n', False),
('shader_carry = no\n', False), ('shader_carry = 0 ; note\n', False),
('shader_carry = 0\t# note\n', False), ('shader_carry = 1 # on\n', True),
('shader_carry = on\n', True), ('shader_carry = "0 ; quoted"\n', True),
('shader_carry = 0\nshader_carry = on\n', True),
('shader_carry = on\nshader_carry = off\n', False),
('shader_carry = 0\nshader_carry = ; nothing\n', False)):
ini.write_text(text)
self.assertEqual(self.mg.shader_carry(out), carry, text)
ini.write_text('shader_carry = 0\n')
with mock.patch.dict(os.environ, {'NX2NAVI_SHADER_CARRY': '1'}):
self.assertTrue(self.mg.shader_carry(out)) # the environment wins over the file
ini.write_text('shader_carry = 1\n')
with mock.patch.dict(os.environ, {'NX2NAVI_SHADER_CARRY': 'Off'}):
self.assertFalse(self.mg.shader_carry(out))
def test_guest_opt_from_the_ini_only_with_the_low_end_mode_on(self):
"""guest_opt_ini takes guest_opt from nx2navi.ini only while low_end_gpu is on as runtime/cfg.c lowend_of
reads it: 0, off, false and no in any case are off."""
out = self.tmp / 'game'
out.mkdir()
env = {k: v for k, v in os.environ.items() if k.upper() != 'NX2NAVI_GUEST_OPT'}
for low, taken in (('1', True), ('yes', True), ('On', True), ('0', False), ('off', False), ('FALSE', False),
('no', False), ('0 ; note', False)):
(out / 'nx2navi.ini').write_text(f'guest_opt = 2\nlow_end_gpu = {low}\n')
with mock.patch.dict(os.environ, env, clear=True):
self.mg.guest_opt_ini(out)
self.assertEqual(os.environ.get('NX2NAVI_GUEST_OPT'), '2' if taken else None, low)
def test_cache_from_before_carrying_names_its_translator(self):
"""Before a new translator goes beside the game, a shader cache with no identities.txt gets one naming the
translator still there, in the form runtime/gfx_shader.c reads (ids_parse): '#' lines, then 64 hex digits."""

View File

@@ -1627,10 +1627,15 @@ def pgo_gen_record(out, clang, env):
(raw / PGO_TRAINING).write_text(json.dumps(record, indent=1) + '\n', encoding='utf-8')
# The values a switch (a row of runtime/cfg.c metas[] whose set is 0|1) reads as off, in any case (cfg.c switch_of).
SWITCH_OFF = ('0', 'off', 'false', 'no')
def guest_opt_ini(out):
"""NX2NAVI_GUEST_OPT from nx2navi.ini next to the exe (the low-end GPU rows of the menu's Game tab write it there)
when the environment does not set it: the next build of the game folder out takes it. Only while low_end_gpu = 1
is in the file too: the mode's settings count only with the mode on (runtime/cfg.c LOWEND_ONLY)."""
when the environment does not set it: the next build of the game folder out takes it. Only while low_end_gpu is on
in the file too (not empty, 0, off, false or no, as runtime/cfg.c lowend_of reads it): the mode's settings count
only with the mode on (runtime/cfg.c LOWEND_ONLY)."""
if os.environ.get('NX2NAVI_GUEST_OPT', '').strip():
return
found, low = '', False
@@ -1642,7 +1647,7 @@ def guest_opt_ini(out):
if eq and key in ('guest_opt', 'nx2navi_guest_opt') and value:
found = value
if eq and key in ('low_end_gpu', 'nx2navi_low_end_gpu'):
low = value not in ('', '0')
low = value.lower() not in ('', *SWITCH_OFF)
except OSError:
pass
if found and low:
@@ -2186,20 +2191,37 @@ def note_cache_translator(out):
os.replace(tmp, ids)
def ini_choice(raw):
"""The value of a setting with a set of values as runtime/cfg.c cfg_load reads it from nx2navi.ini, raw being the
text after '=': unless the whole value is in double quotes, it ends at the first blank followed by ';' or '#'
(cfg.c cut_comment); a value in double quotes then loses them."""
v = raw.strip()
if not (len(v) >= 2 and v[0] == v[-1] == '"'):
m = re.search(r'[ \t][;#]', raw)
if m:
v = raw[:m.start()].strip()
return v[1:-1] if len(v) >= 2 and v[0] == v[-1] == '"' else v
def shader_carry(out):
"""Whether the game carries the shaders prepared before an update over (runtime/gfx_shader.c, NX2NAVI_SHADER_CARRY,
on unless the environment or nx2navi.ini sets it to 0) and there are some: shader-prepared.bin is written by a
finished preparation, and the cache must name the translator its translations are of (SHADER_IDS,
note_cache_translator), else the game has nothing to carry them over by."""
if os.environ.get('NX2NAVI_SHADER_CARRY', '').strip() == '0':
on unless set to 0, off, false or no) and there are some: shader-prepared.bin is written by a finished
preparation, and the cache must name the translator its translations are of (SHADER_IDS, note_cache_translator),
else the game has nothing to carry them over by. The switch is read as the game reads it (runtime/cfg.c): the
environment wins over nx2navi.ini and is taken as written; in the file the last line with a value wins, its
comment cut (ini_choice). Where this read differs from the game's, an update skips a preparation the game will not
carry over, or prepares what it would."""
v = os.environ.get('NX2NAVI_SHADER_CARRY', '').strip()
if not v:
try:
for line in (out / 'nx2navi.ini').read_text(encoding='utf-8-sig', errors='replace').splitlines():
k, eq, raw = line.strip().partition('=')
if eq and k.strip().upper().removeprefix('NX2NAVI_') == 'SHADER_CARRY' and ini_choice(raw):
v = ini_choice(raw)
except OSError:
pass
if v.lower() in SWITCH_OFF:
return False
try:
for line in (out / 'nx2navi.ini').read_text(encoding='utf-8-sig', errors='replace').splitlines():
k, eq, v = line.strip().partition('=')
if eq and k.strip().upper().removeprefix('NX2NAVI_') == 'SHADER_CARRY' and v.strip().strip('"') == '0':
return False
except OSError:
pass
return (out / 'shader-prepared.bin').is_file() and bool(cache_identities(out))