mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-04 00:26:45 +00:00 
			
		
		
		
	Move duplicated usage patter of dtNavMeshQuery::findNearestPoly into a separate function
This commit is contained in:
		
							parent
							
								
									d3ab6c972f
								
							
						
					
					
						commit
						a7fe6c7ba1
					
				
					 3 changed files with 19 additions and 27 deletions
				
			
		| 
						 | 
				
			
			@ -20,15 +20,7 @@ namespace DetourNavigator
 | 
			
		|||
        dtQueryFilter queryFilter;
 | 
			
		||||
        queryFilter.setIncludeFlags(includeFlags);
 | 
			
		||||
 | 
			
		||||
        dtPolyRef startRef = 0;
 | 
			
		||||
        for (int i = 0; i < 3; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
 | 
			
		||||
                &startRef, nullptr);
 | 
			
		||||
            if (!dtStatusFailed(status) && startRef != 0)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
 | 
			
		||||
        if (startRef == 0)
 | 
			
		||||
            return std::optional<osg::Vec3f>();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -140,4 +140,17 @@ namespace DetourNavigator
 | 
			
		|||
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
 | 
			
		||||
            const osg::Vec3f& center, const osg::Vec3f& halfExtents)
 | 
			
		||||
    {
 | 
			
		||||
        dtPolyRef ref = 0;
 | 
			
		||||
        for (int i = 0; i < 3; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            const dtStatus status = query.findNearestPoly(center.ptr(), (halfExtents * (1 << i)).ptr(), &filter, &ref, nullptr);
 | 
			
		||||
            if (!dtStatusFailed(status) && ref != 0)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        return ref;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -103,6 +103,9 @@ namespace DetourNavigator
 | 
			
		|||
        return dtStatusSucceed(status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
 | 
			
		||||
            const osg::Vec3f& center, const osg::Vec3f& halfExtents);
 | 
			
		||||
 | 
			
		||||
    struct MoveAlongSurfaceResult
 | 
			
		||||
    {
 | 
			
		||||
        osg::Vec3f mResultPos;
 | 
			
		||||
| 
						 | 
				
			
			@ -282,27 +285,11 @@ namespace DetourNavigator
 | 
			
		|||
        queryFilter.setAreaCost(AreaType_pathgrid, areaCosts.mPathgrid);
 | 
			
		||||
        queryFilter.setAreaCost(AreaType_ground, areaCosts.mGround);
 | 
			
		||||
 | 
			
		||||
        dtPolyRef startRef = 0;
 | 
			
		||||
        for (int i = 0; i < 3; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
 | 
			
		||||
                &startRef, nullptr);
 | 
			
		||||
            if (!dtStatusFailed(status) && startRef != 0)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
 | 
			
		||||
        if (startRef == 0)
 | 
			
		||||
            return Status::StartPolygonNotFound;
 | 
			
		||||
 | 
			
		||||
        dtPolyRef endRef = 0;
 | 
			
		||||
        for (int i = 0; i < 3; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            const auto status = navMeshQuery.findNearestPoly(end.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
 | 
			
		||||
                &endRef, nullptr);
 | 
			
		||||
            if (!dtStatusFailed(status) && endRef != 0)
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dtPolyRef endRef = findNearestPolyExpanding(navMeshQuery, queryFilter, end, halfExtents);
 | 
			
		||||
        if (endRef == 0)
 | 
			
		||||
            return Status::EndPolygonNotFound;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue