GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sprite/animatedsprite.h Lines: 0 6 0.0 %
Date: 2021-03-17 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-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_SPRITE_ANIMATEDSPRITE_H
25
#define RESOURCES_SPRITE_ANIMATEDSPRITE_H
26
27
#include "resources/sprite/sprite.h"
28
29
class Animation;
30
class AnimationDelayLoad;
31
struct Frame;
32
33
/**
34
 * Animates a sprite by adding playback state.
35
 */
36
class AnimatedSprite final : public Sprite
37
{
38
    public:
39
        /**
40
         * Constructor.
41
         * @param sprite the sprite to animate
42
         */
43
        explicit AnimatedSprite(SpriteDef *restrict const sprite);
44
45
        A_DELETE_COPY(AnimatedSprite)
46
47
        /**
48
         * An helper function, which will request the sprite to animate
49
         * from the resource manager.
50
         *
51
         * @param filename the file of the sprite to animate
52
         * @param variant  the sprite variant
53
         */
54
        static AnimatedSprite *load(const std::string &restrict filename,
55
                                    const int variant) A_WARN_UNUSED;
56
57
        static AnimatedSprite *delayedLoad(const std::string &restrict
58
                                           filename,
59
                                           const int variant) A_WARN_UNUSED;
60
61
        static AnimatedSprite *clone(const AnimatedSprite *restrict const
62
                                     anim);
63
64
        ~AnimatedSprite() override final;
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