ludic/packages/ludic.vehicles/system.ludic
Orkuncakilkaya 231715bf98 fix(leaks): what play allocated every frame and never freed - a shadow uniform's name, the Tick, a ridden vehicle's moves
Found with malloc_history over 1200 frames of play without the interface (the first Ludic function
on each allocating stack, live bytes at two marks): sh_loc built `name + "[0]"` per program per pass
per frame - 24.6 MB of 33 in the window; its callers pass both names as literals now. tick_set fills
the frame loop's one Tick instead of tick_new making one a frame. A ridden boat or horse said
VEHICLE_MOVED as a new fact every frame; the metres are added up in VehiclesState and taken once
(vehicle_moved_take / _kind / _x / _z). Play's growth without the interface: 92 -> 14.7 MB a minute
(maroon-lake tests/leakcheck.sh); what is left is phys_push (Physics' fix on lang/nav) and the HUD's
strings. Packages 407, ludic-dev test 305 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 23:51:37 +03:00

46 lines
1.7 KiB
Text

# system.ludic - vehicles as a system: a reset, and this player's own saved by kind (hired or not,
# and the horse's hay); where they lie is not saved - they are called again. The boats' hulls are
# read back and pushed by the wind in vehicles_tick, which the game calls where the world is run
export function vehicles_reset(vehicles_st: mut VehiclesState) -> void {
let l = ve_all(vehicles_st)
for i in 0 .. len(l) {
let v = l[i]
if v.kind == VEHICLE_BOAT { VehicleHull.gone(v.nid) } else { VehicleLegs.gone(v.nid) }
v.ent = -1
}
tb_clear(vehicles_st.ve.tab)
imap_clear(vehicles_st.ve.nids)
vehicles_st.ve_cur = null
vehicles_st.ve_moved = 0.0
vehicles_st.ve_have_dock = false
vehicles_st.ve_swell_said = 0.0
vehicles_st.ve_kept_horse = false
vehicles_st.ve_kept_boat = false
vehicles_st.ve_kept_food = 40.0
q_clear(vehicle_facts(vehicles_st))
}
export function vehicles_save(vehicles_st: VehiclesState) -> Val {
let v = Value.object()
let h = vehicle_find(vehicles_st, VEHICLE_HORSE)
let b = vehicle_find(vehicles_st, VEHICLE_BOAT)
if h != null {
sv_put_bool(v, "horse_own", h.owned)
sv_put_float(v, "horse_food", h.food)
}
if b != null { sv_put_bool(v, "boat_own", b.owned) }
return v
}
export function vehicles_load(vehicles_st: mut VehiclesState, v: Val, version: int) -> void {
vehicle_drop(vehicles_st)
vehicle_restore(vehicles_st, VEHICLE_HORSE, sv_bool(v, "horse_own", false), sv_float(v, "horse_food", 40.0))
vehicle_restore(vehicles_st, VEHICLE_BOAT, sv_bool(v, "boat_own", false), 0.0)
}
export function vehicles_system() -> System {
let s = system_new("vehicles", PH_SIMULATE)
s.save = fn vehicles_save
s.load = fn vehicles_load
return s
}