Skip to content

Architecture

The shape of a change

Most features follow the same pattern:

flowchart LR
  opt["Options tab<br/>(LuxMainMenu_Options)"] --> cfg["user / main settings"]
  cfg --> glue["Engine glue<br/>(LuxPlayer, LuxEffectHandler, ...)"]
  pure["Pure header<br/>(LuxComfort.h, LuxGuidance.h, ...)"] --> glue
  tests["tests/cpp"] --> pure
  glue --> game["What the player sees"]
  • The decision (how much to scale an effect, when an autosave is due, which prompt to show) is a small header with plain inputs and outputs, no engine types, and its own test file.
  • The glue in the game code reads the settings, asks the header, and applies the answer where the engine needs it. It stays short.
  • Changed lines in stock files carry an AMFP-2026 comment; new files open with an AMFP-2026: header comment that says what the file is for. The C++ reference is generated from exactly those new files.

Installing beside the game

The original exe always read config/main_init.cfg. The Enhanced exe first looks for amfp_enhanced/main_init.cfg (LuxInitConfigPath.h), which points to its own game.cfg, language folder and resources.cfg. That resource list names /amfp_enhanced/override first, and the engine keeps the first file it finds under a name, so our files win without editing the install. The installer generates all of these from the player's own copy of the game.

On Windows, the 64-bit game and its DLLs sit in amfp_enhanced/bin, away from the original game's 32-bit DLLs of the same names. A tiny launcher at the top of the game folder starts it with the game folder as working directory (LuxGameRoot.h).

Comfort: scale on output

The first version scaled the values map scripts asked for. That missed effects the game code starts by itself, baked scaled values into save games, and could not react when the option changed mid-effect. Now every effect keeps its original values, and the comfort multipliers are applied where each one reaches the camera or the screen:

Effect Where it is scaled
Screen shake where the offset reaches the camera; per-frame jitter is low-passed
Image trail, radial blur when handed to the post effect; blur starts outside the screen centre
Field of view pulses the final multiplier, clamped to a narrow band
Camera roll, lean tilt, death roll the roll angle
Hit head spin its speed, and a cap on the total angle
Head bob, landing bounce, hurt panting the bob amplitude
Forced turns and head moves a cap on the angular speed per frame
Lantern swing, arm lag swing amplitude, number of averaged samples
Infection look lag removed with Steady view

Removed amounts drive the edge darkening, drawn on the HUD with our own generated texture (tools/make_comfort_vignette.py). Original is not a set of values in a file: it is the built-in identity, so no setting can make it differ from the shipped game. The pure parts live in LuxComfort.h, LuxComfortCam.h, LuxComfortBody.h and LuxComfortFx.h.

Text: the Rust library

The .lang loader decoded only two-byte UTF-8, and word wrap broke lines only at spaces. Both are fixed in the engine (LangTextDecode.h, WordWrap.h), with the rules in a Rust crate, hpl-cjk-text:

  • It decodes UTF-8 to the engine's 16-bit text. Characters beyond the Basic Multilingual Plane become U+FFFD with a warning, never a surrogate pair, so a line break can never split one.
  • It decides where a line may break: between CJK characters, but never before closing punctuation (、。,」』)!? …) or after opening punctuation (「『( …).
  • The game links it statically through a small C interface (hpl_cjk_text.h, generated by cbindgen and committed). No panic crosses the boundary; all exported types are fixed-width.
  • The same crate is built as a Python module (PyO3), so the translation tooling uses exactly the rules the game uses.

The rule for choosing Rust: only where the logic is intricate, needs many tests, or is shared with the Python tooling. Short code close to engine state stays C++.

All text the new features show lives in overlay/amfp_enhanced/lang/enhanced_english.lang; nothing is hard-coded in the program. Translations ship as separate mods.

Loading

  • Map caches. The shipped .map_cache files are an older format the released engine rejects. The engine now writes its own on the first visit, to the save folder, and reuses them.
  • Progress. Static geometry and entities have counters in the engine. The other phases (script compile, setup, start scripts) are measured against how long they took the last time this map loaded, saved per map (LuxLoadProgress.h). The shown value never goes backwards.
  • Preload. From the current map's script (ChangeMap calls) and level doors, a low-priority thread reads the next maps' cache, map, model, material and texture files into the operating system's file cache (LuxPreload.h, LuxPreloader.cpp). It only reads, and is stopped before every load.

Saves

LuxAutoSave.h decides when an extra autosave is due (map change pending, or play time past the interval) and whether the moment is safe (in control, alive, no story scene, no menu, no enemy hunting). Autosaves (AutoSave_*) and manual saves (Save_*) are told apart by name; only autosaves rotate. With the option Off the game's own count (20) applies; otherwise the newest 5 are kept.

Physics

The original game ran a 32-bit build of the Newton physics engine. This build compiles Newton from source for 64-bit (and with its scalar maths path on ARM64). tools/dev/physics_check.py pushes the same objects the same way in both builds and compares traces: doors and levers swing, settle and come to rest the same within 7 mm and half a degree; a tumbling chair follows the same path until its first bounce, where tiny rounding differences send it another way.

Character animations

Most character animations are .FBX files. The original read them with Autodesk's FBX SDK 2012, which can no longer be obtained. MeshLoaderUfbx reads them with ufbx (MIT / public domain), with the same bone decomposition and key timing (FbxDecompose.h, FbxAnimTimes.h). Checked against the animation files the original loader produced, all 147 comparable animations have the same bones, keys and timing, their poses within 0.6 degrees and 2 mm (tools/dev/fbx_oracle.py).