Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 8996406

Browse files
committed
Revert "Added team pathfinders to be used for default dig strength, so they can cache path costs"
This reverts commit c44d395.
1 parent 107b832 commit 8996406

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

Entities/Scene.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,9 @@ void Scene::Clear()
452452
m_AutoDesigned = true;
453453
m_TotalInvestment = 0;
454454
m_pTerrain = 0;
455-
m_NoTeamPathFinder.reset();
456-
for (std::unique_ptr<PathFinder> &pathFinder : m_PathFinders) {
455+
for (std::unique_ptr<PathFinder> &pathFinder : m_pPathFinders) {
457456
pathFinder.reset();
458457
}
459-
for (std::unique_ptr<PathFinder> &defaultDigStrengthPathFinder : m_DefaultDigStrengthPathfinders) {
460-
defaultDigStrengthPathFinder.reset();
461-
}
462458
m_PathfindingUpdated = false;
463459
m_PartialPathUpdateTimer.Reset();
464460

@@ -937,12 +933,8 @@ int Scene::LoadData(bool placeObjects, bool initPathfinding, bool placeUnits)
937933
//unsigned int numberOfBlocksToAllocate = std::min(128000, sceneArea / (pathFinderGridNodeSize * pathFinderGridNodeSize));
938934
unsigned int numberOfBlocksToAllocate = 4000;
939935

940-
m_NoTeamPathFinder = std::make_unique<PathFinder>(pathFinderGridNodeSize, numberOfBlocksToAllocate);
941-
for (int i = 0; i < m_PathFinders.size(); ++i) {
942-
m_PathFinders[i] = std::make_unique<PathFinder>(pathFinderGridNodeSize, numberOfBlocksToAllocate);
943-
}
944-
for (int i = 0; i < m_DefaultDigStrengthPathfinders.size(); ++i) {
945-
m_DefaultDigStrengthPathfinders[i] = std::make_unique<PathFinder>(pathFinderGridNodeSize, numberOfBlocksToAllocate);
936+
for (int i = 0; i < m_pPathFinders.size(); ++i) {
937+
m_pPathFinders[i] = std::make_unique<PathFinder>(pathFinderGridNodeSize, numberOfBlocksToAllocate);
946938
}
947939
ResetPathFinding();
948940
}
@@ -2986,7 +2978,6 @@ void Scene::ResetPathFinding() {
29862978
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
29872979
g_MovableMan.OverrideMaterialDoors(true, team);
29882980
GetPathFinder(static_cast<Activity::Teams>(team))->RecalculateAllCosts();
2989-
GetPathFinder(static_cast<Activity::Teams>(team), c_PathFindingDefaultDigStrength)->RecalculateAllCosts();
29902981
g_MovableMan.OverrideMaterialDoors(false, team);
29912982
}
29922983
}
@@ -3022,7 +3013,6 @@ void Scene::UpdatePathFinding()
30223013
g_MovableMan.OverrideMaterialDoors(true, team);
30233014

30243015
GetPathFinder(static_cast<Activity::Teams>(team))->UpdateNodeList(updatedNodes);
3025-
GetPathFinder(static_cast<Activity::Teams>(team), c_PathFindingDefaultDigStrength)->UpdateNodeList(updatedNodes);
30263016

30273017
// Place back the material representation of all doors of this team so they are as we found them.
30283018
g_MovableMan.OverrideMaterialDoors(false, team);
@@ -3043,7 +3033,7 @@ void Scene::UpdatePathFinding()
30433033
float Scene::CalculatePath(const Vector &start, const Vector &end, std::list<Vector> &pathResult, float digStrength, Activity::Teams team) {
30443034
float totalCostResult = -1;
30453035

3046-
if (const std::unique_ptr<PathFinder> &pathFinder = GetPathFinder(team, digStrength)) {
3036+
if (const std::unique_ptr<PathFinder> &pathFinder = GetPathFinder(team)) {
30473037
int result = pathFinder->CalculatePath(start, end, pathResult, totalCostResult, digStrength);
30483038

30493039
// It's ok if start and end nodes happen to be the same, the exact pixel locations are added at the front and end of the result regardless
@@ -3126,14 +3116,9 @@ void Scene::Update()
31263116

31273117
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31283118

3129-
std::unique_ptr<PathFinder>& Scene::GetPathFinder(Activity::Teams team, float digStrength) {
3130-
if (team == Activity::Teams::NoTeam) {
3131-
return m_NoTeamPathFinder;
3132-
} else if (std::abs(digStrength - c_PathFindingDefaultDigStrength) < 1.0F) {
3133-
return m_DefaultDigStrengthPathfinders[team];
3134-
} else {
3135-
return m_PathFinders[static_cast<int>(team)];
3136-
}
3119+
std::unique_ptr<PathFinder>& Scene::GetPathFinder(Activity::Teams team) {
3120+
// Note - we use + 1 when getting pathfinders by index, because our shared NoTeam pathfinder occupies index 0, and the rest come after that.
3121+
return m_pPathFinders[static_cast<int>(team) + 1];
31373122
}
31383123

31393124
} // namespace RTE

Entities/Scene.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,8 @@ const SceneObject * PickPlacedActorInRange(int whichSet, Vector &scenePoint, int
13381338
SLTerrain *m_pTerrain;
13391339

13401340
// Pathfinding graph and logic. Owned by this
1341-
std::unique_ptr<PathFinder> m_NoTeamPathFinder; //!< The shared pathfinder for when no team is specified.
1342-
std::array<std::unique_ptr<PathFinder>, Activity::Teams::MaxTeamCount> m_PathFinders; //!< The array of pathfinders for each team.
1343-
std::array<std::unique_ptr<PathFinder>, Activity::Teams::MaxTeamCount> m_DefaultDigStrengthPathfinders; //!< The array of pathfinders for each team to be used for default dig strength.
1341+
// The array of PathFinders for each team. Because we also have a shared pathfinder using index 0, we need to use MaxTeamCount + 1 to handle all the Teams' PathFinders.
1342+
std::array<std::unique_ptr<PathFinder>, Activity::Teams::MaxTeamCount + 1> m_pPathFinders;
13441343
// Is set to true on any frame the pathfinding data has been updated
13451344
bool m_PathfindingUpdated;
13461345
// Timer for when to do an update of the pathfinding data
@@ -1395,9 +1394,8 @@ const SceneObject * PickPlacedActorInRange(int whichSet, Vector &scenePoint, int
13951394
/// Gets the pathfinder for a given team.
13961395
/// </summary>
13971396
/// <param name="team">The team to get the pathfinder for. NoTeam is valid, and will give a shared pathfinder.</param>
1398-
/// <param name="digStrength">The dig strength to get the pathfinder for. A different pathfinder will be used if it's the default dig strength. Defaults to -1 so the normal pathfinder will be used if no argument is passed in.</param>
13991397
/// <returns>A pointer to the pathfinder for the given team.</returns>
1400-
std::unique_ptr<PathFinder> & GetPathFinder(Activity::Teams team, float digStrength = -1);
1398+
std::unique_ptr<PathFinder> & GetPathFinder(Activity::Teams team);
14011399

14021400
/// <summary>
14031401
/// Serializes the SceneObject via the Writer. Necessary because full serialization doesn't know how to deal with duplicate properties.

System/PathFinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace RTE {
118118
// Clear out the results if it happens to contain anything
119119
pathResult.clear();
120120

121-
if (std::abs(digStrength - m_DigStrength) > 1.0F) {
121+
if (m_DigStrength != digStrength) {
122122
// Unfortunately, DigStrength-aware pathing means that we're adjusting node transition costs, so we need to reset our path cache on every call.
123123
// In future we'll potentially store a different pather for different mobility bands, and reuse pathing costs.
124124
// But then again it's probably more fruitful to optimize the graph node to make searches faster, instead.

0 commit comments

Comments
 (0)