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