ManaPlus
animatedsprite.h
Go to the documentation of this file.
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 
28 
29 class Animation;
30 class AnimationDelayLoad;
31 struct Frame;
32 
36 class AnimatedSprite final : public Sprite
37 {
38  public:
43  explicit AnimatedSprite(SpriteDef *restrict const sprite);
44 
46 
47 
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
93 
94  bool setSpriteDirection(const SpriteDirection::Type direction)
95  restrict2 override final;
96 
98  { return 1; }
99 
100  std::string getIdPath() const restrict2 A_WARN_UNUSED;
101 
104  { return mFrameIndex; }
105 
106  unsigned int getFrameCount() const
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 
116  { mDelayLoad = nullptr; }
117 
119  { mSprite = sprite; }
120 
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
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 
166  int mLastTime;
168  unsigned int mFrameIndex;
169  unsigned int mFrameTime;
179  unsigned mNumber;
180  unsigned mNumber1;
183  static bool mEnableCache;
184 };
185 
186 #endif // RESOURCES_SPRITE_ANIMATEDSPRITE_H
Definition: action.h:41
bool setSpriteDirection(const SpriteDirection::Type direction)
bool updateCurrentAnimation(const unsigned int dt)
void setAlpha(float alpha)
static AnimatedSprite * delayedLoad(const std::string &filename, const int variant)
int getHeight() const
std::string getIdPath() const
bool updateNumber(const unsigned num)
bool play(const std::string &spriteAction)
const Frame * mFrame
unsigned int getCurrentFrame() const
int getWidth() const
void draw(Graphics *const graphics, const int posX, const int posY) const
static AnimatedSprite * load(const std::string &filename, const int variant)
const void * getHash() const
void drawRescaled(Graphics *const graphics, const int posX, const int posY, const int dx, const int dy) const
static void setEnableCache(const bool b)
void setLastTime(const int time)
bool isTerminated() const
AnimatedSprite(SpriteDef *const sprite)
unsigned int mFrameTime
static bool mEnableCache
unsigned int mFrameIndex
SpriteDirection::Type mDirection
void setSprite(SpriteDef *const sprite)
unsigned int getFrameCount() const
const Image * getImage() const
SpriteDef * mSprite
void setDelayLoad(const std::string &filename, const int variant)
const Animation * mAnimation
AnimationDelayLoad * mDelayLoad
static AnimatedSprite * clone(const AnimatedSprite *const anim)
const Action * mAction
bool update(const int time)
int getNumberOfLayers() const
void drawRaw(Graphics *const graphics, const int posX, const int posY) const
Definition: sprite.h:34
#define restrict
Definition: localconsts.h:165
#define constexpr2
Definition: localconsts.h:49
#define restrict2
Definition: localconsts.h:166
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
const EmoteSprite * getSprite(const int id, const bool allowNull)
Definition: emotedb.cpp:292
Definition: frame.h:39