ludic.things: a fact's record kept, in two halves swapped when a fact finds the queue empty
th_fact made a ThingFact per placement, removal and use, and the valley places and removes Things all day. The records come back two drains after they were handed out, so a reader placing a Thing while it reads the last drain's list never sees one change (the test holds exactly that). thing_use takes ThingsState mut, since it pushes a fact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
22d1e2d66a
commit
8a4f3f5ad6
6 changed files with 52 additions and 12 deletions
|
|
@ -246,4 +246,24 @@ program ThingsTest {
|
|||
expect_eq(things_spare_count(things_st), 95)
|
||||
expect_eq(thing_nearest(things_st, TH_SIGN, 9.0, 9.0).uid, warm.uid)
|
||||
}
|
||||
test "a fact's record is kept: a drained list holds still while its reader places a Thing, and comes back two drains on" (things_st: mut ThingsState) {
|
||||
things_reset(things_st)
|
||||
q_clear(things_facts(things_st))
|
||||
let a = thing_put(things_st, TH_SIGN, "sign", 1.0, 0.0, 0.0, 0.0, 2.0, 1)
|
||||
thing_put(things_st, TH_SIGN, "sign", 2.0, 0.0, 0.0, 0.0, 2.0, 2)
|
||||
let first = q_drain(things_facts(things_st))
|
||||
expect_eq(len(first), 2)
|
||||
let r0: pointer = first[0]
|
||||
thing_put(things_st, TH_BRANCH, "branch", 3.0, 0.0, 0.0, 0.0, 1.5, 0)
|
||||
expect_eq(first[0].uid, a.uid)
|
||||
expect_eq(first[0].what, THING_PLACED)
|
||||
let second = q_drain(things_facts(things_st))
|
||||
expect_eq(len(second), 1)
|
||||
expect_eq(second[0].kind, TH_BRANCH)
|
||||
thing_put(things_st, TH_LURE, "lure", 4.0, 0.0, 0.0, 0.0, 2.0, 0)
|
||||
let third = q_drain(things_facts(things_st))
|
||||
let r2: pointer = third[0]
|
||||
expect(r2 == r0)
|
||||
expect_eq(third[0].kind, TH_LURE)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue