]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resourcemanager.h
Rework ProgramData to do less unnecessary work
[libs/gl.git] / source / resourcemanager.h
index 1e3cb54f3b439c72fe26811ccd546d6993743327..f5ccac3bbf9a212eefe8611a865bb25a059737b2 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_RESOURCEMANAGER_H_
 #define MSP_GL_RESOURCEMANAGER_H_
 
+#include <msp/core/inttypes.h>
 #include <msp/core/mutex.h>
 #include <msp/core/semaphore.h>
 #include <msp/core/thread.h>
@@ -10,6 +11,8 @@
 namespace Msp {
 namespace GL {
 
+class ResourceWatcher;
+
 class ResourceManager
 {
 public:
@@ -29,11 +32,18 @@ private:
                IO::Seekable *io;
                Resource::AsyncLoader *loader;
                bool loaded;
+               unsigned last_used;
+               UInt64 data_size;
+               std::vector<ResourceWatcher *> watchers;
 
                ManagedResource(Resource &);
 
                void start_loading();
                void finish_loading();
+               void unload();
+
+               void add_watcher(ResourceWatcher &);
+               void remove_watcher(ResourceWatcher &);
        };
 
        class LoadingThread: public Thread
@@ -76,6 +86,11 @@ private:
        bool async_loads;
        ResourceMap resources;
        LoadQueue queue;
+       UInt64 size_limit;
+       unsigned frame;
+       unsigned min_retain_frames;
+       unsigned max_retain_frames;
+       unsigned next_unload;
        LoadingThread thread;
 
 public:
@@ -84,6 +99,9 @@ public:
 
        void set_loading_policy(LoadingPolicy);
        void set_async_loads(bool);
+       void set_size_limit(UInt64);
+       void set_min_retain_frames(unsigned);
+       void set_max_retain_frames(unsigned);
 
        void add_resource(Resource &);
        void *get_data_for_resource(const Resource &);
@@ -92,7 +110,11 @@ public:
        void resource_used(const Resource &);
        void remove_resource(Resource &);
 
+       void watch_resource(const Resource &, ResourceWatcher &);
+       void unwatch_resource(const Resource &, ResourceWatcher &);
+
        void tick();
+       UInt64 get_total_data_size() const;
 };
 
 } // namespace GL