28 #include "render/graphics.h"
80 #ifdef DEBUG_ANIMATIONS
81 as->setSpriteName(filename);
94 return load(filename, variant);
100 return load(filename, variant);
104 #ifdef DEBUG_ANIMATIONS
105 as->setSpriteName(filename);
109 as->setDelayLoad(filename, variant);
119 #ifdef DEBUG_ANIMATIONS
120 sprite->setSpriteName(anim->getSpriteName());
161 if (mSprite ==
nullptr)
163 if (mDelayLoad ==
nullptr)
165 mDelayLoad->setAction(spriteAction);
169 const Action *
const action = mSprite->getAction(spriteAction, mNumber);
170 if (action ==
nullptr)
174 const Animation *
const animation = mAction->getAnimation(mDirection);
176 if ((animation !=
nullptr) &&
177 animation != mAnimation &&
180 mAnimation = animation;
192 if (
A_UNLIKELY(time < mLastTime || mLastTime == 0))
196 if (time <= mLastTime || (mAnimation ==
nullptr))
199 const unsigned int dt = time - mLastTime;
213 return animation != mAnimation || frame != mFrame;
219 if (mFrame ==
nullptr ||
220 mAnimation ==
nullptr ||
228 while ((mFrameTime >
CAST_U32(mFrame->delay) &&
229 mFrame->delay > 0) ||
234 mFrameTime -=
CAST_U32(mFrame->delay);
237 if (mFrameIndex >=
CAST_U32(mAnimation->getLength()))
240 mFrame = &mAnimation->mFrames[mFrameIndex];
242 !mFrame->nextAction.empty())
247 !mFrame->nextAction.empty())
249 const int rand = mFrame->rand;
251 ((rand != 0) && rand >=
mrand() % 100))
253 for (
size_t i = 0; i < mAnimation->getLength(); i ++)
256 &mAnimation->mFrames[i];
258 mFrame->nextAction == frame->nextAction)
262 mAnimation->getLength()))
267 mFrame = &mAnimation->mFrames[mFrameIndex];
280 !mFrame->nextAction.empty())
282 const int rand = mFrame->rand;
284 ((rand != 0) && rand >=
mrand() % 100))
286 play(mFrame->nextAction);
291 else if ((mFrame->image ==
nullptr) &&
294 const int rand = mFrame->rand;
296 ((rand != 0) && rand >=
mrand() % 100))
298 mAnimation =
nullptr;
305 const int rand = mFrame->rand;
307 mFrameIndex >=
CAST_U32(mAnimation->getLength()))
313 if ((rand != 0) &&
mrand() % 100 <= rand)
319 if (mFrame !=
nullptr)
320 mFrameTime = mFrame->delay + 1;
333 if ((mFrame ==
nullptr) || (mFrame->image ==
nullptr))
337 image->setAlpha(mAlpha);
338 graphics->drawImage(image,
339 posX + mFrame->offsetX, posY + mFrame->offsetY);
348 if (mFrame ==
nullptr ||
349 mFrame->image ==
nullptr)
355 image->setAlpha(mAlpha);
356 graphics->drawRescaledImage(image,
357 posX + mFrame->offsetX,
358 posY + mFrame->offsetY,
367 if ((mFrame ==
nullptr) || (mFrame->image ==
nullptr))
371 image->setAlpha(mAlpha);
372 graphics->drawImage(image,
380 if (mDirection != direction)
382 mDirection = direction;
384 if (mAction ==
nullptr)
388 mAction->getAnimation(mDirection);
390 if ((animation !=
nullptr) &&
391 animation != mAnimation &&
392 animation->getLength() > 0)
394 mAnimation = animation;
441 if (mFrame !=
nullptr)
444 if (image !=
nullptr)
445 image->setAlpha(mAlpha);
458 if (mSprite ==
nullptr)
464 mNumber = mSprite->findNumber(num);
478 if (mDelayLoad !=
nullptr)
480 mDelayLoad->clearSprite();
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)
std::string getIdPath() const
bool updateNumber(const unsigned num)
bool play(const std::string &spriteAction)
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
AnimatedSprite(SpriteDef *const sprite)
unsigned int getFrameCount() const
const Image * getImage() const
void setDelayLoad(const std::string &filename, const int variant)
const Animation * mAnimation
AnimationDelayLoad * mDelayLoad
static AnimatedSprite * clone(const AnimatedSprite *const anim)
bool update(const int time)
void drawRaw(Graphics *const graphics, const int posX, const int posY) const
static void addDelayedAnimation(AnimationDelayLoad *const animation)
static void removeDelayLoad(const AnimationDelayLoad *const delayedLoad)
SpriteDef * getSprite(const std::string &path, const int variant)
Resource * getFromCache(const std::string &filename, const int variant)
static const std::string STAND("stand")
#define FUNC_BLOCK(name, id)