-
-
Save SamuXarick/31d62faf40efeff8aee1e2d96126b56f to your computer and use it in GitHub Desktop.
faster estimate or not really? https://github.com/OpenTTD/OpenTTD/blob/master/src/pathfinder/yapf/yapf_ship.cpp#L97-L123
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Original code: https://github.com/OpenTTD/OpenTTD/blob/master/src/pathfinder/yapf/yapf_ship.cpp#L97-L123 */ | |
/** | |
* Called by YAPF to calculate cost estimate. Calculates distance to the destination | |
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate. | |
*/ | |
inline bool PfCalcEstimate(Node &n) | |
{ | |
if (PfDetectDestination(n)) { | |
n.m_estimate = n.m_cost; | |
return true; | |
} | |
const TileIndex destination_tile = m_has_intermediate_dest ? m_intermediate_dest_tile : m_destTile; | |
extern const TileIndexDiffC _tileoffs_by_diagdir[DIAGDIR_END]; | |
static const int YAPF_HALF_TILE_LENGTH = YAPF_TILE_LENGTH >> 1; | |
TileIndex tile = n.m_segment_last_tile; | |
DiagDirection exitdir = TrackdirToExitdir(n.m_segment_last_td); | |
int dx = std::abs(((int)TileX(tile) << 1) + _tileoffs_by_diagdir[exitdir].x - ((int)TileX(destination_tile) << 1)); | |
int dy = std::abs(((int)TileY(tile) << 1) + _tileoffs_by_diagdir[exitdir].y - ((int)TileY(destination_tile) << 1)); | |
n.m_estimate = n.m_cost + std::min(dx, dy) * YAPF_TILE_CORNER_LENGTH + (std::abs(dx - dy) - 1) * YAPF_HALF_TILE_LENGTH; | |
assert(n.m_estimate >= n.m_parent->m_estimate); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment