// 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