private static void RunPlotter(MMPlotter childPlotter, MMCellData childMapData, String OutputDir, int childCellX, int childCellY) { Console.WriteLine("Thread {0}x{1} started", childCellX, childCellY); childPlotter.PlotData(childMapData, OutputDir, childCellX, childCellY); MapMap.Main.numThreads--; Console.WriteLine("Thread {0}x{1} finished", childCellX, childCellY); }
public MMCellData Read(string datafile, string headerfile) { //this.cellData.Reset(); this.cellData = new MMCellData(); List<string> tiles = new List<string>(); if (File.Exists(headerfile)) { using (BinaryReader binReader = new BinaryReader(File.Open(headerfile, FileMode.Open))) { tiles = this.ReadHeader(binReader); } } if (tiles.Count > 0 && File.Exists(datafile)) { using (BinaryReader binReader = new BinaryReader(File.Open(datafile, FileMode.Open))) { this.cellData = this.ReadPack(binReader, tiles); } } return this.cellData; }
public void PlotData( MMCellData cellData, string outputDir, int cellx, int celly) { using (Graphics gfx = Graphics.FromImage(this.subCell)) { int drawx = 0; int drawy = 0; MMGridSquare gs; for (int subx = 0; subx < this.subDiv; subx++) { for (int suby = 0; suby < this.subDiv; suby++) { for (int z = 0; z < 8; z++) { int drawCnt = 0; for (int x = 0; x < this.subWH; x++) { for (int y = 0; y < this.subWH; y++) { drawx = this.startX + (x - y) * 64; if (this.dolayers == true) drawy = this.startY + (x + y) * 32; else drawy = (this.startY + (x + y) * 32) - (192 * z); gs = cellData.GetSquare(x+(subx*this.subWH), y+(suby*this.subWH), z); if (gs != null){ for (Int32 i = MMGridSquare.FLOOR; i <= MMGridSquare.TOP; i++){ foreach (MMTile mmtile in gs.GetTiles(i)){ bool isJumbo = false; String tile = mmtile.tile; if (tile.Replace("JUMBO", "") != tile){ isJumbo = true; } if (tile != null && this.textures.Textures.ContainsKey(tile)){ this.textures.Textures[tile].Draw(gfx, drawx + mmtile.offX, drawy + mmtile.offY); // Console.WriteLine("Drawing {0} at {1}+{2}x{3}+{4}", tile, drawx, mmtile.offX, drawy, mmtile.offY); drawCnt++; } else { //Console.WriteLine("tile {0} not found", tile); String needle = tile.Split('_')[0] + "_" + tile.Split('_')[1]; // Console.WriteLine("Searching for collage: {0}", needle); if (this.collages.ContainsKey(needle.Replace("JUMBO", ""))){ // Console.WriteLine("Drawing from collage instead"); Dictionary<String, List<String>> collageCategory; this.collages.TryGetValue(needle, out collageCategory); IEnumerable<String> sprites; sprites = collageCategory.ElementAt(rand.Next(0, collageCategory.Count)).Value; foreach (String sprite in sprites){ if (this.textures.Textures.ContainsKey(sprite)){ String rSprite = sprite; if (isJumbo && bigtree){ String[] splits = new String[4]; splits = sprite.Split('_'); rSprite = splits[0]+"_"+splits[1]+"JUMBO_"+splits[2]+"_"+splits[3]; } this.textures.Textures[rSprite].Draw(gfx, drawx + mmtile.offX, drawy + mmtile.offY); drawCnt++; //} else { //Console.WriteLine("Collages contain Unknown texture: {0}", sprite); } } //} else { //Console.WriteLine("Unknown texture: {0}", tile); } } } } } } } if (this.dolayers == true && drawCnt > 0) { this.subCell.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_layer_" + z + ".png", System.Drawing.Imaging.ImageFormat.Png); gfx.Clear(Color.Transparent); } } if (this.dolayers == false) { this.subCell.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_full.png", System.Drawing.Imaging.ImageFormat.Png); gfx.Clear(Color.Transparent); } } } } }
private void parseMapData() { MMCellReader cellReader = new MMCellReader(); MMBinReader binReader = new MMBinReader(); // MMPlotter plotter = new MMPlotter(this.divider, this.tex, this.dolayers, this.bigtree); foreach (string mapPath in this.mapsources) { if (Directory.Exists(mapPath)) { string[] packs = Directory.GetFiles(mapPath, "*.lotpack"); foreach (string file in packs) { string filename = file.Substring(file.LastIndexOf(Path.DirectorySeparatorChar) + 1); string[] fileparts = filename.Split(new Char[] { '.' }); string[] nameparts = fileparts[0].Split(new Char[] { '_' }); int cellx = Convert.ToInt32(nameparts[1]); int celly = Convert.ToInt32(nameparts[2]); if (cellx >= this.minX && cellx <= this.maxX && celly >= this.minY && celly <= this.maxY) { string headerFile = nameparts[1] + "_" + nameparts[2] + ".lotheader"; string headerPath = mapPath + Path.DirectorySeparatorChar + headerFile; if (File.Exists(headerPath)) // lotpack { Console.WriteLine("Working on cell: {0} - {1}", nameparts[1], nameparts[2]); MMCellData mapdata = cellReader.Read(file, headerPath); foreach (string savePath in this.mapsources) { string[] saves = Directory.GetFiles(savePath, "map_*_*.bin"); foreach (string binfile in saves) // map_*_*.bin { string binfilename = binfile.Substring(binfile.LastIndexOf(Path.DirectorySeparatorChar) + 1); string[] binfileparts = binfilename.Split(new Char[] { '.' }); string[] binnameparts = binfileparts[0].Split(new Char[] { '_' }); int gsX = Convert.ToInt32(binnameparts[1]); int gsY = Convert.ToInt32(binnameparts[2]); int binToCellX = (int)Math.Floor(gsX * 10D / 300); int binToCellY = (int)Math.Floor(gsY * 10D / 300); if (binToCellX == cellx && binToCellY == celly) { // Console.WriteLine("Working on map_bin: {0} - {1}", binnameparts[1], binnameparts[2]); binReader.Read(binfile, mapdata, tileDefs, gsX * 10 % 300, gsY * 10 % 300); } } } while (MapMap.Main.numThreads >= maxThreads) { Thread.Sleep(500); } MapMap.Main.numThreads++; Console.WriteLine("Threads: {0}/{1}", MapMap.Main.numThreads, maxThreads); MMPlotter plotter = new MMPlotter(this.divider, this.tex, this.dolayers, this.bigtree, this.scale); //ThreadStart childref = new ThreadStart(this.RunPlotter); //Thread childThread = new Thread(childref); Thread childThread = new Thread(() => RunPlotter(plotter, mapdata, this.OutputDir, cellx, celly)); childThread.Start(); } } } } } }
public void Read(string datafile, MMCellData celldata, Dictionary<Int32, String> tileDefs, Int32 offX, Int32 offY) { this.delayedSprites = new List<Int32>(); this.celldata = celldata; this.tileDefs = tileDefs; this.offX = offX; this.offY = offY; if (File.Exists(datafile)) { this.binReader = new BinaryReader(File.Open(datafile, FileMode.Open)); this.ReadPack(); } return; }
public MMCellReader() { this.cellData = new MMCellData(); }