diff -r 4cc327ad39d5 -r 35756db7e577 src/yapf/yapf_rail.cpp --- a/src/yapf/yapf_rail.cpp Sat Jun 02 19:59:29 2007 +0000 +++ b/src/yapf/yapf_rail.cpp Sat Jul 14 19:42:58 2007 +0000 @@ -9,6 +9,8 @@ #include "yapf_costrail.hpp" #include "yapf_destrail.hpp" +#define DEBUG_YAPF_CACHE 0 + int _total_pf_time_us = 0; @@ -44,8 +46,21 @@ static bool stFindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) { - Tpf pf; - return pf.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed); + Tpf pf1; + bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed); + +#if DEBUG_YAPF_CACHE + Tpf pf2; + TileIndex depot_tile2 = INVALID_TILE; + bool reversed2 = false; + pf2.DisableCache(true); + bool result2 = pf2.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, &depot_tile2, &reversed2); + if (result1 != result2 || (result1 && (*depot_tile != depot_tile2 || *reversed != reversed2))) { + DEBUG(yapf, 0, "CACHE ERROR: FindNearestDepotTwoWay() = [%s, %s]", result1 ? "T" : "F", result2 ? "T" : "F"); + } +#endif + + return result1; } FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) @@ -108,8 +123,28 @@ static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // create pathfinder instance - Tpf pf; - return pf.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found); + Tpf pf1; + Trackdir result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found); + +#if DEBUG_YAPF_CACHE + Tpf pf2; + pf2.DisableCache(true); + Trackdir result2 = pf2.ChooseRailTrack(v, tile, enterdir, tracks, path_not_found); + if (result1 != result2) { + DEBUG(yapf, 0, "CACHE ERROR: ChooseRailTrack() = [%d, %d]", result1, result2); + DumpTarget dmp1, dmp2; + pf1.DumpBase(dmp1); + pf2.DumpBase(dmp2); + FILE *f1 = fopen("C:\\yapf1.txt", "wt"); + FILE *f2 = fopen("C:\\yapf2.txt", "wt"); + fwrite(dmp1.m_out.Data(), 1, dmp1.m_out.Size(), f1); + fwrite(dmp2.m_out.Data(), 1, dmp2.m_out.Size(), f2); + fclose(f1); + fclose(f2); + } +#endif + + return result1; } FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) @@ -147,8 +182,19 @@ static bool stCheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2) { - Tpf pf; - return pf.CheckReverseTrain(v, t1, td1, t2, td2); + Tpf pf1; + bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2); + +#if DEBUG_YAPF_CACHE + Tpf pf2; + pf2.DisableCache(true); + bool result2 = pf2.CheckReverseTrain(v, t1, td1, t2, td2); + if (result1 != result2) { + DEBUG(yapf, 0, "CACHE ERROR: CheckReverseTrain() = [%s, %s]", result1 ? "T" : "F", result2 ? "T" : "F"); + } +#endif + + return result1; } FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2) @@ -194,25 +240,22 @@ }; struct CYapfRail1 : CYapfT > {}; -struct CYapfRail2 : CYapfT > {}; -struct CYapfRail3 : CYapfT > {}; +struct CYapfRail2 : CYapfT > {}; struct CYapfAnyDepotRail1 : CYapfT > {}; -struct CYapfAnyDepotRail2 : CYapfT > {}; -struct CYapfAnyDepotRail3 : CYapfT > {}; +struct CYapfAnyDepotRail2 : CYapfT > {}; Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // default is YAPF type 2 typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits, bool*); - PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; + PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; // check if non-default YAPF type needed - if (_patches.forbid_90_deg) - pfnChooseRailTrack = &CYapfRail3::stChooseRailTrack; // Trackdir, forbid 90-deg - else if (_patches.yapf.disable_node_optimization) - pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; // Trackdir, allow 90-deg + if (_patches.forbid_90_deg) { + pfnChooseRailTrack = &CYapfRail2::stChooseRailTrack; // Trackdir, forbid 90-deg + } Trackdir td_ret = pfnChooseRailTrack(v, tile, enterdir, tracks, path_not_found); @@ -233,13 +276,12 @@ typedef bool (*PfnCheckReverseTrain)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir); - PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail2::stCheckReverseTrain; + PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain; // check if non-default YAPF type needed - if (_patches.forbid_90_deg) - pfnCheckReverseTrain = &CYapfRail3::stCheckReverseTrain; // Trackdir, forbid 90-deg - else if (_patches.yapf.disable_node_optimization) - pfnCheckReverseTrain = &CYapfRail1::stCheckReverseTrain; // Trackdir, allow 90-deg + if (_patches.forbid_90_deg) { + pfnCheckReverseTrain = &CYapfRail2::stCheckReverseTrain; // Trackdir, forbid 90-deg + } bool reverse = pfnCheckReverseTrain(v, tile, td, last_veh->tile, td_rev); @@ -261,13 +303,12 @@ Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh)); 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 - if (_patches.forbid_90_deg) - pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail3::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg - else if (_patches.yapf.disable_node_optimization) - pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay; // Trackdir, allow 90-deg + if (_patches.forbid_90_deg) { + pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail2::stFindNearestDepotTwoWay; // Trackdir, forbid 90-deg + } bool ret = pfnFindNearestDepotTwoWay(v, tile, td, last_tile, td_rev, max_distance, reverse_penalty, depot_tile, reversed); return ret;