mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 12:39:55 +00:00
Make OutputTransformIterator more generic
This commit is contained in:
parent
de3a6ca6e6
commit
3dfea1dc1b
@ -49,13 +49,13 @@ namespace DetourNavigator
|
||||
std::optional<SteerTarget> getSteerTarget(const dtNavMeshQuery& navQuery, const osg::Vec3f& startPos,
|
||||
const osg::Vec3f& endPos, const float minTargetDist, const dtPolyRef* path, const std::size_t pathSize);
|
||||
|
||||
template <class OutputIterator>
|
||||
template <class OutputIterator, class Function>
|
||||
class OutputTransformIterator
|
||||
{
|
||||
public:
|
||||
explicit OutputTransformIterator(OutputIterator& impl, const RecastSettings& settings)
|
||||
explicit OutputTransformIterator(OutputIterator& impl, Function&& function)
|
||||
: mImpl(impl)
|
||||
, mSettings(settings)
|
||||
, mFunction(std::forward<Function>(function))
|
||||
{
|
||||
}
|
||||
|
||||
@ -76,15 +76,22 @@ namespace DetourNavigator
|
||||
|
||||
OutputTransformIterator& operator=(const osg::Vec3f& value)
|
||||
{
|
||||
*mImpl.get() = fromNavMeshCoordinates(mSettings, value);
|
||||
*mImpl.get() = mFunction(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::reference_wrapper<OutputIterator> mImpl;
|
||||
std::reference_wrapper<const RecastSettings> mSettings;
|
||||
Function mFunction;
|
||||
};
|
||||
|
||||
template <class OutputIterator>
|
||||
auto withFromNavMeshCoordinates(OutputIterator& impl, const RecastSettings& settings)
|
||||
{
|
||||
return OutputTransformIterator(
|
||||
impl, [&settings](const osg::Vec3f& value) { return fromNavMeshCoordinates(settings, value); });
|
||||
}
|
||||
|
||||
dtPolyRef findNearestPoly(const dtNavMeshQuery& query, const dtQueryFilter& filter, const osg::Vec3f& center,
|
||||
const osg::Vec3f& halfExtents);
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace DetourNavigator
|
||||
if (navMesh == nullptr)
|
||||
return Status::NavMeshNotFound;
|
||||
const Settings& settings = navigator.getSettings();
|
||||
auto outTransform = OutputTransformIterator<OutputIterator>(out, settings.mRecast);
|
||||
auto outTransform = withFromNavMeshCoordinates(out, settings.mRecast);
|
||||
const auto locked = navMesh->lock();
|
||||
return findSmoothPath(locked->getQuery(), toNavMeshCoordinates(settings.mRecast, agentBounds.mHalfExtents),
|
||||
toNavMeshCoordinates(settings.mRecast, stepSize), toNavMeshCoordinates(settings.mRecast, start),
|
||||
|
Loading…
x
Reference in New Issue
Block a user