feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune

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>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-26 04:19:56 +03:00
parent 8cf4b3fed6
commit 71735b10a2
151 changed files with 58668 additions and 54719 deletions

View file

@ -7,12 +7,12 @@ export state ThingsState {
th_marked: int = -1
}
export function things_facts(base_st: mut BaseState, things_st: mut ThingsState) -> Queue<ThingFact> {
if things_st.th_facts == null { things_st.th_facts = queue_new(base_st, "things.facts") }
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(base_st: mut BaseState, things_st: mut ThingsState, what: int, t: Thing) -> void {
function th_fact(things_st: mut ThingsState, what: int, t: Thing) -> void {
let f = new ThingFact
f.what = what
f.uid = t.uid
@ -21,7 +21,7 @@ function th_fact(base_st: mut BaseState, things_st: mut ThingsState, what: int,
f.owner = t.owner
f.x = t.x
f.z = t.z
q_push(base_st, things_facts(base_st, things_st), f)
q_push(things_facts(things_st), f)
}
# whether a world has been set out (things_clear) since the program began
@ -38,11 +38,11 @@ export function things_count(things_st: mut ThingsState) -> int { return len(thi
# 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(base_st: mut BaseState, things_st: mut ThingsState, kind: int, look: string, x: float, y: float, z: float, yaw: float, id: int) -> Thing {
return th_place(base_st, things_st, new Thing, kind, look, x, y, z, yaw, id)
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(base_st: mut BaseState, things_st: mut ThingsState, t: Thing, kind: int, look: string, x: float, y: float, z: float, yaw: float, id: int) -> Thing {
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
@ -54,36 +54,36 @@ function th_place(base_st: mut BaseState, things_st: mut ThingsState, t: Thing,
t.uid = things_st.th_uid
push(things_all(things_st), t)
ThingsWorld.placed(t)
th_fact(base_st, things_st, THING_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(base_st: mut BaseState, things_st: mut ThingsState, kind: int, look: string, x: float, z: float, yaw: float, sink: float, reach: float, id: int) -> Thing {
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(base_st, things_st, t, kind, look, x, ThingsWorld.ground(x, z) - sink, z, yaw, id)
return th_place(things_st, t, kind, look, x, ThingsWorld.ground(x, z) - sink, z, yaw, id)
}
# gone for good
export function thing_remove(base_st: mut BaseState, things_st: mut ThingsState, t: Thing) -> void {
export function thing_remove(things_st: mut ThingsState, t: Thing) -> void {
if t == null { return }
things_st.th_marked = t.uid
things_drop(base_st, things_st, fn th_is_marked)
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(base_st: mut BaseState, things_st: mut ThingsState, gone: fn(Thing) -> bool) -> void {
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(base_st, things_st, THING_REMOVED, t)
th_fact(things_st, THING_REMOVED, t)
} else {
push(keep, t)
}