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>
59 lines
1.7 KiB
Text
59 lines
1.7 KiB
Text
# ludic.base/queue.ludic - a mechanic reports what HAPPENED as facts in a queue it owns, and the
|
|
# game drains it in a later phase. First in, first out; nothing here rolls dice or reorders.
|
|
export property Queue<T> {
|
|
items: []T = null
|
|
tag: QueueTag = null
|
|
}
|
|
# what a queue says about itself, whatever it holds: its name and how many facts wait in it
|
|
export property QueueTag {
|
|
name: string = ""
|
|
pending: int = 0
|
|
}
|
|
|
|
# BaseState is the system runner's (system.ludic). A queue keeps its own count, so pushing and
|
|
# draining one takes only the state that owns the queue.
|
|
export state BaseState {
|
|
cs_list: []System = null
|
|
}
|
|
|
|
# a queue; the name is only for core_undrained
|
|
export function queue_new<T>(name: string) -> Queue<T> {
|
|
let q = new Queue<T>
|
|
q.items = new []T
|
|
q.tag = new QueueTag
|
|
q.tag.name = name
|
|
return q
|
|
}
|
|
|
|
export function q_push<T>(q: Queue<T>, v: T) -> void {
|
|
push(q.items, v)
|
|
q.tag.pending = len(q.items)
|
|
}
|
|
|
|
# the facts in the order they were pushed; the queue is empty afterwards
|
|
export function q_drain<T>(q: Queue<T>) -> []T {
|
|
let out = q.items
|
|
q.items = new []T
|
|
q.tag.pending = 0
|
|
return out
|
|
}
|
|
|
|
export function q_len<T>(q: Queue<T>) -> int { return len(q.items) }
|
|
|
|
export function q_clear<T>(q: Queue<T>) -> void {
|
|
q.items = new []T
|
|
q.tag.pending = 0
|
|
}
|
|
|
|
# a queue's tag, for core_undrained: queues of different facts in one list
|
|
export function q_tag<T>(q: Queue<T>) -> QueueTag { return q.tag }
|
|
|
|
# the names of the given queues still holding facts; ask it at the end of a frame, where a fact
|
|
# left behind is a route nobody wrote
|
|
export function core_undrained(tags: []QueueTag) -> []string {
|
|
let out = new []string
|
|
for i in 0 .. len(tags) {
|
|
if tags[i] != null and tags[i].pending > 0 { push(out, tags[i].name) }
|
|
}
|
|
return out
|
|
}
|