|
|
|
@ -69,7 +69,7 @@ namespace DetourNavigator
|
|
|
|
|
const auto tiles = mTiles.lock();
|
|
|
|
|
for (auto& tile : *tiles)
|
|
|
|
|
{
|
|
|
|
|
if (tile.second.addWater(cellPosition, cellSize, shift))
|
|
|
|
|
if (tile.second->addWater(cellPosition, cellSize, shift))
|
|
|
|
|
{
|
|
|
|
|
tilesPositions.push_back(tile.first);
|
|
|
|
|
result = true;
|
|
|
|
@ -88,9 +88,9 @@ namespace DetourNavigator
|
|
|
|
|
tileBounds.mMin -= osg::Vec2f(border, border);
|
|
|
|
|
tileBounds.mMax += osg::Vec2f(border, border);
|
|
|
|
|
tile = tiles->insert(std::make_pair(tilePosition,
|
|
|
|
|
CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
}
|
|
|
|
|
if (tile->second.addWater(cellPosition, cellSize, shift))
|
|
|
|
|
if (tile->second->addWater(cellPosition, cellSize, shift))
|
|
|
|
|
{
|
|
|
|
|
tilesPositions.push_back(tilePosition);
|
|
|
|
|
result = true;
|
|
|
|
@ -116,8 +116,8 @@ namespace DetourNavigator
|
|
|
|
|
const auto tile = tiles->find(tilePosition);
|
|
|
|
|
if (tile == tiles->end())
|
|
|
|
|
continue;
|
|
|
|
|
const auto tileResult = tile->second.removeWater(cellPosition);
|
|
|
|
|
if (tile->second.isEmpty())
|
|
|
|
|
const auto tileResult = tile->second->removeWater(cellPosition);
|
|
|
|
|
if (tile->second->isEmpty())
|
|
|
|
|
{
|
|
|
|
|
tiles->erase(tile);
|
|
|
|
|
++mTilesGeneration;
|
|
|
|
@ -149,9 +149,9 @@ namespace DetourNavigator
|
|
|
|
|
tileBounds.mMin -= osg::Vec2f(border, border);
|
|
|
|
|
tileBounds.mMax += osg::Vec2f(border, border);
|
|
|
|
|
tile = tiles->insert(std::make_pair(tilePosition,
|
|
|
|
|
CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
}
|
|
|
|
|
if (tile->second.addHeightfield(cellPosition, cellSize, shift, shape))
|
|
|
|
|
if (tile->second->addHeightfield(cellPosition, cellSize, shift, shape))
|
|
|
|
|
{
|
|
|
|
|
tilesPositions.push_back(tilePosition);
|
|
|
|
|
result = true;
|
|
|
|
@ -176,8 +176,8 @@ namespace DetourNavigator
|
|
|
|
|
const auto tile = tiles->find(tilePosition);
|
|
|
|
|
if (tile == tiles->end())
|
|
|
|
|
continue;
|
|
|
|
|
const auto tileResult = tile->second.removeHeightfield(cellPosition);
|
|
|
|
|
if (tile->second.isEmpty())
|
|
|
|
|
const auto tileResult = tile->second->removeHeightfield(cellPosition);
|
|
|
|
|
if (tile->second->isEmpty())
|
|
|
|
|
{
|
|
|
|
|
tiles->erase(tile);
|
|
|
|
|
++mTilesGeneration;
|
|
|
|
@ -192,11 +192,17 @@ namespace DetourNavigator
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getMesh(const TilePosition& tilePosition)
|
|
|
|
|
{
|
|
|
|
|
const auto tiles = mTiles.lock();
|
|
|
|
|
const auto it = tiles->find(tilePosition);
|
|
|
|
|
if (it == tiles->end())
|
|
|
|
|
const auto manager = [&] () -> std::shared_ptr<CachedRecastMeshManager>
|
|
|
|
|
{
|
|
|
|
|
const auto tiles = mTiles.lock();
|
|
|
|
|
const auto it = tiles->find(tilePosition);
|
|
|
|
|
if (it == tiles->end())
|
|
|
|
|
return nullptr;
|
|
|
|
|
return it->second;
|
|
|
|
|
} ();
|
|
|
|
|
if (manager == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return it->second.getMesh();
|
|
|
|
|
return manager->getMesh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TileCachedRecastMeshManager::hasTile(const TilePosition& tilePosition)
|
|
|
|
@ -215,12 +221,12 @@ namespace DetourNavigator
|
|
|
|
|
const auto it = tiles->find(tilePosition);
|
|
|
|
|
if (it == tiles->end())
|
|
|
|
|
return;
|
|
|
|
|
it->second.reportNavMeshChange(recastMeshVersion, navMeshVersion);
|
|
|
|
|
it->second->reportNavMeshChange(recastMeshVersion, navMeshVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TileCachedRecastMeshManager::addTile(const ObjectId id, const CollisionShape& shape,
|
|
|
|
|
const btTransform& transform, const AreaType areaType, const TilePosition& tilePosition, float border,
|
|
|
|
|
std::map<TilePosition, CachedRecastMeshManager>& tiles)
|
|
|
|
|
TilesMap& tiles)
|
|
|
|
|
{
|
|
|
|
|
auto tile = tiles.find(tilePosition);
|
|
|
|
|
if (tile == tiles.end())
|
|
|
|
@ -229,26 +235,26 @@ namespace DetourNavigator
|
|
|
|
|
tileBounds.mMin -= osg::Vec2f(border, border);
|
|
|
|
|
tileBounds.mMax += osg::Vec2f(border, border);
|
|
|
|
|
tile = tiles.insert(std::make_pair(
|
|
|
|
|
tilePosition, CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
tilePosition, std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
|
|
|
|
}
|
|
|
|
|
return tile->second.addObject(id, shape, transform, areaType);
|
|
|
|
|
return tile->second->addObject(id, shape, transform, areaType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TileCachedRecastMeshManager::updateTile(const ObjectId id, const btTransform& transform,
|
|
|
|
|
const AreaType areaType, const TilePosition& tilePosition, std::map<TilePosition, CachedRecastMeshManager>& tiles)
|
|
|
|
|
const AreaType areaType, const TilePosition& tilePosition, TilesMap& tiles)
|
|
|
|
|
{
|
|
|
|
|
const auto tile = tiles.find(tilePosition);
|
|
|
|
|
return tile != tiles.end() && tile->second.updateObject(id, transform, areaType);
|
|
|
|
|
return tile != tiles.end() && tile->second->updateObject(id, transform, areaType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeTile(const ObjectId id,
|
|
|
|
|
const TilePosition& tilePosition, std::map<TilePosition, CachedRecastMeshManager>& tiles)
|
|
|
|
|
const TilePosition& tilePosition, TilesMap& tiles)
|
|
|
|
|
{
|
|
|
|
|
const auto tile = tiles.find(tilePosition);
|
|
|
|
|
if (tile == tiles.end())
|
|
|
|
|
return std::optional<RemovedRecastMeshObject>();
|
|
|
|
|
const auto tileResult = tile->second.removeObject(id);
|
|
|
|
|
if (tile->second.isEmpty())
|
|
|
|
|
const auto tileResult = tile->second->removeObject(id);
|
|
|
|
|
if (tile->second->isEmpty())
|
|
|
|
|
{
|
|
|
|
|
tiles.erase(tile);
|
|
|
|
|
++mTilesGeneration;
|
|
|
|
|