feat(nav): 17.3 - a map in square tiles (nav_tiled, nav_tile_build; a tile must be a whole number of cells or its seams never join, and the shim refuses one that is not; 64-bit polygon refs for 16384 tiles), ground as a NavGround with boulders as convex footprints, one save format for one tile or many, and nav_random_near - a reachable point from the caller's seed, bit-identical on the Mac and the PC. 10 tests on both
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9b8606483d
commit
e6893f58be
16 changed files with 436 additions and 109 deletions
|
|
@ -3,47 +3,15 @@
|
|||
# the ford, stops at the bank when there is none, and a saved mesh answers as the built one did.
|
||||
import "ludic.nav"
|
||||
import "ludic.base"
|
||||
import "fakes/meadow.ludic"
|
||||
program NavTest {
|
||||
numbers float
|
||||
|
||||
# the meadow, flat at y = 0; river 1 has a ford at z 30..34, river 2 none, river 0 is no river
|
||||
function meadow(nav_st: mut NavState, kind: int, river: int, post: bool) -> bool {
|
||||
let n = 40
|
||||
let v = floats((n + 1) * (n + 1) * 3)
|
||||
for j in 0 .. n + 1 {
|
||||
for i in 0 .. n + 1 {
|
||||
let o = (j * (n + 1) + i) * 3
|
||||
v[o] = float(i)
|
||||
v[o + 1] = 0.0
|
||||
v[o + 2] = float(j)
|
||||
}
|
||||
}
|
||||
let t = new []int
|
||||
let area = buffer(n * n * 2)
|
||||
for j in 0 .. n {
|
||||
for i in 0 .. n {
|
||||
let a = j * (n + 1) + i
|
||||
push(t, a)
|
||||
push(t, a + n + 1)
|
||||
push(t, a + 1)
|
||||
push(t, a + 1)
|
||||
push(t, a + n + 1)
|
||||
push(t, a + n + 2)
|
||||
var k = 1
|
||||
if river > 0 and i >= 18 and i < 22 and not (river == 1 and j >= 30 and j < 34) { k = 0 }
|
||||
area[(j * n + i) * 2] = k
|
||||
area[(j * n + i) * 2 + 1] = k
|
||||
}
|
||||
}
|
||||
let cyl = floats(5)
|
||||
cyl[0] = 20.0
|
||||
cyl[1] = -1.0
|
||||
cyl[2] = 20.0
|
||||
cyl[3] = 2.0
|
||||
cyl[4] = 4.0
|
||||
var nc = 0
|
||||
if post { nc = 1 }
|
||||
return nav_build(nav_st, kind, v, (n + 1) * (n + 1), t, n * n * 2, area, cyl, nc, new NavConfig)
|
||||
let g = ground(40, river)
|
||||
if post { g.cyl = post_at(20.0, 20.0, 2.0) }
|
||||
if post { g.nc = 1 }
|
||||
return nav_build(nav_st, kind, g, new NavConfig)
|
||||
}
|
||||
function last_x(nav_st: NavState) -> float { return nav_corner_x(nav_st, nav_corners(nav_st) - 1) }
|
||||
function last_z(nav_st: NavState) -> float { return nav_corner_z(nav_st, nav_corners(nav_st) - 1) }
|
||||
|
|
@ -92,6 +60,31 @@ program NavTest {
|
|||
expect_eq(nav_path(nav_st, NAV_LARGE, 5.0, 0.0, 5.0, 10.0, 0.0, 10.0), -1)
|
||||
}
|
||||
|
||||
test "a random point near is always one a walker there can reach, and a seed is always the same point" (nav_st: mut NavState) {
|
||||
expect(meadow(nav_st, NAV_PERSON, 2, false))
|
||||
for seed in 0 .. 50 {
|
||||
expect(nav_random_near(nav_st, NAV_PERSON, 5.0, 0.0, 10.0, 30.0, seed))
|
||||
expect(nav_near_x(nav_st) < 18.0)
|
||||
}
|
||||
nav_random_near(nav_st, NAV_PERSON, 5.0, 0.0, 10.0, 30.0, 7)
|
||||
let x7 = nav_near_x(nav_st)
|
||||
let z7 = nav_near_z(nav_st)
|
||||
nav_random_near(nav_st, NAV_PERSON, 5.0, 0.0, 10.0, 30.0, 8)
|
||||
expect(Math.abs(nav_near_x(nav_st) - x7) + Math.abs(nav_near_z(nav_st) - z7) > 0.01)
|
||||
nav_random_near(nav_st, NAV_PERSON, 5.0, 0.0, 10.0, 30.0, 7)
|
||||
expect_eq(nav_near_x(nav_st), x7)
|
||||
expect_eq(nav_near_z(nav_st), z7)
|
||||
}
|
||||
|
||||
test "a boulder's footprint is walked round" (nav_st: mut NavState) {
|
||||
let g = ground(40, 0)
|
||||
g.foot = square_at(20.0, 20.0, 3.0)
|
||||
g.nf = len(g.foot)
|
||||
expect(nav_build(nav_st, NAV_PERSON, g, new NavConfig))
|
||||
expect(not nav_straight(nav_st, NAV_PERSON, 5.0, 0.0, 20.0, 35.0, 20.0))
|
||||
expect(nav_path(nav_st, NAV_PERSON, 5.0, 0.0, 20.0, 35.0, 0.0, 20.0) >= 3)
|
||||
}
|
||||
|
||||
test "a mesh saved and loaded answers as the built one did" (nav_st: mut NavState) {
|
||||
expect(meadow(nav_st, NAV_PERSON, 1, true))
|
||||
let path = Os.temp_dir() + "/ludic_nav_test.navmesh"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue