Mercurial > fife-parpg
comparison engine/core/model/structures/layer.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 | 112fc4af772d |
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_LAYER_H | |
23 #define FIFE_LAYER_H | |
24 | |
25 // Standard C++ library includes | |
26 #include <algorithm> | |
27 #include <string> | |
28 #include <vector> | |
29 | |
30 // 3rd party library includes | |
31 | |
32 // FIFE includes | |
33 // These includes are split up in two parts, separated by one empty line | |
34 // First block: files included from the FIFE root src directory | |
35 // Second block: files included from the same folder | |
36 #include "util/base/resourceclass.h" | |
37 #include "model/metamodel/modelcoords.h" | |
38 #include "model/metamodel/object.h" | |
39 | |
40 #include "instance.h" | |
41 | |
42 namespace FIFE { | |
43 | |
44 class Map; | |
45 class Selection; | |
46 class CellGrid; | |
47 class Object; | |
48 class InstanceTree; | |
49 | |
50 /** Defines how pathing can be performed on this layer | |
51 * | |
52 * CELL_EDGES_ONLY allows pather to use only cell edges when moving instances from cell to cell on map | |
53 * CELL_EDGES_AND_DIAGONALS allows pather to use both cell edges and diagonals when moving instances from cell to cell on map | |
54 * FREEFORM allows pather to find shortest route regardless of cellgrid used on the layer | |
55 */ | |
56 enum PathingStrategy { | |
57 CELL_EDGES_ONLY, | |
58 CELL_EDGES_AND_DIAGONALS, | |
59 FREEFORM | |
60 }; | |
61 | |
62 /** Listener interface for changes happening on a layer | |
63 */ | |
64 class LayerChangeListener { | |
65 public: | |
66 virtual ~LayerChangeListener() {}; | |
67 | |
68 /** Called when some instance is changed on layer. @see InstanceChangeType | |
69 * @param layer where change occurred | |
70 * @param changedInstances list of instances containing some changes | |
71 * @note Does not report creations and deletions | |
72 */ | |
73 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0; | |
74 | |
75 /** Called when some instance gets created on layer | |
76 * @param layer where change occurred | |
77 * @param instance which got created | |
78 */ | |
79 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0; | |
80 | |
81 /** Called when some instance gets deleted on layer | |
82 * @param layer where change occurred | |
83 * @param instance which will be deleted | |
84 * @note right after this call, instance actually gets deleted! | |
85 */ | |
86 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0; | |
87 }; | |
88 | |
89 | |
90 /** A basic layer on a map | |
91 */ | |
92 class Layer : public ResourceClass { | |
93 public: | |
94 /** Constructor | |
95 * Layers are created by calling addLayer from map, thus | |
96 * this method should really be called only by elevation or test code | |
97 */ | |
98 Layer(const std::string& identifier, Map* map, CellGrid* grid); | |
99 | |
100 /** Destructs a Layer instance | |
101 */ | |
102 ~Layer(); | |
103 | |
104 /** Get the id of this layer. | |
105 */ | |
106 const std::string& getId() { return m_id; } | |
107 | |
108 /** Get the map this layer is contained in | |
109 */ | |
110 Map* getMap() const { return m_map; } | |
111 | |
112 /** Get the Cellgrid as set in the constructor | |
113 * @return a valid cellgrid | |
114 */ | |
115 CellGrid* getCellGrid() const { return m_grid; } | |
116 | |
117 /** Get the instance tree. | |
118 * @return this layers instance tree. | |
119 */ | |
120 InstanceTree* getInstanceTree(void) const { return m_instanceTree; } | |
121 | |
122 /** Check existance of objects on this layer | |
123 * @return True, if objects exist. | |
124 */ | |
125 bool hasInstances() const; | |
126 | |
127 /** Add an instance of an object at a specific position | |
128 */ | |
129 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id=""); | |
130 | |
131 /** Add an instance of an object at a specific position | |
132 */ | |
133 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id=""); | |
134 | |
135 /** Remove an instance from the layer | |
136 */ | |
137 void deleteInstance(Instance* object); | |
138 | |
139 /** Get the list of instances on this layer | |
140 */ | |
141 const std::vector<Instance*>& getInstances() const { return m_instances; } | |
142 | |
143 /** Get the instance on this layer with the given identifier. | |
144 */ | |
145 Instance* getInstance(const std::string& id); | |
146 | |
147 /** Set object visibility | |
148 */ | |
149 void setInstancesVisible(bool vis); | |
150 | |
151 /** Retrieves the minimum/maximum coordinates of instances on the layer. | |
152 * @param min A reference to a ModelCoordinate that will hold the minimum coordinate. | |
153 * @param max A reference to a ModelCoordinate that will hold the maximum coordinate. | |
154 * @param layer A pointer to another layer that can be used to cast coordinates bettween layers. | |
155 */ | |
156 void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const; | |
157 | |
158 /** Determines if a given cell on the layer contains a blocking instance | |
159 * | |
160 * @param cellCoordinate A const reference to a model coordinate of the cell in question. | |
161 * @return A boolean, true if it is blocked false otherwise. | |
162 */ | |
163 bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate); | |
164 | |
165 /** Toggle object visibility | |
166 * @see setObjectsVisible | |
167 */ | |
168 void toggleInstancesVisible(); | |
169 | |
170 /** Check object visibility | |
171 * @see setObjectsVisible | |
172 */ | |
173 bool areInstancesVisible() const { return m_instances_visibility; } | |
174 | |
175 /** Called periodically to update events on layer | |
176 * @returns true if layer was changed since the last update, false otherwise | |
177 */ | |
178 bool update(); | |
179 | |
180 /** Sets pathing strategy for the layer | |
181 * @see PathingStrategy | |
182 */ | |
183 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; } | |
184 | |
185 /** Gets pathing strategy for the layer | |
186 * @see PathingStrategy | |
187 */ | |
188 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; } | |
189 | |
190 /** Adds new change listener | |
191 * @param listener to add | |
192 */ | |
193 void addChangeListener(LayerChangeListener* listener); | |
194 | |
195 /** Removes associated change listener | |
196 * @param listener to remove | |
197 */ | |
198 void removeChangeListener(LayerChangeListener* listener); | |
199 | |
200 /** Returns true, if layer information was changed during previous update round | |
201 */ | |
202 bool isChanged() { return m_changed; } | |
203 | |
204 /** Returns instances that were changed during previous update round. | |
205 * @note does not contain created or deleted instances | |
206 */ | |
207 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; } | |
208 | |
209 protected: | |
210 std::string m_id; | |
211 | |
212 Map* m_map; | |
213 | |
214 bool m_instances_visibility; | |
215 | |
216 // all the instances on this layer | |
217 std::vector<Instance*> m_instances; | |
218 | |
219 //The instance tree | |
220 InstanceTree* m_instanceTree; | |
221 | |
222 // layer's cellgrid | |
223 CellGrid* m_grid; | |
224 | |
225 // pathing strategy for the layer | |
226 PathingStrategy m_pathingstrategy; | |
227 | |
228 // listeners for layer changes | |
229 std::vector<LayerChangeListener*> m_changelisteners; | |
230 | |
231 // holds changed instances after each update | |
232 std::vector<Instance*> m_changedinstances; | |
233 | |
234 // true if layer (or it's instance) information was changed during previous update round | |
235 bool m_changed; | |
236 }; | |
237 | |
238 } // FIFE | |
239 | |
240 #endif |