예제 #1
0
 // Sims = simular tiles
 public void CountSims(List<string> sourceDir, int minx, int maxx, int miny, int maxy)
 {
     MMCellReader cellReader = new MMCellReader();
     foreach (string mapPath in sourceDir)
     {
         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 >= minx && cellx < maxx && celly >= miny && celly < maxy)
                 {
                     string headerFile = nameparts[1] + "_" + nameparts[2] + ".lotheader";
                     string headerPath = mapPath + Path.DirectorySeparatorChar + headerFile;
                     if (File.Exists(headerPath))
                     {
                         Console.WriteLine("Working on cell: {0} - {1}", nameparts[1], nameparts[2]);
                         MMCellData mapdata = cellReader.Read(file, headerPath);
                         for (int x = 0; x < 900; x++)
                         {
                             for (int y = 0; y < 900; y++)
                             {
                                 MMGridSquare gs = mapdata.GetSquare(0, x, y);
                                 for (Int32 i = MMGridSquare.TOP; i <= MMGridSquare.BOTTOM; i++){
                                     List<MMTile> tiles = gs.GetTiles(i);
                                     if (tiles.Count > 0 && tiles.Count < 3){
                                         string id = tiles[0].tile + tiles[1].tile;
                                         if (this.simsCount.ContainsKey(id)){
                                             this.simsCount[id]++;
                                         } else {
                                             this.simsCount.Add(id, 1);
                                             this.sims.Add(id, gs);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #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();
                            }
                        }
                    }

                }
            }
        }