+
+ if(check_total_size)
+ {
+ while(get_total_data_size()>size_limit)
+ {
+ unsigned unload_limit = frame-min_retain_frames;
+ 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)
+ {
+ UInt64 impact = i->second.data_size*(frame-i->second.last_used);
+ if(!best || impact<best_impact)
+ {
+ best = &i->second;
+ best_impact = impact;
+ }
+ }
+
+ if(!best)
+ break;
+
+ best->unload();
+ }
+ }
+}
+
+UInt64 ResourceManager::get_total_data_size() const
+{
+ UInt64 total = 0;
+ for(ResourceMap::const_iterator i=resources.begin(); i!=resources.end(); ++i)
+ if(i->second.loaded)
+ total += i->second.data_size;
+ return total;