Ticket #1756: PathProfile.patch
File PathProfile.patch, 5.7 KB (added by , 10 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder.cpp
36 36 #include "simulation2/helpers/Rasterize.h" 37 37 #include "simulation2/serialization/SerializeTemplates.h" 38 38 39 #define PATHFIND_PROFILE 1 40 #if PATHFIND_PROFILE 41 #include "lib/timer.h" 42 TIMER_ADD_CLIENT(tc_ProcessSameTurnMoves); 43 TIMER_ADD_CLIENT(tc_FinishAsyncRequests); 44 TIMER_ADD_CLIENT(tc_ProcessLongRequests); 45 TIMER_ADD_CLIENT(tc_ProcessShortRequests); 46 TIMER_ADD_CLIENT(tc_ProcessLongRequests_Loop); 47 #else 48 #define TIMER_ACCRUE(a) ; 49 #endif 50 51 39 52 // Default cost to move a single tile is a fairly arbitrary number, which should be big 40 53 // enough to be precise when multiplied/divided and small enough to never overflow when 41 54 // summing the cost of a whole path. … … 586 599 587 600 void CCmpPathfinder::FinishAsyncRequests() 588 601 { 602 TIMER_ACCRUE(tc_FinishAsyncRequests); 603 589 604 // Save the request queue in case it gets modified while iterating 590 605 std::vector<AsyncLongPathRequest> longRequests; 591 606 m_AsyncLongPathRequests.swap(longRequests); … … 604 619 605 620 void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>& longRequests) 606 621 { 622 TIMER_ACCRUE(tc_ProcessLongRequests); 623 607 624 for (size_t i = 0; i < longRequests.size(); ++i) 608 625 { 626 TIMER_ACCRUE(tc_ProcessLongRequests_Loop); 609 627 const AsyncLongPathRequest& req = longRequests[i]; 610 628 Path path; 611 629 #if PATHFIND_USE_JPS … … 620 638 621 639 void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests) 622 640 { 641 TIMER_ACCRUE(tc_ProcessShortRequests); 642 623 643 for (size_t i = 0; i < shortRequests.size(); ++i) 624 644 { 625 645 const AsyncShortPathRequest& req = shortRequests[i]; … … 633 653 634 654 void CCmpPathfinder::ProcessSameTurnMoves() 635 655 { 656 TIMER_ACCRUE(tc_ProcessSameTurnMoves); 657 636 658 if (!m_AsyncLongPathRequests.empty()) 637 659 { 638 660 // Figure out how many moves we can do this time -
source/simulation2/components/CCmpPathfinder_Hier.cpp
23 23 #include "renderer/TerrainOverlay.h" 24 24 #include "simulation2/helpers/Render.h" 25 25 26 #define PATHFINDER_HIER_PROFILE 1 27 #if PATHFINDER_HIER_PROFILE 28 #include "lib/timer.h" 29 TIMER_ADD_CLIENT(tc_MakeGoalReachable); 30 #else 31 #define TIMER_ACCRUE(a) ; 32 #endif 33 26 34 class PathfinderHierOverlay; 27 35 28 36 /** … … 531 539 532 540 bool CCmpPathfinder_Hier::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass) 533 541 { 542 TIMER_ACCRUE(tc_MakeGoalReachable); 534 543 RegionID source = Get(i0, j0, passClass); 535 544 536 545 // Find everywhere that's reachable … … 553 562 if (!goal.RectContainsGoal(x0, z0, x1, z1)) 554 563 continue; 555 564 556 // If the region contains the goal area, the goal is reachable557 // and we don't need to move it565 // If the region contains the goal area, the goal is reachable 566 // and we don't need to move it 558 567 if (GetChunk(it->ci, it->cj, passClass).RegionContainsGoal(it->r, goal)) 559 return false;560 }568 return false; 569 } 561 570 562 571 // The goal area wasn't reachable, 563 572 // so find the navcell that's nearest to the goal's center -
source/simulation2/components/CCmpPathfinder_JPS.cpp
27 27 28 28 #define PATHFIND_STATS 0 29 29 30 #define USE_JUMPPOINT_CACHE 130 #define USE_JUMPPOINT_CACHE 0 31 31 32 32 #define ACCEPT_DIAGONAL_GAPS 0 33 33 … … 243 243 mirror \ 244 244 ? (transpose ? terrain.get((j), w-1-(i)) : terrain.get(w-1-(i), (j))) \ 245 245 : (transpose ? terrain.get((j), (i)) : terrain.get((i), (j))) \ 246 , passClass)246 , passClass) 247 247 248 248 rows.reserve(h); 249 249 for (int j = 0; j < h; ++j) … … 456 456 PathGoal goal; 457 457 458 458 u16 iGoal, jGoal; // goal tile 459 459 460 460 ICmpPathfinder::pass_class_t passClass; 461 461 462 462 PriorityQueue open; … … 807 807 808 808 PathfinderStateJPS state = { 0 }; 809 809 810 #if USE_JUMPPOINT_CACHE 810 811 state.jpc = m_JumpPointCache[passClass].get(); 811 #if USE_JUMPPOINT_CACHE812 812 if (!state.jpc) 813 813 { 814 814 state.jpc = new JumpPointCache; -
source/simulation2/helpers/PathGoal.cpp
23 23 #include "simulation2/components/ICmpObstructionManager.h" 24 24 #include "simulation2/helpers/Geometry.h" 25 25 26 #define PATHGOAL_PROFILE 1 27 #if PATHGOAL_PROFILE 28 #include "lib/timer.h" 29 TIMER_ADD_CLIENT(tc_NavcellContainsGoal); 30 #else 31 #define TIMER_ACCRUE(a) ; 32 #endif 33 26 34 static bool NavcellContainsCircle(int i, int j, fixed x, fixed z, fixed r, bool inside) 27 35 { 28 36 // Accept any navcell (i,j) that contains a point which is inside[/outside] … … 93 101 94 102 bool PathGoal::NavcellContainsGoal(int i, int j) const 95 103 { 104 TIMER_ACCRUE(tc_NavcellContainsGoal); 96 105 switch (type) 97 106 { 98 107 case POINT: … … 103 112 return gi == i && gj == j; 104 113 } 105 114 case CIRCLE: 106 return NavcellContainsCircle(i, j, x, z, hw, true);115 return NavcellContainsCircle(i, j, x, z, hw, true); 107 116 case INVERTED_CIRCLE: 108 117 return NavcellContainsCircle(i, j, x, z, hw, false); 109 118 case SQUARE: 110 return NavcellContainsSquare(i, j, x, z, u, v, hw, hh, true);119 return NavcellContainsSquare(i, j, x, z, u, v, hw, hh, true); 111 120 case INVERTED_SQUARE: 112 121 return NavcellContainsSquare(i, j, x, z, u, v, hw, hh, false); 113 122 default: