1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:23:52 +00:00

stop navmesh updates when ai off

Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
bzzt lost a hitlab login 2020-05-08 13:37:00 +00:00 committed by Bret Curtis
parent ffbed7ee38
commit c1ebd9474b
5 changed files with 26 additions and 0 deletions

View file

@ -7,6 +7,8 @@
#include <components/esm/esmwriter.hpp> #include <components/esm/esmwriter.hpp>
#include <components/esm/stolenitems.hpp> #include <components/esm/stolenitems.hpp>
#include <components/detournavigator/navigator.hpp>
#include <components/sceneutil/positionattitudetransform.hpp> #include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
@ -900,6 +902,12 @@ namespace MWMechanics
bool MechanicsManager::toggleAI() bool MechanicsManager::toggleAI()
{ {
mAI = !mAI; mAI = !mAI;
MWBase::World* world = MWBase::Environment::get().getWorld();
world->getNavigator()->setUpdatesEnabled(mAI);
if (mAI)
world->getNavigator()->update(world->getPlayerPtr().getRefData().getPosition().asVec3());
return mAI; return mAI;
} }

View file

@ -155,6 +155,11 @@ namespace DetourNavigator
*/ */
virtual void update(const osg::Vec3f& playerPosition) = 0; virtual void update(const osg::Vec3f& playerPosition) = 0;
/**
* @brief disable navigator updates
*/
virtual void setUpdatesEnabled(bool enabled) = 0;
/** /**
* @brief wait locks thread until all tiles are updated from last update call. * @brief wait locks thread until all tiles are updated from last update call.
*/ */

View file

@ -12,6 +12,7 @@ namespace DetourNavigator
NavigatorImpl::NavigatorImpl(const Settings& settings) NavigatorImpl::NavigatorImpl(const Settings& settings)
: mSettings(settings) : mSettings(settings)
, mNavMeshManager(mSettings) , mNavMeshManager(mSettings)
, mUpdatesEnabled(true)
{ {
} }
@ -138,11 +139,18 @@ namespace DetourNavigator
void NavigatorImpl::update(const osg::Vec3f& playerPosition) void NavigatorImpl::update(const osg::Vec3f& playerPosition)
{ {
if (!mUpdatesEnabled)
return;
removeUnusedNavMeshes(); removeUnusedNavMeshes();
for (const auto& v : mAgents) for (const auto& v : mAgents)
mNavMeshManager.update(playerPosition, v.first); mNavMeshManager.update(playerPosition, v.first);
} }
void NavigatorImpl::setUpdatesEnabled(bool enabled)
{
mUpdatesEnabled = enabled;
}
void NavigatorImpl::wait() void NavigatorImpl::wait()
{ {
mNavMeshManager.wait(); mNavMeshManager.wait();

View file

@ -46,6 +46,8 @@ namespace DetourNavigator
void update(const osg::Vec3f& playerPosition) override; void update(const osg::Vec3f& playerPosition) override;
void setUpdatesEnabled(bool enabled) override;
void wait() override; void wait() override;
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& agentHalfExtents) const override; SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& agentHalfExtents) const override;
@ -61,6 +63,7 @@ namespace DetourNavigator
private: private:
Settings mSettings; Settings mSettings;
NavMeshManager mNavMeshManager; NavMeshManager mNavMeshManager;
bool mUpdatesEnabled;
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;

View file

@ -66,6 +66,8 @@ namespace DetourNavigator
void update(const osg::Vec3f& /*playerPosition*/) override {} void update(const osg::Vec3f& /*playerPosition*/) override {}
void setUpdatesEnabled(bool enabled) override {}
void wait() override {} void wait() override {}
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override