Mercurial > hg > openttd
changeset 6132:df7b080653c9 draft
(svn r8869) [YAPF] -Fix: Large Train Stations/Trains makes OpenTTD crash (Jigsaw_Psyche)
author | KUDr <KUDr@openttd.org> |
---|---|
date | Sat, 24 Feb 2007 00:17:46 +0000 |
parents | 518c876ed8ce |
children | 49a563250135 |
files | src/yapf/yapf.hpp src/yapf/yapf_base.hpp src/yapf/yapf_costrail.hpp src/yapf/yapf_rail.cpp src/yapf/yapf_road.cpp src/yapf/yapf_ship.cpp |
diffstat | 6 files changed, 24 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/yapf/yapf.hpp +++ b/src/yapf/yapf.hpp @@ -78,10 +78,10 @@ #include "../misc/hashtable.hpp" #include "../misc/binaryheap.hpp" #include "nodelist.hpp" +#include "follow_track.hpp" #include "yapf_base.hpp" #include "yapf_node.hpp" #include "yapf_common.hpp" -#include "follow_track.hpp" #include "yapf_costbase.hpp" #include "yapf_costcache.hpp"
--- a/src/yapf/yapf_base.hpp +++ b/src/yapf/yapf_base.hpp @@ -7,10 +7,6 @@ #include "../debug.h" -#include "../misc/fixedsizearray.hpp" -#include "../misc/blob.hpp" -#include "nodelist.hpp" - extern int _total_pf_time_us; /** CYapfBaseT - A-star type path finder base class. @@ -46,6 +42,7 @@ class CYapfBaseT { public: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) + typedef typename Types::TrackFollower TrackFollower; typedef typename Types::NodeList NodeList; ///< our node list typedef typename NodeList::Titem Node; ///< this will be our node type typedef typename Node::Key Key; ///< key to hash tables @@ -192,20 +189,20 @@ } /** add multiple nodes - direct children of the given node */ - FORCEINLINE void AddMultipleNodes(Node* parent, TileIndex tile, TrackdirBits td_bits) + FORCEINLINE void AddMultipleNodes(Node* parent, const TrackFollower &tf) { - bool is_choice = (KillFirstBit2x64(td_bits) != 0); - for (TrackdirBits rtds = td_bits; rtds != TRACKDIR_BIT_NONE; rtds = (TrackdirBits)KillFirstBit2x64(rtds)) { + bool is_choice = (KillFirstBit2x64(tf.m_new_td_bits) != 0); + for (TrackdirBits rtds = tf.m_new_td_bits; rtds != TRACKDIR_BIT_NONE; rtds = (TrackdirBits)KillFirstBit2x64(rtds)) { Trackdir td = (Trackdir)FindFirstBit2x64(rtds); Node& n = Yapf().CreateNewNode(); - n.Set(parent, tile, td, is_choice); - Yapf().AddNewNode(n); + n.Set(parent, tf.m_new_tile, td, is_choice); + Yapf().AddNewNode(n, tf); } } /** AddNewNode() - called by Tderived::PfFollowNode() for each child node. * Nodes are evaluated here and added into open list */ - void AddNewNode(Node& n) + void AddNewNode(Node &n, const TrackFollower &tf) { // evaluate the node bool bCached = Yapf().PfNodeCacheFetch(n); @@ -215,7 +212,7 @@ m_stats_cache_hits++; } - bool bValid = Yapf().PfCalcCost(n); + bool bValid = Yapf().PfCalcCost(n, tf); if (bCached) { Yapf().PfNodeCacheFlush(n);
--- a/src/yapf/yapf_costrail.hpp +++ b/src/yapf/yapf_costrail.hpp @@ -66,7 +66,7 @@ } /** return one tile cost. If tile is a tunnel entry, it is moved to the end of tunnel */ - FORCEINLINE int OneTileCost(TileIndex& tile, Trackdir trackdir) + FORCEINLINE int OneTileCost(TileIndex prev_tile, TileIndex& tile, Trackdir trackdir) { int cost = 0; // set base cost @@ -79,11 +79,6 @@ cost += Yapf().PfGetSettings().rail_crossing_penalty; break; - case MP_STATION: - // penalty for passing station tiles - cost += Yapf().PfGetSettings().rail_station_penalty; - break; - default: break; } @@ -178,7 +173,7 @@ /** Called by YAPF to calculate the cost from the origin to the given node. * Calculates only the cost of given node, adds it to the parent node cost * and stores the result into Node::m_cost member */ - FORCEINLINE bool PfCalcCost(Node& n) + FORCEINLINE bool PfCalcCost(Node &n, const TrackFollower &tf) { assert(!n.flags_u.flags_s.m_targed_seen); CPerfStart perf_cost(Yapf().m_perf_cost); @@ -201,8 +196,13 @@ bool target_seen = Yapf().PfDetectDestination(tile, trackdir); + if (tf.m_is_station) { + // station tiles have an extra penalty + segment_cost += Yapf().PfGetSettings().rail_station_penalty * (tf.m_tiles_skipped + 1); + } + while (true) { - segment_cost += Yapf().OneTileCost(tile, trackdir); + segment_cost += Yapf().OneTileCost(prev_tile, tile, trackdir); segment_cost += Yapf().CurveCost(prev_trackdir, trackdir); segment_cost += Yapf().SlopeCost(tile, trackdir); segment_cost += Yapf().SignalCost(n, tile, trackdir);
--- a/src/yapf/yapf_rail.cpp +++ b/src/yapf/yapf_rail.cpp @@ -36,7 +36,7 @@ { TrackFollower F(Yapf().GetVehicle()); if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) - Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits); + Yapf().AddMultipleNodes(&old_node, F); } /// return debug report character to identify the transportation type @@ -99,7 +99,7 @@ { TrackFollower F(Yapf().GetVehicle()); if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) - Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits); + Yapf().AddMultipleNodes(&old_node, F); } /// return debug report character to identify the transportation type
--- a/src/yapf/yapf_road.cpp +++ b/src/yapf/yapf_road.cpp @@ -72,7 +72,7 @@ /** Called by YAPF to calculate the cost from the origin to the given node. * Calculates only the cost of given node, adds it to the parent node cost * and stores the result into Node::m_cost member */ - FORCEINLINE bool PfCalcCost(Node& n) + FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower &tf) { int segment_cost = 0; // start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment @@ -246,7 +246,7 @@ { TrackFollower F(Yapf().GetVehicle()); if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) - Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits); + Yapf().AddMultipleNodes(&old_node, F); } /// return debug report character to identify the transportation type
--- a/src/yapf/yapf_ship.cpp +++ b/src/yapf/yapf_ship.cpp @@ -28,7 +28,7 @@ { TrackFollower F; if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) - Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits); + Yapf().AddMultipleNodes(&old_node, F); } /// return debug report character to identify the transportation type @@ -88,6 +88,7 @@ { public: typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) + typedef typename Types::TrackFollower TrackFollower; typedef typename Types::NodeList::Titem Node; ///< this will be our node type typedef typename Node::Key Key; ///< key to hash tables @@ -99,7 +100,7 @@ /** Called by YAPF to calculate the cost from the origin to the given node. * Calculates only the cost of given node, adds it to the parent node cost * and stores the result into Node::m_cost member */ - FORCEINLINE bool PfCalcCost(Node& n) + FORCEINLINE bool PfCalcCost(Node& n, const TrackFollower &tf) { // base tile cost depending on distance int c = IsDiagonalTrackdir(n.GetTrackdir()) ? 10 : 7;