FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
map.h
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 *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, 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/fifeclass.h"
37 #include "util/resource/resource.h"
38 #include "model/metamodel/timeprovider.h"
39 #include "util/structures/rect.h"
40 
41 #include "location.h"
42 
43 namespace FIFE {
44 
45  class RendererBase;
46  class RenderBackend;
47  class Layer;
48  class CellGrid;
49  class Map;
50  class Camera;
51 
55  public:
56  virtual ~MapChangeListener() {};
57 
65  virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
66 
71  virtual void onLayerCreate(Map* map, Layer* layer) = 0;
72 
78  virtual void onLayerDelete(Map* map, Layer* layer) = 0;
79  };
80 
86  class Map : public FifeClass {
87  public:
88 
93  Map(const std::string& identifier, RenderBackend* renderbackend,
94  const std::vector<RendererBase*>& renderers, TimeProvider* tp_master=NULL);
95 
98  ~Map();
99 
102  const std::string& getId() const { return m_id; }
103 
106  void setId(const std::string& id) { m_id = id; }
107 
110  Layer* createLayer(const std::string& identifier, CellGrid* grid);
111 
114  void deleteLayer(Layer*);
115 
118  const std::list<Layer*>& getLayers() const { return m_layers; }
119 
122  Layer* getLayer(const std::string& identifier);
123 
126  uint32_t getLayerCount() const;
127 
130  void deleteLayers();
131 
134  void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
135  const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
136 
142 
146  bool update();
147 
150  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
151 
154  float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
155 
158  TimeProvider* getTimeProvider() { return &m_timeprovider; }
159 
163  void addChangeListener(MapChangeListener* listener);
164 
168  void removeChangeListener(MapChangeListener* listener);
169 
172  bool isChanged() { return !m_changedlayers.empty(); }
173 
176  std::vector<Layer*>& getChangedLayers() { return m_changedlayers; }
177 
181  Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport);
182 
185  void removeCamera(const std::string& id);
186 
189  Camera* getCamera(const std::string& id);
190 
193  const std::vector<Camera*>& getCameras() const;
194 
195  void setFilename(const std::string& file) { m_filename = file; }
196  const std::string& getFilename() const { return m_filename; }
197 
198  private:
199  std::string m_id;
200  std::string m_filename;
201 
202  std::list<Layer*> m_layers;
203  TimeProvider m_timeprovider;
204 
205  Map(const Map& map);
206  Map& operator=(const Map& map);
207 
208  // listeners for map changes
209  std::vector<MapChangeListener*> m_changelisteners;
210 
211  // holds changed layers after each update
212  std::vector<Layer*> m_changedlayers;
213 
214  // holds the cameras attached to this map
215  std::vector<Camera*> m_cameras;
216 
217  RenderBackend* m_renderbackend;
218 
219  // holds handles to all created renderers
220  std::vector<RendererBase*> m_renderers;
221 
222  // true, if something was changed on map during previous update (layer change, creation, deletion)
223  bool m_changed;
224  };
225 
226 } //FIFE
227 
228 #endif
229 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */