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/resourceclass.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 ImagePool;
48  class AnimationPool;
49  class Layer;
50  class CellGrid;
51  class Map;
52  class Camera;
53 
57  public:
58  virtual ~MapChangeListener() {};
59 
67  virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
68 
73  virtual void onLayerCreate(Map* map, Layer* layer) = 0;
74 
80  virtual void onLayerDelete(Map* map, Layer* layer) = 0;
81  };
82 
88  class Map : public ResourceClass {
89  public:
90 
95  Map(const std::string& identifier, RenderBackend* renderbackend,
96  const std::vector<RendererBase*>& renderers, ImagePool* imagepool,
97  AnimationPool* animpool, TimeProvider* tp_master=NULL);
98 
101  ~Map();
102 
105  const std::string& getId() const { return m_id; }
106 
109  void setId(const std::string& id) { m_id = id; }
110 
113  Layer* createLayer(const std::string& identifier, CellGrid* grid);
114 
117  void deleteLayer(Layer*);
118 
121  const std::list<Layer*>& getLayers() const { return m_layers; }
122 
125  Layer* getLayer(const std::string& identifier);
126 
129  uint32_t getNumLayers() const;
130 
133  void deleteLayers();
134 
137  void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
138  const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
139 
143  bool update();
144 
147  void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
148 
151  float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
152 
155  TimeProvider* getTimeProvider() { return &m_timeprovider; }
156 
160  void addChangeListener(MapChangeListener* listener);
161 
165  void removeChangeListener(MapChangeListener* listener);
166 
169  bool isChanged() { return !m_changedlayers.empty(); }
170 
173  std::vector<Layer*>& getChangedLayers() { return m_changedlayers; }
174 
178  Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport);
179 
182  void removeCamera(const std::string& id);
183 
186  Camera* getCamera(const std::string& id);
187 
190  std::vector<Camera*>& getCameras();
191 
192  private:
193  std::string m_id;
194 
195  std::list<Layer*> m_layers;
196  TimeProvider m_timeprovider;
197 
198  Map(const Map& map);
199  Map& operator=(const Map& map);
200 
201  // listeners for map changes
202  std::vector<MapChangeListener*> m_changelisteners;
203 
204  // holds changed layers after each update
205  std::vector<Layer*> m_changedlayers;
206 
207  // holds the cameras attached to this map
208  std::vector<Camera*> m_cameras;
209 
210  RenderBackend* m_renderbackend;
211  ImagePool* m_imagepool;
212  AnimationPool* m_animpool;
213 
214  // holds handles to all created renderers
215  std::vector<RendererBase*> m_renderers;
216 
217  // true, if something was changed on map during previous update (layer change, creation, deletion)
218  bool m_changed;
219  };
220 
221 } //FIFE
222 
223 #endif
224 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */