ManaPlus
maplayer.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_MAPLAYER_H
24 #define RESOURCES_MAP_MAPLAYER_H
25 
27 
29 
30 #include "being/actor.h"
31 
33 
34 #include "utils/vector.h"
35 
36 #include "resources/map/tileinfo.h"
37 
38 class Image;
39 class MapRowVertexes;
40 class SpecialLayer;
41 
42 struct MetaTile;
43 
49 {
50  public:
51  friend class Map;
52 
58  MapLayer(const std::string &name,
59  const int x,
60  const int y,
61  const int width,
62  const int height,
63  const bool isFringeLayer,
64  const int mask,
65  const int tileCondition);
66 
68 
69 
73 
77  constexpr3 void setTile(const int x,
78  const int y,
79  Image *restrict const img) restrict
80  {
81  mTiles[x + y * mWidth].image = img;
82  }
83 
87  constexpr3 void setTile(const int index,
88  Image *restrict const img) restrict
89  { mTiles[index].image = img; }
90 
99  void draw(Graphics *restrict const graphics,
100  int startX,
101  int startY,
102  int endX,
103  int endY,
104  const int scrollX,
105  const int scrollY) const restrict A_NONNULL(2);
106 
107  void drawSDL(Graphics *restrict const graphics) const restrict2
108  A_NONNULL(2);
109 
110 #ifdef USE_OPENGL
111  void drawOGL(Graphics *restrict const graphics) const restrict2
112  A_NONNULL(2);
113 
114  void updateOGL(Graphics *restrict const graphics,
115  int startX,
116  int startY,
117  int endX,
118  int endY,
119  const int scrollX,
120  const int scrollY) restrict2 A_NONNULL(2);
121 #endif // USE_OPENGL
122 
123  void updateSDL(const Graphics *restrict const graphics,
124  int startX,
125  int startY,
126  int endX,
127  int endY,
128  const int scrollX,
129  const int scrollY) restrict2 A_NONNULL(2);
130 
131  void drawFringe(Graphics *restrict const graphics,
132  int startX,
133  int startY,
134  int endX,
135  int endY,
136  const int scrollX,
137  const int scrollY,
138  const Actors &actors) const restrict A_NONNULL(2);
139 
141  { return mIsFringeLayer; }
142 
145  { mSpecialLayer = val; }
146 
149  { mTempLayer = val; }
150 
152  { return mWidth; }
153 
155  { return mHeight; }
156 
157  void optionChanged(const std::string &restrict value)
158  restrict override final;
159 
160  constexpr3 void setDrawLayerFlags(const MapTypeT &restrict n)
161  restrict noexcept2
162  {
163  mDrawLayerFlags = n;
167  }
168 
169  constexpr3 void setActorsFix(const int y) restrict noexcept2
170  { mActorsFix = y; }
171 
172  int calcMemoryLocal() const override final;
173 
174  int calcMemoryChilds(const int level) const override final;
175 
176  std::string getCounterName() const override final
177  { return mName; }
178 
179 #ifdef UNITTESTS
180  constexpr3 TileInfo *getTiles() const restrict noexcept2
181  {
182  return mTiles;
183  }
184 
185  constexpr3 void setTileCondition(const int c) restrict noexcept2
186  {
187  mTileCondition = c;
188  }
189 #endif // UNITTESTS
190 
191 #ifndef UNITTESTS
192  protected:
193 #endif // UNITTESTS
194  static int getTileDrawWidth(const TileInfo *restrict img,
195  const int endX,
196  int &restrict width,
197  int &restrict nextTile)
199 
200  static int getEmptyTileDrawWidth(const TileInfo *restrict img,
201  const int endX,
202  int &restrict nextTile)
204 
205  void updateConditionTiles(const MetaTile *restrict const metaTiles,
206  const int width,
207  const int height) restrict A_NONNULL(2);
208 
209  void updateCache(const int width,
210  const int height) restrict;
211 
212  void drawSpecialLayer(Graphics *const graphics,
213  const int y,
214  const int startX,
215  const int endX,
216  const int scrollX,
217  const int scrollY) const restrict;
218 
219  private:
220  const int mX;
221  const int mY;
222  const int mPixelX;
223  const int mPixelY;
224  const int mWidth;
225  const int mHeight;
226  TileInfo *restrict const mTiles;
228  const SpecialLayer *restrict mSpecialLayer;
229  const SpecialLayer *restrict mTempLayer;
230  const std::string mName;
231  typedef STD_VECTOR<MapRowVertexes*> MapRows;
232  MapRows mTempRows;
233  int mMask;
236  const bool mIsFringeLayer;
239 };
240 
241 #endif // RESOURCES_MAP_MAPLAYER_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
const bool mIsFringeLayer
Definition: maplayer.h:236
std::string getCounterName() const
Definition: maplayer.h:176
MapType ::T MapTypeT
Definition: maptype.h:38
static int getEmptyTileDrawWidth(const TileInfo *img, const int endX, int &nextTile)
Definition: maplayer.cpp:741
int getHeight() const
Definition: maplayer.h:154
const int mY
Definition: maplayer.h:221
Image * image
Definition: tileinfo.h:42
int calcMemoryLocal() const
Definition: maplayer.cpp:823
TileInfo *const mTiles
Definition: maplayer.h:226
int getWidth() const
Definition: maplayer.h:151
const SpecialLayer * mSpecialLayer
Definition: maplayer.h:228
#define A_WARN_UNUSED
Definition: localconsts.h:160
#define final
Definition: localconsts.h:45
bool mSpecialFlag
Definition: maplayer.h:238
const int mX
Definition: maplayer.h:220
const int mPixelX
Definition: maplayer.h:222
std::list< Actor * > Actors
Definition: actor.h:35
const SpecialLayer * mTempLayer
Definition: maplayer.h:229
void setDrawLayerFlags(const MapTypeT &n)
Definition: maplayer.h:160
#define A_NONNULL(...)
Definition: localconsts.h:167
std::vector< MapRowVertexes * > MapRows
Definition: maplayer.h:231
void drawFringe(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY, const Actors &actors) const
Definition: maplayer.cpp:424
~MapLayer()
Definition: maplayer.cpp:81
bool mHighlightAttackRange
Definition: maplayer.h:237
void drawSpecialLayer(Graphics *const graphics, const int y, const int startX, const int endX, const int scrollX, const int scrollY) const
Definition: maplayer.cpp:369
void setActorsFix(const int y)
Definition: maplayer.h:169
void setTile(const int x, const int y, Image *const img)
Definition: maplayer.h:77
int mActorsFix
Definition: maplayer.h:235
const std::string mName
Definition: maplayer.h:230
void setTempLayer(const SpecialLayer *const val)
Definition: maplayer.h:147
const int mPixelY
Definition: maplayer.h:223
int mTileCondition
Definition: maplayer.h:234
void updateOGL(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
Definition: maplayer.cpp:264
MapTypeT mDrawLayerFlags
Definition: maplayer.h:227
Definition: map.h:71
static int getTileDrawWidth(const TileInfo *img, const int endX, int &width, int &nextTile)
Definition: maplayer.cpp:698
void setTile(const int index, Image *const img)
Definition: maplayer.h:87
void setSpecialLayer(const SpecialLayer *const val)
Definition: maplayer.h:143
void drawSDL(Graphics *const graphics) const
Definition: maplayer.cpp:178
Definition: image.h:61
const int mWidth
Definition: maplayer.h:224
void updateSDL(const Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY)
Definition: maplayer.cpp:199
MapLayer(const std::string &name, const int x, const int y, const int width, const int height, const bool isFringeLayer, const int mask, const int tileCondition)
Definition: maplayer.cpp:49
#define restrict
Definition: localconsts.h:164
void optionChanged(const std::string &value)
Definition: maplayer.cpp:90
#define constexpr3
Definition: localconsts.h:99
#define override
Definition: localconsts.h:46
void draw(Graphics *const graphics, int startX, int startY, int endX, int endY, const int scrollX, const int scrollY) const
Definition: maplayer.cpp:99
const int mHeight
Definition: maplayer.h:225
void updateCache(const int width, const int height)
Definition: maplayer.cpp:789
void drawOGL(Graphics *const graphics) const
Definition: maplayer.cpp:348
void updateConditionTiles(const MetaTile *const metaTiles, const int width, const int height)
Definition: maplayer.cpp:761
int mMask
Definition: maplayer.h:233
int calcMemoryChilds(const int level) const
Definition: maplayer.cpp:830
#define noexcept2
Definition: localconsts.h:49
#define restrict2
Definition: localconsts.h:165
bool isFringeLayer() const
Definition: maplayer.h:140
MapRows mTempRows
Definition: maplayer.h:232