summaryrefslogtreecommitdiff
path: root/src/animatedsprite.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-06-20 00:34:39 +0300
committerAndrei Karas <akaras@inbox.ru>2012-06-21 00:59:10 +0300
commitaa68511ad3d339be8c8f42fc6c083b696d8e687b (patch)
tree1bf138439c28b4a879c6b35e4361801bd5e1d246 /src/animatedsprite.cpp
parent12002b81544038bc5855189c74aca761d0c08f1b (diff)
downloadmanaplus-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.gz
manaplus-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.bz2
manaplus-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.xz
manaplus-aa68511ad3d339be8c8f42fc6c083b696d8e687b.zip
Add delayed images load.
Can work for now only in OpenGL modes.
Diffstat (limited to 'src/animatedsprite.cpp')
-rw-r--r--src/animatedsprite.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 1dc5b16c8..77ec69126 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -22,6 +22,7 @@
#include "animatedsprite.h"
+#include "animationdelayload.h"
#include "graphics.h"
#include "logger.h"
@@ -34,6 +35,8 @@
#include "debug.h"
+bool AnimatedSprite::mEnableCache = false;
+
AnimatedSprite::AnimatedSprite(SpriteDef *sprite):
mDirection(DIRECTION_DOWN),
mLastTime(0),
@@ -44,7 +47,8 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite):
mAnimation(nullptr),
mFrame(nullptr),
mNumber(100),
- mNumber1(100)
+ mNumber1(100),
+ mDelayLoad(nullptr)
{
mAlpha = 1.0f;
@@ -67,6 +71,20 @@ AnimatedSprite *AnimatedSprite::load(const std::string &filename, int variant)
return as;
}
+AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &filename,
+ int variant)
+{
+ if (!mEnableCache)
+ return load(filename, variant);
+ ResourceManager *resman = ResourceManager::getInstance();
+ if (resman->getFromCache(filename, variant))
+ return load(filename, variant);
+
+ AnimatedSprite *as = new AnimatedSprite(nullptr);
+ as->setDelayLoad(filename, variant);
+ return as;
+}
+
AnimatedSprite::~AnimatedSprite()
{
if (mSprite)
@@ -74,6 +92,13 @@ AnimatedSprite::~AnimatedSprite()
mSprite->decRef();
mSprite = nullptr;
}
+ if (mDelayLoad)
+ {
+ mDelayLoad->clearSprite();
+ ResourceManager::removeDelayLoad(mDelayLoad);
+ delete mDelayLoad;
+ mDelayLoad = nullptr;
+ }
}
bool AnimatedSprite::reset()
@@ -94,7 +119,12 @@ bool AnimatedSprite::reset()
bool AnimatedSprite::play(std::string spriteAction)
{
if (!mSprite)
- return false;
+ {
+ if (!mDelayLoad)
+ return false;
+ mDelayLoad->setAction(spriteAction);
+ return true;
+ }
Action *action = mSprite->getAction(spriteAction, mNumber);
if (!action)
@@ -343,3 +373,21 @@ bool AnimatedSprite::updateNumber(unsigned num)
}
return false;
}
+
+void AnimatedSprite::setDelayLoad(const std::string &filename,
+ int variant)
+{
+ if (mDelayLoad)
+ {
+ mDelayLoad->clearSprite();
+ ResourceManager::removeDelayLoad(mDelayLoad);
+ delete mDelayLoad;
+ }
+ mDelayLoad = new AnimationDelayLoad(filename, variant, this);
+ ResourceManager::addDelayedAnimation(mDelayLoad);
+}
+
+void AnimatedSprite::clearDelayLoad()
+{
+ mDelayLoad = nullptr;
+}