wip(ecs): ludic.wildlife on a Table<WildAnimal> - UNBUILT

Written while builds are held (agents share 16 GB; no build or run until the user lifts it), so
it has not been compiled or tested. The animals are rows of a ludic.base Table: x, z, species and
alive as columns, a 32 m grid over the living, the living by species, and a nid map.
wildlife_by_nid is a map lookup instead of a scan of every animal ever made, wildlife_count walks
only its species, wildlife_nearest asks the grid, wildlife_set_alive writes the flag and the row
together, and wildlife_refile files the tick's moves once after it (wildlife_verify holds the
columns to the records). A guest puts its whole table away and brings it back. A test case covers
them; to run once builds are allowed: ludic test packages/ludic.wildlife.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 21:21:29 +03:00
parent ab34f8229b
commit 5ac3d488a4
8 changed files with 142 additions and 15 deletions

View file

@ -230,4 +230,29 @@ program WildlifeTest {
expect_near(r.x, r.wx, 0.001)
expect(r.x != x0 or r.wx == r.sx)
}
test "the table: a nid finds its animal, the living count by species, the nearest, and a refile" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
fk_setup(wildlife_st, wildlife_tests_fake_st)
wildlife_clear(wildlife_st)
let a = wildlife_make(wildlife_st, 0, 10.0, 0.0, false, 0.0, 0, 1.0, 41)
let b = wildlife_make(wildlife_st, 0, 90.0, 0.0, false, 0.0, 0, 1.0, 42)
let c = wildlife_make(wildlife_st, 1, 30.0, 0.0, true, 0.0, 0, 1.0, 43)
expect(wildlife_by_nid(wildlife_st, 42) == b)
expect(wildlife_by_nid(wildlife_st, 7) == null)
expect_eq(wildlife_count(wildlife_st, 0), 2)
expect_eq(wildlife_count(wildlife_st, 1), 0)
expect(wildlife_nearest(wildlife_st, -1, 0.0, 0.0, 0.0) == a)
expect(wildlife_nearest(wildlife_st, 1, 0.0, 0.0, 0.0) == c)
wildlife_remove(a)
expect_eq(wildlife_count(wildlife_st, 0), 1)
expect(wildlife_nearest(wildlife_st, 0, 0.0, 0.0, 0.0) == b)
b.x = -5.0
wildlife_refile(wildlife_st)
expect(wildlife_nearest(wildlife_st, -1, 0.0, 0.0, 20.0) == b)
expect_eq(wildlife_verify(wildlife_st), 0)
expect_eq(wildlife_count_all(wildlife_st), 3)
wildlife_clear(wildlife_st)
expect_eq(wildlife_count_all(wildlife_st), 0)
expect(wildlife_by_nid(wildlife_st, 42) == null)
}
}