compiler(0.R): a dispatched action's record is the queue's to keep - one list per action, filled in place, all free again when the drain ends
dispatch lowered to ludic_act_push(k, new A { ... }): a fresh record every dispatch, and an input
system dispatches Move and FrameTime every frame. The queue now keeps a list per action
(kept<k>, used<k>); ludic_act_new__A hands out the next (made only when all are queued), new's
emitter fills it field by field as it fills a fresh one (every field, default or given), and
drain_actions sets every used<k> back to 0 once the queue is empty. A reducer only ever reads
its action during the drain, so nothing sees a record after it is reused. Actions are visible
to the program's file, where the queue lives, as reducers already were.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e3c6088fb
commit
93bc8a90db
4 changed files with 65 additions and 7 deletions
|
|
@ -11,6 +11,15 @@ program ActionsTest {
|
|||
reducer Door on Knock(d: mut Door, a: Knock) {
|
||||
if a.times >= 2 { d.open = true }
|
||||
}
|
||||
state Tally {
|
||||
sum: int = 0
|
||||
words: string = ""
|
||||
}
|
||||
action Note { n: int = 7, word: string = "hi" }
|
||||
reducer Tally on Note(t: mut Tally, a: Note) {
|
||||
t.sum = t.sum + a.n
|
||||
t.words = t.words + a.word
|
||||
}
|
||||
function input_tick(t: Tick) -> void { dispatch Knock { times: 2 } }
|
||||
function sim_tick(d: mut Door, t: Tick) -> void {
|
||||
if d.open { d.seen = d.seen + "o" } else { d.seen = d.seen + "c" }
|
||||
|
|
@ -27,4 +36,16 @@ program ActionsTest {
|
|||
expect(d.open)
|
||||
expect_eq(d.seen, "o")
|
||||
}
|
||||
test "a dispatched record is kept and filled again: what a dispatch leaves out is its default, not the last one's" (t: Tally) {
|
||||
dispatch Note { n: 1, word: "a" }
|
||||
dispatch Note { n: 2, word: "b" }
|
||||
drain_actions()
|
||||
expect_eq(t.sum, 3)
|
||||
dispatch Note { }
|
||||
dispatch Note { word: "c" }
|
||||
dispatch Note { n: 5 }
|
||||
drain_actions()
|
||||
expect_eq(t.sum, 3 + 7 + 7 + 5)
|
||||
expect_eq(t.words, "abhichi")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue