From: Mikko Rasa Date: Wed, 10 Dec 2014 16:15:24 +0000 (+0200) Subject: Add methods to query the state of a resource X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f17d748c753f0ffa03d53369cc7aaf3288a5c1e7;p=libs%2Fgl.git Add methods to query the state of a resource --- 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 &);