66using System . Collections . Generic ;
77using System . Linq ;
88using System . Text ;
9+ using System ;
10+ using System . Threading ;
911using MapMapLib ;
1012using System . IO ;
1113
@@ -29,6 +31,10 @@ class Main
2931 private int maxY = 99999 ;
3032 private int divider = 3 ;
3133 private bool bigtree = false ;
34+ private static int numThreads = 0 ;
35+ private int maxThreads = 1 ;
36+
37+ private MMCellData childMapData ;
3238
3339 public Main ( )
3440 {
@@ -72,7 +78,7 @@ private void parseMapData()
7278 {
7379 MMCellReader cellReader = new MMCellReader ( ) ;
7480 MMBinReader binReader = new MMBinReader ( ) ;
75- MMPlotter plotter = new MMPlotter ( this . divider , this . tex , this . dolayers , this . bigtree ) ;
81+ // MMPlotter plotter = new MMPlotter(this.divider, this.tex, this.dolayers, this.bigtree);
7682 foreach ( string mapPath in this . mapsources ) {
7783 if ( Directory . Exists ( mapPath ) ) {
7884 string [ ] packs = Directory . GetFiles ( mapPath , "*.lotpack" ) ;
@@ -105,7 +111,17 @@ private void parseMapData()
105111 }
106112 }
107113 }
108- plotter . PlotData ( mapdata , this . OutputDir , cellx , celly ) ;
114+
115+ while ( MapMap . Main . numThreads >= maxThreads ) {
116+ Thread . Sleep ( 500 ) ;
117+ }
118+ MapMap . Main . numThreads ++ ;
119+ Console . WriteLine ( "Threads: {0}/{1}" , MapMap . Main . numThreads , maxThreads ) ;
120+ MMPlotter plotter = new MMPlotter ( this . divider , this . tex , this . dolayers , this . bigtree ) ;
121+ //ThreadStart childref = new ThreadStart(this.RunPlotter);
122+ //Thread childThread = new Thread(childref);
123+ Thread childThread = new Thread ( ( ) => RunPlotter ( plotter , mapdata , this . OutputDir , cellx , celly ) ) ;
124+ childThread . Start ( ) ;
109125 }
110126 }
111127 }
@@ -114,6 +130,13 @@ private void parseMapData()
114130 }
115131 }
116132
133+ private static void RunPlotter ( MMPlotter childPlotter , MMCellData childMapData , String OutputDir , int childCellX , int childCellY ) {
134+ Console . WriteLine ( "Thread {0}x{1} started" , childCellX , childCellY ) ;
135+ childPlotter . PlotData ( childMapData , OutputDir , childCellX , childCellY ) ;
136+ MapMap . Main . numThreads -- ;
137+ Console . WriteLine ( "Thread {0}x{1} finished" , childCellX , childCellY ) ;
138+ }
139+
117140 private void readTexturePacks ( )
118141 {
119142 foreach ( string packPath in this . gfxsources ) {
@@ -187,7 +210,10 @@ private bool parseArgs(string[] args)
187210 }
188211 break ;
189212 case "-bigtree" :
190- this . bigtree = true ;
213+ this . bigtree = Convert . ToBoolean ( args [ id + 1 ] ) ;
214+ break ;
215+ case "-maxthreads" :
216+ this . maxThreads = Convert . ToInt32 ( args [ id + 1 ] ) ;
191217 break ;
192218 case "-minx" :
193219 this . minX = Convert . ToInt32 ( args [ id + 1 ] ) ;
@@ -203,9 +229,9 @@ private bool parseArgs(string[] args)
203229 break ;
204230 }
205231 }
206- Console . WriteLine ( "Boundaries: minx {0} maxx {1} miny {2} maxy {3}" , this . minX , this . maxX , this . minY , this . maxY ) ;
207- //var choice = Console.ReadKey(true);
208232 Console . Clear ( ) ;
233+ Console . WriteLine ( "Boundaries: minx {0} maxx {1} miny {2} maxy {3}" , this . minX , this . maxX , this . minY , this . maxY ) ;
234+ Console . WriteLine ( "Threads: {0}" , this . maxThreads ) ;
209235 Console . WriteLine ( "Starting programm..." ) ;
210236 return true ;
211237 }
0 commit comments