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