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  class TriggerController;
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 FifeClass {
89  public:
90 
95  Map(const std::string& identifier, RenderBackend* renderbackend,
96  const std::vector<RendererBase*>& renderers, TimeProvider* tp_master=NULL);
97 
100  ~Map();
101 
104  const std::string& getId() const { return m_id; }
105 
108  void setId(const std::string& id) { m_id = id; }
109 
112  Layer* createLayer(const std::string& identifier, CellGrid* grid);
113 
116  void deleteLayer(Layer*);
117 
120  const std::list<Layer*>& getLayers() const { return m_layers; }
121 
124  Layer* getLayer(const std::string& identifier);
125 
128  uint32_t getLayerCount() const;
129 
132  void deleteLayers();
133 
136  void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
137  const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
138 
144 
148  bool update();
149 
152  void setTimeMultiplier(float multip) { m_timeProvider.setMultiplier(multip); }
153 
156  float getTimeMultiplier() const { return m_timeProvider.getMultiplier(); }
157 
161 
165  void addChangeListener(MapChangeListener* listener);
166 
170  void removeChangeListener(MapChangeListener* listener);
171 
174  bool isChanged() { return !m_changedLayers.empty(); }
175 
178  std::vector<Layer*>& getChangedLayers() { return m_changedLayers; }
179 
183  Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport);
184 
187  void removeCamera(const std::string& id);
188 
191  Camera* getCamera(const std::string& id);
192 
195  const std::vector<Camera*>& getCameras() const;
196 
200 
201  void setFilename(const std::string& file) { m_filename = file; }
202  const std::string& getFilename() const { return m_filename; }
203 
208  void addInstanceForTransfer(Instance* instance, const Location& target);
209 
213  void removeInstanceForTransfer(Instance* instance);
214 
217  void initializeCellCaches();
218 
221  void finalizeCellCaches();
222 
226 
227  private:
228  std::string m_id;
229  std::string m_filename;
230 
231  std::list<Layer*> m_layers;
233 
234  Map(const Map& map);
235  Map& operator=(const Map& map);
236 
238  std::vector<MapChangeListener*> m_changeListeners;
239 
241  std::vector<Layer*> m_changedLayers;
242 
244  std::vector<Camera*> m_cameras;
245 
248 
250  std::vector<RendererBase*> m_renderers;
251 
253  bool m_changed;
254 
256  std::map<Instance*, Location> m_transferInstances;
257 
259  };
260 
261 } //FIFE
262 
263 #endif
264 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Abstract interface for all the renderbackends.
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:174
~Map()
Destructor.
Definition: map.cpp:61
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:174
void setId(const std::string &id)
Sets the identifier for this map.
Definition: map.h:108
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
Definition: map.cpp:73
Camera * addCamera(const std::string &id, Layer *layer, const Rect &viewport)
Adds camera to the map.
Definition: map.cpp:245
void removeChangeListener(MapChangeListener *listener)
Removes associated change listener.
Definition: map.cpp:234
virtual ~MapChangeListener()
Definition: map.h:58
std::map< Instance *, Location > m_transferInstances
holds instances which should be transferred on the next update
Definition: map.h:256
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
Definition: map.cpp:230
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
void deleteLayers()
Delete all layers from the map.
Definition: map.cpp:122
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:238
TriggerController * getTriggerController() const
Definition: map.h:225
Camera * getCamera(const std::string &id)
Get a camera by its identifier.
Definition: map.cpp:284
uint32_t getLayerCount() const
Get the overall number of layers.
Definition: map.cpp:82
std::vector< Layer * > & getChangedLayers()
Returns layers that were changed during previous update round.
Definition: map.h:178
std::list< Layer * > m_layers
Definition: map.h:231
void deleteLayer(Layer *)
Delete a layer from the map.
Definition: map.cpp:105
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:47
float getTimeMultiplier() const
Gets model speed.
Definition: map.h:156
float getMultiplier() const
std::string m_id
Definition: map.h:225
Map & operator=(const Map &map)
void removeInstanceForTransfer(Instance *instance)
Removes instance that should be transferred to another layer.
Definition: map.cpp:319
A basic layer on a map.
Definition: layer.h:99
Layer * createLayer(const std::string &identifier, CellGrid *grid)
Add a Layer to this Map.
Definition: map.cpp:86
std::string m_filename
Definition: map.h:229
void addInstanceForTransfer(Instance *instance, const Location &target)
Adds instance that is to be transferred to another layer.
Definition: map.cpp:310
void getMinMaxCoordinates(ExactModelCoordinate &min, ExactModelCoordinate &max)
Retrieves the minimum/maximum coordinates of instances on the map.
Definition: map.cpp:142
std::vector< Layer * > m_changedLayers
holds changed layers after each update
Definition: map.h:241
const std::string & getFilename() const
Definition: map.h:202
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: map.h:152
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:267
const std::string & getId() const
Get the identifier for this map.
Definition: map.h:104
std::vector< Camera * > m_cameras
holds the cameras attached to this map
Definition: map.h:244
A 3D Point.
Definition: point.h:202
TimeProvider m_timeProvider
Definition: map.h:232
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:120
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:253
void finalizeCellCaches()
Creates cellcaches for this map.
Definition: map.cpp:350
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
Definition: map.h:160
void initializeCellCaches()
Creates cellcaches for this map.
Definition: map.cpp:326
TriggerController * m_triggerController
Definition: map.h:258
This class serves as a central place to manage triggers for a Map.
A container of Layer(s).
Definition: map.h:88
unsigned int uint32_t
Definition: core.h:40
std::vector< RendererBase * > m_renderers
holds handles to all created renderers
Definition: map.h:250
const std::vector< Camera * > & getCameras() const
Get a list containing all cameras.
Definition: map.cpp:295
RenderBackend * m_renderBackend
pointer to renderbackend
Definition: map.h:247
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:100
void setFilename(const std::string &file)
Definition: map.h:201
uint32_t getActiveCameraCount() const
Return the number of enabled cameras in this map.
Definition: map.cpp:299
Listener interface for changes happening on map.
Definition: map.h:56