ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
3.7 KiB
Text
112 lines
3.7 KiB
Text
# store.ludic - the Things, and the only verbs that make, remove, move, show and hide one; each
|
|
# placing and removing is a fact, and the port is told at once so the game can draw it
|
|
export state ThingsState {
|
|
th_list: []Thing = null
|
|
th_uid: int = 0
|
|
th_facts: Queue<ThingFact> = null
|
|
th_marked: int = -1
|
|
}
|
|
|
|
export function things_facts(things_st: mut ThingsState) -> Queue<ThingFact> {
|
|
if things_st.th_facts == null { things_st.th_facts = queue_new("things.facts") }
|
|
return things_st.th_facts
|
|
}
|
|
|
|
function th_fact(things_st: mut ThingsState, what: int, t: Thing) -> void {
|
|
let f = new ThingFact
|
|
f.what = what
|
|
f.uid = t.uid
|
|
f.kind = t.kind
|
|
f.id = t.id
|
|
f.owner = t.owner
|
|
f.x = t.x
|
|
f.z = t.z
|
|
q_push(things_facts(things_st), f)
|
|
}
|
|
|
|
# whether a world has been set out (things_clear) since the program began
|
|
export function things_ready(things_st: ThingsState) -> bool { return things_st.th_list != null }
|
|
|
|
# every Thing, in the order placed; the list is the package's, never to be pushed to
|
|
export function things_all(things_st: mut ThingsState) -> []Thing {
|
|
if things_st.th_list == null { things_st.th_list = new []Thing }
|
|
return things_st.th_list
|
|
}
|
|
|
|
export function things_count(things_st: mut ThingsState) -> int { return len(things_all(things_st)) }
|
|
|
|
# a new world: every Thing forgotten, quietly (the game has already dropped its drawings)
|
|
export function things_clear(things_st: mut ThingsState) -> void { things_st.th_list = new []Thing }
|
|
|
|
export function thing_spawn(things_st: mut ThingsState, kind: int, look: string, x: float, y: float, z: float, yaw: float, id: int) -> Thing {
|
|
return th_place(things_st, new Thing, kind, look, x, y, z, yaw, id)
|
|
}
|
|
|
|
function th_place(things_st: mut ThingsState, t: Thing, kind: int, look: string, x: float, y: float, z: float, yaw: float, id: int) -> Thing {
|
|
t.kind = kind
|
|
t.look = look
|
|
t.x = x
|
|
t.y = y
|
|
t.z = z
|
|
t.yaw = yaw
|
|
t.id = id
|
|
things_st.th_uid += 1
|
|
t.uid = things_st.th_uid
|
|
push(things_all(things_st), t)
|
|
ThingsWorld.placed(t)
|
|
th_fact(things_st, THING_PLACED, t)
|
|
return t
|
|
}
|
|
|
|
# a Thing on the ground (the port's), set into it by `sink`, used from `reach`
|
|
export function thing_put(things_st: mut ThingsState, kind: int, look: string, x: float, z: float, yaw: float, sink: float, reach: float, id: int) -> Thing {
|
|
let t = new Thing
|
|
t.reach = reach
|
|
return th_place(things_st, t, kind, look, x, ThingsWorld.ground(x, z) - sink, z, yaw, id)
|
|
}
|
|
|
|
# gone for good
|
|
export function thing_remove(things_st: mut ThingsState, t: Thing) -> void {
|
|
if t == null { return }
|
|
things_st.th_marked = t.uid
|
|
things_drop(things_st, fn th_is_marked)
|
|
things_st.th_marked = -1
|
|
}
|
|
|
|
function th_is_marked(things_st: ThingsState, t: Thing) -> bool { return t.uid == things_st.th_marked }
|
|
|
|
# every Thing `gone` says so is removed for good
|
|
export function things_drop(things_st: mut ThingsState, gone: fn(Thing) -> bool) -> void {
|
|
let keep = new []Thing
|
|
let all = things_all(things_st)
|
|
for i in 0 .. len(all) {
|
|
let t = all[i]
|
|
if gone(t) {
|
|
ThingsWorld.removed(t)
|
|
th_fact(things_st, THING_REMOVED, t)
|
|
} else {
|
|
push(keep, t)
|
|
}
|
|
}
|
|
things_st.th_list = keep
|
|
}
|
|
|
|
export function thing_move(t: Thing, x: float, z: float, yaw: float) -> void {
|
|
thing_move_to(t, x, ThingsWorld.ground(x, z), z, yaw)
|
|
}
|
|
|
|
export function thing_move_to(t: Thing, x: float, y: float, z: float, yaw: float) -> void {
|
|
t.x = x
|
|
t.y = y
|
|
t.z = z
|
|
t.yaw = yaw
|
|
ThingsWorld.moved(t)
|
|
}
|
|
|
|
export function thing_set_active(t: Thing, on: bool) -> void {
|
|
if t == null { return }
|
|
t.active = on
|
|
ThingsWorld.shown(t)
|
|
}
|
|
export function thing_hide(t: Thing) -> void { thing_set_active(t, false) }
|
|
export function thing_show(t: Thing) -> void { thing_set_active(t, true) }
|