1
This commit is contained in:
parent
8229584cbe
commit
0223227a47
@ -297,6 +297,7 @@ void NavMeshBuilder::UnInit()
|
||||
struct BuilderParams
|
||||
{
|
||||
float kCellSize = 64;
|
||||
float kCellHeight = 64;
|
||||
const float* bmin = nullptr;
|
||||
const float* bmax = nullptr;
|
||||
rcConfig cfg;
|
||||
@ -305,6 +306,8 @@ struct BuilderParams
|
||||
LinearAllocator* talloc = nullptr;
|
||||
FastLZCompressor* tcomp = nullptr;
|
||||
MeshProcess* tmproc = nullptr;
|
||||
int tw = 0;
|
||||
int th = 0;
|
||||
};
|
||||
|
||||
dtNavMesh* NavMeshBuilder::Build(MapInstance* map_instance)
|
||||
@ -348,32 +351,29 @@ dtNavMesh* NavMeshBuilder::Build(MapInstance* map_instance)
|
||||
int m_cacheCompressedSize = 0;
|
||||
int m_cacheRawSize = 0;
|
||||
|
||||
for (int y = 0; y < th; ++y)
|
||||
{
|
||||
for (int x = 0; x < tw; ++x)
|
||||
{
|
||||
TileCacheData tiles[MAX_LAYERS];
|
||||
memset(tiles, 0, sizeof(tiles));
|
||||
int ntiles = RasterizeTileLayers(x, y, builder_params.cfg, tiles, MAX_LAYERS);
|
||||
for (int y = 0; y < th; ++y) {
|
||||
for (int x = 0; x < tw; ++x) {
|
||||
TileCacheData tiles[MAX_LAYERS];
|
||||
memset(tiles, 0, sizeof(tiles));
|
||||
int ntiles = RasterizeTileLayers(x, y, builder_params.cfg, tiles, MAX_LAYERS);
|
||||
|
||||
for (int i = 0; i < ntiles; ++i)
|
||||
{
|
||||
TileCacheData* tile = &tiles[i];
|
||||
status = tile_cache->addTile(tile->data, tile->dataSize, DT_COMPRESSEDTILE_FREE_DATA, 0);
|
||||
if (dtStatusFailed(status))
|
||||
{
|
||||
dtFree(tile->data);
|
||||
tile->data = 0;
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < ntiles; ++i) {
|
||||
TileCacheData* tile = &tiles[i];
|
||||
status = tile_cache->addTile(tile->data, tile->dataSize, DT_COMPRESSEDTILE_FREE_DATA, 0);
|
||||
if (dtStatusFailed(status))
|
||||
{
|
||||
dtFree(tile->data);
|
||||
tile->data = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
m_cacheLayerCount++;
|
||||
m_cacheCompressedSize += tile->dataSize;
|
||||
m_cacheRawSize += calcLayerBufferSize(builder_params.tcparams.width,
|
||||
builder_params.tcparams.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_cacheLayerCount++;
|
||||
m_cacheCompressedSize += tile->dataSize;
|
||||
m_cacheRawSize += calcLayerBufferSize(builder_params.tcparams.width,
|
||||
builder_params.tcparams.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build initial meshes
|
||||
for (int y = 0; y < th; ++y) {
|
||||
@ -382,11 +382,6 @@ dtNavMesh* NavMeshBuilder::Build(MapInstance* map_instance)
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
m_cacheBuildTimeMs = ctx->getAccumulatedTime(RC_TIMER_TOTAL)/1000.0f;
|
||||
m_cacheBuildMemUsage = builder_params.talloc->high;
|
||||
#endif
|
||||
|
||||
const dtNavMesh* nav = navmesh;
|
||||
int navmeshMemUsage = 0;
|
||||
for (int i = 0; i < nav->getMaxTiles(); ++i) {
|
||||
@ -502,15 +497,15 @@ void NavMeshBuilder::OutputObjFile(MapInstance* map_instance)
|
||||
|
||||
void NavMeshBuilder::InitRcConfig(BuilderParams& builder_params)
|
||||
{
|
||||
#if 0
|
||||
rcConfig& cfg = builder_params.cfg;
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.cs = kCellSize;
|
||||
cfg.ch = kCellHeight;
|
||||
cfg.cs = builder_params.kCellSize;
|
||||
cfg.ch = builder_params.kCellHeight;
|
||||
cfg.walkableSlopeAngle = kAgentMaxSlope;
|
||||
cfg.walkableHeight = (int)ceilf(kAgentHeight / cfg.ch);
|
||||
cfg.walkableClimb = (int)floorf(kAgentMaxClimb / cfg.ch);
|
||||
cfg.walkableRadius = (int)ceilf(kAgentRadius / cfg.cs);
|
||||
cfg.maxEdgeLen = (int)(kEdgeMaxLen / kCellSize);
|
||||
cfg.maxEdgeLen = (int)(kEdgeMaxLen / builder_params.kCellSize);
|
||||
cfg.maxSimplificationError = kEdgeMaxError;
|
||||
cfg.minRegionArea = (int)rcSqr(kRegionMinSize); // Note: area = size*size
|
||||
cfg.mergeRegionArea = (int)rcSqr(kRegionMergeSize); // Note: area = size*size
|
||||
@ -519,30 +514,28 @@ void NavMeshBuilder::InitRcConfig(BuilderParams& builder_params)
|
||||
cfg.borderSize = cfg.walkableRadius + 3; // Reserve enough padding.
|
||||
cfg.width = cfg.tileSize + cfg.borderSize*2;
|
||||
cfg.height = cfg.tileSize + cfg.borderSize*2;
|
||||
cfg.detailSampleDist = kDetailSampleDist < 0.9f ? 0 : kCellSize * kDetailSampleDist;
|
||||
cfg.detailSampleDist = kDetailSampleDist < 0.9f ? 0 : builder_params.kCellSize * kDetailSampleDist;
|
||||
cfg.detailSampleMaxError = kCellHeight * kDetailSampleMaxError;
|
||||
rcVcopy(cfg.bmin, bmin);
|
||||
rcVcopy(cfg.bmax, bmax);
|
||||
#endif
|
||||
rcVcopy(cfg.bmin, builder_params.bmin);
|
||||
rcVcopy(cfg.bmax, builder_params.bmax);
|
||||
}
|
||||
|
||||
void NavMeshBuilder::InitTileCacheParams(BuilderParams& builder_params)
|
||||
{
|
||||
#if 0
|
||||
dtTileCacheParams& tcparams = builder_params.tcparams;
|
||||
// Tile cache params.
|
||||
memset(&tcparams, 0, sizeof(tcparams));
|
||||
rcVcopy(tcparams.orig, bmin);
|
||||
tcparams.cs = kCellSize;
|
||||
tcparams.ch = kCellHeight;
|
||||
rcVcopy(tcparams.orig, builder_params.bmin);
|
||||
tcparams.cs = builder_params.kCellSize;
|
||||
tcparams.ch = builder_params.kCellHeight;
|
||||
tcparams.width = (int)kTileSize;
|
||||
tcparams.height = (int)kTileSize;
|
||||
tcparams.walkableHeight = kAgentHeight;
|
||||
tcparams.walkableRadius = kAgentRadius;
|
||||
tcparams.walkableClimb = kAgentMaxClimb;
|
||||
tcparams.maxSimplificationError = kEdgeMaxError;
|
||||
tcparams.maxTiles = tw*th*EXPECTED_LAYERS_PER_TILE;
|
||||
tcparams.maxTiles = builder_params.tw*builder_params.th*EXPECTED_LAYERS_PER_TILE;
|
||||
tcparams.maxObstacles = 128;
|
||||
#endif
|
||||
}
|
||||
|
||||
int NavMeshBuilder::RasterizeTileLayers(const int tx, const int ty,
|
||||
|
Loading…
x
Reference in New Issue
Block a user