}
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)
}
+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),
void ResourceManager::ManagedResource::start_loading()
{
- io = collection->open_raw(name);
+ io = location.collection->open_raw(location.name);
loader = resource->load(*io);
if(!loader)
{
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;
}
LOAD_MANUALLY
};
+ struct ResourceLocation
+ {
+ DataFile::Collection *collection;
+ std::string name;
+
+ ResourceLocation();
+ ResourceLocation(DataFile::Collection &, const std::string &);
+ };
+
private:
struct ManagedResource
{
};
Resource *resource;
- DataFile::Collection *collection;
- std::string name;
+ ResourceLocation location;
IO::Seekable *io;
Resource::AsyncLoader *loader;
State state;
void add_resource(Resource &);
void *get_data_for_resource(const Resource &);
void set_resource_location(Resource &, DataFile::Collection &, const std::string &);
+ void set_resource_location(Resource &, const ResourceLocation &);
+ const ResourceLocation *get_resource_location(const Resource &) const;
void load_resource(Resource &);
bool is_resource_loaded(const Resource &);
void resource_used(const Resource &);