mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r10392) -Add [YAPF]: added structured dump support into some essential YAPF classes (node-list, nodes, keys, etc.) and CArrayT
This commit is contained in:
parent
a88a1b6f53
commit
c37dc87ad2
|
@ -68,6 +68,19 @@ public:
|
|||
const Titem& item = sa [idx % Tblock_size];
|
||||
return item;
|
||||
}
|
||||
|
||||
template <typename D> void Dump(D &dmp) const
|
||||
{
|
||||
dmp.WriteLine("capacity = %d", Tcapacity);
|
||||
int num_items = Size();
|
||||
dmp.WriteLine("num_items = %d", num_items);
|
||||
CStrA name;
|
||||
for (int i = 0; i < num_items; i++) {
|
||||
const Titem& item = (*this)[i];
|
||||
name.Format("item[%d]", i);
|
||||
dmp.WriteStructT(name.Data(), &item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ARRAY_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 */
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue