Implement save/restore game state - #70
Conversation
…egistry, SAVE/RESTORE functions Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
|
@copilot Do you need _ZGLOBALS? there are SETG and GETG hence you can make these |
|
@copilot You'll need to modify compiler to emit SETG and GETG and add these functions to bootstrap |
… of compile-time _ZGLOBALS registration Co-authored-by: corepunch <83646194+corepunch@users.noreply.github.com>
Good point. Replaced the compile-time |
Already done in 053ba00: |
Game state could not be persisted between sessions. The fix moves dynamic state into
memso a mem dump captures everything, then addsSAVE/RESTOREprimitives that serialize and deserialize that state.Changes
zilscript/bootstrap.lua_ZGLOBALS = {}— global registry for ZIL game variable names, populated at runtime viaSETG; consumed bySAVE/RESTORESETG(name, val)/GETG(name)— new runtime functions;SETGsets the global in_G, registers its name in_ZGLOBALS, and returns the value;GETGreads from_GOBJECT()allocates 8 bytes inmemper object (o._flags_addr) for the FLAGS bitmask;FSET/FCLEARsync changes viawrite_flags_to_mem()so FLAGS are included in any mem dumpSAVE(filename)— writes: magic header + mem bytes (object properties, locations, FLAGS) + ZIL global values from_ZGLOBALS; mem is written in 4 KiB chunks to stay within Lua'stable.unpacklimitsRESTORE(filename)— reads the save file, restoresmem, re-syncs allo.FLAGScaches from mem, then restores ZIL globalszilscript/base.luaSETG/GETG(without_ZGLOBALStracking) so ZIL modules loaded via the bare loader without bootstrap continue to workzilscript/compiler/forms.luaGLOBALform now emitsSETG(%q, val)— global tracking happens automatically at runtime via theSETGfunction; no separate_ZGLOBALSregistration line neededSETGform now emitsSETG(%q, val)— consistent withGLOBAL, tracks globals at runtimeCONSTANTis a separate handler and intentionally does not useSETG(immutable at runtime)zil/test-save.zilONBIT), and numeric/boolean globals → saves → mutates all state → restores → asserts exact matchSave file format
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.