aboutsummaryrefslogtreecommitdiff
path: root/src/AsyncImageLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AsyncImageLoader.cpp')
-rw-r--r--src/AsyncImageLoader.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index 947f637..1769846 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -7,6 +7,7 @@
#include "../external/hash-library/sha256.h"
#include <sys/stat.h>
+#include <malloc.h>
#include <assert.h>
namespace QuickMedia {
@@ -212,6 +213,32 @@ namespace QuickMedia {
});
}
+ std::shared_ptr<ThumbnailData> AsyncImageLoader::get_thumbnail(const std::string &url, bool local, sf::Vector2i resize_target_size) {
+ // TODO: Instead of generating a new hash everytime to access thumbnail, cache the hash of the thumbnail url
+ auto &thumbnail_data = thumbnails[url];
+ if(!thumbnail_data)
+ thumbnail_data = std::make_shared<ThumbnailData>();
+ thumbnail_data->counter = counter;
+ load_thumbnail(url, local, resize_target_size, thumbnail_data);
+ return thumbnail_data;
+ }
+
+ void AsyncImageLoader::update() {
+ bool loaded_textures_changed = false;
+ for(auto it = thumbnails.begin(); it != thumbnails.end();) {
+ if(it->second->counter != counter) {
+ it = thumbnails.erase(it);
+ loaded_textures_changed = true;
+ } else {
+ ++it;
+ }
+ }
+
+ ++counter;
+ if(loaded_textures_changed)
+ malloc_trim(0);
+ }
+
int AsyncImageLoader::get_free_load_index() const {
for(int i = 0; i < NUM_IMAGE_LOAD_THREADS; ++i) {
if(!loading_image[i])
@@ -219,4 +246,4 @@ namespace QuickMedia {
}
return -1;
}
-} \ No newline at end of file
+}