void buildMap(uint mapID) { var tiles = getTileList(mapID); // make sure we process maps which don't have tiles if (tiles.Count == 0) { // convert coord bounds to grid bounds getGridBounds(mapID, out uint minX, out uint minY, out uint maxX, out uint maxY); // add all tiles within bounds to tile list. for (uint i = minX; i <= maxX; ++i) { for (uint j = minY; j <= maxY; ++j) { uint packTileId = StaticMapTree.PackTileID(i, j); if (!tiles.Contains(packTileId)) { tiles.Add(packTileId); ++m_totalTiles; } } } } if (!tiles.Empty()) { // build navMesh dtNavMesh navMesh; buildNavMesh(mapID, out navMesh); if (navMesh == null) { Console.WriteLine($"[Map {mapID:D4}] Failed creating navmesh!"); m_totalTilesProcessed += tiles.Count; return; } // now start building mmtiles for each tile Console.WriteLine($"[Map {mapID:D4}] We have {tiles.Count} tiles. "); foreach (var it in tiles) { // unpack tile coords StaticMapTree.UnpackTileID(it, out uint tileX, out uint tileY); ++m_totalTilesProcessed; if (shouldSkipTile(mapID, tileX, tileY)) { continue; } buildTile(mapID, tileX, tileY, navMesh); } } Console.WriteLine($"[Map {mapID:D4}] Complete!"); }
void buildNavMesh(uint mapID, out dtNavMesh navMesh) { // if map has a parent we use that to generate dtNavMeshParams - worldserver will load all missing tiles from that map int navMeshParamsMapId = _vmapManager.GetParentMapId(mapID); if (navMeshParamsMapId == -1) { navMeshParamsMapId = (int)mapID; } SortedSet <uint> tiles = getTileList((uint)navMeshParamsMapId); // old code for non-statically assigned bitmask sizes: ///*** calculate number of bits needed to store tiles & polys ***/ //int tileBits = dtIlog2(dtNextPow2(tiles.size())); //if (tileBits < 1) tileBits = 1; // need at least one bit! //int polyBits = sizeof(dtPolyRef)*8 - SALT_MIN_BITS - tileBits; int polyBits = SharedConst.DT_POLY_BITS; int maxTiles = tiles.Count; int maxPolysPerTile = 1 << polyBits; /*** calculate bounds of map ***/ uint tileXMin = 64, tileYMin = 64, tileXMax = 0, tileYMax = 0; foreach (var it in tiles) { StaticMapTree.UnpackTileID(it, out uint tileX, out uint tileY); if (tileX > tileXMax) { tileXMax = tileX; } else if (tileX < tileXMin) { tileXMin = tileX; } if (tileY > tileYMax) { tileYMax = tileY; } else if (tileY < tileYMin) { tileYMin = tileY; } } // use Max because '32 - tileX' is negative for values over 32 float[] bmin; float[] bmax; getTileBounds(tileXMax, tileYMax, null, 0, out bmin, out bmax); /*** now create the navmesh ***/ // navmesh creation params dtNavMeshParams navMeshParams = new dtNavMeshParams(); navMeshParams.tileWidth = SharedConst.GRID_SIZE; navMeshParams.tileHeight = SharedConst.GRID_SIZE; rcVcopy(navMeshParams.orig, bmin); navMeshParams.maxTiles = maxTiles; navMeshParams.maxPolys = maxPolysPerTile; navMesh = new dtNavMesh(); if (dtStatusFailed(navMesh.init(navMeshParams))) { Console.WriteLine($"[Map: {mapID:D4}] Failed creating navmesh!"); return; } string fileName = $"mmaps/{mapID:D4}.mmap"; using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create, FileAccess.Write))) { // now that we know navMesh params are valid, we can write them to file writer.Write(bmin[0]); writer.Write(bmin[1]); writer.Write(bmin[2]); writer.Write(SharedConst.GRID_SIZE); writer.Write(SharedConst.GRID_SIZE); writer.Write(maxTiles); writer.Write(maxPolysPerTile); } }
public void buildMap(uint mapID) { int cursorLeft; int cursorTop; lock (_lock) { cursorLeft = Console.CursorLeft; cursorTop = Console.CursorTop; Console.WriteLine($"[Map: {mapID:D4} - 0%]"); } var tiles = getTileList(mapID); // make sure we process maps which don't have tiles if (tiles.Count == 0) { // convert coord bounds to grid bounds getGridBounds(mapID, out uint minX, out uint minY, out uint maxX, out uint maxY); // add all tiles within bounds to tile list. for (uint i = minX; i <= maxX; ++i) { for (uint j = minY; j <= maxY; ++j) { uint packTileId = StaticMapTree.PackTileID(i, j); if (!tiles.Contains(packTileId)) { tiles.Add(packTileId); } } } } if (!tiles.Empty()) { // build navMesh dtNavMesh navMesh; buildNavMesh(mapID, out navMesh); if (navMesh == null) { lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write($"[Map: {mapID:D4}] - Failed creating navmesh!"); } return; } // now start building mmtiles for each tile int i = 0; foreach (var tileId in tiles) { // unpack tile coords StaticMapTree.UnpackTileID(tileId, out uint tileX, out uint tileY); if (!shouldSkipTile(mapID, tileX, tileY)) { lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.Write($"[Map: {mapID:D4} - {i * 100 / tiles.Count}%] - Building tile [{tileX:D2},{tileY:D2}]"); } buildTile(mapID, tileX, tileY, navMesh); } ++i; } } lock (_lock) { Console.SetCursorPosition(cursorLeft, cursorTop); Console.WriteLine($"[Map: {mapID:D4}] - Done!"); } }
public bool convertWorld2() { bool success = readMapSpawns(); if (!success) { return(false); } float invTileSize = 1.0f / 533.33333f; // export Map data foreach (var mapPair in mapData) { var mapSpawn = mapPair.Value; // build global map tree List <ModelSpawn> mapSpawns = new List <ModelSpawn>(); Console.WriteLine($"Calculating model bounds for map {mapPair.Key}..."); foreach (var entry in mapSpawn.UniqueEntries.Values) { // M2 models don't have a bound set in WDT/ADT placement data, i still think they're not used for LoS at all on retail if (Convert.ToBoolean(entry.flags & ModelFlags.M2)) { if (!calculateTransformedBound(entry)) { continue; } } mapSpawns.Add(entry); spawnedModelFiles.Add(entry.name); var tileEntries = Convert.ToBoolean(entry.flags & ModelFlags.ParentSpawn) ? mapSpawn.ParentTileEntries : mapSpawn.TileEntries; AxisAlignedBox bounds = entry.iBound; Vector2 low = new Vector2(bounds.Lo.X * invTileSize, bounds.Lo.Y * invTileSize); Vector2 high = new Vector2(bounds.Hi.X * invTileSize, bounds.Hi.Y * invTileSize); for (uint x = (ushort)low.X; x <= (ushort)high.X; ++x) { for (uint y = (ushort)low.Y; y <= (ushort)high.Y; ++y) { tileEntries.Add(StaticMapTree.PackTileID(x, y), new TileSpawn(entry.ID, entry.flags)); } } } Console.WriteLine($"Creating map tree for map {mapPair.Key}..."); BIH pTree = new BIH(); pTree.build(mapSpawns, BoundsTrait.GetBounds); // ===> possibly move this code to StaticMapTree class // write map tree file string mapfilename = $"{iDestDir}/{mapPair.Key:D4}.vmtree"; using (BinaryWriter writer = new BinaryWriter(File.Open(mapfilename, FileMode.Create, FileAccess.Write))) { //general info writer.WriteString(SharedConst.VMAP_MAGIC); // Nodes writer.WriteString("NODE"); pTree.writeToFile(writer); // spawn id to index map writer.WriteString("SIDX"); writer.Write(mapSpawns.Count); for (int i = 0; i < mapSpawns.Count; ++i) { writer.Write(mapSpawns[i].ID); writer.Write(i); } } // write map tile files, similar to ADT files, only with extra BIH tree node info foreach (var key in mapSpawn.TileEntries.Keys) { var spawnList = mapSpawn.TileEntries[key]; uint x, y; StaticMapTree.UnpackTileID(key, out x, out y); string tilefilename = $"{iDestDir}/{mapPair.Key:D4}_{y:D2}_{x:D2}.vmtile"; using (BinaryWriter writer = new BinaryWriter(File.Open(tilefilename, FileMode.Create, FileAccess.Write))) { var parentTileEntries = mapPair.Value.ParentTileEntries[key]; int nSpawns = spawnList.Count + parentTileEntries.Count; // file header writer.WriteString(SharedConst.VMAP_MAGIC); // write number of tile spawns writer.Write(nSpawns); // write tile spawns foreach (var tileSpawn in spawnList) { ModelSpawn.WriteToFile(writer, mapPair.Value.UniqueEntries[tileSpawn.Id]); } foreach (var spawnItr in parentTileEntries) { ModelSpawn.WriteToFile(writer, mapPair.Value.UniqueEntries[spawnItr.Id]); } } } } // add an object models, listed in temp_gameobject_models file exportGameobjectModels(); // export objects Console.WriteLine("Converting Model Files"); foreach (var mfile in spawnedModelFiles) { Console.WriteLine($"Converting {mfile}"); convertRawFile(mfile); } return(success); }