summaryrefslogtreecommitdiff
path: root/src/resources/sprite
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources/sprite')
-rw-r--r--src/resources/sprite/animatedsprite.cpp485
-rw-r--r--src/resources/sprite/animatedsprite.h186
-rw-r--r--src/resources/sprite/animationdelayload.cpp65
-rw-r--r--src/resources/sprite/animationdelayload.h55
-rw-r--r--src/resources/sprite/imagesprite.cpp60
-rw-r--r--src/resources/sprite/imagesprite.h82
-rw-r--r--src/resources/sprite/sprite.h132
-rw-r--r--src/resources/sprite/spritedef.cpp694
-rw-r--r--src/resources/sprite/spritedef.h166
-rw-r--r--src/resources/sprite/spritedisplay.h50
-rw-r--r--src/resources/sprite/spritereference.h53
11 files changed, 0 insertions, 2028 deletions
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
deleted file mode 100644
index 9d7186335..000000000
--- a/src/resources/sprite/animatedsprite.cpp
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "const/resources/spriteaction.h"
-
-#include "render/graphics.h"
-
-#include "resources/action.h"
-#include "resources/delayedmanager.h"
-
-#include "resources/animation/animation.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/spritedefloader.h"
-
-#include "resources/resourcemanager/resourcemanager.h"
-
-#include "resources/sprite/animationdelayload.h"
-
-#include "utils/delete2.h"
-#include "utils/likely.h"
-#include "utils/mrand.h"
-
-#include "debug.h"
-
-bool AnimatedSprite::mEnableCache = false;
-
-AnimatedSprite::AnimatedSprite(SpriteDef *restrict const sprite) :
- mDirection(SpriteDirection::DOWN),
- mLastTime(0),
- mFrameIndex(0),
- mFrameTime(0),
- mSprite(sprite),
- mAction(nullptr),
- mAnimation(nullptr),
- mFrame(nullptr),
- mNumber(100),
- mNumber1(100),
- mDelayLoad(nullptr),
- mTerminated(false)
-{
- mAlpha = 1.0F;
-
- // Take possession of the sprite
- if (mSprite != nullptr)
- mSprite->incRef();
-}
-
-AnimatedSprite *AnimatedSprite::load(const std::string &restrict filename,
- const int variant)
-{
- SpriteDef *restrict const s = Loader::getSprite(
- filename, variant);
- if (s == nullptr)
- return nullptr;
- AnimatedSprite *restrict const as = new AnimatedSprite(s);
-#ifdef DEBUG_ANIMATIONS
- as->setSpriteName(filename);
-#endif // DEBUG_ANIMATIONS
-
- as->play(SpriteAction::STAND);
- s->decRef();
- return as;
-}
-
-AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &restrict
- filename,
- const int variant)
-{
- if (!mEnableCache)
- return load(filename, variant);
- Resource *restrict const res = ResourceManager::getFromCache(
- filename, variant);
- if (res != nullptr)
- {
- res->decRef();
- return load(filename, variant);
- }
-
- AnimatedSprite *restrict const as = new AnimatedSprite(nullptr);
-#ifdef DEBUG_ANIMATIONS
- as->setSpriteName(filename);
-#endif // DEBUG_ANIMATIONS
-
- as->play(SpriteAction::STAND);
- as->setDelayLoad(filename, variant);
- return as;
-}
-
-AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *restrict const
- anim)
-{
- if (anim == nullptr)
- return nullptr;
- AnimatedSprite *restrict const sprite = new AnimatedSprite(anim->mSprite);
-#ifdef DEBUG_ANIMATIONS
- sprite->setSpriteName(anim->getSpriteName());
-#endif // DEBUG_ANIMATIONS
-
- sprite->play(SpriteAction::STAND);
- return sprite;
-}
-
-AnimatedSprite::~AnimatedSprite()
-{
- if (mSprite != nullptr)
- {
- mSprite->decRef();
- mSprite = nullptr;
- }
- if (mDelayLoad != nullptr)
- {
- mDelayLoad->clearSprite();
- DelayedManager::removeDelayLoad(mDelayLoad);
- delete2(mDelayLoad);
- }
-}
-
-bool AnimatedSprite::reset() restrict2
-{
- const bool ret = mFrameIndex !=0 ||
- mFrameTime != 0 ||
- mLastTime != 0;
-
- mFrameIndex = 0;
- mFrameTime = 0;
- mLastTime = 0;
-
- if (mAnimation != nullptr)
- mFrame = &mAnimation->mFrames[0];
- else
- mFrame = nullptr;
- return ret;
-}
-
-bool AnimatedSprite::play(const std::string &restrict spriteAction) restrict2
-{
- if (mSprite == nullptr)
- {
- if (mDelayLoad == nullptr)
- return false;
- mDelayLoad->setAction(spriteAction);
- return true;
- }
-
- const Action *const action = mSprite->getAction(spriteAction, mNumber);
- if (action == nullptr)
- return false;
-
- mAction = action;
- const Animation *const animation = mAction->getAnimation(mDirection);
-
- if ((animation != nullptr) &&
- animation != mAnimation &&
- animation->getLength() > 0)
- {
- mAnimation = animation;
- reset();
-
- return true;
- }
-
- return false;
-}
-
-bool AnimatedSprite::update(const int time) restrict2
-{
- // Avoid freaking out at first frame or when tick_time overflows
- if (A_UNLIKELY(time < mLastTime || mLastTime == 0))
- mLastTime = time;
-
- // If not enough time has passed yet, do nothing
- if (time <= mLastTime || (mAnimation == nullptr))
- return false;
-
- const unsigned int dt = time - mLastTime;
- mLastTime = time;
-
- const Animation *restrict const animation = mAnimation;
- const Frame *restrict const frame = mFrame;
-
- if (A_UNLIKELY(!updateCurrentAnimation(dt)))
- {
- // Animation finished, reset to default
- play(SpriteAction::STAND);
- mTerminated = true;
- }
-
- // Make sure something actually changed
- return animation != mAnimation || frame != mFrame;
-}
-
-bool AnimatedSprite::updateCurrentAnimation(const unsigned int time) restrict2
-{
- // move code from Animation::isTerminator(*mFrame)
- if (mFrame == nullptr ||
- mAnimation == nullptr ||
- (mFrame->image == nullptr && mFrame->type == FrameType::ANIMATION))
- {
- return false;
- }
-
- mFrameTime += time;
-
- while ((mFrameTime > CAST_U32(mFrame->delay) &&
- mFrame->delay > 0) ||
- (mFrame->type != FrameType::ANIMATION &&
- mFrame->type != FrameType::PAUSE))
- {
- bool fail(true);
- mFrameTime -= CAST_U32(mFrame->delay);
- mFrameIndex++;
-
- if (mFrameIndex >= CAST_U32(mAnimation->getLength()))
- mFrameIndex = 0;
-
- mFrame = &mAnimation->mFrames[mFrameIndex];
- if (mFrame->type == FrameType::LABEL &&
- !mFrame->nextAction.empty())
- {
- fail = false;
- }
- else if (mFrame->type == FrameType::GOTO &&
- !mFrame->nextAction.empty())
- {
- const int rand = mFrame->rand;
- if (rand == 100 ||
- ((rand != 0) && rand >= mrand() % 100))
- {
- for (size_t i = 0; i < mAnimation->getLength(); i ++)
- {
- const Frame *restrict const frame =
- &mAnimation->mFrames[i];
- if (frame->type == FrameType::LABEL &&
- mFrame->nextAction == frame->nextAction)
- {
- mFrameIndex = CAST_U32(i);
- if (mFrameIndex >= CAST_U32(
- mAnimation->getLength()))
- {
- mFrameIndex = 0;
- }
-
- mFrame = &mAnimation->mFrames[mFrameIndex];
-
- fail = false;
- break;
- }
- }
- }
- else
- {
- fail = false;
- }
- }
- else if (mFrame->type == FrameType::JUMP &&
- !mFrame->nextAction.empty())
- {
- const int rand = mFrame->rand;
- if (rand == 100 ||
- ((rand != 0) && rand >= mrand() % 100))
- {
- play(mFrame->nextAction);
- return true;
- }
- }
- // copy code from Animation::isTerminator(*mFrame)
- else if ((mFrame->image == nullptr) &&
- mFrame->type == FrameType::ANIMATION)
- {
- const int rand = mFrame->rand;
- if (rand == 100 ||
- ((rand != 0) && rand >= mrand() % 100))
- {
- mAnimation = nullptr;
- mFrame = nullptr;
- return false;
- }
- }
- else
- {
- const int rand = mFrame->rand;
- if (rand == 100 ||
- mFrameIndex >= CAST_U32(mAnimation->getLength()))
- {
- fail = false;
- }
- else
- {
- if ((rand != 0) && mrand() % 100 <= rand)
- fail = false;
- }
- }
- if (fail)
- {
- if (mFrame != nullptr)
- mFrameTime = mFrame->delay + 1;
- else
- mFrameTime ++;
- }
- }
- return true;
-}
-
-void AnimatedSprite::draw(Graphics *restrict const graphics,
- const int posX,
- const int posY) const restrict2
-{
- FUNC_BLOCK("AnimatedSprite::draw", 1)
- if ((mFrame == nullptr) || (mFrame->image == nullptr))
- return;
-
- Image *restrict const image = mFrame->image;
- image->setAlpha(mAlpha);
- graphics->drawImage(image,
- posX + mFrame->offsetX, posY + mFrame->offsetY);
-}
-
-void AnimatedSprite::drawRescaled(Graphics *restrict const graphics,
- const int posX,
- const int posY,
- const int dx,
- const int dy) const restrict2
-{
- if (mFrame == nullptr ||
- mFrame->image == nullptr)
- {
- return;
- }
-
- Image *restrict const image = mFrame->image;
- image->setAlpha(mAlpha);
- graphics->drawRescaledImage(image,
- posX + mFrame->offsetX,
- posY + mFrame->offsetY,
- dx,
- dy);
-}
-
-void AnimatedSprite::drawRaw(Graphics *restrict const graphics,
- const int posX,
- const int posY) const restrict2
-{
- if ((mFrame == nullptr) || (mFrame->image == nullptr))
- return;
-
- Image *restrict const image = mFrame->image;
- image->setAlpha(mAlpha);
- graphics->drawImage(image,
- posX,
- posY);
-}
-
-bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction)
- restrict2
-{
- if (mDirection != direction)
- {
- mDirection = direction;
-
- if (mAction == nullptr)
- return false;
-
- const Animation *restrict const animation =
- mAction->getAnimation(mDirection);
-
- if ((animation != nullptr) &&
- animation != mAnimation &&
- animation->getLength() > 0)
- {
- mAnimation = animation;
- reset();
- }
-
- return true;
- }
-
- return false;
-}
-
-unsigned int AnimatedSprite::getFrameCount() const restrict2
-{
- if (mAnimation != nullptr)
- return CAST_U32(mAnimation->getLength());
- return 0;
-}
-
-int AnimatedSprite::getWidth() const restrict2
-{
- if ((mFrame != nullptr) && (mFrame->image != nullptr))
- return mFrame->image->mBounds.w;
- return 0;
-}
-
-int AnimatedSprite::getHeight() const restrict2
-{
- if ((mFrame != nullptr) && (mFrame->image != nullptr))
- return mFrame->image->mBounds.h;
- return 0;
-}
-
-std::string AnimatedSprite::getIdPath() const restrict2
-{
- if (mSprite == nullptr)
- return "";
- return mSprite->mIdPath;
-}
-
-const Image* AnimatedSprite::getImage() const restrict2 noexcept2
-{
- return mFrame != nullptr ? mFrame->image : nullptr;
-}
-
-void AnimatedSprite::setAlpha(float alpha) restrict2
-{
- mAlpha = alpha;
-
- if (mFrame != nullptr)
- {
- Image *restrict const image = mFrame->image;
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
-}
-
-const void *AnimatedSprite::getHash() const restrict2
-{
- if (mFrame != nullptr)
- return mFrame;
- return this;
-}
-
-bool AnimatedSprite::updateNumber(const unsigned num) restrict2
-{
- if (mSprite == nullptr)
- return false;
-
- if (mNumber1 != num)
- {
- mNumber1 = num;
- mNumber = mSprite->findNumber(num);
- if (mNumber == 0u)
- {
- mNumber = 100;
- return false;
- }
- return true;
- }
- return false;
-}
-
-void AnimatedSprite::setDelayLoad(const std::string &restrict filename,
- const int variant) restrict2
-{
- if (mDelayLoad != nullptr)
- {
- mDelayLoad->clearSprite();
- DelayedManager::removeDelayLoad(mDelayLoad);
- delete mDelayLoad;
- }
- mDelayLoad = new AnimationDelayLoad(filename, variant, this);
- DelayedManager::addDelayedAnimation(mDelayLoad);
-}
diff --git a/src/resources/sprite/animatedsprite.h b/src/resources/sprite/animatedsprite.h
deleted file mode 100644
index 01a142f31..000000000
--- a/src/resources/sprite/animatedsprite.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_ANIMATEDSPRITE_H
-#define RESOURCES_SPRITE_ANIMATEDSPRITE_H
-
-#include "resources/sprite/sprite.h"
-
-class Animation;
-class AnimationDelayLoad;
-struct Frame;
-
-/**
- * Animates a sprite by adding playback state.
- */
-class AnimatedSprite final : public Sprite
-{
- public:
- /**
- * Constructor.
- * @param sprite the sprite to animate
- */
- explicit AnimatedSprite(SpriteDef *restrict const sprite);
-
- A_DELETE_COPY(AnimatedSprite)
-
- /**
- * An helper function, which will request the sprite to animate
- * from the resource manager.
- *
- * @param filename the file of the sprite to animate
- * @param variant the sprite variant
- */
- static AnimatedSprite *load(const std::string &restrict filename,
- const int variant = 0) A_WARN_UNUSED;
-
- static AnimatedSprite *delayedLoad(const std::string &restrict
- filename,
- const int variant = 0)
- A_WARN_UNUSED;
-
- static AnimatedSprite *clone(const AnimatedSprite *restrict const
- anim);
-
- ~AnimatedSprite();
-
- bool reset() restrict2 override final;
-
- bool play(const std::string &restrict spriteAction)
- restrict2 override final;
-
- bool update(const int time) restrict2 override final;
-
- void draw(Graphics *restrict const graphics,
- const int posX,
- const int posY) const restrict2 override final A_NONNULL(2);
-
- void drawRescaled(Graphics *restrict const graphics,
- const int posX,
- const int posY,
- const int dx,
- const int dy) const restrict2 A_NONNULL(2);
-
- void drawRaw(Graphics *restrict const graphics,
- const int posX,
- const int posY) const restrict2 A_NONNULL(2);
-
- int getWidth() const restrict2 override final A_WARN_UNUSED;
-
- int getHeight() const restrict2 override final A_WARN_UNUSED;
-
- const Image* getImage() const restrict2 noexcept2 override final
- A_WARN_UNUSED;
-
- bool setSpriteDirection(const SpriteDirection::Type direction)
- restrict2 override final;
-
- int getNumberOfLayers() const restrict2 noexcept2 A_WARN_UNUSED
- { return 1; }
-
- std::string getIdPath() const restrict2 A_WARN_UNUSED;
-
- unsigned int getCurrentFrame() const restrict2 noexcept2 override final
- A_WARN_UNUSED
- { return mFrameIndex; }
-
- unsigned int getFrameCount() const
- restrict2 override final A_WARN_UNUSED;
-
- void setAlpha(float alpha) restrict2 override final;
-
- const void *getHash() const restrict2 override final A_WARN_UNUSED;
-
- bool updateNumber(const unsigned num) restrict2 override final;
-
- void clearDelayLoad() restrict2 noexcept2
- { mDelayLoad = nullptr; }
-
- void setSprite(SpriteDef *restrict const sprite) restrict2 noexcept2
- { mSprite = sprite; }
-
- bool isTerminated() const restrict2 noexcept2
- { return mTerminated; }
-
- constexpr2 static void setEnableCache(const bool b) noexcept2
- { mEnableCache = b; }
-
- void setLastTime(const int time) noexcept2
- { mLastTime = time; }
-
-#ifdef UNITTESTS
- SpriteDef *getSprite() restrict2
- { return mSprite; }
-
- const Frame *getFrame() const restrict2
- { return mFrame; }
-
- const Animation *getAnimation() const restrict2
- { return mAnimation; }
-
- unsigned int getFrameIndex() const restrict2
- { return mFrameIndex; }
-
- unsigned int getFrameTime() const restrict2
- { return mFrameTime; }
-#endif // UNITTESTS
-
-#ifdef DEBUG_ANIMATIONS
- void setSpriteName(const std::string &restrict name) noexcept2
- { mSpriteName = name; }
-
- std::string getSpriteName() const noexcept2 A_WARN_UNUSED
- { return mSpriteName; }
-#endif // DEBUG_ANIMATIONS
-
- private:
- bool updateCurrentAnimation(const unsigned int dt) restrict2;
-
- void setDelayLoad(const std::string &restrict filename,
- const int variant) restrict2;
-
-#ifdef DEBUG_ANIMATIONS
- std::string mSpriteName;
-#endif // DEBUG_ANIMATIONS
-
- SpriteDirection::Type mDirection; /**< The sprite direction. */
- int mLastTime; /**< The last time update was called. */
-
- unsigned int mFrameIndex; /**< The index of the current frame. */
- unsigned int mFrameTime; /**< The time since start of frame. */
-
- /**< The sprite definition. */
- SpriteDef *restrict mSprite;
- /**< The currently active action. */
- const Action *restrict mAction;
- /**< The currently active animation. */
- const Animation *restrict mAnimation;
- /**< The currently active frame. */
- const Frame *restrict mFrame;
- unsigned mNumber;
- unsigned mNumber1;
- AnimationDelayLoad *mDelayLoad;
- bool mTerminated;
- static bool mEnableCache;
-};
-
-#endif // RESOURCES_SPRITE_ANIMATEDSPRITE_H
diff --git a/src/resources/sprite/animationdelayload.cpp b/src/resources/sprite/animationdelayload.cpp
deleted file mode 100644
index 37222d068..000000000
--- a/src/resources/sprite/animationdelayload.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "resources/sprite/animationdelayload.h"
-
-#include "const/resources/spriteaction.h"
-
-#include "resources/loaders/spritedefloader.h"
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "debug.h"
-
-AnimationDelayLoad::AnimationDelayLoad(const std::string &fileName,
- const int variant,
- AnimatedSprite *const sprite) :
- mFileName(fileName),
- mVariant(variant),
- mSprite(sprite),
- mAction(SpriteAction::STAND)
-{
-}
-
-AnimationDelayLoad::~AnimationDelayLoad()
-{
- if (mSprite != nullptr)
- {
- mSprite->clearDelayLoad();
- mSprite = nullptr;
- }
-}
-
-void AnimationDelayLoad::clearSprite()
-{
- mSprite = nullptr;
-}
-
-void AnimationDelayLoad::load()
-{
- if (mSprite != nullptr)
- {
- SpriteDef *const s = Loader::getSprite(mFileName, mVariant);
- if (s == nullptr)
- return;
- mSprite->setSprite(s);
- mSprite->play(mAction);
- }
-}
diff --git a/src/resources/sprite/animationdelayload.h b/src/resources/sprite/animationdelayload.h
deleted file mode 100644
index f559b4fb3..000000000
--- a/src/resources/sprite/animationdelayload.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_ANIMATIONDELAYLOAD_H
-#define RESOURCES_SPRITE_ANIMATIONDELAYLOAD_H
-
-#include <string>
-
-#include "localconsts.h"
-
-class AnimatedSprite;
-
-class AnimationDelayLoad final
-{
- public:
- AnimationDelayLoad(const std::string &fileName,
- const int variant,
- AnimatedSprite *const sprite);
-
- A_DELETE_COPY(AnimationDelayLoad)
-
- ~AnimationDelayLoad();
-
- void clearSprite();
-
- void load();
-
- void setAction(const std::string &action)
- { mAction = action; }
-
- private:
- std::string mFileName;
- int mVariant;
- AnimatedSprite *mSprite;
- std::string mAction;
-};
-
-#endif // RESOURCES_SPRITE_ANIMATIONDELAYLOAD_H
diff --git a/src/resources/sprite/imagesprite.cpp b/src/resources/sprite/imagesprite.cpp
deleted file mode 100644
index b5aace2e1..000000000
--- a/src/resources/sprite/imagesprite.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "resources/sprite/imagesprite.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-ImageSprite::ImageSprite(Image *const image) :
- mImage(image)
-{
- if (mImage != nullptr)
- {
- mAlpha = mImage->mAlpha;
- mImage->incRef();
- }
- else
- {
- mAlpha = 1;
- }
-}
-
-ImageSprite::~ImageSprite()
-{
- if (mImage != nullptr)
- {
- mImage->decRef();
- mImage = nullptr;
- }
-}
-
-void ImageSprite::draw(Graphics *const graphics,
- const int posX, const int posY) const
-{
- FUNC_BLOCK("ImageSprite::draw", 1)
- if (mImage == nullptr)
- return;
-
- mImage->setAlpha(mAlpha);
- graphics->drawImage(mImage, posX, posY);
-}
diff --git a/src/resources/sprite/imagesprite.h b/src/resources/sprite/imagesprite.h
deleted file mode 100644
index 9576933d1..000000000
--- a/src/resources/sprite/imagesprite.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_IMAGESPRITE_H
-#define RESOURCES_SPRITE_IMAGESPRITE_H
-
-#include "resources/sprite/sprite.h"
-
-#include "resources/image/image.h"
-
-class Graphics;
-
-class ImageSprite final : public Sprite
-{
- public:
- explicit ImageSprite(Image *const image);
-
- A_DELETE_COPY(ImageSprite)
-
- ~ImageSprite();
-
- bool reset() override final
- { return false; }
-
- bool play(const std::string &action A_UNUSED) override final
- { return false; }
-
- bool update(const int time A_UNUSED) override final
- { return false; }
-
- void draw(Graphics *const graphics,
- const int posX, const int posY)
- const override final A_NONNULL(2);
-
- int getWidth() const override final A_WARN_UNUSED
- { return mImage != nullptr ? mImage->getWidth() : 0; }
-
- int getHeight() const override final A_WARN_UNUSED
- { return mImage != nullptr ? mImage->getHeight() : 0; }
-
- const Image* getImage() const override final A_WARN_UNUSED
- { return mImage; }
-
- bool setSpriteDirection(const SpriteDirection::Type
- direction A_UNUSED) override final
- { return false; }
-
- int getNumberOfLayers() const A_WARN_UNUSED
- { return 1; }
-
- unsigned int getCurrentFrame() const override final A_WARN_UNUSED
- { return 0; }
-
- unsigned int getFrameCount() const override final A_WARN_UNUSED
- { return 1; }
-
- bool updateNumber(const unsigned num A_UNUSED) override final
- { return false; }
-
- private:
- Image *mImage;
-};
-
-#endif // RESOURCES_SPRITE_IMAGESPRITE_H
diff --git a/src/resources/sprite/sprite.h b/src/resources/sprite/sprite.h
deleted file mode 100644
index 0b75feb73..000000000
--- a/src/resources/sprite/sprite.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_SPRITE_H
-#define RESOURCES_SPRITE_SPRITE_H
-
-#include "resources/sprite/spritedef.h"
-
-#include "localconsts.h"
-
-class Graphics;
-class Image;
-
-class Sprite notfinal
-{
- public:
- A_DELETE_COPY(Sprite)
-
- virtual ~Sprite()
- { }
-
- /**
- * Resets the sprite.
- *
- * @returns true if the sprite changed, false otherwise
- */
- virtual bool reset() = 0;
-
- /**
- * Plays an action using the current direction.
- *
- * @returns true if the sprite changed, false otherwise
- */
- virtual bool play(const std::string &action) = 0;
-
- /**
- * Inform the animation of the passed time so that it can output the
- * correct animation frame.
- *
- * @returns true if the sprite changed, false otherwise
- */
- virtual bool update(const int time) = 0;
-
- /**
- * Draw the current animation frame at the coordinates given in screen
- * pixels.
- */
- virtual void draw(Graphics *const graphics,
- const int posX, const int posY)
- const A_NONNULL(2) = 0;
-
- /**
- * Gets the width in pixels of the image of the current frame
- */
- virtual int getWidth() const A_WARN_UNUSED = 0;
-
- /**
- * Gets the height in pixels of the image of the current frame
- */
- virtual int getHeight() const A_WARN_UNUSED = 0;
-
- /**
- * Returns a reference to the current image being drawn.
- */
- virtual const Image* getImage() const A_WARN_UNUSED = 0;
-
- /**
- * Sets the direction.
- *
- * @returns true if the sprite changed, false otherwise
- */
- virtual bool setSpriteDirection(const SpriteDirection::Type
- direction) = 0;
-
- /**
- * Sets the alpha value of the animated sprite
- */
- virtual void setAlpha(float alpha)
- { mAlpha = alpha; }
-
- /**
- * Returns the current alpha opacity of the animated sprite.
- */
- virtual float getAlpha() const A_WARN_UNUSED
- { return mAlpha; }
-
- /**
- * Returns the current frame number for the sprite.
- */
- virtual unsigned int getCurrentFrame() const A_WARN_UNUSED = 0;
-
- /**
- * Returns the frame count for the sprite.
- */
- virtual unsigned int getFrameCount() const A_WARN_UNUSED = 0;
-
- virtual const void *getHash() const A_WARN_UNUSED
- { return nullptr; }
-
- virtual const void *getHash2() const A_WARN_UNUSED
- { return this; }
-
- virtual bool updateNumber(const unsigned num) = 0;
-
- protected:
- Sprite() :
- mAlpha()
- {
- }
-
- float mAlpha; /**< The alpha opacity used to draw */
-};
-
-#endif // RESOURCES_SPRITE_SPRITE_H
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp
deleted file mode 100644
index aa79ef9f8..000000000
--- a/src/resources/sprite/spritedef.cpp
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "resources/sprite/spritedef.h"
-
-#include "configuration.h"
-#include "settings.h"
-
-#include "const/resources/spriteaction.h"
-
-#include "const/resources/map/map.h"
-
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-
-#include "resources/action.h"
-#include "resources/imageset.h"
-
-#include "resources/animation/animation.h"
-
-#include "resources/dye/dye.h"
-
-#include "resources/loaders/imagesetloader.h"
-#include "resources/loaders/xmlloader.h"
-
-#include "resources/sprite/spritereference.h"
-
-#include "debug.h"
-
-SpriteReference *SpriteReference::Empty = nullptr;
-
-const Action *SpriteDef::getAction(const std::string &action,
- const unsigned num) const
-{
- Actions::const_iterator i = mActions.find(num);
- if (i == mActions.end() && num != 100)
- i = mActions.find(100);
-
- if (i == mActions.end() || ((*i).second == nullptr))
- return nullptr;
-
- const ActionMap *const actMap = (*i).second;
- if (actMap == nullptr)
- return nullptr;
- const ActionMap::const_iterator it = actMap->find(action);
-
- if (it == actMap->end())
- {
- logger->log("Warning: no action \"%s\" defined!", action.c_str());
- return nullptr;
- }
-
- return (*it).second;
-}
-
-unsigned SpriteDef::findNumber(const unsigned num) const
-{
- unsigned min = 101;
- FOR_EACH (Actions::const_iterator, it, mActions)
- {
- const unsigned n = (*it).first;
- if (n >= num && n < min)
- min = n;
- }
- if (min == 101)
- return 0;
- return min;
-}
-
-SpriteDef *SpriteDef::load(const std::string &animationFile,
- const int variant, const bool prot)
-{
- BLOCK_START("SpriteDef::load")
- const size_t pos = animationFile.find('|');
- std::string palettes;
- if (pos != std::string::npos)
- palettes = animationFile.substr(pos + 1);
-
- XML::Document *const doc = Loader::getXml(animationFile.substr(0, pos),
- UseVirtFs_true,
- SkipError_false);
- if (doc == nullptr)
- return nullptr;
- XmlNodePtrConst rootNode = doc->rootNode();
-
- if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "sprite"))
- {
- reportAlways("Error, failed to parse sprite %s",
- animationFile.c_str());
- const std::string errorFile = pathJoin(paths.getStringValue("sprites"),
- paths.getStringValue("spriteErrorFile"));
- BLOCK_END("SpriteDef::load")
- doc->decRef();
- if (animationFile != errorFile)
- return load(errorFile, 0, prot);
- return nullptr;
- }
-
- SpriteDef *const def = new SpriteDef;
- def->mSource = animationFile;
- def->mProcessedFiles.insert(animationFile);
- def->loadSprite(rootNode, variant, palettes);
- def->substituteActions();
- if (settings.fixDeadAnimation)
- def->fixDeadAction();
- if (prot)
- {
- def->incRef();
- def->mProtected = true;
- }
- doc->decRef();
- BLOCK_END("SpriteDef::load")
- return def;
-}
-
-void SpriteDef::fixDeadAction()
-{
- FOR_EACH (ActionsIter, it, mActions)
- {
- ActionMap *const d = (*it).second;
- if (d == nullptr)
- continue;
- const ActionMap::iterator i = d->find(SpriteAction::DEAD);
- const ActionMap::iterator i2 = d->find(SpriteAction::STAND);
- // search dead action and check what it not same with stand action
- if (i != d->end() &&
- i->second != nullptr &&
- (i2 == d->end() || i->second != i2->second))
- {
- (i->second)->setLastFrameDelay(0);
- }
- }
-}
-
-void SpriteDef::substituteAction(const std::string &restrict complete,
- const std::string &restrict with)
-{
- FOR_EACH (ActionsConstIter, it, mActions)
- {
- ActionMap *const d = (*it).second;
- if (reportTrue(d == nullptr))
- continue;
- if (d->find(complete) == d->end())
- {
- const ActionMap::iterator i = d->find(with);
- if (i != d->end())
- (*d)[complete] = i->second;
- }
- }
-}
-
-void SpriteDef::substituteActions()
-{
- substituteAction(SpriteAction::STAND, SpriteAction::DEFAULT);
- substituteAction(SpriteAction::MOVE, SpriteAction::STAND);
- substituteAction(SpriteAction::ATTACK, SpriteAction::STAND);
- substituteAction(SpriteAction::CAST, SpriteAction::ATTACK);
- substituteAction(SpriteAction::SIT, SpriteAction::STAND);
- substituteAction(SpriteAction::SITTOP, SpriteAction::SIT);
- substituteAction(SpriteAction::DEAD, SpriteAction::STAND);
- substituteAction(SpriteAction::SPAWN, SpriteAction::STAND);
- substituteAction(SpriteAction::FLY, SpriteAction::MOVE);
- substituteAction(SpriteAction::SWIM, SpriteAction::MOVE);
- substituteAction(SpriteAction::RIDE, SpriteAction::MOVE);
- substituteAction(SpriteAction::STANDSKY, SpriteAction::STAND);
- substituteAction(SpriteAction::STANDWATER, SpriteAction::STAND);
- substituteAction(SpriteAction::STANDRIDE, SpriteAction::STAND);
- substituteAction(SpriteAction::SITSKY, SpriteAction::SIT);
- substituteAction(SpriteAction::SITWATER, SpriteAction::SIT);
- substituteAction(SpriteAction::SITRIDE, SpriteAction::SIT);
- substituteAction(SpriteAction::ATTACKSKY, SpriteAction::ATTACK);
- substituteAction(SpriteAction::ATTACKWATER, SpriteAction::ATTACK);
- substituteAction(SpriteAction::ATTACKRIDE, SpriteAction::ATTACK);
- substituteAction(SpriteAction::CASTSKY, SpriteAction::CAST);
- substituteAction(SpriteAction::CASTWATER, SpriteAction::CAST);
- substituteAction(SpriteAction::CASTRIDE, SpriteAction::CAST);
- substituteAction(SpriteAction::SPAWNSKY, SpriteAction::SPAWN);
- substituteAction(SpriteAction::SPAWNWATER, SpriteAction::SPAWN);
- substituteAction(SpriteAction::SPAWNRIDE, SpriteAction::SPAWN);
- substituteAction(SpriteAction::DEADSKY, SpriteAction::DEAD);
- substituteAction(SpriteAction::DEADWATER, SpriteAction::DEAD);
- substituteAction(SpriteAction::DEADRIDE, SpriteAction::DEAD);
-}
-
-void SpriteDef::loadSprite(XmlNodeConstPtr spriteNode,
- const int variant,
- const std::string &palettes)
-{
- BLOCK_START("SpriteDef::loadSprite")
- if (spriteNode == nullptr)
- {
- BLOCK_END("SpriteDef::loadSprite")
- return;
- }
- // Get the variant
- const int variantCount = XML::getProperty(spriteNode, "variants", 0);
- int variant_offset = 0;
-
- if (variantCount > 0 && variant < variantCount)
- {
- variant_offset = variant * XML::getProperty(spriteNode,
- "variant_offset",
- 0);
- }
-
- for_each_xml_child_node(node, spriteNode)
- {
- if (xmlNameEqual(node, "imageset"))
- loadImageSet(node, palettes);
- else if (xmlNameEqual(node, "action"))
- loadAction(node, variant_offset);
- else if (xmlNameEqual(node, "include"))
- includeSprite(node, variant);
- }
- BLOCK_END("SpriteDef::loadSprite")
-}
-
-void SpriteDef::loadImageSet(XmlNodeConstPtr node,
- const std::string &palettes)
-{
- const std::string name = XML::getProperty(node, "name", "");
-
- // We don't allow redefining image sets. This way, an included sprite
- // definition will use the already loaded image set with the same name.
- if (mImageSets.find(name) != mImageSets.end())
- return;
-
- const int width = XML::getProperty(node, "width", 0);
- const int height = XML::getProperty(node, "height", 0);
- std::string imageSrc = XML::getProperty(node, "src", "");
- Dye::instantiate(imageSrc, palettes);
-
- ImageSet *const imageSet = Loader::getImageSet(imageSrc,
- width, height);
-
- if (imageSet == nullptr)
- {
- reportAlways("%s: Couldn't load imageset: %s",
- mSource.c_str(),
- imageSrc.c_str());
- return;
- }
-
- imageSet->setOffsetX(XML::getProperty(node, "offsetX", 0));
- imageSet->setOffsetY(XML::getProperty(node, "offsetY", 0));
- mImageSets[name] = imageSet;
-}
-
-const ImageSet *SpriteDef::getImageSet(const std::string &imageSetName) const
-{
- const ImageSetCIterator si = mImageSets.find(imageSetName);
- if (si == mImageSets.end())
- {
- reportAlways("%s: Imageset \"%s\" not defined in %s",
- mSource.c_str(),
- imageSetName.c_str(),
- mIdPath.c_str());
- return nullptr;
- }
- return si->second;
-}
-
-void SpriteDef::loadAction(XmlNodeConstPtr node,
- const int variant_offset)
-{
- if (node == nullptr)
- return;
-
- const std::string actionName = XML::getProperty(node, "name", "");
- const std::string imageSetName = XML::getProperty(node, "imageset", "");
- const unsigned hp = XML::getProperty(node, "hp", 100);
- const ImageSet *const imageSet = getImageSet(imageSetName);
-
- if (actionName == SpriteAction::INVALID)
- {
- reportAlways("%s: Unknown action \"%s\" defined in %s",
- mSource.c_str(),
- actionName.c_str(),
- mIdPath.c_str());
- return;
- }
- Action *const action = new Action(actionName);
- action->setNumber(hp);
- addAction(hp, actionName, action);
-
- // dirty hack to fix bad resources in tmw server
- if (actionName == "attack_stab")
- {
- reportAlways("Found legacy attribute attack_stab in animation");
- addAction(hp, "attack", action);
- }
-
- // When first action, set it as default direction.
- // i here always correct, because hp was added above.
- const Actions::const_iterator i = mActions.find(hp);
- if ((*i).second->size() == 1)
- addAction(hp, SpriteAction::DEFAULT, action);
-
- // Load animations
- for_each_xml_child_node(animationNode, node)
- {
- if (xmlNameEqual(animationNode, "animation"))
- loadAnimation(animationNode, action, imageSet, variant_offset);
- }
-}
-
-void SpriteDef::loadAnimation(XmlNodeConstPtr animationNode,
- Action *const action,
- const ImageSet *const imageSet0,
- const int variant_offset) const
-{
- if (action == nullptr ||
- imageSet0 == nullptr ||
- animationNode == nullptr)
- {
- return;
- }
-
- const std::string directionName =
- XML::getProperty(animationNode, "direction", "");
- const SpriteDirection::Type directionType
- = makeSpriteDirection(directionName);
-
- if (directionType == SpriteDirection::INVALID)
- {
- reportAlways("%s: Unknown direction \"%s\" used in %s",
- mSource.c_str(),
- directionName.c_str(),
- mIdPath.c_str());
- return;
- }
-
- Animation *const animation = new Animation(directionName);
- action->setAnimation(directionType, animation);
-
- // Get animation frames
- for_each_xml_child_node(frameNode, animationNode)
- {
- const int delay = XML::getIntProperty(
- frameNode, "delay", 0, 0, 100000);
- const std::string imageSetName = XML::getProperty(frameNode,
- "imageset",
- "");
- const ImageSet *imageSet = imageSet0;
- if (!imageSetName.empty())
- {
- imageSet = getImageSet(imageSetName);
- if (imageSet == nullptr)
- imageSet = imageSet0;
- }
- const int offsetX = XML::getProperty(frameNode, "offsetX", 0)
- + imageSet->getOffsetX() - imageSet->getWidth() / 2
- + mapTileSize / 2;
- const int offsetY = XML::getProperty(frameNode, "offsetY", 0)
- + imageSet->getOffsetY() - imageSet->getHeight() + mapTileSize;
- const int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100);
-
- if (xmlNameEqual(frameNode, "frame"))
- {
- const int index = XML::getProperty(frameNode, "index", -1);
-
- if (index < 0)
- {
- reportAlways(
- "%s: No valid value for 'index' at direction '%s'",
- mSource.c_str(),
- directionName.c_str());
- continue;
- }
-
- Image *const img = imageSet->get(index + variant_offset);
- if (img == nullptr)
- {
- reportAlways("%s: No image at index %d at direction '%s'",
- mSource.c_str(),
- index + variant_offset,
- directionName.c_str());
- continue;
- }
-
- animation->addFrame(img, delay, offsetX, offsetY, rand);
- }
- else if (xmlNameEqual(frameNode, "sequence"))
- {
- const int start = XML::getProperty(frameNode, "start", -1);
- const int end = XML::getProperty(frameNode, "end", -1);
- const std::string value = XML::getProperty(frameNode, "value", "");
- const int repeat = XML::getIntProperty(
- frameNode, "repeat", 1, 0, 100);
-
- if (repeat < 1)
- {
- reportAlways("%s: No valid value for 'repeat' at direction %s",
- mSource.c_str(),
- directionName.c_str());
- continue;
- }
-
- if (value.empty())
- {
- if (addSequence(start, end, delay, offsetX, offsetY,
- variant_offset, repeat, rand, imageSet, animation))
- {
- continue;
- }
- }
- else
- {
- StringVect vals;
- splitToStringVector(vals, value, ',');
- FOR_EACH (StringVectCIter, it, vals)
- {
- const std::string str = *it;
- const size_t idx = str.find('-');
- if (str == "p")
- {
- animation->addPause(delay, rand);
- }
- else if (idx != std::string::npos)
- {
- const int v1 = atoi(str.substr(0, idx).c_str());
- const int v2 = atoi(str.substr(idx + 1).c_str());
- addSequence(v1, v2, delay, offsetX, offsetY,
- variant_offset, repeat, rand, imageSet, animation);
- }
- else
- {
- Image *const img = imageSet->get(atoi(
- str.c_str()) + variant_offset);
- if (img != nullptr)
- {
- animation->addFrame(img, delay,
- offsetX, offsetY, rand);
- }
- }
- }
- }
- }
- else if (xmlNameEqual(frameNode, "pause"))
- {
- animation->addPause(delay, rand);
- }
- else if (xmlNameEqual(frameNode, "end"))
- {
- animation->addTerminator(rand);
- }
- else if (xmlNameEqual(frameNode, "jump"))
- {
- animation->addJump(XML::getProperty(
- frameNode, "action", ""), rand);
- }
- else if (xmlNameEqual(frameNode, "label"))
- {
- const std::string name = XML::getProperty(frameNode, "name", "");
- if (!name.empty())
- animation->addLabel(name);
- }
- else if (xmlNameEqual(frameNode, "goto"))
- {
- const std::string name = XML::getProperty(frameNode, "label", "");
- if (!name.empty())
- animation->addGoto(name, rand);
- }
- } // for frameNode
-}
-
-void SpriteDef::includeSprite(XmlNodeConstPtr includeNode, const int variant)
-{
- std::string filename = XML::getProperty(includeNode, "file", "");
-
- if (filename.empty())
- return;
- filename = pathJoin(paths.getStringValue("sprites"), filename);
-
- if (mProcessedFiles.find(filename) != mProcessedFiles.end())
- {
- reportAlways("%s: Tried to include %s which already is included.",
- mSource.c_str(),
- filename.c_str());
- return;
- }
- mProcessedFiles.insert(filename);
-
- XML::Document *const doc = Loader::getXml(filename,
- UseVirtFs_true,
- SkipError_false);
- if (doc == nullptr)
- return;
- XmlNodeConstPtr rootNode = doc->rootNode();
-
- if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "sprite"))
- {
- reportAlways("%s: No sprite root node in %s",
- mSource.c_str(),
- filename.c_str());
- doc->decRef();
- return;
- }
-
- loadSprite(rootNode, variant);
- doc->decRef();
-}
-
-SpriteDef::~SpriteDef()
-{
- // Actions are shared, so ensure they are deleted only once.
- std::set<Action*> actions;
- FOR_EACH (Actions::iterator, i, mActions)
- {
- FOR_EACHP (ActionMap::iterator, it, (*i).second)
- actions.insert(it->second);
- delete (*i).second;
- }
-
- FOR_EACH (std::set<Action*>::const_iterator, i, actions)
- delete *i;
-
- mActions.clear();
-
- FOR_EACH (ImageSetIterator, i, mImageSets)
- {
- if (i->second != nullptr)
- {
- i->second->decRef();
- i->second = nullptr;
- }
- }
- mImageSets.clear();
-}
-
-SpriteDirection::Type SpriteDef::makeSpriteDirection(const std::string
- &direction)
-{
- if (direction.empty() || direction == "default")
- return SpriteDirection::DEFAULT;
- else if (direction == "up")
- return SpriteDirection::UP;
- else if (direction == "left")
- return SpriteDirection::LEFT;
- else if (direction == "right")
- return SpriteDirection::RIGHT;
- else if (direction == "down")
- return SpriteDirection::DOWN;
- else if (direction == "upleft")
- return SpriteDirection::UPLEFT;
- else if (direction == "upright")
- return SpriteDirection::UPRIGHT;
- else if (direction == "downleft")
- return SpriteDirection::DOWNLEFT;
- else if (direction == "downright")
- return SpriteDirection::DOWNRIGHT;
- else
- return SpriteDirection::INVALID;
-}
-
-void SpriteDef::addAction(const unsigned hp, const std::string &name,
- Action *const action)
-{
- const Actions::const_iterator i = mActions.find(hp);
- if (i == mActions.end())
- mActions[hp] = new ActionMap;
-
- (*mActions[hp])[name] = action;
-}
-
-bool SpriteDef::addSequence(const int start,
- const int end,
- const int delay,
- const int offsetX,
- const int offsetY,
- const int variant_offset,
- int repeat,
- const int rand,
- const ImageSet *const imageSet,
- Animation *const animation) const
-{
- if ((imageSet == nullptr) || (animation == nullptr))
- return true;
-
- if (start < 0 || end < 0)
- {
- reportAlways("%s: No valid value for 'start' or 'end'",
- mSource.c_str());
- return true;
- }
-
- if (start <= end)
- {
- while (repeat > 0)
- {
- int pos = start;
- while (end >= pos)
- {
- Image *const img = imageSet->get(pos + variant_offset);
-
- if (img == nullptr)
- {
- reportAlways("%s: No image at index %d",
- mSource.c_str(),
- pos + variant_offset);
- pos ++;
- continue;
- }
-
- animation->addFrame(img, delay,
- offsetX, offsetY, rand);
- pos ++;
- }
- repeat --;
- }
- }
- else
- {
- while (repeat > 0)
- {
- int pos = start;
- while (end <= pos)
- {
- Image *const img = imageSet->get(pos + variant_offset);
-
- if (img == nullptr)
- {
- reportAlways("%s: No image at index %d",
- mSource.c_str(),
- pos + variant_offset);
- pos ++;
- continue;
- }
-
- animation->addFrame(img, delay,
- offsetX, offsetY, rand);
- pos --;
- }
- repeat --;
- }
- }
- return false;
-}
-
-int SpriteDef::calcMemoryLocal() const
-{
- int sz = static_cast<int>(sizeof(SpriteDef) +
- sizeof(ImageSets) +
- sizeof(Actions) +
- sizeof(std::set<std::string>)) +
- Resource::calcMemoryLocal();
- FOR_EACH (std::set<std::string>::const_iterator, it, mProcessedFiles)
- {
- sz += static_cast<int>((*it).capacity());
- }
- return sz;
-}
-
-int SpriteDef::calcMemoryChilds(const int level) const
-{
- int sz = 0;
- FOR_EACH (ImageSets::const_iterator, it, mImageSets)
- {
- sz += static_cast<int>((*it).first.capacity());
- const ImageSet *const imageSet = (*it).second;
- sz += imageSet->calcMemory(level + 1);
- }
- FOR_EACH (ActionsCIter, it, mActions)
- {
- sz += sizeof(unsigned);
- const ActionMap *const actionMap = (*it).second;
- FOR_EACHP (ActionMap::const_iterator, it2, actionMap)
- {
- sz += static_cast<int>((*it2).first.capacity());
- const Action *const action = (*it2).second;
- sz += action->calcMemory(level + 1);
- }
- }
- return sz;
-}
diff --git a/src/resources/sprite/spritedef.h b/src/resources/sprite/spritedef.h
deleted file mode 100644
index fcb019d31..000000000
--- a/src/resources/sprite/spritedef.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_SPRITEDEF_H
-#define RESOURCES_SPRITE_SPRITEDEF_H
-
-#include "enums/resources/spritedirection.h"
-
-#include "utils/xml.h"
-
-#include <map>
-#include <set>
-
-class Action;
-class Animation;
-class ImageSet;
-
-/**
- * Defines a class to load an animation.
- */
-class SpriteDef final : public Resource
-{
- public:
- A_DELETE_COPY(SpriteDef)
-
- /**
- * Loads a sprite definition file.
- */
- static SpriteDef *load(const std::string &file,
- const int variant,
- const bool prot) A_WARN_UNUSED;
-
- /**
- * Returns the specified action.
- */
- const Action *getAction(const std::string &action,
- const unsigned num) const A_WARN_UNUSED;
-
- unsigned findNumber(const unsigned num) const A_WARN_UNUSED;
-
- /**
- * Converts a string into a SpriteDirection enum.
- */
- static SpriteDirection::Type
- makeSpriteDirection(const std::string &direction) A_WARN_UNUSED;
-
- void addAction(const unsigned hp, const std::string &name,
- Action *const action);
-
- int calcMemoryLocal() const override final;
-
- int calcMemoryChilds(const int level) const override final;
-
- bool addSequence(const int start,
- const int end,
- const int delay,
- const int offsetX,
- const int offsetY,
- const int variant_offset,
- int repeat,
- const int rand,
- const ImageSet *const imageSet,
- Animation *const animation) const;
-
- private:
- /**
- * Constructor.
- */
- SpriteDef() :
- Resource(),
- mImageSets(),
- mActions(),
- mProcessedFiles()
- { }
-
- /**
- * Destructor.
- */
- ~SpriteDef();
-
- /**
- * Loads a sprite element.
- */
- void loadSprite(XmlNodeConstPtr spriteNode,
- const int variant,
- const std::string &palettes = "");
-
- /**
- * Loads an imageset element.
- */
- void loadImageSet(XmlNodeConstPtr node,
- const std::string &palettes);
-
- /**
- * Loads an action element.
- */
- void loadAction(XmlNodeConstPtr node,
- const int variant_offset);
-
- /**
- * Loads an animation element.
- */
- void loadAnimation(XmlNodeConstPtr animationNode,
- Action *const action,
- const ImageSet *const imageSet,
- const int variant_offset) const;
-
- /**
- * Include another sprite into this one.
- */
- void includeSprite(XmlNodeConstPtr includeNode,
- const int variant);
-
- const ImageSet *getImageSet(const std::string &imageSetName) const;
-
- /**
- * Complete missing actions by copying existing ones.
- */
- void substituteActions();
-
- /**
- * Fix bad timeout in last dead action frame
- */
- void fixDeadAction();
-
- /**
- * When there are no animations defined for the action "complete", its
- * animations become a copy of those of the action "with".
- */
- void substituteAction(const std::string &restrict complete,
- const std::string &restrict with);
-
- typedef std::map<std::string, ImageSet*> ImageSets;
- typedef ImageSets::iterator ImageSetIterator;
- typedef ImageSets::const_iterator ImageSetCIterator;
- typedef std::map<std::string, Action*> ActionMap;
- typedef std::map<unsigned, ActionMap*> Actions;
- typedef Actions::const_iterator ActionsConstIter;
- typedef Actions::iterator ActionsIter;
- typedef Actions::const_iterator ActionsCIter;
-
- ImageSets mImageSets;
- Actions mActions;
- std::set<std::string> mProcessedFiles;
-};
-
-#endif // RESOURCES_SPRITE_SPRITEDEF_H
diff --git a/src/resources/sprite/spritedisplay.h b/src/resources/sprite/spritedisplay.h
deleted file mode 100644
index cabae7267..000000000
--- a/src/resources/sprite/spritedisplay.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_SPRITEDISPLAY_H
-#define RESOURCES_SPRITE_SPRITEDISPLAY_H
-
-#include "utils/stringvector.h"
-
-#include "localconsts.h"
-
-struct SpriteReference;
-
-struct SpriteDisplay final
-{
- SpriteDisplay() :
- image(),
- floor(),
- sprites(),
- particles()
- {
- }
-
- A_DEFAULT_COPY(SpriteDisplay)
-
- std::string image;
- std::string floor;
- STD_VECTOR<SpriteReference*> sprites;
- StringVect particles;
-};
-
-#endif // RESOURCES_SPRITE_SPRITEDISPLAY_H
diff --git a/src/resources/sprite/spritereference.h b/src/resources/sprite/spritereference.h
deleted file mode 100644
index 8bc38a532..000000000
--- a/src/resources/sprite/spritereference.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RESOURCES_SPRITE_SPRITEREFERENCE_H
-#define RESOURCES_SPRITE_SPRITEREFERENCE_H
-
-#include "utils/stringvector.h"
-
-#include "localconsts.h"
-
-struct SpriteReference final
-{
- static SpriteReference *Empty;
-
- SpriteReference() :
- sprite(),
- variant(0)
- {}
-
- SpriteReference(const std::string &sprite0, const int variant0) :
- sprite(sprite0),
- variant(variant0)
- {
- }
-
- A_DELETE_COPY(SpriteReference)
-
- std::string sprite;
- int variant;
-};
-
-typedef STD_VECTOR<SpriteReference*>::const_iterator SpriteRefs;
-
-#endif // RESOURCES_SPRITE_SPRITEREFERENCE_H