Ticket #3925: Clip.patch

File Clip.patch, 2.3 KB (added by fsincos, 8 years ago)

First patch of the series, containing Clip and Partial Sort.

  • source/simulation2/components/CCmpPathfinder_Vertex.cpp

    diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp
    index 5ab11b6..f0fa1b3 100644
    a b void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    698698        // to reduce the search space
    699699    }
    700700
     701    // Clip out vertices that are inside an edgeSquare (i.e. trivially unreachable)
     702    for (size_t i = 0; i < edgeSquares.size(); ++i)
     703    {
     704        // If the start point is inside the square, ignore it
     705        if (start.p.X >= edgeSquares[i].p0.X &&
     706            start.p.Y >= edgeSquares[i].p0.Y &&
     707            start.p.X <= edgeSquares[i].p1.X &&
     708            start.p.Y <= edgeSquares[i].p1.Y)
     709            continue;
     710
     711        // Remove every non-start/goal vertex that is inside an edgeSquare;
     712        // since remove() would be inefficient, just mark it as closed instead.
     713        for (size_t j = 2; j < vertexes.size(); ++j)
     714            if (vertexes[j].p.X >= edgeSquares[i].p0.X &&
     715                vertexes[j].p.Y >= edgeSquares[i].p0.Y &&
     716                vertexes[j].p.X <= edgeSquares[i].p1.X &&
     717                vertexes[j].p.Y <= edgeSquares[i].p1.Y)
     718                vertexes[j].status = Vertex::CLOSED;
     719    }
     720
    701721    ENSURE(vertexes.size() < 65536); // we store array indexes as u16
    702722
    703723    // Render the debug overlay
    void CCmpPathfinder::ComputeShortPath(const IObstructionTestFilter& filter,  
    806826            break;
    807827        }
    808828
    809         // Sort the edges so ones nearer this vertex are checked first by CheckVisibility,
    810         // since they're more likely to block the rays
    811         std::sort(edgeSquares.begin(), edgeSquares.end(), SquareSort(vertexes[curr.id].p));
     829        // Sort the edges by distance in order to check those first that have a high probability of blocking a ray.
     830        // The heuristic based on distance is very rough, especially for squares that are further away;
     831        // we're also only really interested in the closest squares since they are the only ones that block a lot of rays.
     832        // Thus we only do a partial sort; the threshold is just a somewhat reasonable value.
     833        if (edgeSquares.size() > 8)
     834            std::partial_sort(edgeSquares.begin(), edgeSquares.begin() + 8, edgeSquares.end(), SquareSort(vertexes[curr.id].p));
    812835
    813836        std::vector<Edge> edgesUnaligned;
    814837        std::vector<EdgeAA> edgesLeft;