forked from bit/DotRecastNetSim
added DtTileCacheBuildResult
This commit is contained in:
parent
a68df35d91
commit
f2d2288283
|
@ -53,39 +53,24 @@ namespace DotRecast.Detour.TileCache
|
||||||
return layers;
|
return layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<byte[]> BuildMultiThread(RcByteOrder order, bool cCompatibility, int tw, int th, int threads)
|
private List<byte[]> BuildMultiThread(RcByteOrder order, bool cCompatibility, int tw, int th, int threads)
|
||||||
{
|
{
|
||||||
var tasks = new ConcurrentQueue<Task<Tuple<int, int, List<byte[]>>>>();
|
var results = new List<DtTileCacheBuildResult>();
|
||||||
for (int y = 0; y < th; ++y)
|
for (int y = 0; y < th; ++y)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < tw; ++x)
|
for (int x = 0; x < tw; ++x)
|
||||||
{
|
{
|
||||||
int tx = x;
|
int tx = x;
|
||||||
int ty = y;
|
int ty = y;
|
||||||
var task = Task.Run(() =>
|
var task = Task.Run(() => Build(tx, ty, order, cCompatibility));
|
||||||
{
|
results.Add(new DtTileCacheBuildResult(tx, ty, task));
|
||||||
var partial = Build(tx, ty, order, cCompatibility);
|
|
||||||
return Tuple.Create(tx, ty, partial);
|
|
||||||
});
|
|
||||||
tasks.Enqueue(task);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var partialResults = tasks
|
return results
|
||||||
.Select(x => x.Result)
|
.SelectMany(x => x.task.Result)
|
||||||
.ToDictionary(x => Tuple.Create(x.Item1, x.Item2), x => x.Item3);
|
.ToList();
|
||||||
|
|
||||||
List<byte[]> layers = new List<byte[]>();
|
|
||||||
for (int y = 0; y < th; ++y)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < tw; ++x)
|
|
||||||
{
|
|
||||||
var key = Tuple.Create(x, y);
|
|
||||||
layers.AddRange(partialResults[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return layers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<byte[]> Build(int tx, int ty, RcByteOrder order, bool cCompatibility);
|
protected abstract List<byte[]> Build(int tx, int ty, RcByteOrder order, bool cCompatibility);
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DotRecast.Detour.TileCache
|
||||||
|
{
|
||||||
|
public class DtTileCacheBuildResult
|
||||||
|
{
|
||||||
|
public readonly int tx;
|
||||||
|
public readonly int ty;
|
||||||
|
public readonly Task<List<byte[]>> task;
|
||||||
|
|
||||||
|
public DtTileCacheBuildResult(int tx, int ty, Task<List<byte[]>> task)
|
||||||
|
{
|
||||||
|
this.tx = tx;
|
||||||
|
this.ty = ty;
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue