Trigger navmesh update on moved player only when player tile has been changed

pull/593/head
elsid 4 years ago
parent ed91cf9397
commit 4a6961b365
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -500,7 +500,7 @@ namespace MWWorld
{
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
navigator->update(player.getRefData().getPosition().asVec3());
navigator->updatePlayerPosition(player.getRefData().getPosition().asVec3());
if (!mCurrentCell || !mCurrentCell->isExterior())
return;

@ -155,11 +155,17 @@ namespace DetourNavigator
virtual void removePathgrid(const ESM::Pathgrid& pathgrid) = 0;
/**
* @brief update start background navmesh update using current scene state.
* @brief update starts background navmesh update using current scene state.
* @param playerPosition setup initial point to order build tiles of navmesh.
*/
virtual void update(const osg::Vec3f& playerPosition) = 0;
/**
* @brief updatePlayerPosition starts background navmesh update using current scene state only when player position has been changed.
* @param playerPosition setup initial point to order build tiles of navmesh.
*/
virtual void updatePlayerPosition(const osg::Vec3f& playerPosition) = 0;
/**
* @brief disable navigator updates
*/

@ -146,6 +146,15 @@ namespace DetourNavigator
mNavMeshManager.update(playerPosition, v.first);
}
void NavigatorImpl::updatePlayerPosition(const osg::Vec3f& playerPosition)
{
const TilePosition tilePosition = getTilePosition(mSettings, toNavMeshCoordinates(mSettings, playerPosition));
if (mLastPlayerPosition.has_value() && *mLastPlayerPosition == tilePosition)
return;
update(playerPosition);
mLastPlayerPosition = tilePosition;
}
void NavigatorImpl::setUpdatesEnabled(bool enabled)
{
mUpdatesEnabled = enabled;

@ -46,6 +46,8 @@ namespace DetourNavigator
void update(const osg::Vec3f& playerPosition) override;
void updatePlayerPosition(const osg::Vec3f& playerPosition) override;
void setUpdatesEnabled(bool enabled) override;
void wait(Loading::Listener& listener, WaitConditionType waitConditionType) override;
@ -66,6 +68,7 @@ namespace DetourNavigator
Settings mSettings;
NavMeshManager mNavMeshManager;
bool mUpdatesEnabled;
std::optional<TilePosition> mLastPlayerPosition;
std::map<osg::Vec3f, std::size_t> mAgents;
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
std::unordered_map<ObjectId, ObjectId> mWaterIds;

@ -71,6 +71,8 @@ namespace DetourNavigator
void update(const osg::Vec3f& /*playerPosition*/) override {}
void updatePlayerPosition(const osg::Vec3f& /*playerPosition*/) override {};
void setUpdatesEnabled(bool /*enabled*/) override {}
void wait(Loading::Listener& /*listener*/, WaitConditionType /*waitConditionType*/) override {}

Loading…
Cancel
Save