Encapsulate world state across all six ports: Level, Bsp, and node sum-types #1
Loading…
Reference in a new issue
No description provided.
Delete branch "refs/pull/1/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Removes global world state and "C-with-structs + free-functions" seams
across all six language ports, without changing rendered output or
controls. Each port keeps its own idioms — the fix is the same shape,
adapted per language, not a literal port of the C++ classes.
The three seams addressed (where each applies):
Leveltype owning vertices/sectors/linedefs,threaded explicitly into player/renderer/BSP. (all six ports)
Bsptype exposingfindSector/traverse, build/classify kept private.boolflag → the language's native sum type.Per port
Level+Bsp+Visplaneclasses; node →std::variant<Leaf, Internal>Levelstruct +Bspstruct (node enum &Visplanewere already idiomatic)Level+BSPtype; node → sealedbspNodeinterface + type-switchLevel+Bsp;Visplanefields sealed behind accessors (node already anenum)Level+Bspclass; node → `BSPLeafLevelstruct of slices — kept comptime/.rodata, zero runtime cost (rest already idiomatic)Plain value aggregates (Vec2, RGBA, Sector, LineDef, Seg, Input) stay
structs everywhere — they have no invariant to protect.
Why
Every subsystem previously reached into module/package/static globals for
the map, making the dependency invisible, untestable against a fixture
map, and impossible to instantiate twice. After this, the map is a value
passed by reference and the BSP/Visplane invariants are owned by their
types.
Verification
Each port built clean on its own toolchain:
-Wall -Wextra(also ran + rendered identically), Swiftswift build,Go
go build+go vet, Rustcargo build(no new clippy lints),Python
py_compile+ BSP smoke test + API audit, Zigzig build.