summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKUDr <kudr@openttd.org>2007-06-27 22:29:57 +0000
committerKUDr <kudr@openttd.org>2007-06-27 22:29:57 +0000
commit15bf8e1e5801c50664a94aaa9a03fd53d5bc6bf3 (patch)
tree9e674070b355047cdc2eff71b8e79f77d03444a9 /src
parent26d6ba98ee9227e1e1452c6707dcda0b8fc8f958 (diff)
downloadopenttd-15bf8e1e5801c50664a94aaa9a03fd53d5bc6bf3.tar.xz
(svn r10366) -Codechange [YAPF]: added DEBUG_YAPF_CACHE macro that (when set to 1) allows to track YAPF "cache errors". They are probably responsible for current MP desyncs. (thanks Rubidium for this great idea!).
I will deal with those errors/desyncs tomorrow.
Diffstat (limited to 'src')
-rw-r--r--src/yapf/yapf_costrail.hpp9
-rw-r--r--src/yapf/yapf_rail.cpp49
2 files changed, 51 insertions, 7 deletions
diff --git a/src/yapf/yapf_costrail.hpp b/src/yapf/yapf_costrail.hpp
index c27a28167..4fd541ce6 100644
--- a/src/yapf/yapf_costrail.hpp
+++ b/src/yapf/yapf_costrail.hpp
@@ -55,6 +55,7 @@ protected:
protected:
int m_max_cost;
CBlobT<int> m_sig_look_ahead_costs;
+ bool m_disable_cache;
public:
bool m_stopped_on_first_two_way_signal;
@@ -64,6 +65,7 @@ protected:
CYapfCostRailT()
: m_max_cost(0)
+ , m_disable_cache(false)
, m_stopped_on_first_two_way_signal(false)
{
// pre-compute look-ahead penalties into array
@@ -468,7 +470,8 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
FORCEINLINE bool CanUseGlobalCache(Node& n) const
{
- return (n.m_parent != NULL)
+ return !m_disable_cache
+ && (n.m_parent != NULL)
&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size());
}
@@ -481,6 +484,10 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
}
}
+ void DisableCache(bool disable)
+ {
+ m_disable_cache = disable;
+ }
};
diff --git a/src/yapf/yapf_rail.cpp b/src/yapf/yapf_rail.cpp
index 43708f818..1437356f4 100644
--- a/src/yapf/yapf_rail.cpp
+++ b/src/yapf/yapf_rail.cpp
@@ -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 @@ public:
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,19 @@ public:
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);
+ }
+#endif
+
+ return result1;
}
FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found)
@@ -147,8 +173,19 @@ public:
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)