diff --git a/packages/ludic.nav/README.md b/packages/ludic.nav/README.md index 0eabe81e..7c2a76a8 100644 --- a/packages/ludic.nav/README.md +++ b/packages/ludic.nav/README.md @@ -82,3 +82,12 @@ and `nav_crowd_us()` is what the stepping has cost. `nav_crowd_add_fixed` adds a but never steers (a player), which `nav_crowd_place` puts where it is, and how fast it goes, each frame. The mechanic decides and the crowd moves, and dropping a mesh drops its crowd first. On the test meadow, twenty walkers crossing head-on never come closer than their two radii, and a step costs about 12 us. + +## Tiles resident by chunk (phase 23.5b) + +`nav_load_index(kind, path)` loads a baked mesh as an index of its tiles and keeps its file open, +with no tile in yet. `nav_tiles_keep(kind, xs, zs, n, rin, rout)` reads in the tiles within `rin` +of any of the n points and lets go of those past `rout` of all of them. It is asked now and then, +not every frame. The file is read through `file_open`, so a shipped game reads straight from its +pack. `nav_tiles_in` / `_bytes` / `_all` say what is resident. Dropping the mesh closes the file. +On Maroon the 900 / 1100 m ring round the start holds 617 of 1807 tiles, 8.9 MB of a person's mesh. diff --git a/packages/ludic.nav/index.ludic b/packages/ludic.nav/index.ludic index 59dfbfc5..8ad555c6 100644 --- a/packages/ludic.nav/index.ludic +++ b/packages/ludic.nav/index.ludic @@ -9,3 +9,4 @@ import "state.ludic" import "build.ludic" import "query.ludic" import "crowd.ludic" +import "resident.ludic" diff --git a/packages/ludic.nav/lib/macos-arm64/libludicnav.dylib b/packages/ludic.nav/lib/macos-arm64/libludicnav.dylib index 9bfb38c7..d2f01a3d 100755 --- a/packages/ludic.nav/lib/macos-arm64/libludicnav.dylib +++ b/packages/ludic.nav/lib/macos-arm64/libludicnav.dylib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:422b71e66182f0c12a32fb4660c536b46d0665bfdd2fa3e6f751d16c14761b55 -size 198464 +oid sha256:8ef7c47b0bf408ed20ac01c4db36d814dbd87b7bb00e9eee44814f416deb21bc +size 199024 diff --git a/packages/ludic.nav/lib/windows-x64/ludicnav.dll b/packages/ludic.nav/lib/windows-x64/ludicnav.dll index 678bc410..e56176e9 100644 --- a/packages/ludic.nav/lib/windows-x64/ludicnav.dll +++ b/packages/ludic.nav/lib/windows-x64/ludicnav.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:14a3b0a5f6e6a6af79f8a6c205baeee57fc47d42148dec4190a8b3fdff633223 -size 375296 +oid sha256:ae422119b560c1f4f1c576a68129bb4b8f552330653578afb6412ccd6b5cc704 +size 377344 diff --git a/packages/ludic.nav/lib/windows-x64/ludicnav.lib b/packages/ludic.nav/lib/windows-x64/ludicnav.lib index e6dca282..2431f8dc 100644 --- a/packages/ludic.nav/lib/windows-x64/ludicnav.lib +++ b/packages/ludic.nav/lib/windows-x64/ludicnav.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:382674cb7e3141c20b852cd25b43c6348de433fad36141b97335c0c44de9b5c7 -size 6228 +oid sha256:2033bbdc0ee9a8b5d67eabb73f1b66dfedbc45ad3bc4aa6fc5445679f4b46547 +size 8192 diff --git a/packages/ludic.nav/native.ludic b/packages/ludic.nav/native.ludic index b7f59072..8f11a053 100644 --- a/packages/ludic.nav/native.ludic +++ b/packages/ludic.nav/native.ludic @@ -26,4 +26,14 @@ extern function nvc_crowd_speed(c: pointer, i: int, speed: float) -> void = "nav extern function nvc_crowd_update(c: pointer, dt: float) -> void = "nav_crowd_update" extern function nvc_crowd_read(c: pointer, i: int, out: pointer) -> int = "nav_crowd_read" extern function nvc_crowd_us(c: pointer) -> int = "nav_crowd_us" +extern function nvc_unstage(buf: pointer) -> void = "nav_unstage" +extern function nvc_index_open(head: pointer) -> pointer = "nav_index_open" +extern function nvc_index_count_in(head: pointer) -> int = "nav_index_count_in" +extern function nvc_index_put(h: pointer, rec: pointer, offset: long) -> int = "nav_index_put" +extern function nvc_index_count(h: pointer) -> int = "nav_index_count" +extern function nvc_index_tile(h: pointer, i: int, out: pointer) -> int = "nav_index_tile" +extern function nvc_index_offset(h: pointer, i: int) -> long = "nav_index_offset" +extern function nvc_index_size(h: pointer, i: int) -> int = "nav_index_size" +extern function nvc_index_in(h: pointer, i: int, data: pointer, size: int) -> int = "nav_index_in" +extern function nvc_index_out(h: pointer, i: int) -> int = "nav_index_out" extern function nvc_load_staged(buf: pointer, size: int) -> pointer = "nav_load_staged" diff --git a/packages/ludic.nav/native/shim/nav_resident.inl b/packages/ludic.nav/native/shim/nav_resident.inl new file mode 100644 index 00000000..d382748d --- /dev/null +++ b/packages/ludic.nav/native/shim/nav_resident.inl @@ -0,0 +1,72 @@ +// nav_resident.inl - a baked mesh whose tiles are resident by chunk (phase 23.5b): the file is +// indexed once (each tile's grid cell, where its bytes are, its ref), and a tile's bytes are read +// in when a player comes near and let go when all are far. The game reads the file (its reads are +// the pack's); the shim only parses what it is handed and keeps the index. + +// a mesh with no tiles yet, from nav_save's 40-byte head; null for anything else +NAV_SHIM void *nav_index_open(const unsigned char *head) { + int magic = 0, version = 0; + memcpy(&magic, head, 4); memcpy(&version, head + 4, 4); + if (magic != NAV_MAGIC || version != NAV_VERSION) return nullptr; + dtNavMeshParams p; + memset(&p, 0, sizeof(p)); + memcpy(p.orig, head + 12, 12); memcpy(&p.tileWidth, head + 24, 4); memcpy(&p.tileHeight, head + 28, 4); + memcpy(&p.maxTiles, head + 32, 4); memcpy(&p.maxPolys, head + 36, 4); + dtNavMesh *mesh = dtAllocNavMesh(); + if (!mesh || dtStatusFailed(mesh->init(&p))) { dtFreeNavMesh(mesh); return nullptr; } + return nav_open(mesh); +} +// how many tiles the file said it holds (from the same head) +NAV_SHIM int nav_index_count_in(const unsigned char *head) { + int count = 0; + memcpy(&count, head + 8, 4); + return count; +} + +// one tile's record, read at `offset`: its ref and size, and the start of its data (its header's +// magic, version, x, y). Returns the data's size, so the caller can seek past it; -1 when not a tile +NAV_SHIM int nav_index_put(void *h, const unsigned char *rec, long long offset) { + Nav *n = static_cast