Ticket #3588: short-rangememusage.patch

File short-rangememusage.patch, 6.0 KB (added by wraitii, 8 years ago)
  • source/simulation2/components/CCmpPathfinder_Vertex.cpp

     
    8181static const u8 QUADRANT_TLBR = QUADRANT_TL|QUADRANT_BR;
    8282static const u8 QUADRANT_ALL = QUADRANT_BLTR|QUADRANT_TLBR;
    8383
    84 // A vertex around the corners of an obstruction
    85 // (paths will be sequences of these vertexes)
    86 struct Vertex
    87 {
    88     enum
    89     {
    90         UNEXPLORED,
    91         OPEN,
    92         CLOSED,
    93     };
    94 
    95     CFixedVector2D p;
    96     fixed g, h;
    97     u16 pred;
    98     u8 status;
    99     u8 quadInward : 4; // the quadrant which is inside the shape (or NONE)
    100     u8 quadOutward : 4; // the quadrants of the next point on the path which this vertex must be in, given 'pred'
    101 };
    102 
    103 // Obstruction edges (paths will not cross any of these).
    104 // Defines the two points of the edge.
    105 struct Edge
    106 {
    107     CFixedVector2D p0, p1;
    108 };
    109 
    110 // Axis-aligned obstruction squares (paths will not cross any of these).
    111 // Defines the opposing corners of an axis-aligned square
    112 // (from which four individual edges can be trivially computed), requiring p0 <= p1
    113 struct Square
    114 {
    115     CFixedVector2D p0, p1;
    116 };
    117 
    118 // Axis-aligned obstruction edges.
    119 // p0 defines one end; c1 is either the X or Y coordinate of the other end,
    120 // depending on the context in which this is used.
    121 struct EdgeAA
    122 {
    123     CFixedVector2D p0;
    124     fixed c1;
    125 };
    126 
    12784// When computing vertexes to insert into the search graph,
    12885// add a small delta so that the vertexes of an edge don't get interpreted
    12986// as crossing the edge (given minor numerical inaccuracies)
     
    362319    }
    363320
    364321    // XXX rewrite this stuff
    365 
     322    std::vector<u16> segmentsR;
     323    std::vector<u16> segmentsL;
    366324    for (int j = j0; j < j1; ++j)
    367325    {
    368         std::vector<u16> segmentsR;
    369         std::vector<u16> segmentsL;
    370 
     326        segmentsR.clear();
     327        segmentsL.clear();
    371328        for (int i = i0; i <= i1; ++i)
    372329        {
    373330            bool a = IS_PASSABLE(grid.get(i, j+1), passClass);
     
    420377            }
    421378        }
    422379    }
    423 
     380    std::vector<u16> segmentsU;
     381    std::vector<u16> segmentsD;
    424382    for (int i = i0; i < i1; ++i)
    425383    {
    426         std::vector<u16> segmentsU;
    427         std::vector<u16> segmentsD;
    428 
     384        segmentsU.clear();
     385        segmentsD.clear();
    429386        for (int j = j0; j <= j1; ++j)
    430387        {
    431388            bool a = IS_PASSABLE(grid.get(i+1, j), passClass);
     
    594551
    595552    // List of collision edges - paths must never cross these.
    596553    // (Edges are one-sided so intersections are fine in one direction, but not the other direction.)
    597     std::vector<Edge> edges;
    598     std::vector<Square> edgeSquares; // axis-aligned squares; equivalent to 4 edges
     554    edges.clear();
     555    edgeSquares.clear(); // axis-aligned squares; equivalent to 4 edges
    599556
    600557    // Create impassable edges at the max-range boundary, so we can't escape the region
    601558    // where we're meant to be searching
     
    617574
    618575    // List of obstruction vertexes (plus start/end points); we'll try to find paths through
    619576    // the graph defined by these vertexes
    620     std::vector<Vertex> vertexes;
     577    vertexes.clear();
    621578
    622579    // Add the start point to the graph
    623580    CFixedVector2D posStart(x0, z0);
     
    818775        // since they're more likely to block the rays
    819776        std::sort(edgeSquares.begin(), edgeSquares.end(), SquareSort(vertexes[curr.id].p));
    820777
    821         std::vector<Edge> edgesUnaligned;
    822         std::vector<EdgeAA> edgesLeft;
    823         std::vector<EdgeAA> edgesRight;
    824         std::vector<EdgeAA> edgesBottom;
    825         std::vector<EdgeAA> edgesTop;
     778        edgesUnaligned.clear();
     779        edgesLeft.clear();
     780        edgesRight.clear();
     781        edgesBottom.clear();
     782        edgesTop.clear();
    826783        SplitAAEdges(vertexes[curr.id].p, edges, edgeSquares, edgesUnaligned, edgesLeft, edgesRight, edgesBottom, edgesTop);
    827784
    828785        // Check the lines to every other vertex
  • source/simulation2/components/CCmpPathfinder_Common.h

     
    7373    entity_id_t notify;
    7474};
    7575
     76// A vertex around the corners of an obstruction
     77// (paths will be sequences of these vertexes)
     78struct Vertex
     79{
     80    enum
     81    {
     82        UNEXPLORED,
     83        OPEN,
     84        CLOSED,
     85    };
     86   
     87    CFixedVector2D p;
     88    fixed g, h;
     89    u16 pred;
     90    u8 status;
     91    u8 quadInward : 4; // the quadrant which is inside the shape (or NONE)
     92    u8 quadOutward : 4; // the quadrants of the next point on the path which this vertex must be in, given 'pred'
     93};
     94
     95// Obstruction edges (paths will not cross any of these).
     96// Defines the two points of the edge.
     97struct Edge
     98{
     99    CFixedVector2D p0, p1;
     100};
     101
     102// Axis-aligned obstruction squares (paths will not cross any of these).
     103// Defines the opposing corners of an axis-aligned square
     104// (from which four individual edges can be trivially computed), requiring p0 <= p1
     105struct Square
     106{
     107    CFixedVector2D p0, p1;
     108};
     109
     110// Axis-aligned obstruction edges.
     111// p0 defines one end; c1 is either the X or Y coordinate of the other end,
     112// depending on the context in which this is used.
     113struct EdgeAA
     114{
     115    CFixedVector2D p0;
     116    fixed c1;
     117};
     118
    76119/**
    77120 * Implementation of ICmpPathfinder
    78121 */
     
    123166   
    124167    u16 m_MaxSameTurnMoves; // max number of moves that can be created and processed in the same turn
    125168
     169    // memory optimizations: those vectors are created once, reused for all calculations;
     170    std::vector<Edge> edgesUnaligned;
     171    std::vector<EdgeAA> edgesLeft;
     172    std::vector<EdgeAA> edgesRight;
     173    std::vector<EdgeAA> edgesBottom;
     174    std::vector<EdgeAA> edgesTop;
     175   
     176    // List of obstruction vertexes (plus start/end points); we'll try to find paths through
     177    // the graph defined by these vertexes
     178    std::vector<Vertex> vertexes;
     179    // List of collision edges - paths must never cross these.
     180    // (Edges are one-sided so intersections are fine in one direction, but not the other direction.)
     181    std::vector<Edge> edges;
     182    std::vector<Square> edgeSquares; // axis-aligned squares; equivalent to 4 edges
     183   
    126184    bool m_DebugOverlay;
    127185    std::vector<SOverlayLine> m_DebugOverlayShortPathLines;
    128186    AtlasOverlay* m_AtlasOverlay;