Skip to content

Commit

Permalink
fix/parameterise threading, remove unnecessary output
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-coder committed Dec 19, 2016
1 parent 88dc9a9 commit 2cd81b3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
36 changes: 31 additions & 5 deletions MapMap/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Threading;
using MapMapLib;
using System.IO;

Expand All @@ -29,6 +31,10 @@ class Main
private int maxY = 99999;
private int divider = 3;
private bool bigtree = false;
private static int numThreads = 0;
private int maxThreads = 1;

private MMCellData childMapData;

public Main()
{
Expand Down Expand Up @@ -72,7 +78,7 @@ private void parseMapData()
{
MMCellReader cellReader = new MMCellReader();
MMBinReader binReader = new MMBinReader();
MMPlotter plotter = new MMPlotter(this.divider, this.tex, this.dolayers, this.bigtree);
// 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");
Expand Down Expand Up @@ -105,7 +111,17 @@ private void parseMapData()
}
}
}
plotter.PlotData(mapdata, this.OutputDir, cellx, celly);

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();
}
}
}
Expand All @@ -114,6 +130,13 @@ private void parseMapData()
}
}

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);
}

private void readTexturePacks()
{
foreach (string packPath in this.gfxsources) {
Expand Down Expand Up @@ -187,7 +210,10 @@ private bool parseArgs(string[] args)
}
break;
case "-bigtree":
this.bigtree = true;
this.bigtree = Convert.ToBoolean(args[id + 1]);
break;
case "-maxthreads":
this.maxThreads = Convert.ToInt32(args[id + 1]);
break;
case "-minx":
this.minX = Convert.ToInt32(args[id + 1]);
Expand All @@ -203,9 +229,9 @@ private bool parseArgs(string[] args)
break;
}
}
Console.WriteLine("Boundaries: minx {0} maxx {1} miny {2} maxy {3}", this.minX, this.maxX, this.minY, this.maxY);
//var choice = Console.ReadKey(true);
Console.Clear();
Console.WriteLine("Boundaries: minx {0} maxx {1} miny {2} maxy {3}", this.minX, this.maxX, this.minY, this.maxY);
Console.WriteLine("Threads: {0}", this.maxThreads);
Console.WriteLine("Starting programm...");
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion MapMapLib/MMCellReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public MMCellReader()

public MMCellData Read(string datafile, string headerfile)
{
this.cellData.Reset();
//this.cellData.Reset();
this.cellData = new MMCellData();
List<string> tiles = new List<string>();
if (File.Exists(headerfile))
{
Expand Down
8 changes: 4 additions & 4 deletions MapMapLib/MMPlotter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ public void PlotData( MMCellData cellData, string outputDir, int cellx, int cell
}
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("Collages contain Unknown texture: {0}", sprite);
}
}
} else {
Console.WriteLine("Unknown texture: {0}", tile);
//} else {
//Console.WriteLine("Unknown texture: {0}", tile);
}
}
}
Expand Down

0 comments on commit 2cd81b3

Please sign in to comment.