Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef YAPF_NODE_HPP
00013 #define YAPF_NODE_HPP
00014
00016 struct CYapfNodeKeyExitDir {
00017 TileIndex m_tile;
00018 Trackdir m_td;
00019 DiagDirection m_exitdir;
00020
00021 FORCEINLINE void Set(TileIndex tile, Trackdir td)
00022 {
00023 m_tile = tile;
00024 m_td = td;
00025 m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
00026 }
00027
00028 FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);}
00029 FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
00030
00031 void Dump(DumpTarget &dmp) const
00032 {
00033 dmp.WriteTile("m_tile", m_tile);
00034 dmp.WriteEnumT("m_td", m_td);
00035 dmp.WriteEnumT("m_exitdir", m_exitdir);
00036 }
00037 };
00038
00039 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
00040 {
00041 FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);}
00042 FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
00043 };
00044
00046 template <class Tkey_, class Tnode>
00047 struct CYapfNodeT {
00048 typedef Tkey_ Key;
00049 typedef Tnode Node;
00050
00051 Tkey_ m_key;
00052 Node *m_hash_next;
00053 Node *m_parent;
00054 int m_cost;
00055 int m_estimate;
00056
00057 FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
00058 {
00059 m_key.Set(tile, td);
00060 m_hash_next = NULL;
00061 m_parent = parent;
00062 m_cost = 0;
00063 m_estimate = 0;
00064 }
00065
00066 FORCEINLINE Node *GetHashNext() {return m_hash_next;}
00067 FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;}
00068 FORCEINLINE TileIndex GetTile() const {return m_key.m_tile;}
00069 FORCEINLINE Trackdir GetTrackdir() const {return m_key.m_td;}
00070 FORCEINLINE const Tkey_& GetKey() const {return m_key;}
00071 FORCEINLINE int GetCost() const {return m_cost;}
00072 FORCEINLINE int GetCostEstimate() const {return m_estimate;}
00073 FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
00074
00075 void Dump(DumpTarget &dmp) const
00076 {
00077 dmp.WriteStructT("m_key", &m_key);
00078 dmp.WriteStructT("m_parent", m_parent);
00079 dmp.WriteLine("m_cost = %d", m_cost);
00080 dmp.WriteLine("m_estimate = %d", m_estimate);
00081 }
00082 };
00083
00084 #endif