summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.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/resources/resourcemanager.cpp
parent12002b81544038bc5855189c74aca761d0c08f1b (diff)
downloadmanaverse-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.gz
manaverse-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.bz2
manaverse-aa68511ad3d339be8c8f42fc6c083b696d8e687b.tar.xz
manaverse-aa68511ad3d339be8c8f42fc6c083b696d8e687b.zip
Add delayed images load.
Can work for now only in OpenGL modes.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp69
1 files changed, 66 insertions, 3 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 37975cf16..16214661c 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -22,6 +22,7 @@
#include "resources/resourcemanager.h"
+#include "animationdelayload.h"
#include "client.h"
#include "configuration.h"
#include "logger.h"
@@ -52,6 +53,7 @@
#include "debug.h"
ResourceManager *ResourceManager::instance = nullptr;
+DelayedAnim ResourceManager::mDelayedAnimations;
ResourceManager::ResourceManager() :
mOldestOrphan(0),
@@ -354,8 +356,15 @@ bool ResourceManager::addResource(const std::string &idPath,
return false;
}
-Resource *ResourceManager::get(const std::string &idPath, generator fun,
- void *data)
+Resource *ResourceManager::getFromCache(const std::string &filename,
+ int variant)
+{
+ std::stringstream ss;
+ ss << filename << "[" << variant << "]";
+ return getFromCache(ss.str());
+}
+
+Resource *ResourceManager::getFromCache(const std::string &idPath)
{
// Check if the id exists, and return the value if it does.
ResourceIterator resIter = mResources.find(idPath);
@@ -376,8 +385,17 @@ Resource *ResourceManager::get(const std::string &idPath, generator fun,
res->incRef();
return res;
}
+ return nullptr;
+}
- Resource *resource = fun(data);
+Resource *ResourceManager::get(const std::string &idPath, generator fun,
+ void *data)
+{
+ Resource *resource = getFromCache(idPath);
+ if (resource)
+ return resource;
+
+ resource = fun(data);
if (resource)
{
@@ -745,3 +763,48 @@ Image *ResourceManager::getRescaled(Image *image, int width, int height)
Image *img = static_cast<Image*>(get(idPath, RescaledLoader::load, &rl));
return img;
}
+
+void ResourceManager::delayedLoad()
+{
+ static int loadTime = 0;
+ if (loadTime < cur_time)
+ {
+// loadTime = tick_time + 10;
+ loadTime = tick_time;
+
+ int k = 0;
+ DelayedAnimIter it = mDelayedAnimations.begin();
+ DelayedAnimIter it_end = mDelayedAnimations.end();
+ while (it != it_end && k < 1)
+ {
+ (*it)->load();
+ AnimationDelayLoad *tmp = *it;
+ it = mDelayedAnimations.erase(it);
+ delete tmp;
+ k ++;
+ }
+ const int time2 = tick_time;
+// if (time2 != loadTime)
+// {
+// logger->log("diff %d", time2 - loadTime);
+// }
+ if (time2 > loadTime)
+ loadTime = time2 + (time2 - loadTime) * 2 + 10;
+// loadTime += 10 - time2;
+ else
+ loadTime = time2 + 3;
+ }
+}
+
+void ResourceManager::removeDelayLoad(AnimationDelayLoad *delayedLoad)
+{
+ for(DelayedAnimIter it = mDelayedAnimations.begin(),
+ it_end = mDelayedAnimations.end(); it != it_end; ++ it)
+ {
+ if (*it == delayedLoad)
+ {
+ mDelayedAnimations.erase(it);
+ return;
+ }
+ }
+}