Keep saves safe in Import Saves and Quit, draw no traced game art, and recompile the game for a new processor.

Import Saves: the saves folder picked in the dialog imports what waits in it (it had made the folder's README the
save); the save backed up is the one the game would load, in runtime/fs_host.c save_recover's order, so an interrupted
commit's only copy is kept, and the rest of the commit journal moves into the backup instead of being deleted; the
imported save goes into place before the old one is deleted, which comes back if that fails; another NX2navi install's
finished commit counts as its save. Tests cover each.

Quit waits while the game writes a save, as Restart does: the game runs on under the menu, and closing the window
finishes only a commit that has begun. The VSync row says "in use: Immediate" when VSync On falls back to tearing, and
its default follows the device profile (cfg_default). Without the game's textures the menu's divider is a plain line
and diamond of its own, not a tracing of the game's ornament.

make_game.py: the compile key holds the processor's features (cpu_tag), so a game folder moved to a PC without AVX2
compiles again instead of crashing; the main thread gets 16 MiB of stack with GNU ld too; any error waits for the
RomFS image, so its .part file is not cut short. The launcher tests use a neutral title id; tools/menu_preview.cpp
has cfg_default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 03:57:02 -05:00
parent 8daedbd806
commit f57a327a86
11 changed files with 166 additions and 93 deletions

View File

@@ -32,7 +32,8 @@ version (fast_clang: the same objects, about a fifth faster).
python tools/make_game.py --make-runtime-lib <kit>/lib --msys <ucrt64> # the release's prebuilt runtime
Nothing is written outside --out. The game folder then holds only what this PC built from the player's files: never
Nothing is written outside --out (but for --make-runtime-lib DIR, which writes DIR). The game folder then holds
only what this PC built from the player's files: never
share it. Needs Python 3.10+ with numpy, lz4, zstandard and zbic (pip), and MSYS2 UCRT64's clang and libraries
(README-BuildKit.md lists the commands). Delete <out>/build-cache afterwards to free about 5 GB; the next build then
compiles everything again.
@@ -938,7 +939,8 @@ def step_compile(out, cache_dir, msys, jobs, romfs_job=None):
rsp = cache_dir / 'link.rsp'
rsp.write_text('\n'.join('"%s"' % o.as_posix() for o in objs), encoding='utf-8')
# lld links several times faster than GNU ld; the stack matches tools/build_game.py's build
ld = ['-fuse-ld=lld', '-Wl,--stack,16777216'] if (msys / 'bin' / 'ld.lld.exe').is_file() else []
# 16 MiB for the main thread with either linker (GNU ld takes the same flag): the default 2 MiB is too little
ld = (['-fuse-ld=lld'] if (msys / 'bin' / 'ld.lld.exe').is_file() else []) + ['-Wl,--stack,16777216']
lib = ['-Wl,--whole-archive', str(prebuilt[0]), '-Wl,--no-whole-archive'] if prebuilt else []
stamp = [[o.name, o.stat().st_size, o.stat().st_mtime_ns] for o in objs]
if prebuilt:
@@ -1012,15 +1014,31 @@ def load_state(path):
return state
def cpu_tag():
"""This processor's features the lifted code's level follows (cpu_level), as Windows reports them; part of the
compile key, so a game folder moved to a PC without them (or a new processor) is compiled again rather than kept
with instructions the processor lacks. 'any' where it cannot be read."""
if os.name != 'nt':
return 'any'
try:
import ctypes
present = ctypes.windll.kernel32.IsProcessorFeaturePresent
# PF_SSE4_2_INSTRUCTIONS_AVAILABLE 38, PF_AVX2_INSTRUCTIONS_AVAILABLE 40, PF_AVX512F_INSTRUCTIONS_AVAILABLE 41
return ''.join('1' if present(f) else '0' for f in (38, 40, 41))
except (OSError, AttributeError):
return 'any'
def step_key(step, identity, out=None):
"""What a step's output depends on. exefs and romfs: the game files only; lift: the unpacked ExeFS and the
lifter; compile: the lift, the runtime sources and this script."""
lifter; compile: the lift, the runtime sources, this script and the processor (cpu_tag)."""
if step in ('exefs', 'romfs'):
return f'{step}-1|{identity}'
lift = f'lift|{exefs_digest(out)}|{lift_digest()}'
if step == 'lift':
return lift
compile_key = f'compile|{lift}|{tree_digest(KIT / "runtime", ("**/*",))}|{sha256_file(Path(__file__))}|{kit_version()}'
compile_key = (f'compile|{lift}|{tree_digest(KIT / "runtime", ("**/*",))}|{sha256_file(Path(__file__))}|{kit_version()}'
f'|cpu {cpu_tag()}')
if step == 'compile':
return compile_key
# shaders: the built game and the translator that prepared them
@@ -1130,8 +1148,9 @@ def main():
break
if romfs_job:
romfs_job.join()
except SystemExit:
# a failed lift or compile: the RomFS image still finishes and is kept, so the next run starts after it
except (SystemExit, Exception):
# a failed lift or compile, or an error of this script: the RomFS image still finishes and is kept, so the
# next run starts after it (the thread is a daemon, and the process ending would cut its .part file short)
if romfs_job and romfs_job.thread.is_alive():
say('waiting for the RomFS image before stopping')
romfs_job.thread.join()

View File

@@ -62,6 +62,10 @@ const char *cfg_value(const char *name) {
const CfgMeta *m = cfg_meta(name);
return v ? v : m ? m->def : "";
}
const char *cfg_default(const char *key) { // no device profile here: the row's own default
const CfgMeta *m = cfg_meta(key);
return m ? m->def : NULL;
}
int cfg_int(const char *name) { return atoi(cfg_value(name)); }
double cfg_double(const char *name) { return atof(cfg_value(name)); }
int cfg_bool(const char *name) { return strcmp(cfg_value(name), "0") != 0; }