OpenTTD: src/pathfinder/yapf/yapf_node.hpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

yapf_node.hpp
Go to the documentation of this file.
1 /* $Id: yapf_node.hpp 23640 2011-12-20 17:57:56Z truebrain $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef YAPF_NODE_HPP
13 #define YAPF_NODE_HPP
14
16 struct CYapfNodeKeyExitDir {
17 TileIndex m_tile;
18 Trackdir m_td;
19 DiagDirection m_exitdir;
20
21 inline void Set(TileIndex tile, Trackdir td)
22 {
23 m_tile = tile;
24 m_td = td;
25 m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
26 }
27
28 inline int CalcHash() const {return m_exitdir | (m_tile << 2);}
29 inline bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
30
31 void Dump(DumpTarget &dmp) const
32 {
33 dmp.WriteTile("m_tile", m_tile);
34 dmp.WriteEnumT("m_td", m_td);
35 dmp.WriteEnumT("m_exitdir", m_exitdir);
36 }
37 };
38
39 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
40 {
41 inline int CalcHash() const {return m_td | (m_tile << 4);}
42 inline bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
43 };
44
46 template <class Tkey_, class Tnode>
47 struct CYapfNodeT {
48 typedef Tkey_ Key;
49 typedef Tnode Node;
50
51 Tkey_ m_key;
52 Node *m_hash_next;
53 Node *m_parent;
54 int m_cost;
55 int m_estimate;
56
57 inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
58 {
59 m_key.Set(tile, td);
60 m_hash_next = NULL;
61 m_parent = parent;
62 m_cost = 0;
63 m_estimate = 0;
64 }
65
66 inline Node *GetHashNext() {return m_hash_next;}
67 inline void SetHashNext(Node *pNext) {m_hash_next = pNext;}
68 inline TileIndex GetTile() const {return m_key.m_tile;}
69 inline Trackdir GetTrackdir() const {return m_key.m_td;}
70 inline const Tkey_& GetKey() const {return m_key;}
71 inline int GetCost() const {return m_cost;}
72 inline int GetCostEstimate() const {return m_estimate;}
73 inline bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
74
75 void Dump(DumpTarget &dmp) const
76 {
77 dmp.WriteStructT("m_key", &m_key);
78 dmp.WriteStructT("m_parent", m_parent);
79 dmp.WriteLine("m_cost = %d", m_cost);
80 dmp.WriteLine("m_estimate = %d", m_estimate);
81 }
82 };
83
84 #endif /* YAPF_NODE_HPP */