Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/tests/test_HierPathfinder.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
wraitii: :p | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < grid.m_W; ++i) | ||||
printf("\n"); | printf("\n"); | ||||
} | } | ||||
} | } | ||||
void assert_blank(HierarchicalPathfinder& hierPath) | void assert_blank(HierarchicalPathfinder& hierPath) | ||||
{ | { | ||||
// test that the map has the same global region everywhere | // test that the map has the same global region everywhere | ||||
HierarchicalPathfinder::GlobalRegionID globalRegionID = hierPath.GetGlobalRegion(35, 23, PASS_1); | HierarchicalPathfinder::GlobalRegionID globalRegionID = hierPath.GetGlobalRegion(35, 23, PASS_1); | ||||
for (size_t i = 0; i < mapSize; ++i) | for (u16 i = 0; i < mapSize; ++i) | ||||
for (size_t j = 0; j < mapSize; ++j) | for (u16 j = 0; j < mapSize; ++j) | ||||
{ | { | ||||
TS_ASSERT(globalRegionID == hierPath.GetGlobalRegion(i, j, PASS_1)); | TS_ASSERT(globalRegionID == hierPath.GetGlobalRegion(i, j, PASS_1)); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | 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); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | 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. | // Global region: check we are now split in two. | ||||
TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); | TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) != hierPath.GetGlobalRegion(150, 50, PASS_1)); | ||||
for (size_t j = 0; j < mapSize; ++j) | for (u16 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); | TS_ASSERT(hierPath.GetGlobalRegion(125, j, PASS_1) == 0); | ||||
} | } | ||||
for (size_t i = 0; i < 125; ++i) | for (u16 i = 0; i < 125; ++i) | ||||
for (size_t j = 0; j < mapSize; ++j) | for (u16 j = 0; j < mapSize; ++j) | ||||
{ | { | ||||
TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | TS_ASSERT(hierPath.GetGlobalRegion(50, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | ||||
} | } | ||||
for (size_t i = 126; i < mapSize; ++i) | for (u16 i = 126; i < mapSize; ++i) | ||||
for (size_t j = 0; j < mapSize; ++j) | for (u16 j = 0; j < mapSize; ++j) | ||||
{ | { | ||||
TS_ASSERT(hierPath.GetGlobalRegion(150, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | TS_ASSERT(hierPath.GetGlobalRegion(150, 50, PASS_1) == hierPath.GetGlobalRegion(i, j, PASS_1)); | ||||
TS_ASSERT(hierPath.GetGlobalRegion(i, j, PASS_2) == 0); | 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); | ||||
▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
:p