Ticket #1942: Clip.patch

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

Small optimization, removing some trivially unreachable vertices.

  • source/simulation2/components/CCmpPathfinder_Vertex.cpp

    diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp
    index 5ab11b6..e817108 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 && start.p.Y >= edgeSquares[i].p0.Y && start.p.X <= edgeSquares[i].p1.X && start.p.Y <= edgeSquares[i].p1.Y)
     706            continue;
     707
     708        // Remove every non-start/goal vertex that is inside an edgeSquare;
     709        // since remove() would be inefficient, just mark it as closed instead.
     710        for (size_t j = 2; j < vertexes.size(); ++j)
     711        {
     712            if (vertexes[j].p.X >= edgeSquares[i].p0.X && vertexes[j].p.Y >= edgeSquares[i].p0.Y && vertexes[j].p.X <= edgeSquares[i].p1.X && vertexes[j].p.Y <= edgeSquares[i].p1.Y)
     713                vertexes[j].status = Vertex::CLOSED;
     714        }
     715    }
     716
    701717    ENSURE(vertexes.size() < 65536); // we store array indexes as u16
    702718
    703719    // Render the debug overlay