FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
map.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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"
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  class Instance;
52 
56  public:
57  virtual ~MapChangeListener() {};
58 
66  virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
67 
72  virtual void onLayerCreate(Map* map, Layer* layer) = 0;
73 
79  virtual void onLayerDelete(Map* map, Layer* layer) = 0;
80  };
81 
87  class Map : public FifeClass {
88  public:
89 
94  Map(const std::string& identifier, RenderBackend* renderbackend,
95  const std::vector<RendererBase*>& renderers, TimeProvider* tp_master=NULL);
96 
99  ~Map();
100 
103  const std::string& getId() const { return m_id; }
104 
107  void setId(const std::string& id) { m_id = id; }
108 
111  Layer* createLayer(const std::string& identifier, CellGrid* grid);
112 
115  void deleteLayer(Layer*);
116 
119  const std::list<Layer*>& getLayers() const { return m_layers; }
120 
123  Layer* getLayer(const std::string& identifier);
124 
127  uint32_t getLayerCount() const;
128 
131  void deleteLayers();
132 
135  void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
136  const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
137 
143 
147  bool update();
148 
151  void setTimeMultiplier(float multip) { m_timeProvider.setMultiplier(multip); }
152 
155  float getTimeMultiplier() const { return m_timeProvider.getMultiplier(); }
156 
160 
164  void addChangeListener(MapChangeListener* listener);
165 
169  void removeChangeListener(MapChangeListener* listener);
170 
173  bool isChanged() { return !m_changedLayers.empty(); }
174 
177  std::vector<Layer*>& getChangedLayers() { return m_changedLayers; }
178 
182  Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport);
183 
186  void removeCamera(const std::string& id);
187 
190  Camera* getCamera(const std::string& id);
191 
194  const std::vector<Camera*>& getCameras() const;
195 
196  void setFilename(const std::string& file) { m_filename = file; }
197  const std::string& getFilename() const { return m_filename; }
198 
203  void addInstanceForTransfer(Instance* instance, const Location& target);
204 
208  void removeInstanceForTransfer(Instance* instance);
209 
212  void initializeCellCaches();
213 
216  void finalizeCellCaches();
217  private:
218  std::string m_id;
219  std::string m_filename;
220 
221  std::list<Layer*> m_layers;
223 
224  Map(const Map& map);
225  Map& operator=(const Map& map);
226 
228  std::vector<MapChangeListener*> m_changeListeners;
229 
231  std::vector<Layer*> m_changedLayers;
232 
234  std::vector<Camera*> m_cameras;
235 
238 
240  std::vector<RendererBase*> m_renderers;
241 
243  bool m_changed;
244 
246  std::map<Instance*, Location> m_transferInstances;
247  };
248 
249 } //FIFE
250 
251 #endif
252 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Abstract interface for all the renderbackends.
Definition: renderbackend.h:92
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
Definition: timeprovider.h:42
bool update()
Called periodically to update events on map.
Definition: map.cpp:170
~Map()
Destructor.
Definition: map.cpp:58
A Rectangle on screen.
Definition: rect.h:80
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
bool isChanged()
Returns true, if map information was changed during previous update round.
Definition: map.h:173
void setId(const std::string &id)
Sets the identifier for this map.
Definition: map.h:107
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
Definition: map.cpp:69
Camera * addCamera(const std::string &id, Layer *layer, const Rect &viewport)
Adds camera to the map.
Definition: map.cpp:241
void removeChangeListener(MapChangeListener *listener)
Removes associated change listener.
Definition: map.cpp:230
virtual ~MapChangeListener()
Definition: map.h:57
std::map< Instance *, Location > m_transferInstances
holds instances which should be transferred on the next update
Definition: map.h:246
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
Definition: map.cpp:226
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
void deleteLayers()
Delete all layers from the map.
Definition: map.cpp:118
virtual void onMapChanged(Map *map, std::vector< Layer * > &changedLayers)=0
Called when some layer is changed on map.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:58
std::vector< MapChangeListener * > m_changeListeners
listeners for map changes
Definition: map.h:228
Camera * getCamera(const std::string &id)
Get a camera by its identifier.
Definition: map.cpp:280
uint32_t getLayerCount() const
Get the overall number of layers.
Definition: map.cpp:78
std::vector< Layer * > & getChangedLayers()
Returns layers that were changed during previous update round.
Definition: map.h:177
std::list< Layer * > m_layers
Definition: map.h:221
void deleteLayer(Layer *)
Delete a layer from the map.
Definition: map.cpp:101
Map(const std::string &identifier, RenderBackend *renderbackend, const std::vector< RendererBase * > &renderers, TimeProvider *tp_master=NULL)
Construct a map To add map to model, one should call Model::addMap (otherwise map is not registered w...
Definition: map.cpp:46
float getTimeMultiplier() const
Gets model speed.
Definition: map.h:155
float getMultiplier() const
std::string m_id
Definition: map.h:218
Map & operator=(const Map &map)
void removeInstanceForTransfer(Instance *instance)
Removes instance that should be transferred to another layer.
Definition: map.cpp:304
A basic layer on a map.
Definition: layer.h:98
Layer * createLayer(const std::string &identifier, CellGrid *grid)
Add a Layer to this Map.
Definition: map.cpp:82
std::string m_filename
Definition: map.h:219
void addInstanceForTransfer(Instance *instance, const Location &target)
Adds instance that is to be transferred to another layer.
Definition: map.cpp:295
void getMinMaxCoordinates(ExactModelCoordinate &min, ExactModelCoordinate &max)
Retrieves the minimum/maximum coordinates of instances on the map.
Definition: map.cpp:138
std::vector< Layer * > m_changedLayers
holds changed layers after each update
Definition: map.h:231
const std::string & getFilename() const
Definition: map.h:197
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: map.h:151
virtual void onLayerDelete(Map *map, Layer *layer)=0
Called when some instance gets deleted on layer.
void removeCamera(const std::string &id)
Removes a camera from the map.
Definition: map.cpp:263
const std::string & getId() const
Get the identifier for this map.
Definition: map.h:103
std::vector< Camera * > m_cameras
holds the cameras attached to this map
Definition: map.h:234
A 3D Point.
Definition: point.h:202
TimeProvider m_timeProvider
Definition: map.h:222
virtual void onLayerCreate(Map *map, Layer *layer)=0
Called when some layer gets created on the map.
const std::list< Layer * > & getLayers() const
Get the layers on this map.
Definition: map.h:119
void getMatchingCoordinates(const ModelCoordinate &coord_to_map, const Layer *from_layer, const Layer *to_layer, std::vector< ModelCoordinate > &matching_coords) const
Maps coordinate from one layer to another.
bool m_changed
true, if something was changed on map during previous update (layer change, creation, deletion)
Definition: map.h:243
void finalizeCellCaches()
Creates cellcaches for this map.
Definition: map.cpp:335
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
Definition: map.h:159
void initializeCellCaches()
Creates cellcaches for this map.
Definition: map.cpp:311
A container of Layer(s).
Definition: map.h:87
unsigned int uint32_t
Definition: core.h:40
std::vector< RendererBase * > m_renderers
holds handles to all created renderers
Definition: map.h:240
const std::vector< Camera * > & getCameras() const
Get a list containing all cameras.
Definition: map.cpp:291
RenderBackend * m_renderBackend
pointer to renderbackend
Definition: map.h:237
An Instance is an &quot;instantiation&quot; of an Object at a Location.
Definition: instance.h:97
void setFilename(const std::string &file)
Definition: map.h:196
Listener interface for changes happening on map.
Definition: map.h:55