ludic.things: a removed Thing's record placed again, oldest first past a lag of 32; things_reserve sizes the grid once
thing_put and thing_spawn made a new record for every Thing placed, and the world places and removes them all day (an animal's sign and bed, a drop, a fish), so play grew by a record per placement. Removed records wait in a queue compacted in place; once 32 wait, the oldest is set back as new with a new uid. ludic.base's grid_reserve makes the buckets for n rows now, since a rehash in play leaves the old bucket array behind. Tests: a record comes back only past the lag, as new, with a new uid, the indexes agree, and the spare queue stays bounded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5d71892b7c
commit
1af62d0879
7 changed files with 101 additions and 2 deletions
|
|
@ -215,4 +215,30 @@ program ThingsTest {
|
|||
expect(out[0] == a)
|
||||
expect_eq(things_changed(things_st, seen, rows, out), 2)
|
||||
}
|
||||
test "a removed Thing's record is placed again once enough wait, as new, with a new uid" (things_st: mut ThingsState) {
|
||||
things_reset(things_st)
|
||||
let first = thing_put(things_st, TH_LURE, "lure", 1.0, 1.0, 0.0, 0.0, 2.0, 7)
|
||||
first.used = 5
|
||||
first.owner = 3
|
||||
thing_hide(first)
|
||||
let old_uid = first.uid
|
||||
thing_remove(things_st, first)
|
||||
for i in 0 .. 32 { thing_remove(things_st, thing_put(things_st, TH_BRANCH, "branch", float(i), 0.0, 0.0, 0.0, 1.5, 0)) }
|
||||
expect_eq(things_spare_count(things_st), 33)
|
||||
let again = thing_put(things_st, TH_SIGN, "sign", 4.0, 4.0, 0.0, 0.0, 2.0, 1)
|
||||
let ap: pointer = again
|
||||
let fp: pointer = first
|
||||
expect(ap == fp)
|
||||
expect(again.uid != old_uid)
|
||||
expect_eq(again.kind, TH_SIGN)
|
||||
expect_eq(again.used, 0)
|
||||
expect_eq(again.owner, -1)
|
||||
expect(again.active)
|
||||
expect_eq(thing_nearest(things_st, TH_SIGN, 4.0, 4.0).uid, again.uid)
|
||||
expect_eq(things_verify(things_st), 0)
|
||||
for i in 0 .. 500 { thing_remove(things_st, thing_put(things_st, TH_BRANCH, "branch", 0.0, float(i), 0.0, 0.0, 1.5, 0)) }
|
||||
expect(things_spare_count(things_st) <= 33)
|
||||
things_reserve(things_st, 5000)
|
||||
expect_eq(things_verify(things_st), 0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue