GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sprite/animatedsprite.h Lines: 0 6 0.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_SPRITE_ANIMATEDSPRITE_H
24
#define RESOURCES_SPRITE_ANIMATEDSPRITE_H
25
26
#include "resources/sprite/sprite.h"
27
28
class Animation;
29
class AnimationDelayLoad;
30
struct Frame;
31
32
/**
33
 * Animates a sprite by adding playback state.
34
 */
35
class AnimatedSprite final : public Sprite
36
{
37
    public:
38
        /**
39
         * Constructor.
40
         * @param sprite the sprite to animate
41
         */
42
        explicit AnimatedSprite(SpriteDef *restrict const sprite);
43
44
        A_DELETE_COPY(AnimatedSprite)
45
46
        /**
47
         * An helper function, which will request the sprite to animate
48
         * from the resource manager.
49
         *
50
         * @param filename the file of the sprite to animate
51
         * @param variant  the sprite variant
52
         */
53
        static AnimatedSprite *load(const std::string &restrict filename,
54
                                    const int variant = 0) A_WARN_UNUSED;
55
56
        static AnimatedSprite *delayedLoad(const std::string &restrict
57
                                           filename,
58
                                           const int variant = 0)
59
                                           A_WARN_UNUSED;
60
61
        static AnimatedSprite *clone(const AnimatedSprite *restrict const
62
                                     anim);
63
64
        ~AnimatedSprite();
65
66
        bool reset() restrict2 override final;
67
68
        bool play(const std::string &restrict spriteAction)
69
                  restrict2 override final;
70
71
        bool update(const int time) restrict2 override final;
72
73
        void draw(Graphics *restrict const graphics,
74
                  const int posX,
75
                  const int posY) const restrict2 override final A_NONNULL(2);
76
77
        void drawRescaled(Graphics *restrict const graphics,
78
                          const int posX,
79
                          const int posY,
80
                          const int dx,
81
                          const int dy) const restrict2 A_NONNULL(2);
82
83
        void drawRaw(Graphics *restrict const graphics,
84
                     const int posX,
85
                     const int posY) const restrict2 A_NONNULL(2);
86
87
        int getWidth() const restrict2 override final A_WARN_UNUSED;
88
89
        int getHeight() const restrict2 override final A_WARN_UNUSED;
90
91
        const Image* getImage() const restrict2 noexcept2 override final
92
                              A_WARN_UNUSED;
93
94
        bool setSpriteDirection(const SpriteDirection::Type direction)
95
                                restrict2 override final;
96
97
        int getNumberOfLayers() const restrict2 noexcept2 A_WARN_UNUSED
98
        { return 1; }
99
100
        std::string getIdPath() const restrict2 A_WARN_UNUSED;
101
102
        unsigned int getCurrentFrame() const restrict2 noexcept2 override final
103
                                     A_WARN_UNUSED
104
        { return mFrameIndex; }
105
106
        unsigned int getFrameCount() const
107
                                   restrict2 override final A_WARN_UNUSED;
108
109
        void setAlpha(float alpha) restrict2 override final;
110
111
        const void *getHash() const restrict2 override final A_WARN_UNUSED;
112
113
        bool updateNumber(const unsigned num) restrict2 override final;
114
115
        void clearDelayLoad() restrict2 noexcept2
116
        { mDelayLoad = nullptr; }
117
118
        void setSprite(SpriteDef *restrict const sprite) restrict2 noexcept2
119
        { mSprite = sprite; }
120
121
        bool isTerminated() const restrict2 noexcept2
122
        { return mTerminated; }
123
124
        constexpr2 static void setEnableCache(const bool b) noexcept2
125
        { mEnableCache = b; }
126
127
        void setLastTime(const int time) noexcept2
128
        { mLastTime = time; }
129
130
#ifdef UNITTESTS
131
        SpriteDef *getSprite() restrict2
132
        { return mSprite; }
133
134
        const Frame *getFrame() const restrict2
135
        { return mFrame; }
136
137
        const Animation *getAnimation() const restrict2
138
        { return mAnimation; }
139
140
        unsigned int getFrameIndex() const restrict2
141
        { return mFrameIndex; }
142
143
        unsigned int getFrameTime() const restrict2
144
        { return mFrameTime; }
145
#endif  // UNITTESTS
146
147
#ifdef DEBUG_ANIMATIONS
148
        void setSpriteName(const std::string &restrict name) noexcept2
149
        { mSpriteName = name; }
150
151
        std::string getSpriteName() const noexcept2 A_WARN_UNUSED
152
        { return mSpriteName; }
153
#endif  // DEBUG_ANIMATIONS
154
155
    private:
156
        bool updateCurrentAnimation(const unsigned int dt) restrict2;
157
158
        void setDelayLoad(const std::string &restrict filename,
159
                          const int variant) restrict2;
160
161
#ifdef DEBUG_ANIMATIONS
162
        std::string mSpriteName;
163
#endif  // DEBUG_ANIMATIONS
164
165
        SpriteDirection::Type mDirection;  /**< The sprite direction. */
166
        int mLastTime;                 /**< The last time update was called. */
167
168
        unsigned int mFrameIndex;      /**< The index of the current frame. */
169
        unsigned int mFrameTime;       /**< The time since start of frame. */
170
171
        /**< The sprite definition. */
172
        SpriteDef *restrict mSprite;
173
        /**< The currently active action. */
174
        const Action *restrict mAction;
175
        /**< The currently active animation. */
176
        const Animation *restrict mAnimation;
177
        /**< The currently active frame. */
178
        const Frame *restrict mFrame;
179
        unsigned mNumber;
180
        unsigned mNumber1;
181
        AnimationDelayLoad *mDelayLoad;
182
        bool mTerminated;
183
        static bool mEnableCache;
184
};
185
186
#endif  // RESOURCES_SPRITE_ANIMATEDSPRITE_H