1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-25 07:44:08 +00:00

Use callback to iterate over chunks

This commit is contained in:
elsid 2018-11-04 18:34:31 +03:00
parent db5638bf6d
commit b477775e16
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
2 changed files with 49 additions and 50 deletions

View File

@ -50,8 +50,8 @@ namespace DetourNavigator
ChunkyTriMesh& operator=(const ChunkyTriMesh&) = delete;
/// Returns the chunk indices which overlap the input rectable.
template <class OutputIterator>
void getChunksOverlappingRect(const Rect& rect, OutputIterator out) const
template <class Function>
void forEachChunksOverlappingRect(const Rect& rect, Function&& function) const
{
// Traverse tree
for (std::size_t i = 0; i < mNodes.size(); )
@ -61,7 +61,7 @@ namespace DetourNavigator
const bool isLeafNode = node->mOffset >= 0;
if (isLeafNode && overlap)
*out++ = i;
function(i);
if (overlap || isLeafNode)
i++;

View File

@ -149,13 +149,10 @@ namespace
std::vector<unsigned char> areas(chunkyMesh.getMaxTrisPerChunk(), AreaType_null);
const osg::Vec2f tileBoundsMin(config.bmin[0], config.bmin[2]);
const osg::Vec2f tileBoundsMax(config.bmax[0], config.bmax[2]);
std::vector<std::size_t> cids;
chunkyMesh.getChunksOverlappingRect(Rect {tileBoundsMin, tileBoundsMax}, std::back_inserter(cids));
bool result = false;
if (cids.empty())
return false;
for (const auto cid : cids)
chunkyMesh.forEachChunksOverlappingRect(Rect {tileBoundsMin, tileBoundsMax},
[&] (const std::size_t cid)
{
const auto chunk = chunkyMesh.getChunk(cid);
@ -202,9 +199,11 @@ namespace
if (!trianglesRasterized)
throw NavigatorException("Failed to create rasterize triangles from recast mesh for navmesh");
}
return true;
result = true;
});
return result;
}
void rasterizeWaterTriangles(rcContext& context, const osg::Vec3f& agentHalfExtents, const RecastMesh& recastMesh,