Merge pull request #2245 from elsid/navigator_refactor

Refactor navigator related code
pull/2248/head
Bret Curtis 6 years ago committed by GitHub
commit cb1a5f3679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -338,7 +338,7 @@ namespace MWWorld
{
if (const auto object = mPhysics->getObject(ptr))
navigator->removeObject(DetourNavigator::ObjectId(object));
else if (const auto actor = mPhysics->getActor(ptr))
else if (mPhysics->getActor(ptr))
{
navigator->removeAgent(world->getPathfindingHalfExtents(ptr));
mRendering.removeActorPath(ptr);
@ -809,7 +809,7 @@ namespace MWWorld
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
navigator->update(player.getRefData().getPosition().asVec3());
}
else if (const auto actor = mPhysics->getActor(ptr))
else if (mPhysics->getActor(ptr))
{
navigator->removeAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr));
}

@ -162,9 +162,7 @@ namespace DetourNavigator
boost::optional<AsyncNavMeshUpdater::Job> AsyncNavMeshUpdater::getNextJob()
{
std::unique_lock<std::mutex> lock(mMutex);
if (mJobs.empty())
mHasJob.wait_for(lock, std::chrono::milliseconds(10));
if (mJobs.empty())
if (!mHasJob.wait_for(lock, std::chrono::milliseconds(10), [&] { return !mJobs.empty(); }))
{
mFirstStart.lock()->reset();
mDone.notify_all();

@ -191,7 +191,7 @@ namespace DetourNavigator
*/
virtual std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const = 0;
virtual Settings getSettings() const = 0;
virtual const Settings& getSettings() const = 0;
};
}

@ -133,7 +133,7 @@ namespace DetourNavigator
return mNavMeshManager.getNavMeshes();
}
Settings NavigatorImpl::getSettings() const
const Settings& NavigatorImpl::getSettings() const
{
return mSettings;
}

@ -46,7 +46,7 @@ namespace DetourNavigator
std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const override;
Settings getSettings() const override;
const Settings& getSettings() const override;
private:
Settings mSettings;

@ -5,8 +5,9 @@
namespace DetourNavigator
{
struct NavigatorStub final : public Navigator
class NavigatorStub final : public Navigator
{
public:
NavigatorStub() = default;
void addAgent(const osg::Vec3f& /*agentHalfExtents*/) override {}
@ -65,7 +66,7 @@ namespace DetourNavigator
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override
{
return SharedNavMeshCacheItem();
return mEmptyNavMeshCacheItem;
}
std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const override
@ -73,10 +74,14 @@ namespace DetourNavigator
return std::map<osg::Vec3f, SharedNavMeshCacheItem>();
}
Settings getSettings() const override
const Settings& getSettings() const override
{
return Settings {};
return mDefaultSettings;
}
private:
Settings mDefaultSettings {};
SharedNavMeshCacheItem mEmptyNavMeshCacheItem;
};
}

@ -105,6 +105,9 @@ namespace DetourNavigator
if (!resetIfUnique(it->second))
return false;
mCache.erase(agentHalfExtents);
mChangedTiles.erase(agentHalfExtents);
mPlayerTile.erase(agentHalfExtents);
mLastRecastMeshManagerRevision.erase(agentHalfExtents);
return true;
}
@ -172,10 +175,6 @@ namespace DetourNavigator
else
tileToPost->second = addChangeType(tileToPost->second, tile.second);
}
for (const auto& tile : tilesToPost)
changedTiles->second.erase(tile.first);
if (changedTiles->second.empty())
mChangedTiles.erase(changedTiles);
}
const auto maxTiles = std::min(mSettings.mMaxTilesNumber, navMesh.getParams()->maxTiles);
mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile)
@ -191,6 +190,8 @@ namespace DetourNavigator
});
}
mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost);
if (changedTiles != mChangedTiles.end())
changedTiles->second.clear();
log("cache update posted for agent=", agentHalfExtents,
" playerTile=", lastPlayerTile->second,
" recastMeshManagerRevision=", lastRevision);

@ -61,8 +61,8 @@ namespace DetourNavigator
for (const auto& tile : currentTiles)
if (!newTiles.count(tile) && removeTile(id, tile, tiles.get()))
changedTiles.push_back(tile);
std::swap(currentTiles, newTiles);
}
std::swap(currentTiles, newTiles);
if (!changedTiles.empty())
++mRevision;
return changedTiles;

@ -102,7 +102,7 @@ namespace SceneUtil
osg::ref_ptr<osg::Geometry> geometry(new osg::Geometry);
geometry->setStateSet(stateSet);
geometry->setUseDisplayList(false);
geometry->setUseDisplayList(true);
geometry->setVertexArray(mVertices);
geometry->setColorArray(mColors, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(mMode, 0, static_cast<int>(mVertices->size())));

Loading…
Cancel
Save