public void AddBaseTile(uint packedGridPos, Detour.dtRawTileData data, MmapTileHeader fileHeader, uint dataSize) { if (!_baseTiles.ContainsKey(packedGridPos)) { PhasedTile phasedTile = new PhasedTile(); phasedTile.data = data; phasedTile.fileHeader = fileHeader; phasedTile.dataSize = (int)dataSize; _baseTiles[packedGridPos] = phasedTile; } }
public bool loadMap(uint mapId, int x, int y) { // make sure the mmap is loaded and ready to load tiles if (!loadMapData(mapId)) { return(false); } // get this mmap data MMapData mmap = loadedMMaps[mapId]; Contract.Assert(mmap.navMesh != null); // check if we already have this tile loaded uint packedGridPos = packTileID(x, y); if (mmap.loadedTileRefs.ContainsKey(packedGridPos)) { return(false); } // load this tile . mmaps/MMMXXYY.mmtile string filename = string.Format(TILE_FILE_NAME_FORMAT, Global.WorldMgr.GetDataPath(), mapId, x, y); if (!File.Exists(filename)) { Log.outDebug(LogFilter.Maps, "MMAP:loadMap: Could not open mmtile file '{0}'", filename); return(false); } using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read))) { MmapTileHeader fileHeader = reader.ReadStruct <MmapTileHeader>(); Array.Reverse(fileHeader.mmapMagic); if (new string(fileHeader.mmapMagic) != MapConst.mmapMagic) { Log.outError(LogFilter.Maps, "MMAP:loadMap: Bad header in mmap {0:D4}{1:D2}{2:D2}.mmtile", mapId, x, y); return(false); } if (fileHeader.mmapVersion != MapConst.mmapVersion) { Log.outError(LogFilter.Maps, "MMAP:loadMap: {0:D4}{1:D2}{2:D2}.mmtile was built with generator v{3}, expected v{4}", mapId, x, y, fileHeader.mmapVersion, MapConst.mmapVersion); return(false); } var bytes = reader.ReadBytes((int)fileHeader.size); Detour.dtRawTileData data = new Detour.dtRawTileData(); data.FromBytes(bytes, 0); ulong tileRef = 0; // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed if (Detour.dtStatusSucceed(mmap.navMesh.addTile(data, 0, 0, ref tileRef))) { mmap.loadedTileRefs.Add(packedGridPos, tileRef); ++loadedTiles; Log.outInfo(LogFilter.Maps, "MMAP:loadMap: Loaded mmtile {0:D4}[{1:D2}, {2:D2}]", mapId, x, y); var phasedMaps = phaseMapData.LookupByKey(mapId); if (!phasedMaps.Empty()) { mmap.AddBaseTile(packedGridPos, data, fileHeader, fileHeader.size); LoadPhaseTiles(phasedMaps, x, y); } return(true); } Log.outError(LogFilter.Maps, "MMAP:loadMap: Could not load {0:D4}{1:D2}{2:D2}.mmtile into navmesh", mapId, x, y); return(false); } }
bool LoadMapImpl(string basePath, uint mapId, uint x, uint y) { // make sure the mmap is loaded and ready to load tiles if (!LoadMapData(basePath, mapId)) { return(false); } // get this mmap data MMapData mmap = loadedMMaps[mapId]; Cypher.Assert(mmap.navMesh != null); // check if we already have this tile loaded uint packedGridPos = PackTileID(x, y); if (mmap.loadedTileRefs.ContainsKey(packedGridPos)) { return(false); } // load this tile . mmaps/MMMXXYY.mmtile string fileName = string.Format(TILE_FILE_NAME_FORMAT, basePath, mapId, x, y); if (!File.Exists(fileName)) { if (parentMapData.ContainsKey(mapId)) { fileName = string.Format(TILE_FILE_NAME_FORMAT, basePath, parentMapData[mapId], x, y); } } if (!File.Exists(fileName)) { Log.outDebug(LogFilter.Maps, "MMAP:loadMap: Could not open mmtile file '{0}'", fileName); return(false); } using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read))) { MmapTileHeader fileHeader = reader.Read <MmapTileHeader>(); if (fileHeader.mmapMagic != MapConst.mmapMagic) { Log.outError(LogFilter.Maps, "MMAP:loadMap: Bad header in mmap {0:D4}{1:D2}{2:D2}.mmtile", mapId, x, y); return(false); } if (fileHeader.mmapVersion != MapConst.mmapVersion) { Log.outError(LogFilter.Maps, "MMAP:loadMap: {0:D4}{1:D2}{2:D2}.mmtile was built with generator v{3}, expected v{4}", mapId, x, y, fileHeader.mmapVersion, MapConst.mmapVersion); return(false); } var bytes = reader.ReadBytes((int)fileHeader.size); Detour.dtRawTileData data = new Detour.dtRawTileData(); data.FromBytes(bytes, 0); ulong tileRef = 0; // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed if (Detour.dtStatusSucceed(mmap.navMesh.addTile(data, 1, 0, ref tileRef))) { mmap.loadedTileRefs.Add(packedGridPos, tileRef); ++loadedTiles; Log.outInfo(LogFilter.Maps, "MMAP:loadMap: Loaded mmtile {0:D4}[{1:D2}, {2:D2}]", mapId, x, y); return(true); } Log.outError(LogFilter.Maps, "MMAP:loadMap: Could not load {0:D4}{1:D2}{2:D2}.mmtile into navmesh", mapId, x, y); return(false); } }