Ticket #3588: UnorderedSetHierPath.patch

File UnorderedSetHierPath.patch, 3.8 KB (added by wraitii, 8 years ago)
  • HierarchicalPathfinder.cpp

     
    576576    RegionID source = Get(i0, j0, passClass);
    577577
    578578    // Find everywhere that's reachable
    579     std::set<RegionID> reachableRegions;
     579    ReachableSet reachableRegions;
    580580    FindReachableRegions(source, reachableRegions, passClass);
    581581
    582582    // Check whether any reachable region contains the goal
     
    641641
    642642void HierarchicalPathfinder::FindNearestPassableNavcell(u16& i, u16& j, pass_class_t passClass)
    643643{
    644     std::set<RegionID> regions;
     644    ReachableSet regions;
    645645    FindPassableRegions(regions, passClass);
    646646    FindNearestNavcellInRegions(regions, i, j, passClass);
    647647}
    648648
    649 void HierarchicalPathfinder::FindNearestNavcellInRegions(const std::set<RegionID>& regions, u16& iGoal, u16& jGoal, pass_class_t passClass)
     649void HierarchicalPathfinder::FindNearestNavcellInRegions(const ReachableSet& regions, u16& iGoal, u16& jGoal, pass_class_t passClass)
    650650{
    651651    // Find the navcell in the given regions that's nearest to the goal navcell:
    652652    // * For each region, record the (squared) minimal distance to the goal point
     
    703703    jGoal = jBest;
    704704}
    705705
    706 void HierarchicalPathfinder::FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass)
     706void HierarchicalPathfinder::FindReachableRegions(RegionID from, ReachableSet& reachable, pass_class_t passClass)
    707707{
    708708    // Flood-fill the region graph, starting at 'from',
    709709    // collecting all the regions that are reachable via edges
     
    725725    }
    726726}
    727727
    728 void HierarchicalPathfinder::FindPassableRegions(std::set<RegionID>& regions, pass_class_t passClass)
     728void HierarchicalPathfinder::FindPassableRegions(ReachableSet& regions, pass_class_t passClass)
    729729{
    730730    // Construct a set of all regions of all chunks for this pass class
    731731    for (const Chunk& chunk : m_Chunks[passClass])
     
    769769            if (from.r == 0)
    770770                continue;
    771771
    772             std::set<RegionID> reachable;
     772            ReachableSet reachable;
    773773            FindReachableRegions(from, reachable, passClass);
    774774
    775775            for (const RegionID& region : reachable)
  • HierarchicalPathfinder.h

     
    2424#include "Render.h"
    2525#include "graphics/SColor.h"
    2626
     27#include <unordered_set>
     28
    2729/**
    2830 * Hierarchical pathfinder.
    2931 *
     
    7375            return ((ci == b.ci) && (cj == b.cj) && (r == b.r));
    7476        }
    7577    };
     78    struct RegionIDHash
     79    {
     80        size_t operator() (const RegionID &a) const {
     81            return *((u32*)&a);
     82        }
     83    };
    7684
    7785    HierarchicalPathfinder();
    7886    ~HierarchicalPathfinder();
     
    147155    };
    148156
    149157    typedef std::map<RegionID, std::set<RegionID> > EdgesMap;
     158    typedef std::unordered_set<RegionID, RegionIDHash> ReachableSet;
    150159
    151160    void FindEdges(u8 ci, u8 cj, pass_class_t passClass, EdgesMap& edges);
    152161
    153     void FindReachableRegions(RegionID from, std::set<RegionID>& reachable, pass_class_t passClass);
     162    void FindReachableRegions(RegionID from, ReachableSet& reachable, pass_class_t passClass);
    154163
    155     void FindPassableRegions(std::set<RegionID>& regions, pass_class_t passClass);
     164    void FindPassableRegions(ReachableSet& regions, pass_class_t passClass);
    156165
    157166    /**
    158167     * Updates @p iGoal and @p jGoal to the navcell that is the nearest to the
     
    159168     * initial goal coordinates, in one of the given @p regions.
    160169     * (Assumes @p regions is non-empty.)
    161170     */
    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);
    163172
    164173    Chunk& GetChunk(u8 ci, u8 cj, pass_class_t passClass)
    165174    {