mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-01 03:21:41 +00:00
stop navmesh updates when ai off
Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
parent
ffbed7ee38
commit
c1ebd9474b
@ -7,6 +7,8 @@
|
||||
#include <components/esm/esmwriter.hpp>
|
||||
#include <components/esm/stolenitems.hpp>
|
||||
|
||||
#include <components/detournavigator/navigator.hpp>
|
||||
|
||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
@ -900,6 +902,12 @@ namespace MWMechanics
|
||||
bool MechanicsManager::toggleAI()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,11 @@ namespace DetourNavigator
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -12,6 +12,7 @@ namespace DetourNavigator
|
||||
NavigatorImpl::NavigatorImpl(const Settings& settings)
|
||||
: mSettings(settings)
|
||||
, mNavMeshManager(mSettings)
|
||||
, mUpdatesEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -138,11 +139,18 @@ namespace DetourNavigator
|
||||
|
||||
void NavigatorImpl::update(const osg::Vec3f& playerPosition)
|
||||
{
|
||||
if (!mUpdatesEnabled)
|
||||
return;
|
||||
removeUnusedNavMeshes();
|
||||
for (const auto& v : mAgents)
|
||||
mNavMeshManager.update(playerPosition, v.first);
|
||||
}
|
||||
|
||||
void NavigatorImpl::setUpdatesEnabled(bool enabled)
|
||||
{
|
||||
mUpdatesEnabled = enabled;
|
||||
}
|
||||
|
||||
void NavigatorImpl::wait()
|
||||
{
|
||||
mNavMeshManager.wait();
|
||||
|
@ -46,6 +46,8 @@ namespace DetourNavigator
|
||||
|
||||
void update(const osg::Vec3f& playerPosition) override;
|
||||
|
||||
void setUpdatesEnabled(bool enabled) override;
|
||||
|
||||
void wait() override;
|
||||
|
||||
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& agentHalfExtents) const override;
|
||||
@ -61,6 +63,7 @@ namespace DetourNavigator
|
||||
private:
|
||||
Settings mSettings;
|
||||
NavMeshManager mNavMeshManager;
|
||||
bool mUpdatesEnabled;
|
||||
std::map<osg::Vec3f, std::size_t> mAgents;
|
||||
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
|
||||
std::unordered_map<ObjectId, ObjectId> mWaterIds;
|
||||
|
@ -66,6 +66,8 @@ namespace DetourNavigator
|
||||
|
||||
void update(const osg::Vec3f& /*playerPosition*/) override {}
|
||||
|
||||
void setUpdatesEnabled(bool enabled) override {}
|
||||
|
||||
void wait() override {}
|
||||
|
||||
SharedNavMeshCacheItem getNavMesh(const osg::Vec3f& /*agentHalfExtents*/) const override
|
||||
|
Loading…
Reference in New Issue
Block a user