mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 10:05:23 +01:00
0031e27dba
The world system is no longer a flat stereographic projection around Warsaw in int32 at 2^-10 m. Absolute positions are int64 micrometres in ECEF, the tiles lie on a cube sphere with their frames written in the data, and the curvature is in the data. Three bodies (the Earth, a fictional planet, a plane) share tiles, layers and streaming; old .scn compile onto the plane and behave as today. The layers stream apart, the logic by regions and the state of the simulation. The source (text regions in the SVN) is apart from the GPU cache. Names get the package's name space, joins between sceneries are shared nodes. The plan is seven steps from staging. The open questions of the review get proposals: railway geometry as an optional segment kind (from the //$h designs of the track editor), tile levels 13 and 10, an own cube grid instead of S2, Copernicus DEM and Sentinel-2 for the Earth outside sceneries, PL-geoid2021 and EGM2008, and the load rule of the logic regions. Moved without rewriting: the physics on the scale of a country (docs/physics-country-scale.md), Lua in sceneries (docs/scenery-lua.md), the review of what loads the renderer (docs/renderer-load-review.md) and the findings to be filed (docs/world-format-findings.md).
3.2 KiB
3.2 KiB
Lua in sceneries
As of 02.12.2026. Split out of the design of the world format (docs/world-format-eu07.md, #516). Settled on 26.11.2026: in the end
Lua describes the logic of a scenery, and the classic events stay as a compatibility format, always read.
Lua today
- LuaJIT (Lua 5.1), the
WITH_LUAoption, on by default. A scenery loads a script with theluadirective in.scn(state_serializer::deserialize_lua). - The
eu07.eventsAPI (scripting/lua.cpp): creating, finding and triggering events, the occupancy of tracks and isolated sections, reading and writing memcells,dynobj_putvalues,randomand the log. An event of typeluacalls a Lua function. - Scenery scripts have the full standard library (
luaL_openlibs),ioandosincluded. Screen scripts (scripting/luaprogram.cpp) already run in a sandbox, with an instruction limit. - Objects reach Lua as raw pointers (
lightuserdata).
Lua: the target
| Stage | Scope | Compatibility |
|---|---|---|
| L1 Full API | every event type, memcells, launchers as callbacks (entering a track, time, radius), model state, sounds | events work as today |
L2 Lua in .eu07 |
scenery scripts in the logic layer of the package as source text; LuaJIT bytecode isn't portable between versions | the lua directive in .scn keeps working |
| L3 Converter | the compiler or the editor turns classic events into equivalent Lua code; a self-test compares the result with the original | .scn with events always read |
| L4 Lua by default | new sceneries write their logic in Lua, the editor edits it | events still supported |
Requirements for Lua in the new format:
- Handles instead of pointers. Objects by id from the name table. Pointers used as table keys give a
pairsorder that depends on addresses, that is different on different machines. - Determinism. A network game repeats commands step by step, and the blackbox replays a run. A script uses only simulation time
and
eu07.randomseeded by the game.os.time,os.clockandmath.randomare blocked or replaced. - A sandbox as in the screens:
string,math,table, noio,osor files from outside the scenery, with an instruction limit per step. Scripts from theluadirective run by default as today, with the full library. In pctga, however, there isn't a single scenery Lua script, so the sandbox can be the default for all at no cost to compatibility. The sandbox applies to the new API from L2, and for old scripts a switch ineu07.initurns it on. - Order. Lua callbacks run at a fixed place of the simulation step, in the order of the event queue, never from other threads.
- Positions in the API, if they come, are in the scenery's system, as in
.scn. A script then doesn't depend on the world system. A separate function transforms them. - Streaming. Lua doesn't touch the data of tiles. Changes of look go through the state in the logic.
Stages and the world format
The Lua stages go in parallel with the world format. L1 doesn't depend on the format and can start right away on staging. L2 needs
the logic layer of the source format (step 2 of the world format plan). L3 and L4 come after the editor saves the source format, as
the converter and the Lua editing go through the editor.