]> git.tdb.fi Git - libs/gl.git/commitdiff
Add methods to query the state of a resource
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Dec 2014 16:15:24 +0000 (18:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Dec 2014 16:15:24 +0000 (18:15 +0200)
source/resource.cpp
source/resource.h
source/resourcemanager.cpp
source/resourcemanager.h

index e63341c8517296e1083d25a5daa9ab28c705f587..4be6ee26bcef7d6bafa241a42fdf0bf00dde1fe4 100644 (file)
@@ -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
index 0ecba526ef956e7da5e701d67df007dba13989c2..8d34c357fe6b93ba85862fd1df50b1620066a8ca 100644 (file)
@@ -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;
 };
index c6e3f357b9ce67b6f72fef04f30b5ff5e96483ab..6461c33620eb3aa386418afadad48cab8f6a51d6 100644 (file)
@@ -101,6 +101,12 @@ void ResourceManager::load_resource(Resource &r)
        }
 }
 
+bool ResourceManager::is_resource_loaded(const Resource &r)
+{
+       ManagedResource *managed = reinterpret_cast<ManagedResource *>(r.get_manager_data());
+       return managed ? managed->state==ManagedResource::LOADED : false;
+}
+
 void ResourceManager::resource_used(const Resource &r)
 {
        ManagedResource *managed = reinterpret_cast<ManagedResource *>(r.get_manager_data());
index a2a4975db5185eaf3eadf7348e995f9a0b4ca5b7..e83a61328e590c528d1c05f7157dea0d523e995d 100644 (file)
@@ -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 &);