mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 19:59:55 +00:00
Trigger navmesh update on moved player only when player tile has been changed
This commit is contained in:
parent
ed91cf9397
commit
4a6961b365
5 changed files with 22 additions and 2 deletions
|
@ -500,7 +500,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
|
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
|
||||||
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
navigator->update(player.getRefData().getPosition().asVec3());
|
navigator->updatePlayerPosition(player.getRefData().getPosition().asVec3());
|
||||||
|
|
||||||
if (!mCurrentCell || !mCurrentCell->isExterior())
|
if (!mCurrentCell || !mCurrentCell->isExterior())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -155,11 +155,17 @@ namespace DetourNavigator
|
||||||
virtual void removePathgrid(const ESM::Pathgrid& pathgrid) = 0;
|
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.
|
* @param playerPosition setup initial point to order build tiles of navmesh.
|
||||||
*/
|
*/
|
||||||
virtual void update(const osg::Vec3f& playerPosition) = 0;
|
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
|
* @brief disable navigator updates
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -146,6 +146,15 @@ namespace DetourNavigator
|
||||||
mNavMeshManager.update(playerPosition, v.first);
|
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)
|
void NavigatorImpl::setUpdatesEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
mUpdatesEnabled = enabled;
|
mUpdatesEnabled = enabled;
|
||||||
|
|
|
@ -46,6 +46,8 @@ namespace DetourNavigator
|
||||||
|
|
||||||
void update(const osg::Vec3f& playerPosition) override;
|
void update(const osg::Vec3f& playerPosition) override;
|
||||||
|
|
||||||
|
void updatePlayerPosition(const osg::Vec3f& playerPosition) override;
|
||||||
|
|
||||||
void setUpdatesEnabled(bool enabled) override;
|
void setUpdatesEnabled(bool enabled) override;
|
||||||
|
|
||||||
void wait(Loading::Listener& listener, WaitConditionType waitConditionType) override;
|
void wait(Loading::Listener& listener, WaitConditionType waitConditionType) override;
|
||||||
|
@ -66,6 +68,7 @@ namespace DetourNavigator
|
||||||
Settings mSettings;
|
Settings mSettings;
|
||||||
NavMeshManager mNavMeshManager;
|
NavMeshManager mNavMeshManager;
|
||||||
bool mUpdatesEnabled;
|
bool mUpdatesEnabled;
|
||||||
|
std::optional<TilePosition> mLastPlayerPosition;
|
||||||
std::map<osg::Vec3f, std::size_t> mAgents;
|
std::map<osg::Vec3f, std::size_t> mAgents;
|
||||||
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
|
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
|
||||||
std::unordered_map<ObjectId, ObjectId> mWaterIds;
|
std::unordered_map<ObjectId, ObjectId> mWaterIds;
|
||||||
|
|
|
@ -71,6 +71,8 @@ namespace DetourNavigator
|
||||||
|
|
||||||
void update(const osg::Vec3f& /*playerPosition*/) override {}
|
void update(const osg::Vec3f& /*playerPosition*/) override {}
|
||||||
|
|
||||||
|
void updatePlayerPosition(const osg::Vec3f& /*playerPosition*/) override {};
|
||||||
|
|
||||||
void setUpdatesEnabled(bool /*enabled*/) override {}
|
void setUpdatesEnabled(bool /*enabled*/) override {}
|
||||||
|
|
||||||
void wait(Loading::Listener& /*listener*/, WaitConditionType /*waitConditionType*/) override {}
|
void wait(Loading::Listener& /*listener*/, WaitConditionType /*waitConditionType*/) override {}
|
||||||
|
|
Loading…
Reference in a new issue