2018-03-13 22:49:08 +00:00
|
|
|
#include "navigator.hpp"
|
|
|
|
#include "debug.hpp"
|
|
|
|
#include "settingsutils.hpp"
|
|
|
|
|
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
|
|
|
Navigator::Navigator(const Settings& settings)
|
|
|
|
: mSettings(settings)
|
|
|
|
, mNavMeshManager(mSettings)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Navigator::addAgent(const osg::Vec3f& agentHalfExtents)
|
|
|
|
{
|
|
|
|
++mAgents[agentHalfExtents];
|
2018-04-01 17:24:02 +00:00
|
|
|
mNavMeshManager.addAgent(agentHalfExtents);
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Navigator::removeAgent(const osg::Vec3f& agentHalfExtents)
|
|
|
|
{
|
|
|
|
const auto it = mAgents.find(agentHalfExtents);
|
|
|
|
if (it == mAgents.end() || --it->second)
|
|
|
|
return;
|
|
|
|
mAgents.erase(it);
|
|
|
|
mNavMeshManager.reset(agentHalfExtents);
|
|
|
|
}
|
|
|
|
|
2018-04-02 21:04:19 +00:00
|
|
|
bool Navigator::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
|
|
|
|
{
|
|
|
|
return mNavMeshManager.addObject(id, shape, transform);
|
|
|
|
}
|
|
|
|
|
2018-05-26 14:44:25 +00:00
|
|
|
bool Navigator::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform)
|
|
|
|
{
|
|
|
|
return mNavMeshManager.updateObject(id, shape, transform);
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:49:08 +00:00
|
|
|
bool Navigator::removeObject(std::size_t id)
|
|
|
|
{
|
|
|
|
return mNavMeshManager.removeObject(id);
|
|
|
|
}
|
|
|
|
|
2018-04-01 17:24:02 +00:00
|
|
|
void Navigator::update(const osg::Vec3f& playerPosition)
|
2018-03-13 22:49:08 +00:00
|
|
|
{
|
|
|
|
for (const auto& v : mAgents)
|
2018-04-01 17:24:02 +00:00
|
|
|
mNavMeshManager.update(playerPosition, v.first);
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Navigator::wait()
|
|
|
|
{
|
|
|
|
mNavMeshManager.wait();
|
|
|
|
}
|
2018-04-07 13:11:23 +00:00
|
|
|
|
|
|
|
std::map<osg::Vec3f, std::shared_ptr<NavMeshCacheItem>> Navigator::getNavMeshes() const
|
|
|
|
{
|
|
|
|
return mNavMeshManager.getNavMeshes();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Settings& Navigator::getSettings() const
|
|
|
|
{
|
|
|
|
return mSettings;
|
|
|
|
}
|
2018-03-13 22:49:08 +00:00
|
|
|
}
|