comparison engine/core/pathfinder/routepather/routepather.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_PATHFINDER_ROUTEPATHER
23 #define FIFE_PATHFINDER_ROUTEPATHER
24
25 // Standard C++ library includes
26 #include <map>
27 #include <vector>
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "model/metamodel/abstractpather.h"
36 #include "model/structures/location.h"
37 #include "model/structures/map.h"
38 #include "util/structures/priorityqueue.h"
39
40 namespace FIFE {
41
42 class Search;
43 class SearchSpace;
44 class RoutePatherSearch;
45
46 class RoutePather : public AbstractPather {
47 public:
48 /** Constructor.
49 *
50 */
51 RoutePather() : m_map(0), m_nextFreeSessionId(0), m_maxticks(1000) {
52 }
53
54 void setMap(Map* map);
55 int getNextLocation(const Instance* instance, const Location& target,
56 double distance_to_travel, Location& nextLocation,
57 Location& facingLocation, int session_id=-1,
58 int priority = MEDIUM_PRIORITY);
59
60 /** Updates the route pather.
61 *
62 * Advances the active search by so many time steps. If the search
63 * completes then this function pops it from the active session list and
64 * continues updating the next session until it runs out of time.
65 */
66 void update();
67
68 /** Cancels a session.
69 *
70 * Cancels a route pather session. Determines if it is an active session
71 * or not and acts accordingly.
72 *
73 * @param session_id The id of the session to cancel.
74 * @return True if the session could be canceled false otherwise.
75 */
76 bool cancelSession(const int session_id);
77
78 /** Adds a search space to the route pather.
79 *
80 * @param search_space A pointer to the search space to add.
81 * @return a boolean signifying whether the search space was correctly added or not.
82 */
83 bool addSearchSpace(SearchSpace* search_space);
84
85 /** Retrieves a searchspace associated with the given layer.
86 *
87 * @param A pointer to the search space
88 * @return A pointer to the search space if it could be found, 0 otherwise.
89 */
90 SearchSpace* getSearchSpace(Layer * const layer);
91
92 std::string getName() const { return "RoutePather"; };
93 private:
94 typedef std::list<Location> Path;
95 typedef PriorityQueue<Search*, int> SessionQueue;
96 typedef std::list<int> SessionList;
97 typedef std::map<int, Path> PathMap;
98 typedef std::map<Layer*, SearchSpace*> SearchSpaceMap;
99 /** Makes the instance follow the given path.
100 *
101 * Calculates the next position the instance should move to given the
102 * the instance's speed.
103 *
104 * @param instance A pointer to the instance to move.
105 * @param speed The speed to move the instance.
106 * @param nextLocation An out variable which will store the instances next location.
107 * @param facingLocation An out variable which will store the instances facing location.
108 */
109 void followPath(const Instance* instance, Path& path, double speed, Location& nextLocation, Location& facingLocation);
110
111 /** Adds a session id to the session map.
112 *
113 * Stores the given session id in the session map.
114 *
115 * @param sessionId The session id to store.
116 */
117 void addSessionId(const int sessionId);
118
119
120 /** Determines if the given session Id is valid.
121 *
122 * Searches the session list to determine if a search with the given session id
123 * has been registered.
124 *
125 * @return true if one has, false otherwise.
126 */
127 bool sessionIdValid(const int sessionId);
128
129 /** Removes a session id from the session map.
130 *
131 * @param sessionId The session id to remove.
132 * @return True if the sessionId could be removed, false otherwise.
133 */
134 bool invalidateSessionId(const int sessionId);
135
136 //The map the search is running on.
137 Map* m_map;
138
139 //A map of currently running sessions (searches).
140 SessionQueue m_sessions;
141
142 //A list of session ids that have been registered.
143 SessionList m_registeredSessionIds;
144
145 //Calculated paths for the movement phase.
146 PathMap m_paths;
147
148 //A map of searchspaces.
149 SearchSpaceMap m_searchspaces;
150
151 //The next free session id.
152 int m_nextFreeSessionId;
153
154 //The maximum number of ticks allowed.
155 int m_maxticks;
156 };
157
158 }
159
160 #endif