GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/map/maplayer.h Lines: 4 8 50.0 %
Date: 2017-11-29 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-2017  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();
73
74
        /**
75
         * Set tile image, with x and y in layer coordinates.
76
         */
77
        void setTile(const int x,
78
                     const int y,
79
                     Image *restrict const img) restrict;
80
81
        /**
82
         * Set tile image with x + y * width already known.
83
         */
84
        void setTile(const int index,
85
                     Image *restrict const img) restrict
86
        { mTiles[index].image = img; }
87
88
        /**
89
         * Draws this layer to the given graphics context. The coordinates are
90
         * expected to be in map range and will be translated to local layer
91
         * coordinates and clipped to the layer's dimensions.
92
         *
93
         * The given actors are only drawn when this layer is the fringe
94
         * layer.
95
         */
96
        void draw(Graphics *restrict const graphics,
97
                  int startX,
98
                  int startY,
99
                  int endX,
100
                  int endY,
101
                  const int scrollX,
102
                  const int scrollY) const restrict A_NONNULL(2);
103
104
        void drawSDL(Graphics *restrict const graphics) const restrict2
105
                     A_NONNULL(2);
106
107
#ifdef USE_OPENGL
108
        void drawOGL(Graphics *restrict const graphics) const restrict2
109
                     A_NONNULL(2);
110
111
        void updateOGL(Graphics *restrict const graphics,
112
                       int startX,
113
                       int startY,
114
                       int endX,
115
                       int endY,
116
                       const int scrollX,
117
                       const int scrollY) restrict2 A_NONNULL(2);
118
#endif  // USE_OPENGL
119
120
        void updateSDL(const Graphics *restrict const graphics,
121
                       int startX,
122
                       int startY,
123
                       int endX,
124
                       int endY,
125
                       const int scrollX,
126
                       const int scrollY) restrict2 A_NONNULL(2);
127
128
        void drawFringe(Graphics *restrict const graphics,
129
                        int startX,
130
                        int startY,
131
                        int endX,
132
                        int endY,
133
                        const int scrollX,
134
                        const int scrollY,
135
                        const Actors &actors) const restrict A_NONNULL(2);
136
137
        bool isFringeLayer() const restrict noexcept2 A_WARN_UNUSED
138
90
        { return mIsFringeLayer; }
139
140
        void setSpecialLayer(const SpecialLayer *restrict const val) restrict
141
60
        { mSpecialLayer = val; }
142
143
        void setTempLayer(const SpecialLayer *restrict const val) restrict
144
60
        { mTempLayer = val; }
145
146
        int getWidth() const restrict noexcept2 A_WARN_UNUSED
147
        { return mWidth; }
148
149
        int getHeight() const restrict noexcept2 A_WARN_UNUSED
150
        { return mHeight; }
151
152
        void optionChanged(const std::string &restrict value)
153
                           restrict override final;
154
155
        void setDrawLayerFlags(const MapTypeT &restrict n) restrict;
156
157
        void setActorsFix(const int y) restrict
158
        { mActorsFix = y; }
159
160
        int calcMemoryLocal() const override final;
161
162
        int calcMemoryChilds(const int level) const override final;
163
164
        std::string getCounterName() const override final
165
        { return mName; }
166
167
#ifdef UNITTESTS
168
        TileInfo *getTiles() const
169
        {
170
            return mTiles;
171
        }
172
173
        void setTileCondition(const int c)
174
        {
175
10
            mTileCondition = c;
176
        }
177
#endif  // UNITTESTS
178
179
#ifndef UNITTESTS
180
    protected:
181
#endif  // UNITTESTS
182
        static int getTileDrawWidth(const TileInfo *restrict img,
183
                                    const int endX,
184
                                    int &restrict width,
185
                                    int &restrict nextTile)
186
                                    A_WARN_UNUSED A_NONNULL(1);
187
188
        static int getEmptyTileDrawWidth(const TileInfo *restrict img,
189
                                         const int endX,
190
                                         int &restrict nextTile)
191
                                         A_WARN_UNUSED A_NONNULL(1);
192
193
        void updateConditionTiles(const MetaTile *restrict const metaTiles,
194
                                  const int width,
195
                                  const int height) restrict A_NONNULL(2);
196
197
        void updateCache(const int width,
198
                         const int height) restrict;
199
200
        void drawSpecialLayer(Graphics *const graphics,
201
                              const int y,
202
                              const int startX,
203
                              const int endX,
204
                              const int scrollX,
205
                              const int scrollY) const restrict;
206
207
    private:
208
        const int mX;
209
        const int mY;
210
        const int mPixelX;
211
        const int mPixelY;
212
        const int mWidth;
213
        const int mHeight;
214
        TileInfo *restrict const mTiles;
215
        MapTypeT mDrawLayerFlags;
216
        const SpecialLayer *restrict mSpecialLayer;
217
        const SpecialLayer *restrict mTempLayer;
218
        const std::string mName;
219
        typedef STD_VECTOR<MapRowVertexes*> MapRows;
220
        MapRows mTempRows;
221
        int mMask;
222
        int mTileCondition;
223
        int mActorsFix;
224
        const bool mIsFringeLayer;    /**< Whether the actors are drawn. */
225
        bool mHighlightAttackRange;
226
        bool mSpecialFlag;
227
};
228
229
#endif  // RESOURCES_MAP_MAPLAYER_H