Skip to content

Commit 2cd81b3

Browse files
committed
fix/parameterise threading, remove unnecessary output
1 parent 88dc9a9 commit 2cd81b3

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

MapMap/Main.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Text;
9+
using System;
10+
using System.Threading;
911
using MapMapLib;
1012
using 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
}

MapMapLib/MMCellReader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public MMCellReader()
2121

2222
public MMCellData Read(string datafile, string headerfile)
2323
{
24-
this.cellData.Reset();
24+
//this.cellData.Reset();
25+
this.cellData = new MMCellData();
2526
List<string> tiles = new List<string>();
2627
if (File.Exists(headerfile))
2728
{

MapMapLib/MMPlotter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,12 @@ public void PlotData( MMCellData cellData, string outputDir, int cellx, int cell
429429
}
430430
this.textures.Textures[rSprite].Draw(gfx, drawx + mmtile.offX, drawy + mmtile.offY);
431431
drawCnt++;
432-
} else {
433-
Console.WriteLine("Collages contain Unknown texture: {0}", sprite);
432+
//} else {
433+
//Console.WriteLine("Collages contain Unknown texture: {0}", sprite);
434434
}
435435
}
436-
} else {
437-
Console.WriteLine("Unknown texture: {0}", tile);
436+
//} else {
437+
//Console.WriteLine("Unknown texture: {0}", tile);
438438
}
439439
}
440440
}

0 commit comments

Comments
 (0)