|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef YAPF_NODE_HPP |
|
4 #define YAPF_NODE_HPP |
|
5 |
|
6 /** Yapf Node Key that evaluates hash from (and compares) tile & exit dir. */ |
|
7 struct CYapfNodeKeyExitDir { |
|
8 TileIndex m_tile; |
|
9 Trackdir m_td; |
|
10 DiagDirection m_exitdir; |
|
11 |
|
12 FORCEINLINE void Set(TileIndex tile, Trackdir td) |
|
13 { |
|
14 m_tile = tile; |
|
15 m_td = td; |
|
16 m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td); |
|
17 } |
|
18 |
|
19 FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);} |
|
20 FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);} |
|
21 }; |
|
22 |
|
23 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir |
|
24 { |
|
25 FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);} |
|
26 FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);} |
|
27 }; |
|
28 |
|
29 /** Yapf Node base */ |
|
30 template <class Tkey_, class Tnode> |
|
31 struct CYapfNodeT { |
|
32 typedef Tkey_ Key; |
|
33 typedef Tnode Node; |
|
34 |
|
35 Tkey_ m_key; |
|
36 Node *m_hash_next; |
|
37 Node *m_parent; |
|
38 int m_cost; |
|
39 int m_estimate; |
|
40 |
|
41 FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td) |
|
42 { |
|
43 m_key.Set(tile, td); |
|
44 m_hash_next = NULL; |
|
45 m_parent = parent; |
|
46 m_cost = 0; |
|
47 m_estimate = 0; |
|
48 } |
|
49 |
|
50 FORCEINLINE Node* GetHashNext() {return m_hash_next;} |
|
51 FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;} |
|
52 FORCEINLINE TileIndex GetTile() const {return m_key.m_tile;} |
|
53 FORCEINLINE Trackdir GetTrackdir() const {return m_key.m_td;} |
|
54 FORCEINLINE const Tkey_& GetKey() const {return m_key;} |
|
55 FORCEINLINE int GetCost() {return m_cost;} |
|
56 FORCEINLINE int GetCostEstimate() {return m_estimate;} |
|
57 FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;} |
|
58 }; |
|
59 |
|
60 /** Yapf Node for ships */ |
|
61 template <class Tkey_> |
|
62 struct CYapfShipNodeT |
|
63 : CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> > |
|
64 { |
|
65 |
|
66 }; |
|
67 |
|
68 // now define two major node types (that differ by key type) |
|
69 typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir; |
|
70 typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir; |
|
71 |
|
72 // Default NodeList types |
|
73 typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 14, 16> CShipNodeListExitDir; |
|
74 typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 16, 20> CShipNodeListTrackDir; |
|
75 |
|
76 |
|
77 #endif /* YAPF_NODE_HPP */ |