From f17d748c753f0ffa03d53369cc7aaf3288a5c1e7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Dec 2014 18:15:24 +0200 Subject: [PATCH] Add methods to query the state of a resource --- source/resource.cpp | 5 +++++ source/resource.h | 1 + source/resourcemanager.cpp | 6 ++++++ source/resourcemanager.h | 1 + 4 files changed, 13 insertions(+) diff --git a/source/resource.cpp b/source/resource.cpp index e63341c8..4be6ee26 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -28,5 +28,10 @@ void Resource::set_manager(ResourceManager *m) manager_data = 0; } +bool Resource::is_loaded() const +{ + return manager ? manager->is_resource_loaded(*this) : true; +} + } // namespace GL } // namespace Msp diff --git a/source/resource.h b/source/resource.h index 0ecba526..8d34c357 100644 --- a/source/resource.h +++ b/source/resource.h @@ -35,6 +35,7 @@ public: ResourceManager *get_manager() const { return manager; } void *get_manager_data() const { return manager_data; } virtual AsyncLoader *load(IO::Seekable &) = 0; + virtual bool is_loaded() const; virtual UInt64 get_data_size() const = 0; virtual void unload() = 0; }; diff --git a/source/resourcemanager.cpp b/source/resourcemanager.cpp index c6e3f357..6461c336 100644 --- a/source/resourcemanager.cpp +++ b/source/resourcemanager.cpp @@ -101,6 +101,12 @@ void ResourceManager::load_resource(Resource &r) } } +bool ResourceManager::is_resource_loaded(const Resource &r) +{ + ManagedResource *managed = reinterpret_cast(r.get_manager_data()); + return managed ? managed->state==ManagedResource::LOADED : false; +} + void ResourceManager::resource_used(const Resource &r) { ManagedResource *managed = reinterpret_cast(r.get_manager_data()); diff --git a/source/resourcemanager.h b/source/resourcemanager.h index a2a4975d..e83a6132 100644 --- a/source/resourcemanager.h +++ b/source/resourcemanager.h @@ -127,6 +127,7 @@ public: void *get_data_for_resource(const Resource &); void set_resource_location(Resource &, DataFile::Collection &, const std::string &); void load_resource(Resource &); + bool is_resource_loaded(const Resource &); void resource_used(const Resource &); void remove_resource(Resource &); -- 2.45.2