Ticket #2025: pathfind_test_banch_vanilla_update.patch

File pathfind_test_banch_vanilla_update.patch, 3.5 KB (added by tuan kuranes, 11 years ago)
  • source/simulation2/components/tests/test_Pathfinder.h

     
    6868        CMapReader* mapReader = new CMapReader(); // it'll call "delete this" itself
    6969
    7070        LDR_BeginRegistering();
    71         mapReader->LoadMap(L"maps/scenarios/Median Oasis.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     71        mapReader->LoadMap(L"maps/scenarios/Median Oasis 01.pmp", &terrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    7272            &sim2, &sim2.GetSimContext(), -1, false);
    7373        LDR_EndRegistering();
    7474        TS_ASSERT_OK(LDR_NonprogressiveLoad());
     
    9090            printf("%d: %f %f\n", (int)i, path.m_Waypoints[i].x.ToDouble(), path.m_Waypoints[i].z.ToDouble());
    9191#endif
    9292
    93         double t = timer_Time();
    9493
    9594        srand(1234);
     95
     96        std::vector<ICmpPathfinder::Goal> goals;
     97
     98        std::vector<entity_pos_t> x0s;
     99        std::vector<entity_pos_t> z0s;
    96100        for (size_t j = 0; j < 1024*2; ++j)
    97101        {
    98102            entity_pos_t x0 = entity_pos_t::FromInt(rand() % 512);
     
    100104            entity_pos_t x1 = x0 + entity_pos_t::FromInt(rand() % 64);
    101105            entity_pos_t z1 = z0 + entity_pos_t::FromInt(rand() % 64);
    102106            ICmpPathfinder::Goal goal = { ICmpPathfinder::Goal::POINT, x1, z1 };
     107            x0s.push_back(x0);
     108            z0s.push_back(z0);
     109            goals.push_back(goal);
     110        }
    103111
    104             ICmpPathfinder::Path path;
    105             cmp->ComputePath(x0, z0, goal, cmp->GetPassabilityClass("default"), cmp->GetCostClass("default"), path);
     112        double t = timer_Time();
     113
     114       
     115        ICmpPathfinder::Path path;
     116        for (size_t j = 0; j < 1024*2; ++j)
     117        {
     118            cmp->ComputePath(x0s[j], z0s[j], goals[j], cmp->GetPassabilityClass("default"), cmp->GetCostClass("default"), path);
    106119        }
    107120
    108121        t = timer_Time() - t;
    109         printf("[%f]", t);
     122        printf("\nTestCmpPathfinder ComputePath[%f]", t);
    110123    }
    111124
    112125    void test_performance_short_DISABLED()
     
    124137        CmpPtr<ICmpPathfinder> cmpPathfinder(sim2, SYSTEM_ENTITY);
    125138
    126139        srand(0);
     140
    127141        for (size_t i = 0; i < 200; ++i)
    128142        {
    129143            fixed x = fixed::FromFloat(1.5f*range.ToFloat() * rand()/(float)RAND_MAX);
     
    131145//          printf("# %f %f\n", x.ToFloat(), z.ToFloat());
    132146            cmpObstructionMan->AddUnitShape(INVALID_ENTITY, x, z, fixed::FromInt(2), 0, INVALID_ENTITY);
    133147        }
     148           
     149        double t = timer_Time();
    134150
    135         NullObstructionFilter filter;
    136         ICmpPathfinder::Goal goal = { ICmpPathfinder::Goal::POINT, range, range };
    137         ICmpPathfinder::Path path;
    138         cmpPathfinder->ComputeShortPath(filter, range/3, range/3, fixed::FromInt(2), range, goal, 0, path);
    139         for (size_t i = 0; i < path.m_Waypoints.size(); ++i)
    140             printf("# %d: %f %f\n", (int)i, path.m_Waypoints[i].x.ToFloat(), path.m_Waypoints[i].z.ToFloat());
     151        for (size_t j = 0; j < 1024*2; ++j)
     152        {
     153
     154            NullObstructionFilter filter;
     155            ICmpPathfinder::Goal goal = { ICmpPathfinder::Goal::POINT, range, range };
     156            ICmpPathfinder::Path path;
     157
     158            cmpPathfinder->ComputeShortPath(filter, range/3, range/3, fixed::FromInt(2), range, goal, 0, path);
     159        }
     160           
     161        t = timer_Time() - t;
     162       
     163        printf("\nTestCmpPathfinder ComputeShortPath[%f]\n", t);
     164        {
     165            NullObstructionFilter filter;
     166            ICmpPathfinder::Goal goal = { ICmpPathfinder::Goal::POINT, range, range };
     167            ICmpPathfinder::Path path;
     168
     169            cmpPathfinder->ComputeShortPath(filter, range/3, range/3, fixed::FromInt(2), range, goal, 0, path);
     170                for (size_t i = 0; i < path.m_Waypoints.size(); ++i)
     171                    printf("# %d: %f %f\n", (int)i, path.m_Waypoints[i].x.ToFloat(), path.m_Waypoints[i].z.ToFloat());
     172        }
    141173    }
    142174};