| 159 | } |
| 160 | |
| 161 | bool NavMesh::loadNavMeshFile() |
| 162 | { |
| 163 | auto data = FileUtils::getInstance()->getDataFromFile(_navFilePath); |
| 164 | if (data.isNull()) |
| 165 | return false; |
| 166 | |
| 167 | // Read header. |
| 168 | unsigned int offset = 0; |
| 169 | TileCacheSetHeader header = *(reinterpret_cast<TileCacheSetHeader*>(data.getBytes() + offset)); |
| 170 | offset += sizeof(TileCacheSetHeader); |
| 171 | if (header.magic != TILECACHESET_MAGIC) |
| 172 | { |
| 173 | return false; |
| 174 | } |
| 175 | if (header.version != TILECACHESET_VERSION) |
| 176 | { |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | _navMesh = dtAllocNavMesh(); |
| 181 | if (!_navMesh) |
| 182 | { |
| 183 | return false; |
| 184 | } |
| 185 | dtStatus status = _navMesh->init(&header.meshParams); |
| 186 | if (dtStatusFailed(status)) |
| 187 | { |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | _tileCache = dtAllocTileCache(); |
| 192 | if (!_tileCache) |
| 193 | { |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | _allocator = new LinearAllocator(32000); |
| 198 | _compressor = new FastLZCompressor(); |
| 199 | _meshProcess = new MeshProcess(_geomData); |
| 200 | status = _tileCache->init(&header.cacheParams, _allocator, _compressor, _meshProcess); |
| 201 | |
| 202 | if (dtStatusFailed(status)) |
| 203 | { |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | // Read tiles. |
| 208 | for (int i = 0; i < header.numTiles; ++i) |
| 209 | { |
| 210 | TileCacheTileHeader tileHeader = *((TileCacheTileHeader*)(data.getBytes() + offset)); |
| 211 | offset += sizeof(TileCacheTileHeader); |
| 212 | if (!tileHeader.tileRef || !tileHeader.dataSize) |
| 213 | break; |
| 214 | |
| 215 | unsigned char* tileData = (unsigned char*)dtAlloc(tileHeader.dataSize, DT_ALLOC_PERM); |
| 216 | if (!tileData) |
| 217 | break; |
| 218 | memcpy(tileData, (data.getBytes() + offset), tileHeader.dataSize); |
nothing calls this directly
no test coverage detected