Ticket #1756: pathperf7_dry1.patch

File pathperf7_dry1.patch, 3.8 KB (added by yunta, 11 years ago)

Apply after pathperf7.

  • source/simulation2/components/CCmpPathfinder.cpp

    diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp
    index a4097d0..87b0aa9 100644
    a b void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathReques  
    629629    }
    630630}
    631631
    632 void CCmpPathfinder::ProcessSameTurnMoves()
     632
     633template <class RequestType> void CCmpPathfinder::ProcessSameTurnMoves(std::vector<RequestType> &m_AsyncPathRequests, void (CCmpPathfinder::*ProcessRequests)(const std::vector<RequestType>&))
    633634{
    634     if (!m_AsyncLongPathRequests.empty())
     635    if (!m_AsyncPathRequests.empty())
    635636    {
    636637        // Figure out how many moves we can do this time
    637638        i32 moveCount = m_MaxSameTurnMoves - m_SameTurnMovesCount;
    void CCmpPathfinder::ProcessSameTurnMoves()  
    640641            return;
    641642
    642643        // Copy the long request elements we are going to process into a new array
    643         std::vector<AsyncLongPathRequest> longRequests;
    644         if ((i32)m_AsyncLongPathRequests.size() <= moveCount)
     644        std::vector<RequestType> requests;
     645        if ((i32)m_AsyncPathRequests.size() <= moveCount)
    645646        {
    646             m_AsyncLongPathRequests.swap(longRequests);
    647             moveCount = (i32)longRequests.size();
     647            m_AsyncPathRequests.swap(requests);
     648            moveCount = (i32)requests.size();
    648649        }
    649650        else
    650651        {
    651             longRequests.resize(moveCount);
    652             copy(m_AsyncLongPathRequests.begin(), m_AsyncLongPathRequests.begin() + moveCount, longRequests.begin());
    653             m_AsyncLongPathRequests.erase(m_AsyncLongPathRequests.begin(), m_AsyncLongPathRequests.begin() + moveCount);
     652            requests.resize(moveCount);
     653            copy(m_AsyncPathRequests.begin(), m_AsyncPathRequests.begin() + moveCount, requests.begin());
     654            m_AsyncPathRequests.erase(m_AsyncPathRequests.begin(), m_AsyncPathRequests.begin() + moveCount);
    654655        }
    655656
    656         ProcessLongRequests(longRequests);
     657        (this->*ProcessRequests)(requests);
    657658
    658659        m_SameTurnMovesCount = (u16)(m_SameTurnMovesCount + moveCount);
    659660    }
    660    
    661     if (!m_AsyncShortPathRequests.empty())
    662     {
    663         // Figure out how many moves we can do now
    664         i32 moveCount = m_MaxSameTurnMoves - m_SameTurnMovesCount;
     661}
    665662
    666         if (moveCount <= 0)
    667             return;
    668663
    669         // Copy the short request elements we are going to process into a new array
    670         std::vector<AsyncShortPathRequest> shortRequests;
    671         if ((i32)m_AsyncShortPathRequests.size() <= moveCount)
    672         {
    673             m_AsyncShortPathRequests.swap(shortRequests);
    674             moveCount = (i32)shortRequests.size();
    675         }
    676         else
    677         {
    678             shortRequests.resize(moveCount);
    679             copy(m_AsyncShortPathRequests.begin(), m_AsyncShortPathRequests.begin() + moveCount, shortRequests.begin());
    680             m_AsyncShortPathRequests.erase(m_AsyncShortPathRequests.begin(), m_AsyncShortPathRequests.begin() + moveCount);
    681         }
     664void CCmpPathfinder::ProcessSameTurnMoves()
     665{
     666    ProcessSameTurnMoves(m_AsyncLongPathRequests, &CCmpPathfinder::ProcessLongRequests);
     667    ProcessSameTurnMoves(m_AsyncShortPathRequests, &CCmpPathfinder::ProcessShortRequests);
     668}
    682669
    683         ProcessShortRequests(shortRequests);
    684670
    685         m_SameTurnMovesCount = (u16)(m_SameTurnMovesCount + moveCount);
    686     }
    687 }
    688671
    689672//////////////////////////////////////////////////////////
    690673
  • source/simulation2/components/CCmpPathfinder_Common.h

    diff --git a/source/simulation2/components/CCmpPathfinder_Common.h b/source/simulation2/components/CCmpPathfinder_Common.h
    index 9f39729..9555437 100644
    a b public:  
    394394    void ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests);
    395395
    396396    virtual void ProcessSameTurnMoves();
     397    template <class RequestType> void ProcessSameTurnMoves(std::vector<RequestType> &m_AsyncPathRequests, void (CCmpPathfinder::*ProcessRequests)(const std::vector<RequestType>&));
    397398
    398399    /**
    399400     * Compute the navcell indexes on the grid nearest to a given point