Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/tests/test_HierPathfinder.h
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < grid.m_W; ++i) | ||||
printf("%i", grid.get(i, j)); | printf("%i", grid.get(i, j)); | ||||
} | } | ||||
printf("\n"); | printf("\n"); | ||||
} | } | ||||
} | } | ||||
void assert_blank(HierarchicalPathfinder& hierPath) | void assert_blank(HierarchicalPathfinder& hierPath) | ||||
{ | { | ||||
// test that the map has the same global region everywhere | |||||
HierarchicalPathfinder::GlobalRegionID globalRegionID = hierPath.GetGlobalRegion(35, 23, PASS_1); | |||||
for (size_t i = 0; i < mapSize; ++i) | |||||
Itms: Should be `u16`, not `size_t` (`mapSize` is `u16`, the function declaration has this as well). | |||||
for (size_t j = 0; j < mapSize; ++j) | |||||
{ | |||||
TS_ASSERT(globalRegionID == hierPath.GetGlobalRegion(i, j, PASS_1)); | |||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | |||||
} | |||||
u16 i = 89; | u16 i = 89; | ||||
u16 j = 34; | u16 j = 34; | ||||
hierPath.FindNearestPassableNavcell(i, j, PASS_1); | hierPath.FindNearestPassableNavcell(i, j, PASS_1); | ||||
TS_ASSERT(i == 89 && j == 34); | TS_ASSERT(i == 89 && j == 34); | ||||
for (auto& chunk : hierPath.m_Chunks[PASS_1]) | for (auto& chunk : hierPath.m_Chunks[PASS_1]) | ||||
TS_ASSERT(chunk.m_RegionsID.size() == 1); | TS_ASSERT(chunk.m_RegionsID.size() == 1); | ||||
Show All 38 Lines | void test_reachability_and_update() | ||||
for (u16 j = 0; j < mapSize; ++j) | for (u16 j = 0; j < mapSize; ++j) | ||||
{ | { | ||||
grid.set(125, j, 7); | grid.set(125, j, 7); | ||||
dirtyGrid.set(125, j, 1); | dirtyGrid.set(125, j, 1); | ||||
} | } | ||||
hierPath.Update(&grid, dirtyGrid); | hierPath.Update(&grid, dirtyGrid); | ||||
// Global region: check we are now split in two. | |||||
TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); | |||||
for (size_t j = 0; j < mapSize; ++j) | for (size_t j = 0; j < mapSize; ++j) | ||||
{ | |||||
TS_ASSERT(hierPath.Get(125, j, PASS_1).r == 0); | TS_ASSERT(hierPath.Get(125, j, PASS_1).r == 0); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(125, j, PASS_1) == 0); | |||||
} | |||||
for (size_t i = 0; i < 125; ++i) | |||||
for (size_t j = 0; j < mapSize; ++j) | |||||
{ | |||||
TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | |||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | |||||
} | |||||
for (size_t i = 126; i < mapSize; ++i) | |||||
for (size_t j = 0; j < mapSize; ++j) | |||||
{ | |||||
TS_ASSERT(hierPath.GetGlobalRegion(150, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | |||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | |||||
} | |||||
// number of connected regions: 3 in the middle (both sides), 2 in the corners. | // number of connected regions: 3 in the middle (both sides), 2 in the corners. | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 3); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 3); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(170, 120, PASS_1)].size() == 3); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(170, 120, PASS_1)].size() == 3); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(20, 20, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(20, 20, PASS_1)].size() == 2); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(220, 220, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(220, 220, PASS_1)].size() == 2); | ||||
std::set<HierarchicalPathfinder::RegionID> reachables; | std::set<HierarchicalPathfinder::RegionID> reachables; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | void test_reachability_and_update() | ||||
} | } | ||||
for (u16 j = 110; j < 141; ++j) | for (u16 j = 110; j < 141; ++j) | ||||
{ | { | ||||
grid.set(140, j, 7); | grid.set(140, j, 7); | ||||
dirtyGrid.set(140, j, 1); | dirtyGrid.set(140, j, 1); | ||||
} | } | ||||
hierPath.Update(&grid, dirtyGrid); | hierPath.Update(&grid, dirtyGrid); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(120, 120, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); | |||||
reachables.clear(); | reachables.clear(); | ||||
hierPath.FindReachableRegions(hierPath.Get(170, 120, PASS_1), reachables, PASS_1); | hierPath.FindReachableRegions(hierPath.Get(170, 120, PASS_1), reachables, PASS_1); | ||||
TS_ASSERT(reachables.size() == 9); | TS_ASSERT(reachables.size() == 9); | ||||
reachables.clear(); | reachables.clear(); | ||||
hierPath.FindReachableRegions(hierPath.Get(120, 120, PASS_1), reachables, PASS_1); | hierPath.FindReachableRegions(hierPath.Get(120, 120, PASS_1), reachables, PASS_1); | ||||
TS_ASSERT(reachables.size() == 1); | TS_ASSERT(reachables.size() == 1); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 0); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 0); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(20, 120, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(20, 120, PASS_1)].size() == 2); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(170, 120, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(170, 120, PASS_1)].size() == 2); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(200, 120, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(200, 120, PASS_1)].size() == 2); | ||||
////////////////////////////////////////////////////// | ////////////////////////////////////////////////////// | ||||
// Open it | // Open it | ||||
for (u16 j = 110; j < 141; ++j) | for (u16 j = 110; j < 141; ++j) | ||||
{ | { | ||||
grid.set(140, j, 6); | grid.set(140, j, 6); | ||||
dirtyGrid.set(140, j, 1); | dirtyGrid.set(140, j, 1); | ||||
} | } | ||||
hierPath.Update(&grid, dirtyGrid); | hierPath.Update(&grid, dirtyGrid); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(120, 120, PASS_1) == hierPath.GetGlobalRegion(150, 50, PASS_1)); | |||||
reachables.clear(); | reachables.clear(); | ||||
hierPath.FindReachableRegions(hierPath.Get(170, 120, PASS_1), reachables, PASS_1); | hierPath.FindReachableRegions(hierPath.Get(170, 120, PASS_1), reachables, PASS_1); | ||||
TS_ASSERT(reachables.size() == 9); | TS_ASSERT(reachables.size() == 9); | ||||
reachables.clear(); | reachables.clear(); | ||||
hierPath.FindReachableRegions(hierPath.Get(120, 120, PASS_1), reachables, PASS_1); | hierPath.FindReachableRegions(hierPath.Get(120, 120, PASS_1), reachables, PASS_1); | ||||
TS_ASSERT(reachables.size() == 9); | TS_ASSERT(reachables.size() == 9); | ||||
TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 2); | TS_ASSERT(hierPath.m_Edges[PASS_1][hierPath.Get(120, 120, PASS_1)].size() == 2); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Should be u16, not size_t (mapSize is u16, the function declaration has this as well).