forked from bit/DotRecastNetSim
add DtTileCacheLayerBuilder
This commit is contained in:
parent
6450704a8f
commit
67fb861ac1
|
@ -3,17 +3,17 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache
|
namespace DotRecast.Detour.TileCache
|
||||||
{
|
{
|
||||||
public class DtTileCacheBuildResult
|
public class DtTileCacheLayerBuildResult
|
||||||
{
|
{
|
||||||
public readonly int tx;
|
public readonly int tx;
|
||||||
public readonly int ty;
|
public readonly int ty;
|
||||||
public readonly Task<List<byte[]>> task;
|
public readonly List<byte[]> layers;
|
||||||
|
|
||||||
public DtTileCacheBuildResult(int tx, int ty, Task<List<byte[]>> task)
|
public DtTileCacheLayerBuildResult(int tx, int ty, List<byte[]> layers)
|
||||||
{
|
{
|
||||||
this.tx = tx;
|
this.tx = tx;
|
||||||
this.ty = ty;
|
this.ty = ty;
|
||||||
this.task = task;
|
this.layers = layers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -39,7 +39,7 @@ namespace DotRecast.Detour.TileCache
|
||||||
_compFactory = compFactory;
|
_compFactory = compFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<byte[]> Build(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int threads, int tw, int th)
|
public List<DtTileCacheLayerBuildResult> Build(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int threads, int tw, int th)
|
||||||
{
|
{
|
||||||
if (threads == 1)
|
if (threads == 1)
|
||||||
{
|
{
|
||||||
|
@ -49,25 +49,25 @@ namespace DotRecast.Detour.TileCache
|
||||||
return BuildMultiThread(geom, cfg, order, cCompatibility, tw, th, threads);
|
return BuildMultiThread(geom, cfg, order, cCompatibility, tw, th, threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<byte[]> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int tw, int th)
|
private List<DtTileCacheLayerBuildResult> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int tw, int th)
|
||||||
{
|
{
|
||||||
List<byte[]> layers = new List<byte[]>();
|
var results = new List<DtTileCacheLayerBuildResult>();
|
||||||
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)
|
||||||
{
|
{
|
||||||
var list = BuildTileCacheLayer(geom, cfg, x, y, order, cCompatibility);
|
var result = BuildTileCacheLayer(geom, cfg, x, y, order, cCompatibility);
|
||||||
layers.AddRange(list);
|
results.Add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return layers;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<byte[]> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int tw, int th, int threads)
|
private List<DtTileCacheLayerBuildResult> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, RcByteOrder order, bool cCompatibility, int tw, int th, int threads)
|
||||||
{
|
{
|
||||||
var results = new List<DtTileCacheBuildResult>();
|
var results = new List<Task<DtTileCacheLayerBuildResult>>();
|
||||||
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)
|
||||||
|
@ -75,12 +75,12 @@ namespace DotRecast.Detour.TileCache
|
||||||
int tx = x;
|
int tx = x;
|
||||||
int ty = y;
|
int ty = y;
|
||||||
var task = Task.Run(() => BuildTileCacheLayer(geom, cfg, tx, ty, order, cCompatibility));
|
var task = Task.Run(() => BuildTileCacheLayer(geom, cfg, tx, ty, order, cCompatibility));
|
||||||
results.Add(new DtTileCacheBuildResult(tx, ty, task));
|
results.Add(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
.SelectMany(x => x.task.Result)
|
.Select(x => x.Result)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ namespace DotRecast.Detour.TileCache
|
||||||
return lset;
|
return lset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual List<byte[]> BuildTileCacheLayer(IInputGeomProvider geom, RcConfig cfg, int tx, int ty, RcByteOrder order, bool cCompatibility)
|
protected virtual DtTileCacheLayerBuildResult BuildTileCacheLayer(IInputGeomProvider geom, RcConfig cfg, int tx, int ty, RcByteOrder order, bool cCompatibility)
|
||||||
{
|
{
|
||||||
RcHeightfieldLayerSet lset = BuildHeightfieldLayerSet(geom, cfg, tx, ty);
|
RcHeightfieldLayerSet lset = BuildHeightfieldLayerSet(geom, cfg, tx, ty);
|
||||||
List<byte[]> result = new List<byte[]>();
|
List<byte[]> result = new List<byte[]>();
|
||||||
|
@ -133,7 +133,7 @@ namespace DotRecast.Detour.TileCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return new DtTileCacheLayerBuildResult(tx, ty, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@ freely, subject to the following restrictions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io.Compress;
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using DotRecast.Detour.TileCache.Test.Io;
|
using DotRecast.Detour.TileCache.Test.Io;
|
||||||
|
@ -70,6 +71,9 @@ public class TestTileLayerBuilder : DtTileCacheLayerBuilder
|
||||||
|
|
||||||
public List<byte[]> Build(RcByteOrder order, bool cCompatibility, int threads)
|
public List<byte[]> Build(RcByteOrder order, bool cCompatibility, int threads)
|
||||||
{
|
{
|
||||||
return Build(_geom, _cfg, order, cCompatibility, threads, tw, th);
|
var results = Build(_geom, _cfg, order, cCompatibility, threads, tw, th);
|
||||||
|
return results
|
||||||
|
.SelectMany(x => x.layers)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue