GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/map/maplayer.h Lines: 5 12 41.7 %
Date: 2018-11-12 Branches: 0 0 0.0 %

Line Branch Exec Source
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
26
#include "listeners/configlistener.h"
27
28
#include "resources/memorycounter.h"
29
30
#include "being/actor.h"
31
32
#include "enums/resources/map/maptype.h"
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
44
/**
45
 * A map layer. Stores a grid of tiles and their offset, and implements layer
46
 * rendering.
47
 */
48
class MapLayer final : public MemoryCounter, public ConfigListener
49
{
50
    public:
51
        friend class Map;
52
53
        /**
54
         * Constructor, taking layer origin, size and whether this layer is the
55
         * fringe layer. The fringe layer is the layer that draws the actors.
56
         * There can be only one fringe layer per map.
57
         */
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
67
        A_DELETE_COPY(MapLayer)
68
69
        /**
70
         * Destructor.
71
         */
72
        ~MapLayer() override final;
73
74
        /**
75
         * Set tile image, with x and y in layer coordinates.
76
         */
77
        constexpr3 void setTile(const int x,
78
                                const int y,
79
                                Image *restrict const img) restrict
80
        {
81
50200
            mTiles[x + y * mWidth].image = img;
82
        }
83
84
        /**
85
         * Set tile image with x + y * width already known.
86
         */
87
        constexpr3 void setTile(const int index,
88
                                Image *restrict const img) restrict
89
        { mTiles[index].image = img; }
90
91
        /**
92
         * Draws this layer to the given graphics context. The coordinates are
93
         * expected to be in map range and will be translated to local layer
94
         * coordinates and clipped to the layer's dimensions.
95
         *
96
         * The given actors are only drawn when this layer is the fringe
97
         * layer.
98
         */
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
140
        constexpr3 bool isFringeLayer() const restrict noexcept2 A_WARN_UNUSED
141
45
        { return mIsFringeLayer; }
142
143
        constexpr3 void setSpecialLayer(const SpecialLayer *restrict const val)
144
                                        restrict noexcept2
145
30
        { mSpecialLayer = val; }
146
147
        constexpr3 void setTempLayer(const SpecialLayer *restrict const val)
148
                                     restrict noexcept2
149
30
        { mTempLayer = val; }
150
151
        constexpr3 int getWidth() const restrict noexcept2 A_WARN_UNUSED
152
        { return mWidth; }
153
154
        constexpr3 int getHeight() const restrict noexcept2 A_WARN_UNUSED
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;
164
            mSpecialFlag = (mDrawLayerFlags != MapType::SPECIAL &&
165
                mDrawLayerFlags != MapType::SPECIAL2 &&
166
                mDrawLayerFlags != MapType::SPECIAL4);
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
5
            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)
198
                                    A_WARN_UNUSED A_NONNULL(1);
199
200
        static int getEmptyTileDrawWidth(const TileInfo *restrict img,
201
                                         const int endX,
202
                                         int &restrict nextTile)
203
                                         A_WARN_UNUSED A_NONNULL(1);
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;
227
        MapTypeT mDrawLayerFlags;
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;
234
        int mTileCondition;
235
        int mActorsFix;
236
        const bool mIsFringeLayer;    /**< Whether the actors are drawn. */
237
        bool mHighlightAttackRange;
238
        bool mSpecialFlag;
239
};
240
241
#endif  // RESOURCES_MAP_MAPLAYER_H