mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
(svn r10349) -Fix [FS#941, YAPF, r10301]: tile/trackdir must be used as node key and also as segment key in the cache (SmatZ).
In the past it was possible to use tile/exitdir as the key because segments beginning on the same tile/exitdir were incorrectly considered the same. What I still don't understand is why this bug happened only on 64 bit systems (linux, Win64).
This commit is contained in:
parent
735c47d7d7
commit
5b8e48f555
@ -11,14 +11,13 @@ struct CYapfRailSegmentKey
|
|||||||
uint32 m_value;
|
uint32 m_value;
|
||||||
|
|
||||||
FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
|
FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
|
||||||
FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyExitDir& node_key) {Set(node_key);}
|
FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key) {Set(node_key);}
|
||||||
|
|
||||||
FORCEINLINE void Set(const CYapfRailSegmentKey& src) {m_value = src.m_value;}
|
FORCEINLINE void Set(const CYapfRailSegmentKey& src) {m_value = src.m_value;}
|
||||||
FORCEINLINE void Set(const CYapfNodeKeyExitDir& node_key) {m_value = (((int)node_key.m_tile) << 2) | node_key.m_exitdir;}
|
FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key) {m_value = (((int)node_key.m_tile) << 3) | node_key.m_td;}
|
||||||
|
|
||||||
FORCEINLINE int32 CalcHash() const {return m_value;}
|
FORCEINLINE int32 CalcHash() const {return m_value;}
|
||||||
FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 2);}
|
FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 3);}
|
||||||
FORCEINLINE DiagDirection GetExitDir() const {return (DiagDirection)(m_value & 3);}
|
|
||||||
FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;}
|
FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,7 +102,6 @@ struct CYapfRailSegment
|
|||||||
|
|
||||||
FORCEINLINE const Key& GetKey() const {return m_key;}
|
FORCEINLINE const Key& GetKey() const {return m_key;}
|
||||||
FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();}
|
FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();}
|
||||||
FORCEINLINE DiagDirection GetExitDir() const {return m_key.GetExitDir();}
|
|
||||||
FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;}
|
FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;}
|
||||||
FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;}
|
FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;}
|
||||||
};
|
};
|
||||||
|
@ -194,25 +194,22 @@ struct CYapfRail_TypesT
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CYapfRail1 : CYapfT<CYapfRail_TypesT<CYapfRail1 , CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
|
struct CYapfRail1 : CYapfT<CYapfRail_TypesT<CYapfRail1 , CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
|
||||||
struct CYapfRail2 : CYapfT<CYapfRail_TypesT<CYapfRail2 , CFollowTrackRail , CRailNodeListExitDir , CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
|
struct CYapfRail2 : CYapfT<CYapfRail_TypesT<CYapfRail2 , CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
|
||||||
struct CYapfRail3 : CYapfT<CYapfRail_TypesT<CYapfRail3 , CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationTileOrStationRailT, CYapfFollowRailT> > {};
|
|
||||||
|
|
||||||
struct CYapfAnyDepotRail1 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail1, CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
struct CYapfAnyDepotRail1 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail1, CFollowTrackRail , CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
||||||
struct CYapfAnyDepotRail2 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail2, CFollowTrackRail , CRailNodeListExitDir , CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
struct CYapfAnyDepotRail2 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail2, CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
||||||
struct CYapfAnyDepotRail3 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail3, CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
|
||||||
|
|
||||||
|
|
||||||
Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found)
|
Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found)
|
||||||
{
|
{
|
||||||
// default is YAPF type 2
|
// default is YAPF type 2
|
||||||
typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits, bool*);
|
typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits, bool*);
|
||||||
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack;
|
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
if (_patches.forbid_90_deg)
|
if (_patches.forbid_90_deg) {
|
||||||
pfnChooseRailTrack = &CYapfRail3::stChooseRailTrack; // Trackdir, forbid 90-deg
|
pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // Trackdir, forbid 90-deg
|
||||||
else if (_patches.yapf.disable_node_optimization)
|
}
|
||||||
pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; // Trackdir, allow 90-deg
|
|
||||||
|
|
||||||
Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_not_found);
|
Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_not_found);
|
||||||
|
|
||||||
@ -233,13 +230,12 @@ bool YapfCheckReverseTrain(Vehicle* v)
|
|||||||
|
|
||||||
|
|
||||||
typedef bool (*PfnCheckReverseTrain)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir);
|
typedef bool (*PfnCheckReverseTrain)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir);
|
||||||
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail2::stCheckReverseTrain;
|
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
if (_patches.forbid_90_deg)
|
if (_patches.forbid_90_deg) {
|
||||||
pfnCheckReverseTrain = &CYapfRail3::stCheckReverseTrain; // Trackdir, forbid 90-deg
|
pfnCheckReverseTrain = &CYapfRail2::stCheckReverseTrain; // Trackdir, forbid 90-deg
|
||||||
else if (_patches.yapf.disable_node_optimization)
|
}
|
||||||
pfnCheckReverseTrain = &CYapfRail1::stCheckReverseTrain; // Trackdir, allow 90-deg
|
|
||||||
|
|
||||||
bool reverse = pfnCheckReverseTrain(v, tile, td, last_veh->tile, td_rev);
|
bool reverse = pfnCheckReverseTrain(v, tile, td, last_veh->tile, td_rev);
|
||||||
|
|
||||||
@ -261,13 +257,12 @@ bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_pe
|
|||||||
Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh));
|
Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh));
|
||||||
|
|
||||||
typedef bool (*PfnFindNearestDepotTwoWay)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*);
|
typedef bool (*PfnFindNearestDepotTwoWay)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*);
|
||||||
PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay;
|
PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
if (_patches.forbid_90_deg)
|
if (_patches.forbid_90_deg) {
|
||||||
pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail3::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg
|
pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg
|
||||||
else if (_patches.yapf.disable_node_optimization)
|
}
|
||||||
pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay; // Trackdir, allow 90-deg
|
|
||||||
|
|
||||||
bool ret = pfnFindNearestDepotTwoWay(v, tile, td, last_tile, td_rev, max_distance, reverse_penalty, depot_tile, reversed);
|
bool ret = pfnFindNearestDepotTwoWay(v, tile, td, last_tile, td_rev, max_distance, reverse_penalty, depot_tile, reversed);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user