namespace Msp {
namespace GL {
-class ResourceWatcher;
+class ResourceObserver;
class resource_load_error: public std::runtime_error
{
State state;
unsigned last_used;
UInt64 data_size;
- std::vector<ResourceWatcher *> watchers;
+ std::vector<ResourceObserver *> observers;
ManagedResource(Resource &);
void finish_loading();
void unload();
- void add_watcher(ResourceWatcher &);
- void remove_watcher(ResourceWatcher &);
+ void add_observer(ResourceObserver &);
+ void remove_observer(ResourceObserver &);
};
typedef std::list<ManagedResource *> LoadQueue;
unsigned capacity;
unsigned size;
std::list<resource_load_error> error_queue;
+ Mutex data_size_mutex;
+ UInt64 loaded_data_size;
volatile bool done;
public:
public:
bool sync();
bool needs_work() const { return size<capacity; }
+ UInt64 get_and_reset_loaded_data_size();
void terminate();
};
LoadingPolicy policy;
bool async_loads;
+ mutable Mutex map_mutex;
ResourceMap resources;
LoadQueue queue;
+ UInt64 total_data_size;
UInt64 size_limit;
unsigned frame;
unsigned min_retain_frames;
void set_max_retain_frames(unsigned);
void add_resource(Resource &);
- void *get_data_for_resource(const Resource &);
+private:
+ const ManagedResource &get_managed_resource(const Resource &) const;
+ ManagedResource &get_managed_resource(const Resource &);
+public:
+ void *get_data_for_resource(const Resource &r) { return &get_managed_resource(r); }
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 resource_used(const Resource &);
void remove_resource(Resource &);
- void watch_resource(const Resource &, ResourceWatcher &);
- void unwatch_resource(const Resource &, ResourceWatcher &);
+ void observe_resource(const Resource &, ResourceObserver &);
+ void unobserve_resource(const Resource &, ResourceObserver &);
void tick();
private:
void unload_by_age();
void unload_by_size();
public:
- UInt64 get_total_data_size() const;
+ UInt64 get_total_data_size() const { return total_data_size; }
private:
static bool age_order(ManagedResource *, ManagedResource *);