Ticket #3588: short-rangememusage.patch
File short-rangememusage.patch, 6.0 KB (added by , 8 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder_Vertex.cpp
81 81 static const u8 QUADRANT_TLBR = QUADRANT_TL|QUADRANT_BR; 82 82 static const u8 QUADRANT_ALL = QUADRANT_BLTR|QUADRANT_TLBR; 83 83 84 // A vertex around the corners of an obstruction85 // (paths will be sequences of these vertexes)86 struct Vertex87 {88 enum89 {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 Edge106 {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 square112 // (from which four individual edges can be trivially computed), requiring p0 <= p1113 struct Square114 {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 EdgeAA122 {123 CFixedVector2D p0;124 fixed c1;125 };126 127 84 // When computing vertexes to insert into the search graph, 128 85 // add a small delta so that the vertexes of an edge don't get interpreted 129 86 // as crossing the edge (given minor numerical inaccuracies) … … 362 319 } 363 320 364 321 // XXX rewrite this stuff 365 322 std::vector<u16> segmentsR; 323 std::vector<u16> segmentsL; 366 324 for (int j = j0; j < j1; ++j) 367 325 { 368 std::vector<u16> segmentsR; 369 std::vector<u16> segmentsL; 370 326 segmentsR.clear(); 327 segmentsL.clear(); 371 328 for (int i = i0; i <= i1; ++i) 372 329 { 373 330 bool a = IS_PASSABLE(grid.get(i, j+1), passClass); … … 420 377 } 421 378 } 422 379 } 423 380 std::vector<u16> segmentsU; 381 std::vector<u16> segmentsD; 424 382 for (int i = i0; i < i1; ++i) 425 383 { 426 std::vector<u16> segmentsU; 427 std::vector<u16> segmentsD; 428 384 segmentsU.clear(); 385 segmentsD.clear(); 429 386 for (int j = j0; j <= j1; ++j) 430 387 { 431 388 bool a = IS_PASSABLE(grid.get(i+1, j), passClass); … … 594 551 595 552 // List of collision edges - paths must never cross these. 596 553 // (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 edges554 edges.clear(); 555 edgeSquares.clear(); // axis-aligned squares; equivalent to 4 edges 599 556 600 557 // Create impassable edges at the max-range boundary, so we can't escape the region 601 558 // where we're meant to be searching … … 617 574 618 575 // List of obstruction vertexes (plus start/end points); we'll try to find paths through 619 576 // the graph defined by these vertexes 620 std::vector<Vertex> vertexes;577 vertexes.clear(); 621 578 622 579 // Add the start point to the graph 623 580 CFixedVector2D posStart(x0, z0); … … 818 775 // since they're more likely to block the rays 819 776 std::sort(edgeSquares.begin(), edgeSquares.end(), SquareSort(vertexes[curr.id].p)); 820 777 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(); 826 783 SplitAAEdges(vertexes[curr.id].p, edges, edgeSquares, edgesUnaligned, edgesLeft, edgesRight, edgesBottom, edgesTop); 827 784 828 785 // Check the lines to every other vertex -
source/simulation2/components/CCmpPathfinder_Common.h
73 73 entity_id_t notify; 74 74 }; 75 75 76 // A vertex around the corners of an obstruction 77 // (paths will be sequences of these vertexes) 78 struct 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. 97 struct 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 105 struct 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. 113 struct EdgeAA 114 { 115 CFixedVector2D p0; 116 fixed c1; 117 }; 118 76 119 /** 77 120 * Implementation of ICmpPathfinder 78 121 */ … … 123 166 124 167 u16 m_MaxSameTurnMoves; // max number of moves that can be created and processed in the same turn 125 168 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 126 184 bool m_DebugOverlay; 127 185 std::vector<SOverlayLine> m_DebugOverlayShortPathLines; 128 186 AtlasOverlay* m_AtlasOverlay;