comparison engine/core/model/structures/map.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_MAP_MAP_H
23 #define FIFE_MAP_MAP_H
24
25 // Standard C++ library includes
26 #include <list>
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 "util/resource/resource.h"
38 #include "model/metamodel/timeprovider.h"
39
40 #include "location.h"
41
42 namespace FIFE {
43
44 class Layer;
45 class CellGrid;
46 class Map;
47
48 /** Listener interface for changes happening on map
49 */
50 class MapChangeListener {
51 public:
52 virtual ~MapChangeListener() {};
53
54 /** Called when some layer is changed on map. @see LayerChangeListener
55 * Layer is effectively changed, in case some of its instances
56 * is created, deleted or changed during latest update cycle
57 * @param map where change occurred
58 * @param changedLayers list of layers containing some changes
59 * @note Does not report layer creations and deletions
60 */
61 virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
62
63 /** Called when some layer gets created on the map
64 * @param map where change occurred
65 * @param layer which got created
66 */
67 virtual void onLayerCreate(Map* map, Layer* layer) = 0;
68
69 /** Called when some instance gets deleted on layer
70 * @param map where change occurred
71 * @param layer which will be deleted
72 * @note right after this call, layer actually gets deleted!
73 */
74 virtual void onLayerDelete(Map* map, Layer* layer) = 0;
75 };
76
77 /** A container of \c Layer(s).
78 *
79 * The actual data is contained in \c Layer objects
80 * @see Layer
81 */
82 class Map : public ResourceClass {
83 public:
84
85 /** Construct a map
86 * To add map to model, one should call Model::addMap (otherwise
87 * map is not registered with the engine properly)
88 */
89 Map(const std::string& identifier, TimeProvider* tp_master=NULL);
90
91 /** Destructor
92 */
93 ~Map();
94
95 /** Get the identifier for this map.
96 */
97 const std::string& getId() { return m_id; }
98
99 /** Add a Layer to this Map. Map owns the returned pointer to the new Layer, so don't delete it!
100 */
101 Layer* createLayer(const std::string& identifier, CellGrid* grid);
102
103 /** Delete a layer from the map
104 */
105 void deleteLayer(Layer*);
106
107 /** Get the layers on this map.
108 */
109 const std::list<Layer*>& getLayers() const { return m_layers; }
110
111 /** Get the layer with the given id.
112 */
113 Layer* getLayer(const std::string& identifier);
114
115 /** Get the overall number of layers
116 */
117 size_t getNumLayers() const;
118
119 /** Delete all layers from the map
120 */
121 void deleteLayers();
122
123 /** Maps coordinate from one layer to another
124 */
125 void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
126 const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
127
128 /** Called periodically to update events on map
129 * @returns true, if map was changed
130 */
131 bool update();
132
133 /** Sets speed for the map. See Model::setTimeMultiplier.
134 */
135 void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
136
137 /** Gets model speed. @see setTimeMultiplier.
138 */
139 float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
140
141 /** Gets timeprovider used in the map
142 */
143 TimeProvider* getTimeProvider() { return &m_timeprovider; }
144
145 /** Adds new change listener
146 * @param listener to add
147 */
148 void addChangeListener(MapChangeListener* listener);
149
150 /** Removes associated change listener
151 * @param listener to remove
152 */
153 void removeChangeListener(MapChangeListener* listener);
154
155 /** Returns true, if map information was changed during previous update round
156 */
157 bool isChanged() { return !m_changedlayers.empty(); }
158
159 /** Returns layers that were changed during previous update round
160 */
161 std::vector<Layer*>& getChangedLayers() { return m_changedlayers; }
162
163 private:
164 std::string m_id;
165
166 std::list<Layer*> m_layers;
167 TimeProvider m_timeprovider;
168
169 Map(const Map& map);
170 Map& operator=(const Map& map);
171
172 // listeners for map changes
173 std::vector<MapChangeListener*> m_changelisteners;
174
175 // holds changed layers after each update
176 std::vector<Layer*> m_changedlayers;
177
178 // true, if something was changed on map during previous update (layer change, creation, deletion)
179 bool m_changed;
180 };
181
182 } //FIFE
183
184 #endif
185 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */