Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache pathfinding results to speed up calculations #1541

Merged
merged 40 commits into from
Sep 9, 2020
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
875ddd5
Add new files
idshibanov Aug 26, 2020
0da1c0b
Convert to class
idshibanov Aug 26, 2020
71a24c0
Move world files into new folder
idshibanov Aug 26, 2020
a8e1699
Update node structure
idshibanov Aug 26, 2020
2678b21
Add VS include directory
idshibanov Aug 26, 2020
91e15ec
Plug in pathfinder
idshibanov Aug 27, 2020
5155a28
Instant distance prediction
idshibanov Aug 27, 2020
c3a62e4
Test new pathfinding
idshibanov Sep 4, 2020
944ab10
Share tile passable call
idshibanov Sep 4, 2020
cd3fdc7
Fix move cost
idshibanov Sep 4, 2020
bf23401
Move passability rules to World class
idshibanov Sep 5, 2020
ec117e8
Fix the destination object logic
idshibanov Sep 5, 2020
706278e
Merge branch 'master' of https://github.com/ihhub/fheroes2.git into p…
idshibanov Sep 5, 2020
a8e635a
Remove unused code
idshibanov Sep 6, 2020
e4e3be7
Code style correction
ihhub Sep 7, 2020
bbcbb8b
Make clang-format happy
ihhub Sep 7, 2020
f5cf3d4
Address feedback
idshibanov Sep 7, 2020
cd4d988
Fix pathing bugs
idshibanov Sep 8, 2020
47046fd
Fix monster protection logic
idshibanov Sep 8, 2020
c0dfd18
Remove old code
idshibanov Sep 8, 2020
7ac6b19
Remove unused variable
ihhub Sep 8, 2020
1b2868d
Remove unused parameter
idshibanov Sep 8, 2020
5aa1683
Merge branch 'pathfinding-array' of git@github.com:idshibanov/fheroes…
idshibanov Sep 8, 2020
7bc5f9c
Fix boat check
idshibanov Sep 8, 2020
7be946c
Small speedup
ihhub Sep 8, 2020
27ebac8
Speed up monster protection logic
idshibanov Sep 9, 2020
023c775
Merge branch 'pathfinding-array' of git@github.com:idshibanov/fheroes…
idshibanov Sep 9, 2020
42482c2
Simplify old road logic
idshibanov Sep 9, 2020
af4d5cc
Don't need direction for road calculation
idshibanov Sep 9, 2020
aaf3a73
Set road boolean
idshibanov Sep 9, 2020
7e9a94f
Replace Direction::Get with faster Maps::GetDirection
idshibanov Sep 9, 2020
65ecebf
Add optimized version of Maps::isValidDirection
idshibanov Sep 9, 2020
eb9ee13
Unwrap loop in Maps::GetTilesUnderProtection
idshibanov Sep 9, 2020
c16e125
Optimize World::isValidPath
idshibanov Sep 9, 2020
6f66b8b
Cache direction offset
idshibanov Sep 9, 2020
03f10d3
Fix first step move cost
idshibanov Sep 9, 2020
2b417c0
Remove unused limit param
idshibanov Sep 9, 2020
f3237e8
Revert to use passable_disable
idshibanov Sep 9, 2020
1ce26fd
Formatting
idshibanov Sep 9, 2020
7b6a5ba
Use parent class method
ihhub Sep 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix first step move cost
  • Loading branch information
idshibanov committed Sep 9, 2020
commit 03f10d3c6e8297bf8951e01850d1352aee67d79f
10 changes: 9 additions & 1 deletion src/fheroes2/world/world_pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ std::list<Route::Step> Pathfinder::buildPath( int from, int target, uint8_t skil
reEvaluateIfNeeded( from, skill );

// trace the path from end point
PathfindingNode & firstNode = _cache[target];
uint32_t cost = firstNode._cost;

// add cost of the first node
if ( firstNode._from != -1 )
cost += cost - _cache[firstNode._from]._cost;

int currentNode = target;
uint32_t cost = _cache[currentNode]._cost;
while ( currentNode != from && currentNode != -1 ) {
PathfindingNode & node = _cache[currentNode];

Expand Down Expand Up @@ -193,6 +199,8 @@ void Pathfinder::evaluateMap( int start, uint8_t skill )
for ( size_t i = 0; i < directions.size(); ++i ) {
if ( Maps::isValidDirection( currentNodeIdx, directions[i] ) ) {
const int newIndex = currentNodeIdx + offset[i];
if ( newIndex == start )
continue;

const uint32_t moveCost = currentNode._cost + getMovementPenalty( currentNodeIdx, newIndex, directions[i], skill );
PathfindingNode & newNode = _cache[newIndex];
Expand Down