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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_MAP_MAP_H
25 #define RESOURCES_MAP_MAP_H
26 
27 #include "position.h"
28 
29 #include "being/actor.h"
30 
32 
36 
38 
39 #include "utils/vector.h"
40 
42 
44 
45 class AmbientLayer;
46 #ifdef USE_OPENGL
47 class AtlasResource;
48 #endif // USE_OPENGL
49 
50 class MapHeights;
51 class MapItem;
52 class MapLayer;
53 class ObjectsLayer;
54 class SpecialLayer;
55 class Tileset;
56 class TileAnimation;
57 class WalkLayer;
58 
59 struct MetaTile;
60 
61 typedef STD_VECTOR<Tileset*> Tilesets;
62 typedef STD_VECTOR<MapLayer*> Layers;
63 typedef Layers::const_iterator LayersCIter;
64 
65 typedef STD_VECTOR<AmbientLayer*> AmbientLayerVector;
66 typedef AmbientLayerVector::const_iterator AmbientLayerVectorCIter;
67 typedef AmbientLayerVector::iterator AmbientLayerVectorIter;
68 
72 class Map final : public Properties,
73  public ConfigListener,
74  public MemoryCounter
75 {
76  public:
80  Map(const std::string &name,
81  const int width,
82  const int height,
83  const int tileWidth,
84  const int tileHeight);
85 
87 
88 
91  ~Map() override final;
92 
98 
102  void update(const int ticks) restrict2;
103 
108  void draw(Graphics *restrict const graphics,
109  int scrollX,
110  int scrollY) restrict2 A_NONNULL(2);
111 
115  void drawCollision(Graphics *restrict const graphics,
116  const int scrollX,
117  const int scrollY,
118  const MapTypeT drawFlags) const
119  restrict2 A_NONNULL(2);
120 
124  void addLayer(MapLayer *const layer) restrict2 A_NONNULL(2);
125 
129  void addTileset(Tileset *const tileset) restrict2 A_NONNULL(2);
130 
134  const Tileset *getTilesetWithGid(const int gid) const
136 
140  const MetaTile *getMetaTile(const int x,
141  const int y) const
143 
144  void addBlockMask(const int x, const int y,
145  const BlockTypeT type) restrict2;
146 
147  void setBlockMask(const int x, const int y,
148  const BlockTypeT type) restrict2;
149 
154  bool getWalk(const int x, const int y,
155  const unsigned char blockWalkMask) const
157 
158  void setWalk(const int x, const int y) restrict2;
159 
160  unsigned char getBlockMask(const int x,
161  const int y) const restrict2;
162 
167  { return mWidth; }
168 
173  { return mHeight; }
174 
179  { return mTileWidth; }
180 
185  { return mTileHeight; }
186 
187  const std::string getMusicFile() const restrict2 A_WARN_UNUSED;
188 
189  void setMusicFile(const std::string &restrict file) restrict2;
190 
191  const std::string getName() const restrict2 A_WARN_UNUSED;
192 
196  const std::string getFilename() const restrict2 A_WARN_UNUSED;
197 
198  const std::string getGatName() const restrict2 A_WARN_UNUSED;
199 
203  Path findPath(const int startX, const int startY,
204  const int destX, const int destY,
205  const unsigned char blockWalkmask,
206  const int maxCost) restrict2 A_WARN_UNUSED;
207 
211  void addParticleEffect(const std::string &restrict effectFile,
212  const int x,
213  const int y,
214  const int w,
215  const int h) restrict2;
216 
221 
225  void addAnimation(const int gid,
226  TileAnimation *restrict const animation) restrict2
227  A_NONNULL(3);
228 
230 
232  { return mDrawLayersFlags; }
233 
234  void addExtraLayer() restrict2;
235 
236  void saveExtraLayer() const restrict2;
237 
239  { return mTempLayer; }
240 
242  { return mSpecialLayer; }
243 
244  void setHasWarps(const bool n) restrict2 noexcept2
245  { mHasWarps = n; }
246 
248  { return mHasWarps; }
249 
250  std::string getUserMapDirectory() const restrict2 A_WARN_UNUSED;
251 
252  void addPortal(const std::string &restrict name,
253  const int type,
254  const int x, const int y,
255  const int dx, const int dy) restrict2;
256 
257  void addRange(const std::string &restrict name,
258  const int type,
259  const int x, const int y,
260  const int dx, const int dy) restrict2;
261 
262  void addPortalTile(const std::string &restrict name,
263  const int type,
264  const int x, const int y) restrict2;
265 
266  void updatePortalTile(const std::string &restrict name,
267  const int type,
268  const int x, const int y,
269  const bool addNew) restrict2;
270 
273  { return mMapPortals; }
274 
278  const TileAnimation *getAnimationForGid(const int gid)
279  const restrict2 A_WARN_UNUSED;
280 
281  void optionChanged(const std::string &restrict value)
282  restrict2 override final;
283 
284  MapItem *findPortalXY(const int x,
285  const int y) const restrict2 A_WARN_UNUSED;
286 
288  { return CAST_S32(mActors.size()); }
289 
290  void setPvpMode(const int mode) restrict2;
291 
293  { return mPvp; }
294 
297  { return mObjects; }
298 
299  std::string getObjectData(const unsigned x,
300  const unsigned y,
301  const int type) const
303 
304  void indexTilesets() restrict2;
305 
307 
308  void setActorsFix(const int x, const int y) restrict2;
309 
311  { return mVersion; }
312 
313  void setVersion(const int n) restrict2 noexcept2
314  { mVersion = n; }
315 
316  void reduce() restrict2;
317 
319  { mRedrawMap = true; }
320 
322  { return mLayers.empty(); }
323 
324  void setCustom(const bool b) restrict2 noexcept2
325  { mCustom = b; }
326 
328  { return mCustom; }
329 
330  const std::map<int, TileAnimation*> &getTileAnimations() const
332  { return mTileAnimations; }
333 
334 #ifdef USE_OPENGL
336 
338  { mAtlas = atlas; }
339 
340  bool haveAtlas() const
341  { return mAtlas != nullptr; }
342 #endif // USE_OPENGL
343 
345  { return mMetaTiles; }
346 
348  { return mWalkLayer; }
349 
351  { mWalkLayer = layer; }
352 
353  void addHeights(const MapHeights *restrict const heights) restrict2
354  A_NONNULL(2);
355 
356  uint8_t getHeightOffset(const int x, const int y) const restrict2;
357 
358  void setMask(const int mask) restrict2;
359 
361 
363  { return mHeights != nullptr; }
364 
366 
367  void preCacheLayers() restrict2;
368 
369  int calcMemoryLocal() const override final;
370 
371  int calcMemoryChilds(const int level) const override final;
372 
374  { return mName; }
375 
376  void screenResized();
377 
378  protected:
379  friend class Actor;
380  friend class Minimap;
381 
385  Actors::iterator addActor(Actor *const actor) restrict2 A_NONNULL(2);
386 
390  void removeActor(const Actors::iterator &restrict iterator) restrict2;
391 
392  private:
396  void updateAmbientLayers(const float scrollX,
397  const float scrollY) restrict2;
398 
402  void drawAmbientLayers(Graphics *restrict const graphics,
403  const MapLayerPositionT type,
404  const int detail) const restrict2 A_NONNULL(2);
405 
409  bool contains(const int x,
410  const int y) const restrict2 A_WARN_UNUSED;
411 
412  const int mWidth;
413  const int mHeight;
414  const int mTileWidth;
415  const int mTileHeight;
424  bool mHasWarps;
425 
426  // draw flags
428 
429  // Pathfinding members
430  unsigned int mOnClosedList;
431  unsigned int mOnOpenList;
432 
433  // Overlay data
438 
439  // Particle effect data
441  {
442  ParticleEffectData(const std::string &restrict file0,
443  const int x0,
444  const int y0,
445  const int w0,
446  const int h0) noexcept2 :
447  file(file0),
448  x(x0),
449  y(y0),
450  w(w0),
451  h(h0)
452  {
453  }
454 
456 
457  const2 std::string file;
458  const2 int x;
459  const2 int y;
460  const2 int w;
461  const2 int h;
462  };
464 
466 
468 
469  std::string mName;
471  float mOpacity;
473  int mPvp;
479  int mVersion;
480 
485 
486  int mLastX;
487  int mLastY;
490 
491  int mDrawX;
492  int mDrawY;
495  int mMask;
496 #ifdef USE_OPENGL
498 #endif // USE_OPENGL
499 
504  bool mCustom;
506  bool mClear;
507 };
508 
509 #endif // RESOURCES_MAP_MAP_H
std::list< Actor * > Actors
Definition: actor.h:36
BlockType ::T BlockTypeT
Definition: blocktype.h:41
#define CAST_S32
Definition: cast.h:30
Definition: actor.h:42
Definition: map.h:75
const RenderType mOpenGL
Definition: map.h:472
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:822
void setMask(const int mask)
Definition: map.cpp:1676
void preCacheLayers()
Definition: map.cpp:1746
Layers mLayers
Definition: map.h:419
const int mHeight
Definition: map.h:413
std::map< int, TileAnimation * > mTileAnimations
Definition: map.h:467
void setBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:746
Map(const std::string &name, const int width, const int height, const int tileWidth, const int tileHeight)
Definition: map.cpp:97
const MetaTile * getMetaTiles() const
Definition: map.h:344
int getPvpMode() const
Definition: map.h:292
const MapHeights * mHeights
Definition: map.h:500
void addParticleEffect(const std::string &effectFile, const int x, const int y, const int w, const int h)
Definition: map.cpp:1101
int mDrawScrollY
Definition: map.h:494
bool mCustom
Definition: map.h:504
uint8_t getHeightOffset(const int x, const int y) const
Definition: map.cpp:1631
float mOpacity
Definition: map.h:471
bool mRedrawMap
Definition: map.h:501
void saveExtraLayer() const
Definition: map.cpp:1226
bool getHasWarps() const
Definition: map.h:247
unsigned int mOnClosedList
Definition: map.h:430
int mMaxTileHeight
Definition: map.h:416
std::vector< ParticleEffectData > mParticleEffects
Definition: map.h:463
std::string getCounterName() const
Definition: map.h:373
void setAtlas(AtlasResource *const atlas)
Definition: map.h:337
float mLastAScrollX
Definition: map.h:436
bool mHasWarps
Definition: map.h:424
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:829
void setPvpMode(const int mode)
Definition: map.cpp:1361
const std::string getFilename() const
Definition: map.cpp:848
bool haveAtlas() const
Definition: map.h:340
void drawAmbientLayers(Graphics *const graphics, const MapLayerPositionT type, const int detail) const
Definition: map.cpp:659
WalkLayer * mWalkLayer
Definition: map.h:418
Layers mDrawUnderLayers
Definition: map.h:420
int mLastX
Definition: map.h:486
bool mDrawOnlyFringe
Definition: map.h:505
AtlasResource * mAtlas
Definition: map.h:497
void setDrawLayersFlags(const MapTypeT &n)
Definition: map.cpp:1703
const int mTileWidth
Definition: map.h:414
SpecialLayer * mTempLayer
Definition: map.h:482
void screenResized()
Definition: map.cpp:1807
bool contains(const int x, const int y) const
Definition: map.cpp:812
bool mBeingOpacity
Definition: map.h:502
void addPortalTile(const std::string &name, const int type, const int x, const int y)
Definition: map.cpp:1300
bool isHeightsPresent() const
Definition: map.h:362
void updateConditionLayers()
Definition: map.cpp:1732
void addTileset(Tileset *const tileset)
Definition: map.cpp:320
std::vector< MapItem * > mMapPortals
Definition: map.h:465
void addLayer(MapLayer *const layer)
Definition: map.cpp:313
void updatePortalTile(const std::string &name, const int type, const int x, const int y, const bool addNew)
Definition: map.cpp:1313
int getHeight() const
Definition: map.h:172
int getTileHeight() const
Definition: map.h:184
bool mClear
Definition: map.h:506
void update(const int ticks)
Definition: map.cpp:328
MetaTile *const mMetaTiles
Definition: map.h:417
void draw(Graphics *const graphics, int scrollX, int scrollY)
Definition: map.cpp:339
int mVersion
Definition: map.h:479
Tilesets mTilesets
Definition: map.h:422
MapLayer * mFringeLayer
Definition: map.h:484
Actors mActors
Definition: map.h:423
std::string getObjectData(const unsigned x, const unsigned y, const int type) const
Definition: map.cpp:1393
float mLastAScrollY
Definition: map.h:437
int mDrawScrollX
Definition: map.h:493
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:785
void updateAmbientLayers(const float scrollX, const float scrollY)
Definition: map.cpp:619
unsigned int mOnOpenList
Definition: map.h:431
void drawCollision(Graphics *const graphics, const int scrollX, const int scrollY, const MapTypeT drawFlags) const
Definition: map.cpp:569
int mActorFixX
Definition: map.h:477
const std::vector< MapItem * > & getPortals() const
Definition: map.h:271
Path findPath(const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkmask, const int maxCost)
Definition: map.cpp:863
int getActorsCount() const
Definition: map.h:287
int getVersion() const
Definition: map.h:310
void setCustom(const bool b)
Definition: map.h:324
MapTypeT getDrawLayersFlags() const
Definition: map.h:231
void indexTilesets()
Definition: map.cpp:1415
const std::string getName() const
Definition: map.cpp:840
void addBlockMask(const int x, const int y, const BlockTypeT type)
Definition: map.cpp:707
void addRange(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1279
const int mTileHeight
Definition: map.h:415
const TileAnimation * getAnimationForGid(const int gid) const
Definition: map.cpp:1352
Tileset ** mIndexedTilesets
Definition: map.h:475
ObjectsLayer * mObjects
Definition: map.h:483
void initializeParticleEffects() const
Definition: map.cpp:1109
int mLastScrollY
Definition: map.h:489
SpecialLayer * mSpecialLayer
Definition: map.h:481
int mDrawY
Definition: map.h:492
const std::map< int, TileAnimation * > & getTileAnimations() const
Definition: map.h:330
const std::string getGatName() const
Definition: map.cpp:855
SpecialLayer * getSpecialLayer() const
Definition: map.h:241
int mMask
Definition: map.h:495
int mLastY
Definition: map.h:487
~Map()
Definition: map.cpp:180
int mIndexedTilesetsSize
Definition: map.h:476
void reduce()
Definition: map.cpp:1473
const WalkLayer * getWalkLayer() const
Definition: map.h:347
bool empty() const
Definition: map.h:321
void updateDrawLayersList()
Definition: map.cpp:1638
int getWidth() const
Definition: map.h:166
int mPvp
Definition: map.h:473
void setActorsFix(const int x, const int y)
Definition: map.cpp:1724
void setVersion(const int n)
Definition: map.h:313
void addHeights(const MapHeights *const heights)
Definition: map.cpp:1625
SpecialLayer * getTempLayer() const
Definition: map.h:238
void initializeAmbientLayers()
Definition: map.cpp:234
unsigned char getBlockMask(const int x, const int y) const
Definition: map.cpp:796
void addExtraLayer()
Definition: map.cpp:1142
int getTileWidth() const
Definition: map.h:178
void optionChanged(const std::string &value)
Definition: map.cpp:211
int calcMemoryLocal() const
Definition: map.cpp:1756
void addPortal(const std::string &name, const int type, const int x, const int y, const int dx, const int dy)
Definition: map.cpp:1291
int mDrawX
Definition: map.h:491
int getAtlasCount() const
Definition: map.cpp:1821
int calcMemoryChilds(const int level) const
Definition: map.cpp:1774
void addAnimation(const int gid, TileAnimation *const animation)
Definition: map.cpp:1691
const std::string getMusicFile() const
Definition: map.cpp:835
MapItem * findPortalXY(const int x, const int y) const
Definition: map.cpp:1338
const ObjectsLayer * getObjectsLayer() const
Definition: map.h:295
AmbientLayerVector mBackgrounds
Definition: map.h:434
const MetaTile * getMetaTile(const int x, const int y) const
Definition: map.cpp:817
std::string getUserMapDirectory() const
Definition: map.cpp:1273
int mActorFixY
Definition: map.h:478
bool mTilesetsIndexed
Definition: map.h:474
const int mWidth
Definition: map.h:412
void setMusicFile(const std::string &file)
Definition: map.cpp:1686
bool mCachedDraw
Definition: map.h:503
bool isCustom() const
Definition: map.h:327
int mOverlayDetail
Definition: map.h:470
Layers mDrawOverLayers
Definition: map.h:421
AmbientLayerVector mForegrounds
Definition: map.h:435
void setWalkLayer(WalkLayer *const layer)
Definition: map.h:350
void setHasWarps(const bool n)
Definition: map.h:244
std::string mName
Definition: map.h:469
void clearIndexedTilesets()
Definition: map.cpp:1463
void redrawMap()
Definition: map.h:318
int mLastScrollX
Definition: map.h:488
MapTypeT mDrawLayersFlags
Definition: map.h:427
const Tileset * getTilesetWithGid(const int gid) const
Definition: map.cpp:700
void setWalk(const int x, const int y)
Definition: map.cpp:807
#define restrict
Definition: localconsts.h:165
#define const2
Definition: localconsts.h:191
#define restrict2
Definition: localconsts.h:166
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41
MapLayerPosition ::T MapLayerPositionT
MapType ::T MapTypeT
Definition: maptype.h:39
static const int blockWalkMask
std::list< Position > Path
Definition: position.h:49
RenderType
Definition: rendertype.h:26
std::vector< MapLayer * > Layers
Definition: map.h:62
Layers::const_iterator LayersCIter
Definition: map.h:63
std::vector< AmbientLayer * > AmbientLayerVector
Definition: map.h:65
std::vector< Tileset * > Tilesets
Definition: map.h:59
AmbientLayerVector::const_iterator AmbientLayerVectorCIter
Definition: map.h:66
AmbientLayerVector::iterator AmbientLayerVectorIter
Definition: map.h:67
std::string file
Definition: map.h:457
ParticleEffectData(const std::string &file0, const int x0, const int y0, const int w0, const int h0)
Definition: map.h:442
#define STD_VECTOR
Definition: vector.h:30