예제 #1
0
 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);
 }
예제 #2
0
        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);
                                //ThreadStart childref = new ThreadStart(this.RunPlotter);
                                //Thread childThread = new Thread(childref);
                                Thread childThread = new Thread(() => RunPlotter(plotter, mapdata, this.OutputDir, cellx, celly));
                                childThread.Start();
                            }
                        }
                    }

                }
            }
        }