Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/tests/test_Pathfinder.h
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | #endif | ||||
{ | { | ||||
entity_pos_t x0 = entity_pos_t::FromInt(rand() % 512); | entity_pos_t x0 = entity_pos_t::FromInt(rand() % 512); | ||||
entity_pos_t z0 = entity_pos_t::FromInt(rand() % 512); | entity_pos_t z0 = entity_pos_t::FromInt(rand() % 512); | ||||
entity_pos_t x1 = x0 + entity_pos_t::FromInt(rand() % 64); | entity_pos_t x1 = x0 + entity_pos_t::FromInt(rand() % 64); | ||||
entity_pos_t z1 = z0 + entity_pos_t::FromInt(rand() % 64); | entity_pos_t z1 = z0 + entity_pos_t::FromInt(rand() % 64); | ||||
PathGoal goal = { PathGoal::POINT, x1, z1 }; | PathGoal goal = { PathGoal::POINT, x1, z1 }; | ||||
WaypointPath path; | WaypointPath path; | ||||
cmp->ComputePath(x0, z0, goal, cmp->GetPassabilityClass("default"), path); | cmp->ComputePathImmediate(x0, z0, goal, cmp->GetPassabilityClass("default"), path); | ||||
} | } | ||||
t = timer_Time() - t; | t = timer_Time() - t; | ||||
printf("[%f]", t); | printf("[%f]", t); | ||||
} | } | ||||
void test_performance_short_DISABLED() | void test_performance_short_DISABLED() | ||||
{ | { | ||||
Show All 14 Lines | void test_performance_short_DISABLED() | ||||
{ | { | ||||
fixed x = fixed::FromFloat(1.5f*range.ToFloat() * rand()/(float)RAND_MAX); | fixed x = fixed::FromFloat(1.5f*range.ToFloat() * rand()/(float)RAND_MAX); | ||||
fixed z = fixed::FromFloat(1.5f*range.ToFloat() * rand()/(float)RAND_MAX); | fixed z = fixed::FromFloat(1.5f*range.ToFloat() * rand()/(float)RAND_MAX); | ||||
// printf("# %f %f\n", x.ToFloat(), z.ToFloat()); | // printf("# %f %f\n", x.ToFloat(), z.ToFloat()); | ||||
cmpObstructionMan->AddUnitShape(INVALID_ENTITY, x, z, fixed::FromInt(2), 0, INVALID_ENTITY); | cmpObstructionMan->AddUnitShape(INVALID_ENTITY, x, z, fixed::FromInt(2), 0, INVALID_ENTITY); | ||||
} | } | ||||
PathGoal goal = { PathGoal::POINT, range, range }; | PathGoal goal = { PathGoal::POINT, range, range }; | ||||
WaypointPath path = cmpPathfinder->ComputeShortPath(ShortPathRequest{ 0, range/3, range/3, fixed::FromInt(2), range, goal, 0, false, 0, 0 }); | WaypointPath path = cmpPathfinder->ComputeShortPathImmediate(ShortPathRequest{ 0, range/3, range/3, fixed::FromInt(2), range, goal, 0, false, 0, 0 }); | ||||
for (size_t i = 0; i < path.m_Waypoints.size(); ++i) | for (size_t i = 0; i < path.m_Waypoints.size(); ++i) | ||||
printf("# %d: %f %f\n", (int)i, path.m_Waypoints[i].x.ToFloat(), path.m_Waypoints[i].z.ToFloat()); | printf("# %d: %f %f\n", (int)i, path.m_Waypoints[i].x.ToFloat(), path.m_Waypoints[i].z.ToFloat()); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
void DumpGrid(std::ostream& stream, const Grid<T>& grid, int mask) | void DumpGrid(std::ostream& stream, const Grid<T>& grid, int mask) | ||||
{ | { | ||||
for (u16 j = 0; j < grid.m_H; ++j) | for (u16 j = 0; j < grid.m_H; ++j) | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | void DumpPath(std::ostream& stream, int i0, int j0, int i1, int j1, CmpPtr<ICmpPathfinder>& cmpPathfinder) | ||||
entity_pos_t x0 = entity_pos_t::FromInt(i0); | entity_pos_t x0 = entity_pos_t::FromInt(i0); | ||||
entity_pos_t z0 = entity_pos_t::FromInt(j0); | entity_pos_t z0 = entity_pos_t::FromInt(j0); | ||||
entity_pos_t x1 = entity_pos_t::FromInt(i1); | entity_pos_t x1 = entity_pos_t::FromInt(i1); | ||||
entity_pos_t z1 = entity_pos_t::FromInt(j1); | entity_pos_t z1 = entity_pos_t::FromInt(j1); | ||||
PathGoal goal = { PathGoal::POINT, x1, z1 }; | PathGoal goal = { PathGoal::POINT, x1, z1 }; | ||||
WaypointPath path; | WaypointPath path; | ||||
cmpPathfinder->ComputePath(x0, z0, goal, cmpPathfinder->GetPassabilityClass("default"), path); | cmpPathfinder->ComputePathImmediate(x0, z0, goal, cmpPathfinder->GetPassabilityClass("default"), path); | ||||
u32 debugSteps; | u32 debugSteps; | ||||
double debugTime; | double debugTime; | ||||
Grid<u8> debugGrid; | Grid<u8> debugGrid; | ||||
cmpPathfinder->GetDebugData(debugSteps, debugTime, debugGrid); | cmpPathfinder->GetDebugData(debugSteps, debugTime, debugGrid); | ||||
// stream << " <g style='visibility:hidden'>\n"; | // stream << " <g style='visibility:hidden'>\n"; | ||||
stream << " <g>\n"; | stream << " <g>\n"; | ||||
Show All 32 Lines | void RepeatPath(int n, int i0, int j0, int i1, int j1, CmpPtr<ICmpPathfinder>& cmpPathfinder) | ||||
entity_pos_t z1 = entity_pos_t::FromInt(j1); | entity_pos_t z1 = entity_pos_t::FromInt(j1); | ||||
PathGoal goal = { PathGoal::POINT, x1, z1 }; | PathGoal goal = { PathGoal::POINT, x1, z1 }; | ||||
double t = timer_Time(); | double t = timer_Time(); | ||||
for (int i = 0; i < n; ++i) | for (int i = 0; i < n; ++i) | ||||
{ | { | ||||
WaypointPath path; | WaypointPath path; | ||||
cmpPathfinder->ComputePath(x0, z0, goal, cmpPathfinder->GetPassabilityClass("default"), path); | cmpPathfinder->ComputePathImmediate(x0, z0, goal, cmpPathfinder->GetPassabilityClass("default"), path); | ||||
} | } | ||||
t = timer_Time() - t; | t = timer_Time() - t; | ||||
debug_printf("### RepeatPath %fms each (%fs total)\n", 1000*t / n, t); | debug_printf("### RepeatPath %fms each (%fs total)\n", 1000*t / n, t); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator