MCPcopy Create free account
hub / github.com/axmolengine/axmol / loadNavMeshFile

Method loadNavMeshFile

core/navmesh/NavMesh.cpp:161–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161bool 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);

Callers

nothing calls this directly

Calls 14

getInstanceFunction · 0.85
dtAllocNavMeshFunction · 0.85
dtStatusFailedFunction · 0.85
dtAllocTileCacheFunction · 0.85
dtAllocFunction · 0.85
dtAllocCrowdFunction · 0.85
dtAllocNavMeshQueryFunction · 0.85
getDataFromFileMethod · 0.80
isNullMethod · 0.80
getBytesMethod · 0.80
buildNavMeshTileMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected