Ticket #3588: UnorderedSetHierPath.patch
File UnorderedSetHierPath.patch, 3.8 KB (added by , 8 years ago) |
---|
-
HierarchicalPathfinder.cpp
576 576 RegionID source = Get(i0, j0, passClass); 577 577 578 578 // Find everywhere that's reachable 579 std::set<RegionID>reachableRegions;579 ReachableSet reachableRegions; 580 580 FindReachableRegions(source, reachableRegions, passClass); 581 581 582 582 // Check whether any reachable region contains the goal … … 641 641 642 642 void HierarchicalPathfinder::FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass) 643 643 { 644 std::set<RegionID>regions;644 ReachableSet regions; 645 645 FindPassableRegions(regions, passClass); 646 646 FindNearestNavcellInRegions(regions, i, j, passClass); 647 647 } 648 648 649 void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set<RegionID>& regions, u16& iGoal, u16& jGoal, pass_class_t passClass)649 void HierarchicalPathfinder::FindNearestNavcellInRegions(const ReachableSet& regions, u16& iGoal, u16& jGoal, pass_class_t passClass) 650 650 { 651 651 // Find the navcell in the given regions that's nearest to the goal navcell: 652 652 // * For each region, record the (squared) minimal distance to the goal point … … 703 703 jGoal = jBest; 704 704 } 705 705 706 void HierarchicalPathfinder::FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass)706 void HierarchicalPathfinder::FindReachableRegions(RegionID from, ReachableSet& reachable, pass_class_t passClass) 707 707 { 708 708 // Flood-fill the region graph, starting at 'from', 709 709 // collecting all the regions that are reachable via edges … … 725 725 } 726 726 } 727 727 728 void HierarchicalPathfinder::FindPassableRegions( std::set<RegionID>& regions, pass_class_t passClass)728 void HierarchicalPathfinder::FindPassableRegions(ReachableSet& regions, pass_class_t passClass) 729 729 { 730 730 // Construct a set of all regions of all chunks for this pass class 731 731 for (const Chunk& chunk : m_Chunks[passClass]) … … 769 769 if (from.r == 0) 770 770 continue; 771 771 772 std::set<RegionID>reachable;772 ReachableSet reachable; 773 773 FindReachableRegions(from, reachable, passClass); 774 774 775 775 for (const RegionID& region : reachable) -
HierarchicalPathfinder.h
24 24 #include "Render.h" 25 25 #include "graphics/SColor.h" 26 26 27 #include <unordered_set> 28 27 29 /** 28 30 * Hierarchical pathfinder. 29 31 * … … 73 75 return ((ci == b.ci) && (cj == b.cj) && (r == b.r)); 74 76 } 75 77 }; 78 struct RegionIDHash 79 { 80 size_t operator() (const RegionID &a) const { 81 return *((u32*)&a); 82 } 83 }; 76 84 77 85 HierarchicalPathfinder(); 78 86 ~HierarchicalPathfinder(); … … 147 155 }; 148 156 149 157 typedef std::map<RegionID, std::set<RegionID> > EdgesMap; 158 typedef std::unordered_set<RegionID, RegionIDHash> ReachableSet; 150 159 151 160 void FindEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges); 152 161 153 void FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass);162 void FindReachableRegions(RegionID from, ReachableSet& reachable, pass_class_t passClass); 154 163 155 void FindPassableRegions( std::set<RegionID>& regions, pass_class_t passClass);164 void FindPassableRegions(ReachableSet& regions, pass_class_t passClass); 156 165 157 166 /** 158 167 * Updates @p iGoal and @p jGoal to the navcell that is the nearest to the … … 159 168 * initial goal coordinates, in one of the given @p regions. 160 169 * (Assumes @p regions is non-empty.) 161 170 */ 162 void FindNearestNavcellInRegions(const std::set<RegionID>& regions, u16& iGoal, u16& jGoal, pass_class_t passClass);171 void FindNearestNavcellInRegions(const ReachableSet& regions, u16& iGoal, u16& jGoal, pass_class_t passClass); 163 172 164 173 Chunk& GetChunk(u8 ci, u8 cj, pass_class_t passClass) 165 174 {