FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
map.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 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 
138  void getMinMaxCoordinates(ExactModelCoordinate& min, ExactModelCoordinate& max);
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, const Rect& viewport);
179 
182  void removeCamera(const std::string& id);
183 
186  Camera* getCamera(const std::string& id);
187 
190  const std::vector<Camera*>& getCameras() const;
191 
194  uint32_t getActiveCameraCount() 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 
220  TriggerController* getTriggerController() const { return m_triggerController; };
221 
222  private:
223  std::string m_id;
224  std::string m_filename;
225 
226  std::list<Layer*> m_layers;
228 
229  Map(const Map& map);
230  Map& operator=(const Map& map);
231 
233  std::vector<MapChangeListener*> m_changeListeners;
234 
236  std::vector<Layer*> m_changedLayers;
237 
239  std::vector<Camera*> m_cameras;
240 
243 
245  std::vector<RendererBase*> m_renderers;
246 
248  bool m_changed;
249 
251  std::map<Instance*, Location> m_transferInstances;
252 
254  };
255 
256 }
257 
258 #endif
const std::string & getFilename() const
Definition: map.h:197
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 isChanged()
Returns true, if map information was changed during previous update round.
Definition: map.h:169
const std::string & getId() const
Get the identifier for this map.
Definition: map.h:104
void setId(const std::string &id)
Sets the identifier for this map.
Definition: map.h:108
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:251
const std::list< Layer * > & getLayers() const
Get the layers on this map.
Definition: map.h:120
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:59
std::vector< MapChangeListener * > m_changeListeners
listeners for map changes
Definition: map.h:233
std::vector< Layer * > & getChangedLayers()
Returns layers that were changed during previous update round.
Definition: map.h:173
std::list< Layer * > m_layers
Definition: map.h:226
virtual void onMapChanged(Map *map, std::vector< Layer *> &changedLayers)=0
Called when some layer is changed on map.
std::string m_id
Definition: map.h:220
A basic layer on a map.
Definition: layer.h:99
std::string m_filename
Definition: map.h:224
std::vector< Layer * > m_changedLayers
holds changed layers after each update
Definition: map.h:236
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: map.h:147
virtual void onLayerDelete(Map *map, Layer *layer)=0
Called when some layer gets deleted on map.
std::vector< Camera * > m_cameras
holds the cameras attached to this map
Definition: map.h:239
TimeProvider m_timeProvider
Definition: map.h:227
float getTimeMultiplier() const
Gets model speed.
Definition: map.h:151
virtual void onLayerCreate(Map *map, Layer *layer)=0
Called when some layer gets created on the map.
bool m_changed
true, if something was changed on map during previous update (layer change, creation, deletion)
Definition: map.h:248
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
Definition: map.h:155
TriggerController * m_triggerController
Definition: map.h:253
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:245
RenderBackend * m_renderBackend
pointer to renderbackend
Definition: map.h:242
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
void setFilename(const std::string &file)
Definition: map.h:196
Listener interface for changes happening on map.
Definition: map.h:56