ManaPlus
map.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2017 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef RESOURCES_MAP_MAP_H
24 #define RESOURCES_MAP_MAP_H
25 
26 #include "position.h"
27 
28 #include "being/actor.h"
29 
31 
35 
37 
38 #include "utils/vector.h"
39 
41 
43 
44 class AmbientLayer;
45 class MapHeights;
46 class MapItem;
47 class MapLayer;
48 class ObjectsLayer;
49 class Resource;
50 class SpecialLayer;
51 class Tileset;
52 class TileAnimation;
53 class WalkLayer;
54 
55 struct MetaTile;
56 
57 typedef STD_VECTOR<Tileset*> Tilesets;
58 typedef STD_VECTOR<MapLayer*> Layers;
59 typedef Layers::const_iterator LayersCIter;
60 
61 typedef STD_VECTOR<AmbientLayer*> AmbientLayerVector;
62 typedef AmbientLayerVector::const_iterator AmbientLayerVectorCIter;
63 typedef AmbientLayerVector::iterator AmbientLayerVectorIter;
64 
68 class Map final : public Properties,
69  public ConfigListener,
70  public MemoryCounter
71 {
72  public:
76  Map(const std::string &name,
77  const int width,
78  const int height,
79  const int tileWidth,
80  const int tileHeight);
81 
83 
84 
87  ~Map();
88 
94 
98  void update(const int ticks = 1) restrict2;
99 
104  void draw(Graphics *restrict const graphics,
105  int scrollX,
106  int scrollY) restrict2 A_NONNULL(2);
107 
111  void drawCollision(Graphics *restrict const graphics,
112  const int scrollX,
113  const int scrollY,
114  const MapTypeT drawFlags) const
115  restrict2 A_NONNULL(2);
116 
120  void addLayer(MapLayer *const layer) restrict2 A_NONNULL(2);
121 
125  void addTileset(Tileset *const tileset) restrict2 A_NONNULL(2);
126 
130  const Tileset *getTilesetWithGid(const int gid) const
131  restrict2 A_WARN_UNUSED;
132 
136  const MetaTile *getMetaTile(const int x,
137  const int y) const
138  restrict2 A_WARN_UNUSED;
139 
140  void addBlockMask(const int x, const int y,
141  const BlockTypeT type) restrict2;
142 
143  void setBlockMask(const int x, const int y,
144  const BlockTypeT type) restrict2;
145 
150  bool getWalk(const int x, const int y,
151  const unsigned char blockWalkMask) const
152  restrict2 A_WARN_UNUSED;
153 
154  void setWalk(const int x, const int y) restrict2;
155 
156  unsigned char getBlockMask(const int x,
157  const int y) const restrict2;
158 
162  int getWidth() const restrict2 noexcept2 A_WARN_UNUSED
163  { return mWidth; }
164 
168  int getHeight() const restrict2 noexcept2 A_WARN_UNUSED
169  { return mHeight; }
170 
174  int getTileWidth() const restrict2 noexcept2 A_WARN_UNUSED
175  { return mTileWidth; }
176 
180  int getTileHeight() const restrict2 noexcept2 A_WARN_UNUSED
181  { return mTileHeight; }
182 
183  const std::string getMusicFile() const restrict2 A_WARN_UNUSED;
184 
185  void setMusicFile(const std::string &restrict file) restrict2;
186 
187  const std::string getName() const restrict2 A_WARN_UNUSED;
188 
192  const std::string getFilename() const restrict2 A_WARN_UNUSED;
193 
194  const std::string getGatName() const restrict2 A_WARN_UNUSED;
195 
199  Path findPath(const int startX, const int startY,
200  const int destX, const int destY,
201  const unsigned char blockWalkmask,
202  const int maxCost = 20) restrict2 A_WARN_UNUSED;
203 
207  void addParticleEffect(const std::string &restrict effectFile,
208  const int x,
209  const int y,
210  const int w = 0,
211  const int h = 0) restrict2;
212 
217 
221  void addAnimation(const int gid,
222  TileAnimation *restrict const animation) restrict2
223  A_NONNULL(3);
224 
226 
227  MapTypeT getDrawLayersFlags() const restrict2 A_WARN_UNUSED
228  { return mDrawLayersFlags; }
229 
230  void addExtraLayer() restrict2;
231 
232  void saveExtraLayer() const restrict2;
233 
234  SpecialLayer *getTempLayer() const restrict2 noexcept2 A_WARN_UNUSED
235  { return mTempLayer; }
236 
237  SpecialLayer *getSpecialLayer() const restrict2 noexcept2 A_WARN_UNUSED
238  { return mSpecialLayer; }
239 
240  void setHasWarps(const bool n) restrict2 noexcept2
241  { mHasWarps = n; }
242 
243  bool getHasWarps() const restrict2 noexcept2 A_WARN_UNUSED
244  { return mHasWarps; }
245 
246  std::string getUserMapDirectory() const restrict2 A_WARN_UNUSED;
247 
248  void addPortal(const std::string &restrict name,
249  const int type,
250  const int x, const int y,
251  const int dx, const int dy) restrict2;
252 
253  void addRange(const std::string &restrict name,
254  const int type,
255  const int x, const int y,
256  const int dx, const int dy) restrict2;
257 
258  void addPortalTile(const std::string &restrict name,
259  const int type,
260  const int x, const int y) restrict2;
261 
262  void updatePortalTile(const std::string &restrict name,
263  const int type,
264  const int x, const int y,
265  const bool addNew = true) restrict2;
266 
267  const STD_VECTOR<MapItem*> &getPortals() const restrict2 noexcept2
268  A_WARN_UNUSED
269  { return mMapPortals; }
270 
274  const TileAnimation *getAnimationForGid(const int gid)
275  const restrict2 A_WARN_UNUSED;
276 
277  void optionChanged(const std::string &restrict value)
278  restrict2 override final;
279 
280  MapItem *findPortalXY(const int x,
281  const int y) const restrict2 A_WARN_UNUSED;
282 
283  int getActorsCount() const restrict2 A_WARN_UNUSED
284  { return CAST_S32(mActors.size()); }
285 
286  void setPvpMode(const int mode) restrict2;
287 
288  int getPvpMode() const restrict2 noexcept2 A_WARN_UNUSED
289  { return mPvp; }
290 
291  const ObjectsLayer* getObjectsLayer() const restrict2 noexcept2
292  A_WARN_UNUSED
293  { return mObjects; }
294 
295  std::string getObjectData(const unsigned x,
296  const unsigned y,
297  const int type) const
298  restrict2 A_WARN_UNUSED;
299 
300  void indexTilesets() restrict2;
301 
303 
304  void setActorsFix(const int x, const int y) restrict2;
305 
306  int getVersion() const restrict2 noexcept2 A_WARN_UNUSED
307  { return mVersion; }
308 
309  void setVersion(const int n) restrict2 noexcept2
310  { mVersion = n; }
311 
312  void reduce() restrict2;
313 
314  void redrawMap() restrict2 noexcept2
315  { mRedrawMap = true; }
316 
317  bool empty() const restrict2 A_WARN_UNUSED
318  { return mLayers.empty(); }
319 
320  void setCustom(const bool b) restrict2 noexcept2
321  { mCustom = b; }
322 
323  bool isCustom() const restrict2 noexcept2 A_WARN_UNUSED
324  { return mCustom; }
325 
326  const std::map<int, TileAnimation*> &getTileAnimations() const
327  restrict2 noexcept2 A_WARN_UNUSED
328  { return mTileAnimations; }
329 
330  void setAtlas(Resource *restrict const atlas) restrict2 noexcept2
331  { mAtlas = atlas; }
332 
333  const MetaTile *getMetaTiles() const restrict2 noexcept2
334  { return mMetaTiles; }
335 
336  const WalkLayer *getWalkLayer() const restrict2 noexcept2
337  { return mWalkLayer; }
338 
339  void setWalkLayer(WalkLayer *restrict const layer) restrict2 noexcept2
340  { mWalkLayer = layer; }
341 
342  void addHeights(const MapHeights *restrict const heights) restrict2
343  A_NONNULL(2);
344 
345  uint8_t getHeightOffset(const int x, const int y) const restrict2;
346 
347  void setMask(const int mask) restrict2;
348 
350 
351  bool isHeightsPresent() const restrict2 noexcept2
352  { return mHeights != nullptr; }
353 
355 
356  void preCacheLayers() restrict2;
357 
358  int calcMemoryLocal() const override final;
359 
360  int calcMemoryChilds(const int level) const override final;
361 
362  std::string getCounterName() const override final
363  { return mName; }
364 
365  bool haveAtlas() const
366  { return mAtlas != nullptr; }
367 
368  protected:
369  friend class Actor;
370  friend class Minimap;
371 
375  Actors::iterator addActor(Actor *const actor) restrict2 A_NONNULL(2);
376 
380  void removeActor(const Actors::iterator &restrict iterator) restrict2;
381 
382  private:
386  void updateAmbientLayers(const float scrollX,
387  const float scrollY) restrict2;
388 
392  void drawAmbientLayers(Graphics *restrict const graphics,
393  const MapLayerPositionT type,
394  const int detail) const restrict2 A_NONNULL(2);
395 
399  bool contains(const int x,
400  const int y) const restrict2 A_WARN_UNUSED;
401 
402  const int mWidth;
403  const int mHeight;
404  const int mTileWidth;
405  const int mTileHeight;
414  bool mHasWarps;
415 
416  // draw flags
418 
419  // Pathfinding members
420  unsigned int mOnClosedList;
421  unsigned int mOnOpenList;
422 
423  // Overlay data
428 
429  // Particle effect data
431  {
432  ParticleEffectData(const std::string &restrict file0,
433  const int x0,
434  const int y0,
435  const int w0,
436  const int h0) noexcept2 :
437  file(file0),
438  x(x0),
439  y(y0),
440  w(w0),
441  h(h0)
442  {
443  }
444 
446 
447  const2 std::string file;
448  const2 int x;
449  const2 int y;
450  const2 int w;
451  const2 int h;
452  };
454 
456 
458 
459  std::string mName;
461  float mOpacity;
463  int mPvp;
469  int mVersion;
470 
475 
476  int mLastX;
477  int mLastY;
480 
481  int mDrawX;
482  int mDrawY;
485  int mMask;
491  bool mCustom;
493 };
494 
495 #endif // RESOURCES_MAP_MAP_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
int mLastScrollY
Definition: map.h:479
Resource * mAtlas
Definition: map.h:486
const int mTileHeight
Definition: map.h:405
void addTileset(Tileset *const tileset)
Definition: map.cpp:311
const std::string getGatName() const
Definition: map.cpp:843
std::vector< Tileset * > Tilesets
Definition: map.h:55
MapType ::T MapTypeT
Definition: maptype.h:38
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:695
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:817
bool mDrawOnlyFringe
Definition: map.h:492
bool empty() const
Definition: map.h:317
const ObjectsLayer * getObjectsLayer() const
Definition: map.h:291
std::string getUserMapDirectory() const
Definition: map.cpp:1250
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:810
void addRange(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1256
std::string file
Definition: map.h:447
void setPvpMode(const int mode)
Definition: map.cpp:1338
void setAtlas(Resource *const atlas)
Definition: map.h:330
AmbientLayerVector mBackgrounds
Definition: map.h:424
void setDrawLayersFlags(const MapTypeT &n)
Definition: map.cpp:1684
int getTileHeight() const
Definition: map.h:180
void updateConditionLayers()
Definition: map.cpp:1713
int mLastX
Definition: map.h:476
const MapHeights * mHeights
Definition: map.h:487
const std::string getMusicFile() const
Definition: map.cpp:823
Tilesets mTilesets
Definition: map.h:412
int mPvp
Definition: map.h:463
#define A_WARN_UNUSED
Definition: localconsts.h:172
WalkLayer * mWalkLayer
Definition: map.h:408
int mDrawScrollY
Definition: map.h:484
std::string getCounterName() const
Definition: map.h:362
void addHeights(const MapHeights *const heights)
Definition: map.cpp:1606
#define final
Definition: localconsts.h:45
int getPvpMode() const
Definition: map.h:288
void updatePortalTile(const std::string &name, const int type, const int x, const int y, const bool addNew=true)
Definition: map.cpp:1290
BlockType ::T BlockTypeT
Definition: blocktype.h:40
int mOverlayDetail
Definition: map.h:460
int mActorFixY
Definition: map.h:468
void setVersion(const int n)
Definition: map.h:309
const MetaTile * getMetaTiles() const
Definition: map.h:333
const std::vector< MapItem * > & getPortals() const
Definition: map.h:267
SpecialLayer * mSpecialLayer
Definition: map.h:471
int mDrawX
Definition: map.h:481
void setWalkLayer(WalkLayer *const layer)
Definition: map.h:339
void optionChanged(const std::string &value)
Definition: map.cpp:202
std::list< Actor * > Actors
Definition: actor.h:35
bool mHasWarps
Definition: map.h:414
void updateAmbientLayers(const float scrollX, const float scrollY)
Definition: map.cpp:607
const Tileset * getTilesetWithGid(const int gid) const
Definition: map.cpp:688
void addLayer(MapLayer *const layer)
Definition: map.cpp:304
void setWalk(const int x, const int y)
Definition: map.cpp:795
void setBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:734
void update(const int ticks=1)
Definition: map.cpp:319
const WalkLayer * getWalkLayer() const
Definition: map.h:336
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:457
ObjectsLayer * mObjects
Definition: map.h:473
#define A_NONNULL(...)
Definition: localconsts.h:179
bool contains(const int x, const int y) const
Definition: map.cpp:800
unsigned char getBlockMask(const int x, const int y) const
Definition: map.cpp:784
~Map()
Definition: map.cpp:173
#define STD_VECTOR
Definition: vector.h:29
bool mTilesetsIndexed
Definition: map.h:464
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1277
ParticleEffectData(const std::string &file0, const int x0, const int y0, const int w0, const int h0)
Definition: map.h:432
void indexTilesets()
Definition: map.cpp:1392
const int mTileWidth
Definition: map.h:404
int getHeight() const
Definition: map.h:168
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:330
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
std::string getObjectData(const unsigned x, const unsigned y, const int type) const
Definition: map.cpp:1370
void updateDrawLayersList()
Definition: map.cpp:1619
std::vector< MapItem * > mMapPortals
Definition: map.h:455
Layers mLayers
Definition: map.h:409
float mLastAScrollX
Definition: map.h:426
int mLastScrollX
Definition: map.h:478
bool mCustom
Definition: map.h:491
bool isHeightsPresent() const
Definition: map.h:351
#define CAST_S32
Definition: cast.h:29
void clearIndexedTilesets()
Definition: map.cpp:1440
std::vector< MapLayer * > Layers
Definition: map.h:58
bool getHasWarps() const
Definition: map.h:243
Layers::const_iterator LayersCIter
Definition: map.h:59
void addPortal(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1268
void initializeParticleEffects() const
Definition: map.cpp:1096
int getVersion() const
Definition: map.h:306
MapTypeT mDrawLayersFlags
Definition: map.h:417
int calcMemoryLocal() const
Definition: map.cpp:1737
void addParticleEffect(const std::string &effectFile, const int x, const int y, const int w=0, const int h=0)
Definition: map.cpp:1088
void setMask(const int mask)
Definition: map.cpp:1657
int mActorFixX
Definition: map.h:467
#define const2
Definition: localconsts.h:206
int getActorsCount() const
Definition: map.h:283
SpecialLayer * getSpecialLayer() const
Definition: map.h:237
const std::string getFilename() const
Definition: map.cpp:836
void redrawMap()
Definition: map.h:314
std::string mName
Definition: map.h:459
AmbientLayerVector mForegrounds
Definition: map.h:425
bool mRedrawMap
Definition: map.h:488
int mIndexedTilesetsSize
Definition: map.h:466
void preCacheLayers()
Definition: map.cpp:1727
void setCustom(const bool b)
Definition: map.h:320
void addAnimation(const int gid, TileAnimation *const animation)
Definition: map.cpp:1672
bool mCachedDraw
Definition: map.h:490
int mMaxTileHeight
Definition: map.h:406
const TileAnimation * getAnimationForGid(const int gid) const
Definition: map.cpp:1329
uint8_t getHeightOffset(const int x, const int y) const
Definition: map.cpp:1612
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1315
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:773
const int mHeight
Definition: map.h:403
Definition: map.h:68
void saveExtraLayer() const
Definition: map.cpp:1203
bool haveAtlas() const
Definition: map.h:365
const MetaTile * getMetaTile(const int x, const int y) const
Definition: map.cpp:805
int getWidth() const
Definition: map.h:162
SpecialLayer * mTempLayer
Definition: map.h:472
SpecialLayer * getTempLayer() const
Definition: map.h:234
MetaTile *const mMetaTiles
Definition: map.h:407
const int mWidth
Definition: map.h:402
unsigned int mOnOpenList
Definition: map.h:421
int mDrawY
Definition: map.h:482
int mLastY
Definition: map.h:477
unsigned int mOnClosedList
Definition: map.h:420
MapTypeT getDrawLayersFlags() const
Definition: map.h:227
MapLayerPosition ::T MapLayerPositionT
void initializeAmbientLayers()
Definition: map.cpp:225
int getTileWidth() const
Definition: map.h:174
int calcMemoryChilds(const int level) const
Definition: map.cpp:1755
MapLayer * mFringeLayer
Definition: map.h:474
Definition: actor.h:40
float mLastAScrollY
Definition: map.h:427
const std::map< int, TileAnimation * > & getTileAnimations() const
Definition: map.h:326
std::list< Position > Path
Definition: position.h:48
const RenderType mOpenGL
Definition: map.h:462
#define restrict
Definition: localconsts.h:176
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:61
float mOpacity
Definition: map.h:461
Layers mDrawUnderLayers
Definition: map.h:410
#define override
Definition: localconsts.h:46
void drawCollision(Graphics *const graphics, const int scrollX, const int scrollY, const MapTypeT drawFlags) const
Definition: map.cpp:557
int mVersion
Definition: map.h:469
void reduce()
Definition: map.cpp:1450
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:63
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:93
bool mBeingOpacity
Definition: map.h:489
int mDrawScrollX
Definition: map.h:483
Layers mDrawOverLayers
Definition: map.h:411
const std::string getName() const
Definition: map.cpp:828
void setHasWarps(const bool n)
Definition: map.h:240
Tileset ** mIndexedTilesets
Definition: map.h:465
void setMusicFile(const std::string &file)
Definition: map.cpp:1667
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:453
void drawAmbientLayers(Graphics *const graphics, const MapLayerPositionT type, const int detail) const
Definition: map.cpp:647
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:62
Actors mActors
Definition: map.h:413
Path findPath(const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkmask, const int maxCost=20)
Definition: map.cpp:851
#define noexcept2
Definition: localconsts.h:49
int mMask
Definition: map.h:485
#define restrict2
Definition: localconsts.h:177
void setActorsFix(const int x, const int y)
Definition: map.cpp:1705
RenderType
Definition: rendertype.h:24
void addExtraLayer()
Definition: map.cpp:1127
bool isCustom() const
Definition: map.h:323