author | truelight |
Sun, 04 Nov 2007 23:06:39 +0000 | |
changeset 7833 | ba402b153b79 |
parent 7263 | 5663a736e104 |
child 9111 | 48ce04029fe4 |
permissions | -rw-r--r-- |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
1 |
/* $Id$ */ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
2 |
|
6121
2aae24b0881f
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
5587
diff
changeset
|
3 |
/** @file yapf_common.hpp */ |
2aae24b0881f
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
5587
diff
changeset
|
4 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
5 |
#ifndef YAPF_COMMON_HPP |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
6 |
#define YAPF_COMMON_HPP |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
7 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
8 |
/** YAPF origin provider base class - used when origin is one tile / multiple trackdirs */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
9 |
template <class Types> |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
10 |
class CYapfOriginTileT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
11 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
12 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
13 |
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
14 |
typedef typename Types::NodeList::Titem Node; ///< this will be our node type |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
15 |
typedef typename Node::Key Key; ///< key to hash tables |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
16 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
17 |
protected: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
18 |
TileIndex m_orgTile; ///< origin tile |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
19 |
TrackdirBits m_orgTrackdirs; ///< origin trackdir mask |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
20 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
21 |
/// to access inherited path finder |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
22 |
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
23 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
24 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
25 |
/// Set origin tile / trackdir mask |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
26 |
void SetOrigin(TileIndex tile, TrackdirBits trackdirs) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
27 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
28 |
m_orgTile = tile; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
29 |
m_orgTrackdirs = trackdirs; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
30 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
31 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
32 |
/// Called when YAPF needs to place origin nodes into open list |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
33 |
void PfSetStartupNodes() |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
34 |
{ |
7833
ba402b153b79
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents:
7263
diff
changeset
|
35 |
bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE); |
ba402b153b79
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
truelight
parents:
7263
diff
changeset
|
36 |
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) { |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
37 |
Trackdir td = (Trackdir)FindFirstBit2x64(tdb); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
38 |
Node& n1 = Yapf().CreateNewNode(); |
3978
30b43c605f21
(svn r5162) - CodeChange: [YAPF] added flag "choice seen" into YAPF node for trains
KUDr
parents:
3914
diff
changeset
|
39 |
n1.Set(NULL, m_orgTile, td, is_choice); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
40 |
Yapf().AddStartupNode(n1); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
41 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
42 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
43 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
44 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
45 |
/** YAPF origin provider base class - used when there are two tile/trackdir origins */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
46 |
template <class Types> |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
47 |
class CYapfOriginTileTwoWayT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
48 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
49 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
50 |
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
51 |
typedef typename Types::NodeList::Titem Node; ///< this will be our node type |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
52 |
typedef typename Node::Key Key; ///< key to hash tables |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
53 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
54 |
protected: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
55 |
TileIndex m_orgTile; ///< first origin tile |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
56 |
Trackdir m_orgTd; ///< first origin trackdir |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
57 |
TileIndex m_revTile; ///< second (reversed) origin tile |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
58 |
Trackdir m_revTd; ///< second (reversed) origin trackdir |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
59 |
int m_reverse_penalty; ///< penalty to be added for using the reversed origin |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
60 |
bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
61 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
62 |
/// to access inherited path finder |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
63 |
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
64 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
65 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
66 |
/// set origin (tiles, trackdirs, etc.) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
67 |
void SetOrigin(TileIndex tile, Trackdir td, TileIndex tiler = INVALID_TILE, Trackdir tdr = INVALID_TRACKDIR, int reverse_penalty = 0, bool treat_first_red_two_way_signal_as_eol = true) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
68 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
69 |
m_orgTile = tile; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
70 |
m_orgTd = td; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
71 |
m_revTile = tiler; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
72 |
m_revTd = tdr; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
73 |
m_reverse_penalty = reverse_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
74 |
m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
75 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
76 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
77 |
/// Called when YAPF needs to place origin nodes into open list |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
78 |
void PfSetStartupNodes() |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
79 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
80 |
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
81 |
Node& n1 = Yapf().CreateNewNode(); |
3978
30b43c605f21
(svn r5162) - CodeChange: [YAPF] added flag "choice seen" into YAPF node for trains
KUDr
parents:
3914
diff
changeset
|
82 |
n1.Set(NULL, m_orgTile, m_orgTd, false); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
83 |
Yapf().AddStartupNode(n1); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
84 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
85 |
if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
86 |
Node& n2 = Yapf().CreateNewNode(); |
3978
30b43c605f21
(svn r5162) - CodeChange: [YAPF] added flag "choice seen" into YAPF node for trains
KUDr
parents:
3914
diff
changeset
|
87 |
n2.Set(NULL, m_revTile, m_revTd, false); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
88 |
n2.m_cost = m_reverse_penalty; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
89 |
Yapf().AddStartupNode(n2); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
90 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
91 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
92 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
93 |
/// return true if first two-way signal should be treated as dead end |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
94 |
FORCEINLINE bool TreatFirstRedTwoWaySignalAsEOL() |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
95 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
96 |
return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
97 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
98 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
99 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
100 |
/** YAPF destination provider base class - used when destination is single tile / multiple trackdirs */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
101 |
template <class Types> |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
102 |
class CYapfDestinationTileT |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
103 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
104 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
105 |
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
106 |
typedef typename Types::NodeList::Titem Node; ///< this will be our node type |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
107 |
typedef typename Node::Key Key; ///< key to hash tables |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
108 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
109 |
protected: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
110 |
TileIndex m_destTile; ///< destination tile |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
111 |
TrackdirBits m_destTrackdirs; ///< destination trackdir mask |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
112 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
113 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
114 |
/// set the destination tile / more trackdirs |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
115 |
void SetDestination(TileIndex tile, TrackdirBits trackdirs) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
116 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
117 |
m_destTile = tile; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
118 |
m_destTrackdirs = trackdirs; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
119 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
120 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
121 |
protected: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
122 |
/// to access inherited path finder |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
123 |
Tpf& Yapf() {return *static_cast<Tpf*>(this);} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
124 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
125 |
public: |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
126 |
/// Called by YAPF to detect if node ends in the desired destination |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
127 |
FORCEINLINE bool PfDetectDestination(Node& n) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
128 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
129 |
bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
130 |
return bDest; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
131 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
132 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
133 |
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3978
diff
changeset
|
134 |
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
135 |
inline bool PfCalcEstimate(Node& n) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
136 |
{ |
7263
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
137 |
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0}; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
138 |
static int dg_dir_to_y_offs[] = {0, 1, 0, -1}; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
139 |
if (PfDetectDestination(n)) { |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
140 |
n.m_estimate = n.m_cost; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
141 |
return true; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
142 |
} |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
143 |
|
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
144 |
TileIndex tile = n.GetTile(); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
145 |
DiagDirection exitdir = TrackdirToExitdir(n.GetTrackdir()); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
146 |
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir]; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
147 |
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir]; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
148 |
int x2 = 2 * TileX(m_destTile); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
149 |
int y2 = 2 * TileY(m_destTile); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
150 |
int dx = abs(x1 - x2); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
151 |
int dy = abs(y1 - y2); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
152 |
int dmin = min(dx, dy); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
153 |
int dxy = abs(dx - dy); |
7263
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
154 |
int d = dmin * 7 + (dxy - 1) * (10 / 2); |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
155 |
n.m_estimate = n.m_cost + d; |
5663a736e104
(svn r10578) -Fix [YAPF, ships]: Ships received curve penalty for non-diagonal straight move. (JazzyJaffa)
KUDr
parents:
6121
diff
changeset
|
156 |
assert(n.m_estimate >= n.m_parent->m_estimate); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
157 |
return true; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
158 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
159 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
160 |
|
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
161 |
/** YAPF template that uses Ttypes template argument to determine all YAPF |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3978
diff
changeset
|
162 |
* components (base classes) from which the actual YAPF is composed. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3978
diff
changeset
|
163 |
* For example classes consult: CYapfRail_TypesT template and its instantiations: |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
3978
diff
changeset
|
164 |
* CYapfRail1, CYapfRail2, CYapfRail3, CYapfAnyDepotRail1, CYapfAnyDepotRail2, CYapfAnyDepotRail3 */ |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
165 |
template <class Ttypes> |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
166 |
class CYapfT |
3914
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
167 |
: public Ttypes::PfBase ///< Instance of CYapfBaseT - main YAPF loop and support base class |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
168 |
, public Ttypes::PfCost ///< Cost calculation provider base class |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
169 |
, public Ttypes::PfCache ///< Segment cost cache provider |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
170 |
, public Ttypes::PfOrigin ///< Origin (tile or two-tile origin) |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
171 |
, public Ttypes::PfDestination ///< Destination detector and distance (estimate) calculation provider |
6bdd22b93698
(svn r5018) [YAPF] Added some comments to YAPF implementation.
KUDr
parents:
3900
diff
changeset
|
172 |
, public Ttypes::PfFollow ///< Node follower (stepping provider) |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
173 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
174 |
}; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
175 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
176 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
177 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
178 |
#endif /* YAPF_COMMON_HPP */ |