1
This commit is contained in:
parent
dfb6837666
commit
c45c43d7fa
@ -52,6 +52,9 @@ void MapService::Init(int width, int height, int cell_width)
|
||||
if (width < 1 || height < 1 || cell_width < 1) {
|
||||
abort();
|
||||
}
|
||||
#ifdef FIND_PATH_TEST
|
||||
use_navmesh_ = true;
|
||||
#endif
|
||||
map_width_ = width;
|
||||
map_height_ = height;
|
||||
cell_width_ = cell_width;
|
||||
|
@ -27,7 +27,10 @@ void NavMeshBuilder::Build(MapInstance* map_instance)
|
||||
BuilderParams builder_params;
|
||||
{
|
||||
builder_params.map_instance = map_instance;
|
||||
builder_params.gemo = new f8::InputGeom();
|
||||
builder_params.geom = new f8::InputGeom();
|
||||
builder_params.geom->Init(map_instance->map_meta_->i->map_width(),
|
||||
map_instance->map_meta_->i->map_height());
|
||||
builder_params.ctx = new BuildContext();
|
||||
}
|
||||
InitBuilderParams(builder_params);
|
||||
CreateTileCache(builder_params);
|
||||
@ -39,8 +42,8 @@ void NavMeshBuilder::Build(MapInstance* map_instance)
|
||||
void NavMeshBuilder::InitBuilderParams(BuilderParams& builder_params)
|
||||
{
|
||||
// Init cache
|
||||
rcCalcGridSize(builder_params.gemo->GetMeshBoundsMin(),
|
||||
builder_params.gemo->GetMeshBoundsMax(),
|
||||
rcCalcGridSize(builder_params.geom->GetMeshBoundsMin(),
|
||||
builder_params.geom->GetMeshBoundsMax(),
|
||||
builder_params.kCellSize,
|
||||
&builder_params.grid_width,
|
||||
&builder_params.grid_height);
|
||||
@ -55,7 +58,7 @@ void NavMeshBuilder::InitTileCacheParams(BuilderParams& builder_params, dtTileCa
|
||||
{
|
||||
// Tile cache params.
|
||||
memset(&tcparams, 0, sizeof(tcparams));
|
||||
rcVcopy(tcparams.orig, builder_params.gemo->GetMeshBoundsMin());
|
||||
rcVcopy(tcparams.orig, builder_params.geom->GetMeshBoundsMin());
|
||||
tcparams.cs = builder_params.kCellSize;
|
||||
tcparams.ch = builder_params.kCellHeight;
|
||||
tcparams.width = (int)builder_params.kTileSize;
|
||||
@ -71,7 +74,7 @@ void NavMeshBuilder::InitTileCacheParams(BuilderParams& builder_params, dtTileCa
|
||||
void NavMeshBuilder::InitNavMeshParams(BuilderParams& builder_params, dtNavMeshParams& params)
|
||||
{
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
rcVcopy(params.orig, builder_params.gemo->GetMeshBoundsMin());
|
||||
rcVcopy(params.orig, builder_params.geom->GetMeshBoundsMin());
|
||||
params.tileWidth = builder_params.kTileSize * builder_params.kCellSize;
|
||||
params.tileHeight = builder_params.kTileSize * builder_params.kCellSize;
|
||||
#if 1
|
||||
@ -112,8 +115,8 @@ void NavMeshBuilder::BuildTiles(BuilderParams& builder_params)
|
||||
cfg.height = cfg.tileSize + cfg.borderSize*2;
|
||||
cfg.detailSampleDist = builder_params.kDetailSampleDist < 0.9f ? 0 : builder_params.kCellSize * builder_params.kDetailSampleDist;
|
||||
cfg.detailSampleMaxError = builder_params.kCellHeight * builder_params.kDetailSampleMaxError;
|
||||
rcVcopy(cfg.bmin, builder_params.gemo->GetMeshBoundsMin());
|
||||
rcVcopy(cfg.bmax, builder_params.gemo->GetMeshBoundsMax());
|
||||
rcVcopy(cfg.bmin, builder_params.geom->GetMeshBoundsMin());
|
||||
rcVcopy(cfg.bmax, builder_params.geom->GetMeshBoundsMax());
|
||||
}
|
||||
|
||||
for (int y = 0; y < builder_params.tile_height; ++y) {
|
||||
@ -157,9 +160,9 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
|
||||
FastLZCompressor comp;
|
||||
RasterizationContext rc;
|
||||
|
||||
const float* verts = builder_params.gemo->GetVerts();
|
||||
const int nverts = builder_params.gemo->GetVertCount();
|
||||
const rcChunkyTriMesh* chunkyMesh = builder_params.gemo->GetChunkyMesh();
|
||||
const float* verts = builder_params.geom->GetVerts();
|
||||
const int nverts = builder_params.geom->GetVertCount();
|
||||
const rcChunkyTriMesh* chunkyMesh = builder_params.geom->GetChunkyMesh();
|
||||
|
||||
// Tile bounds.
|
||||
const float tcs = cfg.tileSize * cfg.cs;
|
||||
@ -273,8 +276,8 @@ int NavMeshBuilder::RasterizeTileLayers(BuilderParams& builder_params,
|
||||
|
||||
#if 0
|
||||
// (Optional) Mark areas.
|
||||
const ConvexVolume* vols = builder_params.gemo->GetConvexVolumes();
|
||||
for (int i = 0; i < builder_params.gemo->GetConvexVolumeCount(); ++i) {
|
||||
const ConvexVolume* vols = builder_params.geom->GetConvexVolumes();
|
||||
for (int i = 0; i < builder_params.geom->GetConvexVolumeCount(); ++i) {
|
||||
rcMarkConvexPolyArea(builder_params.ctx, vols[i].verts, vols[i].nverts,
|
||||
vols[i].hmin, vols[i].hmax,
|
||||
vols[i].areaMod, *rc.chf);
|
||||
|
@ -171,6 +171,17 @@ struct MeshProcess : public dtTileCacheMeshProcess
|
||||
}
|
||||
};
|
||||
|
||||
class BuildContext : public rcContext
|
||||
{
|
||||
protected:
|
||||
virtual void doResetLog() {}
|
||||
virtual void doLog(const rcLogCategory category, const char* msg, const int len) {}
|
||||
virtual void doResetTimers() {}
|
||||
virtual void doStartTimer(const rcTimerLabel label) {}
|
||||
virtual void doStopTimer(const rcTimerLabel label) {}
|
||||
virtual int doGetAccumulatedTime(const rcTimerLabel label) const { return 0;}
|
||||
};
|
||||
|
||||
class MapInstance;
|
||||
class NavMeshHelper
|
||||
{
|
||||
@ -235,7 +246,7 @@ struct BuilderParams
|
||||
int tile_height = 0;
|
||||
|
||||
MapInstance* map_instance = nullptr;
|
||||
f8::InputGeom* gemo = nullptr;
|
||||
f8::InputGeom* geom = nullptr;
|
||||
dtNavMesh* navmesh = nullptr;
|
||||
rcContext* ctx = nullptr;
|
||||
dtTileCache* tile_cache = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user