]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resourcemanager.cpp
Make resource locations externally accessible
[libs/gl.git] / source / resourcemanager.cpp
index 6461c33620eb3aa386418afadad48cab8f6a51d6..40dcff9bc36876b649edaec7c0aeecca0aee45c1 100644 (file)
@@ -70,19 +70,29 @@ void *ResourceManager::get_data_for_resource(const Resource &r)
 }
 
 void ResourceManager::set_resource_location(Resource &r, DataFile::Collection &c, const string &n)
+{
+       set_resource_location(r, ResourceLocation(c, n));
+}
+
+void ResourceManager::set_resource_location(Resource &r, const ResourceLocation &l)
 {
        ManagedResource &managed = get_item(resources, &r);
-       managed.collection = &c;
-       managed.name = n;
+       managed.location = l;
 
        if(policy==LOAD_IMMEDIATELY)
                load_resource(r);
 }
 
+const ResourceManager::ResourceLocation *ResourceManager::get_resource_location(const Resource &r) const
+{
+       const ManagedResource &managed = get_item(resources, &r);
+       return managed.location.collection ? &managed.location : 0;
+}
+
 void ResourceManager::load_resource(Resource &r)
 {
        ManagedResource &managed = get_item(resources, &r);
-       if(!managed.collection)
+       if(!managed.location.collection)
                throw runtime_error("no location");
 
        if(managed.state!=ManagedResource::NOT_LOADED)
@@ -242,9 +252,18 @@ bool ResourceManager::age_order(ManagedResource *mr1, ManagedResource *mr2)
 }
 
 
+ResourceManager::ResourceLocation::ResourceLocation():
+       collection(0)
+{ }
+
+ResourceManager::ResourceLocation::ResourceLocation(DataFile::Collection &c, const string &n):
+       collection(&c),
+       name(n)
+{ }
+
+
 ResourceManager::ManagedResource::ManagedResource(Resource &r):
        resource(&r),
-       collection(0),
        io(0),
        loader(0),
        state(NOT_LOADED),
@@ -254,7 +273,7 @@ ResourceManager::ManagedResource::ManagedResource(Resource &r):
 
 void ResourceManager::ManagedResource::start_loading()
 {
-       io = collection->open_raw(name);
+       io = location.collection->open_raw(location.name);
        loader = resource->load(*io);
        if(!loader)
        {
@@ -350,7 +369,7 @@ void ResourceManager::LoadingThread::main()
                        catch(const exception &e)
                        {
                                MutexLock lock(queue_mutex);
-                               error_queue.push_back(resource_load_error(managed->name, e));
+                               error_queue.push_back(resource_load_error(managed->location.name, e));
                                managed->state = ManagedResource::LOAD_ERROR;
                        }