ludic/packages/ludic.vehicles/keep.ludic
Orkuncakilkaya fffedf71d0 ludic.physics, ludic.character, ludic.vehicles: fact records reused, and phys_sink allocates nothing
The per-frame sweep over physics, character, vehicles and nav found three fact makers that made a record per fact: contacts and splashes, the character's and the vehicles'. Each keeps a pool now, as wildlife's and npc's do (q_unheld). phys_sink, asked on every removal, built two new lists each time; it filters into a kept spare pair and swaps. ludic.nav's paths and crowds already allocate nothing, and none of the four builds a string per call. What remains at load, reset or a world swap is not per frame. vehicle_feed takes its state mut. vehicles_test: 1000 fed facts, drained turn by turn, use at most 4 records. All packages 421.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 02:03:09 +03:00

39 lines
1.5 KiB
Text

# keep.ludic - what a player does with their own between rides: hires it, feeds the horse, lets it
# wander where it is tied, and what a saved trip says of them
# hired or rented for the trip
export function vehicle_own(v: Vehicle) -> void { if v != null { v.owned = true } }
# hay for a horse, up to a full belly
export function vehicle_feed(vehicles_st: mut VehiclesState, v: Vehicle, amount: float) -> void {
if v == null { return }
v.food = Math.min(v.food + amount, 100.0)
ve_say(vehicles_st, VEHICLE_FED, v, amount)
}
# a horse nobody rides goes where its animal goes, round the home it is tied at (home_x, home_z)
export function vehicle_follow(v: Vehicle, x: float, y: float, z: float, yaw: float) -> void {
if v == null or v.rider >= 0 { return }
v.x = x
v.y = y
v.z = z
v.yaw = yaw
VehicleLegs.stand(v.nid, x, y, z)
}
# a saved trip's word on this player's own: hired, and how fed
export function vehicle_restore(vehicles_st: mut VehiclesState, kind: int, owned: bool, food: float) -> void {
if kind == VEHICLE_HORSE {
vehicles_st.ve_kept_horse = owned
vehicles_st.ve_kept_food = food
} else { vehicles_st.ve_kept_boat = owned }
let v = vehicle_find(vehicles_st, kind)
if v != null { ve_apply_kept(vehicles_st, v) }
}
function ve_apply_kept(vehicles_st: VehiclesState, v: Vehicle) -> void {
if v.kind == VEHICLE_HORSE {
v.owned = vehicles_st.ve_kept_horse
v.food = vehicles_st.ve_kept_food
} else { v.owned = vehicles_st.ve_kept_boat }
}