Return empty path when navmesh is not found for agent

pull/541/head
elsid 6 years ago
parent 1d3668cd22
commit 16675fd254
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -65,9 +65,10 @@ namespace
}
};
TEST_F(DetourNavigatorNavigatorTest, find_path_for_empty_should_throw_exception)
TEST_F(DetourNavigatorNavigatorTest, find_path_for_empty_should_return_empty)
{
EXPECT_THROW(mNavigator->findPath(mAgentHalfExtents, mStart, mEnd, Flag_walk, mOut), InvalidArgument);
mNavigator->findPath(mAgentHalfExtents, mStart, mEnd, Flag_walk, mOut);
EXPECT_EQ(mPath, std::deque<osg::Vec3f>());
}
TEST_F(DetourNavigatorNavigatorTest, find_path_for_existing_agent_with_no_navmesh_should_throw_exception)
@ -76,11 +77,12 @@ namespace
EXPECT_THROW(mNavigator->findPath(mAgentHalfExtents, mStart, mEnd, Flag_walk, mOut), NavigatorException);
}
TEST_F(DetourNavigatorNavigatorTest, find_path_for_removed_agent_should_throw_exception)
TEST_F(DetourNavigatorNavigatorTest, find_path_for_removed_agent_should_return_empty)
{
mNavigator->addAgent(mAgentHalfExtents);
mNavigator->removeAgent(mAgentHalfExtents);
EXPECT_THROW(mNavigator->findPath(mAgentHalfExtents, mStart, mEnd, Flag_walk, mOut), InvalidArgument);
mNavigator->findPath(mAgentHalfExtents, mStart, mEnd, Flag_walk, mOut);
EXPECT_EQ(mPath, std::deque<osg::Vec3f>());
}
TEST_F(DetourNavigatorNavigatorTest, add_agent_should_count_each_agent)

@ -171,6 +171,8 @@ namespace DetourNavigator
"out is not an OutputIterator"
);
const auto navMesh = getNavMesh(agentHalfExtents);
if (!navMesh)
return out;
const auto settings = getSettings();
return findSmoothPath(navMesh.lock()->getValue(), toNavMeshCoordinates(settings, agentHalfExtents),
toNavMeshCoordinates(settings, start), toNavMeshCoordinates(settings, end), includeFlags,

@ -133,7 +133,13 @@ namespace DetourNavigator
else
lastPlayerTile->second = playerTile;
std::map<TilePosition, ChangeType> tilesToPost;
const auto& cached = getCached(agentHalfExtents);
const auto cached = getCached(agentHalfExtents);
if (!cached)
{
std::ostringstream stream;
stream << "Agent with half extents is not found: " << agentHalfExtents;
throw InvalidArgument(stream.str());
}
const auto changedTiles = mChangedTiles.find(agentHalfExtents);
{
const auto locked = cached.lock();
@ -218,13 +224,11 @@ namespace DetourNavigator
}
}
const SharedNavMeshCacheItem& NavMeshManager::getCached(const osg::Vec3f& agentHalfExtents) const
SharedNavMeshCacheItem NavMeshManager::getCached(const osg::Vec3f& agentHalfExtents) const
{
const auto cached = mCache.find(agentHalfExtents);
if (cached != mCache.end())
return cached->second;
std::ostringstream stream;
stream << "Agent with half extents is not found: " << agentHalfExtents;
throw InvalidArgument(stream.str());
return SharedNavMeshCacheItem();
}
}

@ -67,7 +67,7 @@ namespace DetourNavigator
void addChangedTile(const TilePosition& tilePosition, const ChangeType changeType);
const SharedNavMeshCacheItem& getCached(const osg::Vec3f& agentHalfExtents) const;
SharedNavMeshCacheItem getCached(const osg::Vec3f& agentHalfExtents) const;
};
}

@ -106,6 +106,11 @@ namespace Misc
return Locked<const T>(*mMutex, *mValue);
}
operator bool() const
{
return static_cast<bool>(mValue);
}
private:
std::shared_ptr<std::mutex> mMutex;
std::shared_ptr<T> mValue;

Loading…
Cancel
Save