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-2018 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 #ifdef USE_OPENGL
46 class AtlasResource;
47 #endif // USE_OPENGL
48 
49 class MapHeights;
50 class MapItem;
51 class MapLayer;
52 class ObjectsLayer;
53 class SpecialLayer;
54 class Tileset;
55 class TileAnimation;
56 class WalkLayer;
57 
58 struct MetaTile;
59 
60 typedef STD_VECTOR<Tileset*> Tilesets;
61 typedef STD_VECTOR<MapLayer*> Layers;
62 typedef Layers::const_iterator LayersCIter;
63 
64 typedef STD_VECTOR<AmbientLayer*> AmbientLayerVector;
65 typedef AmbientLayerVector::const_iterator AmbientLayerVectorCIter;
66 typedef AmbientLayerVector::iterator AmbientLayerVectorIter;
67 
71 class Map final : public Properties,
72  public ConfigListener,
73  public MemoryCounter
74 {
75  public:
79  Map(const std::string &name,
80  const int width,
81  const int height,
82  const int tileWidth,
83  const int tileHeight);
84 
86 
87 
90  ~Map() override final;
91 
97 
101  void update(const int ticks) restrict2;
102 
107  void draw(Graphics *restrict const graphics,
108  int scrollX,
109  int scrollY) restrict2 A_NONNULL(2);
110 
114  void drawCollision(Graphics *restrict const graphics,
115  const int scrollX,
116  const int scrollY,
117  const MapTypeT drawFlags) const
118  restrict2 A_NONNULL(2);
119 
123  void addLayer(MapLayer *const layer) restrict2 A_NONNULL(2);
124 
128  void addTileset(Tileset *const tileset) restrict2 A_NONNULL(2);
129 
133  const Tileset *getTilesetWithGid(const int gid) const
134  restrict2 A_WARN_UNUSED;
135 
139  const MetaTile *getMetaTile(const int x,
140  const int y) const
141  restrict2 A_WARN_UNUSED;
142 
143  void addBlockMask(const int x, const int y,
144  const BlockTypeT type) restrict2;
145 
146  void setBlockMask(const int x, const int y,
147  const BlockTypeT type) restrict2;
148 
153  bool getWalk(const int x, const int y,
154  const unsigned char blockWalkMask) const
155  restrict2 A_WARN_UNUSED;
156 
157  void setWalk(const int x, const int y) restrict2;
158 
159  unsigned char getBlockMask(const int x,
160  const int y) const restrict2;
161 
165  int getWidth() const restrict2 noexcept2 A_WARN_UNUSED
166  { return mWidth; }
167 
171  int getHeight() const restrict2 noexcept2 A_WARN_UNUSED
172  { return mHeight; }
173 
177  int getTileWidth() const restrict2 noexcept2 A_WARN_UNUSED
178  { return mTileWidth; }
179 
183  int getTileHeight() const restrict2 noexcept2 A_WARN_UNUSED
184  { return mTileHeight; }
185 
186  const std::string getMusicFile() const restrict2 A_WARN_UNUSED;
187 
188  void setMusicFile(const std::string &restrict file) restrict2;
189 
190  const std::string getName() const restrict2 A_WARN_UNUSED;
191 
195  const std::string getFilename() const restrict2 A_WARN_UNUSED;
196 
197  const std::string getGatName() const restrict2 A_WARN_UNUSED;
198 
202  Path findPath(const int startX, const int startY,
203  const int destX, const int destY,
204  const unsigned char blockWalkmask,
205  const int maxCost) restrict2 A_WARN_UNUSED;
206 
210  void addParticleEffect(const std::string &restrict effectFile,
211  const int x,
212  const int y,
213  const int w,
214  const int h) restrict2;
215 
220 
224  void addAnimation(const int gid,
225  TileAnimation *restrict const animation) restrict2
226  A_NONNULL(3);
227 
229 
230  MapTypeT getDrawLayersFlags() const restrict2 A_WARN_UNUSED
231  { return mDrawLayersFlags; }
232 
233  void addExtraLayer() restrict2;
234 
235  void saveExtraLayer() const restrict2;
236 
237  SpecialLayer *getTempLayer() const restrict2 noexcept2 A_WARN_UNUSED
238  { return mTempLayer; }
239 
240  SpecialLayer *getSpecialLayer() const restrict2 noexcept2 A_WARN_UNUSED
241  { return mSpecialLayer; }
242 
243  void setHasWarps(const bool n) restrict2 noexcept2
244  { mHasWarps = n; }
245 
246  bool getHasWarps() const restrict2 noexcept2 A_WARN_UNUSED
247  { return mHasWarps; }
248 
249  std::string getUserMapDirectory() const restrict2 A_WARN_UNUSED;
250 
251  void addPortal(const std::string &restrict name,
252  const int type,
253  const int x, const int y,
254  const int dx, const int dy) restrict2;
255 
256  void addRange(const std::string &restrict name,
257  const int type,
258  const int x, const int y,
259  const int dx, const int dy) restrict2;
260 
261  void addPortalTile(const std::string &restrict name,
262  const int type,
263  const int x, const int y) restrict2;
264 
265  void updatePortalTile(const std::string &restrict name,
266  const int type,
267  const int x, const int y,
268  const bool addNew) restrict2;
269 
270  const STD_VECTOR<MapItem*> &getPortals() const restrict2 noexcept2
271  A_WARN_UNUSED
272  { return mMapPortals; }
273 
277  const TileAnimation *getAnimationForGid(const int gid)
278  const restrict2 A_WARN_UNUSED;
279 
280  void optionChanged(const std::string &restrict value)
281  restrict2 override final;
282 
283  MapItem *findPortalXY(const int x,
284  const int y) const restrict2 A_WARN_UNUSED;
285 
286  int getActorsCount() const restrict2 A_WARN_UNUSED
287  { return CAST_S32(mActors.size()); }
288 
289  void setPvpMode(const int mode) restrict2;
290 
291  int getPvpMode() const restrict2 noexcept2 A_WARN_UNUSED
292  { return mPvp; }
293 
294  const ObjectsLayer* getObjectsLayer() const restrict2 noexcept2
295  A_WARN_UNUSED
296  { return mObjects; }
297 
298  std::string getObjectData(const unsigned x,
299  const unsigned y,
300  const int type) const
301  restrict2 A_WARN_UNUSED;
302 
303  void indexTilesets() restrict2;
304 
306 
307  void setActorsFix(const int x, const int y) restrict2;
308 
309  int getVersion() const restrict2 noexcept2 A_WARN_UNUSED
310  { return mVersion; }
311 
312  void setVersion(const int n) restrict2 noexcept2
313  { mVersion = n; }
314 
315  void reduce() restrict2;
316 
317  void redrawMap() restrict2 noexcept2
318  { mRedrawMap = true; }
319 
320  bool empty() const restrict2 A_WARN_UNUSED
321  { return mLayers.empty(); }
322 
323  void setCustom(const bool b) restrict2 noexcept2
324  { mCustom = b; }
325 
326  bool isCustom() const restrict2 noexcept2 A_WARN_UNUSED
327  { return mCustom; }
328 
329  const std::map<int, TileAnimation*> &getTileAnimations() const
330  restrict2 noexcept2 A_WARN_UNUSED
331  { return mTileAnimations; }
332 
333 #ifdef USE_OPENGL
334  int getAtlasCount() const restrict2 A_WARN_UNUSED;
335 
336  void setAtlas(AtlasResource *restrict const atlas) restrict2 noexcept2
337  { mAtlas = atlas; }
338 
339  bool haveAtlas() const
340  { return mAtlas != nullptr; }
341 #endif // USE_OPENGL
342 
343  const MetaTile *getMetaTiles() const restrict2 noexcept2
344  { return mMetaTiles; }
345 
346  const WalkLayer *getWalkLayer() const restrict2 noexcept2
347  { return mWalkLayer; }
348 
349  void setWalkLayer(WalkLayer *restrict const layer) restrict2 noexcept2
350  { mWalkLayer = layer; }
351 
352  void addHeights(const MapHeights *restrict const heights) restrict2
353  A_NONNULL(2);
354 
355  uint8_t getHeightOffset(const int x, const int y) const restrict2;
356 
357  void setMask(const int mask) restrict2;
358 
360 
361  bool isHeightsPresent() const restrict2 noexcept2
362  { return mHeights != nullptr; }
363 
365 
366  void preCacheLayers() restrict2;
367 
368  int calcMemoryLocal() const override final;
369 
370  int calcMemoryChilds(const int level) const override final;
371 
372  std::string getCounterName() const override final
373  { return mName; }
374 
375  protected:
376  friend class Actor;
377  friend class Minimap;
378 
382  Actors::iterator addActor(Actor *const actor) restrict2 A_NONNULL(2);
383 
387  void removeActor(const Actors::iterator &restrict iterator) restrict2;
388 
389  private:
393  void updateAmbientLayers(const float scrollX,
394  const float scrollY) restrict2;
395 
399  void drawAmbientLayers(Graphics *restrict const graphics,
400  const MapLayerPositionT type,
401  const int detail) const restrict2 A_NONNULL(2);
402 
406  bool contains(const int x,
407  const int y) const restrict2 A_WARN_UNUSED;
408 
409  const int mWidth;
410  const int mHeight;
411  const int mTileWidth;
412  const int mTileHeight;
421  bool mHasWarps;
422 
423  // draw flags
425 
426  // Pathfinding members
427  unsigned int mOnClosedList;
428  unsigned int mOnOpenList;
429 
430  // Overlay data
435 
436  // Particle effect data
438  {
439  ParticleEffectData(const std::string &restrict file0,
440  const int x0,
441  const int y0,
442  const int w0,
443  const int h0) noexcept2 :
444  file(file0),
445  x(x0),
446  y(y0),
447  w(w0),
448  h(h0)
449  {
450  }
451 
453 
454  const2 std::string file;
455  const2 int x;
456  const2 int y;
457  const2 int w;
458  const2 int h;
459  };
461 
463 
465 
466  std::string mName;
468  float mOpacity;
470  int mPvp;
476  int mVersion;
477 
482 
483  int mLastX;
484  int mLastY;
487 
488  int mDrawX;
489  int mDrawY;
492  int mMask;
493 #ifdef USE_OPENGL
495 #endif // USE_OPENGL
496 
501  bool mCustom;
503 };
504 
505 #endif // RESOURCES_MAP_MAP_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
int mLastScrollY
Definition: map.h:486
const int mTileHeight
Definition: map.h:412
void addTileset(Tileset *const tileset)
Definition: map.cpp:318
void updatePortalTile(const std::string &name, const int type, const int x, const int y, const bool addNew)
Definition: map.cpp:1308
const std::string getGatName() const
Definition: map.cpp:850
std::vector< Tileset * > Tilesets
Definition: map.h:58
MapType ::T MapTypeT
Definition: maptype.h:38
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:702
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:824
bool mDrawOnlyFringe
Definition: map.h:502
bool empty() const
Definition: map.h:320
const ObjectsLayer * getObjectsLayer() const
Definition: map.h:294
std::string getUserMapDirectory() const
Definition: map.cpp:1268
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:817
void addRange(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1274
std::string file
Definition: map.h:454
void setPvpMode(const int mode)
Definition: map.cpp:1356
AmbientLayerVector mBackgrounds
Definition: map.h:431
void setDrawLayersFlags(const MapTypeT &n)
Definition: map.cpp:1699
int getAtlasCount() const
Definition: map.cpp:1804
int getTileHeight() const
Definition: map.h:183
void updateConditionLayers()
Definition: map.cpp:1728
int mLastX
Definition: map.h:483
const MapHeights * mHeights
Definition: map.h:497
const std::string getMusicFile() const
Definition: map.cpp:830
Tilesets mTilesets
Definition: map.h:419
int mPvp
Definition: map.h:470
#define A_WARN_UNUSED
Definition: localconsts.h:152
WalkLayer * mWalkLayer
Definition: map.h:415
int mDrawScrollY
Definition: map.h:491
std::string getCounterName() const
Definition: map.h:372
void addHeights(const MapHeights *const heights)
Definition: map.cpp:1621
#define final
Definition: localconsts.h:45
int getPvpMode() const
Definition: map.h:291
BlockType ::T BlockTypeT
Definition: blocktype.h:40
int mOverlayDetail
Definition: map.h:467
int mActorFixY
Definition: map.h:475
void setVersion(const int n)
Definition: map.h:312
const MetaTile * getMetaTiles() const
Definition: map.h:343
const std::vector< MapItem * > & getPortals() const
Definition: map.h:270
SpecialLayer * mSpecialLayer
Definition: map.h:478
int mDrawX
Definition: map.h:488
void setWalkLayer(WalkLayer *const layer)
Definition: map.h:349
void optionChanged(const std::string &value)
Definition: map.cpp:209
std::list< Actor * > Actors
Definition: actor.h:35
bool mHasWarps
Definition: map.h:421
void updateAmbientLayers(const float scrollX, const float scrollY)
Definition: map.cpp:614
const Tileset * getTilesetWithGid(const int gid) const
Definition: map.cpp:695
void addLayer(MapLayer *const layer)
Definition: map.cpp:311
void setWalk(const int x, const int y)
Definition: map.cpp:802
void setBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:741
const WalkLayer * getWalkLayer() const
Definition: map.h:346
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:464
ObjectsLayer * mObjects
Definition: map.h:480
#define A_NONNULL(...)
Definition: localconsts.h:159
bool contains(const int x, const int y) const
Definition: map.cpp:807
unsigned char getBlockMask(const int x, const int y) const
Definition: map.cpp:791
~Map()
Definition: map.cpp:178
#define STD_VECTOR
Definition: vector.h:29
bool mTilesetsIndexed
Definition: map.h:471
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1295
ParticleEffectData(const std::string &file0, const int x0, const int y0, const int w0, const int h0)
Definition: map.h:439
void indexTilesets()
Definition: map.cpp:1410
const int mTileWidth
Definition: map.h:411
int getHeight() const
Definition: map.h:171
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:337
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
void setAtlas(AtlasResource *const atlas)
Definition: map.h:336
std::string getObjectData(const unsigned x, const unsigned y, const int type) const
Definition: map.cpp:1388
void updateDrawLayersList()
Definition: map.cpp:1634
std::vector< MapItem * > mMapPortals
Definition: map.h:462
Layers mLayers
Definition: map.h:416
float mLastAScrollX
Definition: map.h:433
int mLastScrollX
Definition: map.h:485
bool mCustom
Definition: map.h:501
bool isHeightsPresent() const
Definition: map.h:361
#define CAST_S32
Definition: cast.h:29
void clearIndexedTilesets()
Definition: map.cpp:1458
std::vector< MapLayer * > Layers
Definition: map.h:61
bool getHasWarps() const
Definition: map.h:246
Layers::const_iterator LayersCIter
Definition: map.h:62
void addPortal(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1286
void initializeParticleEffects() const
Definition: map.cpp:1104
int getVersion() const
Definition: map.h:309
MapTypeT mDrawLayersFlags
Definition: map.h:424
int calcMemoryLocal() const
Definition: map.cpp:1752
void setMask(const int mask)
Definition: map.cpp:1672
int mActorFixX
Definition: map.h:474
#define const2
Definition: localconsts.h:182
int getActorsCount() const
Definition: map.h:286
SpecialLayer * getSpecialLayer() const
Definition: map.h:240
const std::string getFilename() const
Definition: map.cpp:843
void redrawMap()
Definition: map.h:317
std::string mName
Definition: map.h:466
AmbientLayerVector mForegrounds
Definition: map.h:432
bool mRedrawMap
Definition: map.h:498
int mIndexedTilesetsSize
Definition: map.h:473
void preCacheLayers()
Definition: map.cpp:1742
void setCustom(const bool b)
Definition: map.h:323
void addAnimation(const int gid, TileAnimation *const animation)
Definition: map.cpp:1687
bool mCachedDraw
Definition: map.h:500
int mMaxTileHeight
Definition: map.h:413
const TileAnimation * getAnimationForGid(const int gid) const
Definition: map.cpp:1347
uint8_t getHeightOffset(const int x, const int y) const
Definition: map.cpp:1627
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1333
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:780
const int mHeight
Definition: map.h:410
void update(const int ticks)
Definition: map.cpp:326
Definition: map.h:71
void saveExtraLayer() const
Definition: map.cpp:1221
bool haveAtlas() const
Definition: map.h:339
const MetaTile * getMetaTile(const int x, const int y) const
Definition: map.cpp:812
int getWidth() const
Definition: map.h:165
SpecialLayer * mTempLayer
Definition: map.h:479
SpecialLayer * getTempLayer() const
Definition: map.h:237
MetaTile *const mMetaTiles
Definition: map.h:414
void addParticleEffect(const std::string &effectFile, const int x, const int y, const int w, const int h)
Definition: map.cpp:1096
const int mWidth
Definition: map.h:409
unsigned int mOnOpenList
Definition: map.h:428
int mDrawY
Definition: map.h:489
int mLastY
Definition: map.h:484
unsigned int mOnClosedList
Definition: map.h:427
MapTypeT getDrawLayersFlags() const
Definition: map.h:230
MapLayerPosition ::T MapLayerPositionT
Path findPath(const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkmask, const int maxCost)
Definition: map.cpp:858
void initializeAmbientLayers()
Definition: map.cpp:232
int getTileWidth() const
Definition: map.h:177
int calcMemoryChilds(const int level) const
Definition: map.cpp:1770
MapLayer * mFringeLayer
Definition: map.h:481
Definition: actor.h:40
float mLastAScrollY
Definition: map.h:434
const std::map< int, TileAnimation * > & getTileAnimations() const
Definition: map.h:329
std::list< Position > Path
Definition: position.h:48
const RenderType mOpenGL
Definition: map.h:469
#define restrict
Definition: localconsts.h:156
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:64
float mOpacity
Definition: map.h:468
Layers mDrawUnderLayers
Definition: map.h:417
#define override
Definition: localconsts.h:46
void drawCollision(Graphics *const graphics, const int scrollX, const int scrollY, const MapTypeT drawFlags) const
Definition: map.cpp:564
int mVersion
Definition: map.h:476
void reduce()
Definition: map.cpp:1468
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:66
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:96
bool mBeingOpacity
Definition: map.h:499
int mDrawScrollX
Definition: map.h:490
Layers mDrawOverLayers
Definition: map.h:418
const std::string getName() const
Definition: map.cpp:835
void setHasWarps(const bool n)
Definition: map.h:243
Tileset ** mIndexedTilesets
Definition: map.h:472
void setMusicFile(const std::string &file)
Definition: map.cpp:1682
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:460
void drawAmbientLayers(Graphics *const graphics, const MapLayerPositionT type, const int detail) const
Definition: map.cpp:654
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:65
Actors mActors
Definition: map.h:420
AtlasResource * mAtlas
Definition: map.h:494
#define noexcept2
Definition: localconsts.h:49
int mMask
Definition: map.h:492
#define restrict2
Definition: localconsts.h:157
void setActorsFix(const int x, const int y)
Definition: map.cpp:1720
RenderType
Definition: rendertype.h:24
void addExtraLayer()
Definition: map.cpp:1137
bool isCustom() const
Definition: map.h:326