diff options
author | KUDr <KUDr@openttd.org> | 2007-06-29 23:45:13 +0000 |
---|---|---|
committer | KUDr <KUDr@openttd.org> | 2007-06-29 23:45:13 +0000 |
commit | 90fe88a7af790433befa6714de8fce350bd9f184 (patch) | |
tree | e40b1c0408670ce5543e72064145c4f7559c5004 /src/yapf | |
parent | ec1e0b8152ec5432041a200b796bb744e3e21111 (diff) | |
download | openttd-90fe88a7af790433befa6714de8fce350bd9f184.tar.xz |
(svn r10392) -Add [YAPF]: added structured dump support into some essential YAPF classes (node-list, nodes, keys, etc.) and CArrayT
Diffstat (limited to 'src/yapf')
-rw-r--r-- | src/yapf/nodelist.hpp | 5 | ||||
-rw-r--r-- | src/yapf/yapf.hpp | 1 | ||||
-rw-r--r-- | src/yapf/yapf_base.hpp | 6 | ||||
-rw-r--r-- | src/yapf/yapf_node.hpp | 15 | ||||
-rw-r--r-- | src/yapf/yapf_node_rail.hpp | 43 | ||||
-rw-r--r-- | src/yapf/yapf_rail.cpp | 9 |
6 files changed, 78 insertions, 1 deletions
diff --git a/src/yapf/nodelist.hpp b/src/yapf/nodelist.hpp index 000c36659..a174d69d8 100644 --- a/src/yapf/nodelist.hpp +++ b/src/yapf/nodelist.hpp @@ -127,6 +127,11 @@ public: FORCEINLINE int TotalCount() {return m_arr.Size();} FORCEINLINE Titem_& ItemAt(int idx) {return m_arr[idx];} + + template <class D> void Dump(D &dmp) const + { + dmp.WriteStructT("m_arr", &m_arr); + } }; #endif /* NODELIST_HPP */ diff --git a/src/yapf/yapf.hpp b/src/yapf/yapf.hpp index 4faff60b5..2e107b052 100644 --- a/src/yapf/yapf.hpp +++ b/src/yapf/yapf.hpp @@ -78,6 +78,7 @@ typedef CPerfStartFake CPerfStart; #include "../misc/array.hpp" #include "../misc/hashtable.hpp" #include "../misc/binaryheap.hpp" +#include "../misc/dbg_helpers.h" #include "nodelist.hpp" #include "follow_track.hpp" #include "yapf_base.hpp" diff --git a/src/yapf/yapf_base.hpp b/src/yapf/yapf_base.hpp index ecf384213..43dd1793b 100644 --- a/src/yapf/yapf_base.hpp +++ b/src/yapf/yapf_base.hpp @@ -280,6 +280,12 @@ public: const Vehicle* GetVehicle() const {return m_veh;} + void DumpBase(DumpTarget &dmp) const + { + dmp.WriteStructT("m_nodes", &m_nodes); + dmp.WriteLine("m_num_steps = %d", m_num_steps); + } + // methods that should be implemented at derived class Types::Tpf (derived from CYapfBaseT) #if 0 diff --git a/src/yapf/yapf_node.hpp b/src/yapf/yapf_node.hpp index 577a40b7d..305e848a7 100644 --- a/src/yapf/yapf_node.hpp +++ b/src/yapf/yapf_node.hpp @@ -20,6 +20,13 @@ struct CYapfNodeKeyExitDir { FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);} FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);} + + void Dump(DumpTarget &dmp) const + { + dmp.WriteTile("m_tile", m_tile); + dmp.WriteEnumT("m_td", m_td); + dmp.WriteEnumT("m_exitdir", m_exitdir); + } }; struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir @@ -57,6 +64,14 @@ struct CYapfNodeT { FORCEINLINE int GetCost() {return m_cost;} FORCEINLINE int GetCostEstimate() {return m_estimate;} FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;} + + void Dump(DumpTarget &dmp) const + { + dmp.WriteStructT("m_key", &m_key); + dmp.WriteStructT("m_parent", m_parent); + dmp.WriteLine("m_cost = %d", m_cost); + dmp.WriteLine("m_estimate = %d", m_estimate); + } }; /** Yapf Node for ships */ diff --git a/src/yapf/yapf_node_rail.hpp b/src/yapf/yapf_node_rail.hpp index 4097fc505..59aa696f7 100644 --- a/src/yapf/yapf_node_rail.hpp +++ b/src/yapf/yapf_node_rail.hpp @@ -19,6 +19,12 @@ struct CYapfRailSegmentKey FORCEINLINE int32 CalcHash() const {return m_value;} FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 3);} FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;} + + void Dump(DumpTarget &dmp) const + { + dmp.WriteTile("tile", GetTile()); + dmp.WriteEnumT("td", GetTrackdir()); + } }; /* Enum used in PfCalcCost() to see why was the segment closed. */ @@ -63,7 +69,7 @@ enum EndSegmentReasonBits { /* Additional (composite) values. */ - /* What reasons mean that the target can be fond and needs to be detected. */ + /* What reasons mean that the target can be found and needs to be detected. */ ESRB_POSSIBLE_TARGET = ESRB_DEPOT | ESRB_WAYPOINT | ESRB_STATION, /* What reasons can be stored back into cached segment. */ @@ -75,6 +81,19 @@ enum EndSegmentReasonBits { DECLARE_ENUM_AS_BIT_SET(EndSegmentReasonBits); +inline CStrA ValueStr(EndSegmentReasonBits bits) +{ + static const char* end_segment_reason_names[] = { + "DEAD_END", "RAIL_TYPE", "INFINITE_LOOP", "SEGMENT_TOO_LONG", "CHOICE_FOLLOWS", + "DEPOT", "WAYPOINT", "STATION", + "PATH_TOO_LONG", "FIRST_TWO_WAY_RED", "LOOK_AHEAD_END", "TARGET_REACHED" + }; + + CStrA out; + out.Format("0x%04X (%s)", bits, ComposeNameT(bits, end_segment_reason_names, "UNK", ESRB_NONE, "NONE").Data()); + return out.Transfer(); +} + /** cached segment cost for rail YAPF */ struct CYapfRailSegment { @@ -104,6 +123,17 @@ struct CYapfRailSegment FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();} FORCEINLINE CYapfRailSegment* GetHashNext() {return m_hash_next;} FORCEINLINE void SetHashNext(CYapfRailSegment* next) {m_hash_next = next;} + + void Dump(DumpTarget &dmp) const + { + dmp.WriteStructT("m_key", &m_key); + dmp.WriteTile("m_last_tile", m_last_tile); + dmp.WriteEnumT("m_last_td", m_last_td); + dmp.WriteLine("m_cost = %d", m_cost); + dmp.WriteTile("m_last_signal_tile", m_last_signal_tile); + dmp.WriteEnumT("m_last_signal_td", m_last_signal_td); + dmp.WriteEnumT("m_end_segment_reason", m_end_segment_reason); + } }; /** Yapf Node for rail YAPF */ @@ -145,6 +175,17 @@ struct CYapfRailNodeT FORCEINLINE TileIndex GetLastTile() const {assert(m_segment != NULL); return m_segment->m_last_tile;} FORCEINLINE Trackdir GetLastTrackdir() const {assert(m_segment != NULL); return m_segment->m_last_td;} FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td) {assert(m_segment != NULL); m_segment->m_last_tile = tile; m_segment->m_last_td = td;} + + void Dump(DumpTarget &dmp) const + { + base::Dump(dmp); + dmp.WriteStructT("m_segment", m_segment); + dmp.WriteLine("m_num_signals_passed = %d", m_num_signals_passed); + dmp.WriteLine("m_targed_seen = %s", flags_u.flags_s.m_targed_seen ? "Yes" : "No"); + dmp.WriteLine("m_choice_seen = %s", flags_u.flags_s.m_choice_seen ? "Yes" : "No"); + dmp.WriteLine("m_last_signal_was_red = %s", flags_u.flags_s.m_last_signal_was_red ? "Yes" : "No"); + dmp.WriteEnumT("m_last_red_signal_type", m_last_red_signal_type); + } }; // now define two major node types (that differ by key type) diff --git a/src/yapf/yapf_rail.cpp b/src/yapf/yapf_rail.cpp index 1437356f4..964993bf4 100644 --- a/src/yapf/yapf_rail.cpp +++ b/src/yapf/yapf_rail.cpp @@ -132,6 +132,15 @@ public: 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 |