1 #ifndef MSP_GL_RESOURCEMANAGER_H_
2 #define MSP_GL_RESOURCEMANAGER_H_
4 #include <msp/core/inttypes.h>
5 #include <msp/core/mutex.h>
6 #include <msp/core/semaphore.h>
7 #include <msp/core/thread.h>
8 #include <msp/datafile/collection.h>
14 class ResourceWatcher;
27 struct ManagedResource
38 DataFile::Collection *collection;
41 Resource::AsyncLoader *loader;
45 std::vector<ResourceWatcher *> watchers;
47 ManagedResource(Resource &);
50 void finish_loading();
53 void add_watcher(ResourceWatcher &);
54 void remove_watcher(ResourceWatcher &);
57 class LoadingThread: public Thread
70 ResourceManager &manager;
72 ManagedResource *volatile resource;
76 LoadingThread(ResourceManager &);
82 void set_resource(ManagedResource *);
83 ManagedResource *get_resource() const { return resource; }
85 State get_state() const { return state; }
90 typedef std::map<const Resource *, ManagedResource> ResourceMap;
91 typedef std::list<ManagedResource *> LoadQueue;
95 ResourceMap resources;
99 unsigned min_retain_frames;
100 unsigned max_retain_frames;
101 unsigned next_unload;
102 LoadingThread thread;
108 void set_loading_policy(LoadingPolicy);
109 void set_async_loads(bool);
110 void set_size_limit(UInt64);
111 void set_min_retain_frames(unsigned);
112 void set_max_retain_frames(unsigned);
114 void add_resource(Resource &);
115 void *get_data_for_resource(const Resource &);
116 void set_resource_location(Resource &, DataFile::Collection &, const std::string &);
117 void load_resource(Resource &);
118 void resource_used(const Resource &);
119 void remove_resource(Resource &);
121 void watch_resource(const Resource &, ResourceWatcher &);
122 void unwatch_resource(const Resource &, ResourceWatcher &);
125 UInt64 get_total_data_size() const;