Ticket #1756: PathProfile.patch

File PathProfile.patch, 5.7 KB (added by kanetaka, 10 years ago)
  • source/simulation2/components/CCmpPathfinder.cpp

     
    3636#include "simulation2/helpers/Rasterize.h"
    3737#include "simulation2/serialization/SerializeTemplates.h"
    3838
     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
    3952// Default cost to move a single tile is a fairly arbitrary number, which should be big
    4053// enough to be precise when multiplied/divided and small enough to never overflow when
    4154// summing the cost of a whole path.
     
    586599
    587600void CCmpPathfinder::FinishAsyncRequests()
    588601{
     602    TIMER_ACCRUE(tc_FinishAsyncRequests);
     603
    589604    // Save the request queue in case it gets modified while iterating
    590605    std::vector<AsyncLongPathRequest> longRequests;
    591606    m_AsyncLongPathRequests.swap(longRequests);
     
    604619
    605620void CCmpPathfinder::ProcessLongRequests(const std::vector<AsyncLongPathRequest>& longRequests)
    606621{
     622    TIMER_ACCRUE(tc_ProcessLongRequests);
     623
    607624    for (size_t i = 0; i < longRequests.size(); ++i)
    608625    {
     626        TIMER_ACCRUE(tc_ProcessLongRequests_Loop);
    609627        const AsyncLongPathRequest& req = longRequests[i];
    610628        Path path;
    611629#if PATHFIND_USE_JPS
     
    620638
    621639void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests)
    622640{
     641    TIMER_ACCRUE(tc_ProcessShortRequests);
     642
    623643    for (size_t i = 0; i < shortRequests.size(); ++i)
    624644    {
    625645        const AsyncShortPathRequest& req = shortRequests[i];
     
    633653
    634654void CCmpPathfinder::ProcessSameTurnMoves()
    635655{
     656    TIMER_ACCRUE(tc_ProcessSameTurnMoves);
     657
    636658    if (!m_AsyncLongPathRequests.empty())
    637659    {
    638660        // Figure out how many moves we can do this time
  • source/simulation2/components/CCmpPathfinder_Hier.cpp

     
    2323#include "renderer/TerrainOverlay.h"
    2424#include "simulation2/helpers/Render.h"
    2525
     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
    2634class PathfinderHierOverlay;
    2735
    2836/**
     
    531539
    532540bool CCmpPathfinder_Hier::MakeGoalReachable(u16 i0, u16 j0, PathGoal& goal, pass_class_t passClass)
    533541{
     542    TIMER_ACCRUE(tc_MakeGoalReachable);
    534543    RegionID source = Get(i0, j0, passClass);
    535544
    536545    // Find everywhere that's reachable
     
    553562        if (!goal.RectContainsGoal(x0, z0, x1, z1))
    554563            continue;
    555564
    556         // If the region contains the goal area, the goal is reachable
    557         // and we don't need to move it
     565            // If the region contains the goal area, the goal is reachable
     566            // and we don't need to move it
    558567        if (GetChunk(it->ci, it->cj, passClass).RegionContainsGoal(it->r, goal))
    559             return false;
    560     }
     568                return false;
     569        }
    561570
    562571    // The goal area wasn't reachable,
    563572    // so find the navcell that's nearest to the goal's center
  • source/simulation2/components/CCmpPathfinder_JPS.cpp

     
    2727
    2828#define PATHFIND_STATS 0
    2929
    30 #define USE_JUMPPOINT_CACHE 1
     30#define USE_JUMPPOINT_CACHE 0
    3131
    3232#define ACCEPT_DIAGONAL_GAPS 0
    3333
     
    243243        mirror \
    244244        ? (transpose ? terrain.get((j), w-1-(i)) : terrain.get(w-1-(i), (j))) \
    245245        : (transpose ? terrain.get((j), (i)) : terrain.get((i), (j))) \
    246     , passClass)
     246        , passClass)
    247247
    248248        rows.reserve(h);
    249249        for (int j = 0; j < h; ++j)
     
    456456    PathGoal goal;
    457457
    458458    u16 iGoal, jGoal; // goal tile
    459 
     459   
    460460    ICmpPathfinder::pass_class_t passClass;
    461461
    462462    PriorityQueue open;
     
    807807
    808808    PathfinderStateJPS state = { 0 };
    809809
     810#if USE_JUMPPOINT_CACHE
    810811    state.jpc = m_JumpPointCache[passClass].get();
    811 #if USE_JUMPPOINT_CACHE
    812812    if (!state.jpc)
    813813    {
    814814        state.jpc = new JumpPointCache;
  • source/simulation2/helpers/PathGoal.cpp

     
    2323#include "simulation2/components/ICmpObstructionManager.h"
    2424#include "simulation2/helpers/Geometry.h"
    2525
     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
    2634static bool NavcellContainsCircle(int i, int j, fixed x, fixed z, fixed r, bool inside)
    2735{
    2836    // Accept any navcell (i,j) that contains a point which is inside[/outside]
     
    93101
    94102bool PathGoal::NavcellContainsGoal(int i, int j) const
    95103{
     104    TIMER_ACCRUE(tc_NavcellContainsGoal);
    96105    switch (type)
    97106    {
    98107    case POINT:
     
    103112        return gi == i && gj == j;
    104113    }
    105114    case CIRCLE:
    106         return NavcellContainsCircle(i, j, x, z, hw, true);
     115            return NavcellContainsCircle(i, j, x, z, hw, true);
    107116    case INVERTED_CIRCLE:
    108117        return NavcellContainsCircle(i, j, x, z, hw, false);
    109118    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);
    111120    case INVERTED_SQUARE:
    112121        return NavcellContainsSquare(i, j, x, z, u, v, hw, hh, false);
    113122    default: