if(!managed.collection)
throw runtime_error("no location");
- if(managed.loader)
+ if(managed.state!=ManagedResource::NOT_LOADED)
return;
- managed.start_loading();
-
if(async_loads)
+ {
+ managed.state = ManagedResource::LOAD_QUEUED;
queue.push_back(&managed);
+ }
else
{
+ managed.start_loading();
while(!managed.loader->process()) ;
managed.finish_loading();
}
void ResourceManager::resource_used(const Resource &r)
{
ManagedResource *managed = reinterpret_cast<ManagedResource *>(r.get_manager_data());
- if(!managed->loaded && !managed->loader && policy!=LOAD_MANUALLY)
+ if(managed->state==ManagedResource::NOT_LOADED && policy!=LOAD_MANUALLY)
load_resource(*managed->resource);
managed->last_used = frame;
next_unload = 0;
for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
- if(i->second.loaded)
+ if(i->second.state==ManagedResource::LOADED)
{
if(i->second.last_used<=unload_limit)
i->second.unload();
ManagedResource *best = 0;
UInt64 best_impact = 0;
for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
- if(i->second.loaded && i->second.last_used<unload_limit)
+ if(i->second.state==ManagedResource::LOADED && i->second.last_used<unload_limit)
{
UInt64 impact = i->second.data_size*(frame-i->second.last_used);
if(!best || impact>best_impact)
{
UInt64 total = 0;
for(ResourceMap::const_iterator i=resources.begin(); i!=resources.end(); ++i)
- if(i->second.loaded)
+ if(i->second.state==ManagedResource::LOADED)
total += i->second.data_size;
return total;
}
collection(0),
io(0),
loader(0),
- loaded(false),
+ state(NOT_LOADED),
last_used(0),
data_size(0)
{ }
io = 0;
throw logic_error("no loader created");
}
+ state = LOADING;
}
void ResourceManager::ManagedResource::finish_loading()
{
delete loader;
loader = 0;
- loaded = true;
+ state = LOADED;
delete io;
io = 0;
data_size = resource->get_data_size();
void ResourceManager::ManagedResource::unload()
{
resource->unload();
- loaded = false;
+ state = NOT_LOADED;
for(vector<ResourceWatcher *>::const_iterator i=watchers.begin(); i!=watchers.end(); ++i)
(*i)->resource_unloaded(*resource);
}
resource = r;
+ resource->start_loading();
state = BUSY;
sem.signal();
}