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

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

@ -191,7 +191,7 @@ namespace DetourNavigator
*/ */
virtual std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const = 0; 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(); return mNavMeshManager.getNavMeshes();
} }
Settings NavigatorImpl::getSettings() const const Settings& NavigatorImpl::getSettings() const
{ {
return mSettings; return mSettings;
} }

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

@ -5,8 +5,9 @@
namespace DetourNavigator namespace DetourNavigator
{ {
struct NavigatorStub final : public Navigator class NavigatorStub final : public Navigator
{ {
public:
NavigatorStub() = default; NavigatorStub() = default;
void addAgent(const osg::Vec3f& /*agentHalfExtents*/) override {} void addAgent(const osg::Vec3f& /*agentHalfExtents*/) override {}
@ -65,7 +66,7 @@ namespace DetourNavigator
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override
{ {
return SharedNavMeshCacheItem(); return mEmptyNavMeshCacheItem;
} }
std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const override std::map<osg::Vec3f, SharedNavMeshCacheItem> getNavMeshes() const override
@ -73,10 +74,14 @@ namespace DetourNavigator
return std::map<osg::Vec3f, SharedNavMeshCacheItem>(); 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)) if (!resetIfUnique(it->second))
return false; return false;
mCache.erase(agentHalfExtents); mCache.erase(agentHalfExtents);
mChangedTiles.erase(agentHalfExtents);
mPlayerTile.erase(agentHalfExtents);
mLastRecastMeshManagerRevision.erase(agentHalfExtents);
return true; return true;
} }
@ -172,10 +175,6 @@ namespace DetourNavigator
else else
tileToPost->second = addChangeType(tileToPost->second, tile.second); 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); const auto maxTiles = std::min(mSettings.mMaxTilesNumber, navMesh.getParams()->maxTiles);
mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile) mRecastMeshManager.forEachTilePosition([&] (const TilePosition& tile)
@ -191,6 +190,8 @@ namespace DetourNavigator
}); });
} }
mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost); mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost);
if (changedTiles != mChangedTiles.end())
changedTiles->second.clear();
log("cache update posted for agent=", agentHalfExtents, log("cache update posted for agent=", agentHalfExtents,
" playerTile=", lastPlayerTile->second, " playerTile=", lastPlayerTile->second,
" recastMeshManagerRevision=", lastRevision); " recastMeshManagerRevision=", lastRevision);

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

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

Loading…
Cancel
Save