]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resourcemanager.h
Use an explicit material slot name in RenderPass
[libs/gl.git] / source / resourcemanager.h
index a2a4975db5185eaf3eadf7348e995f9a0b4ca5b7..afa2c2d073e45b32b25332a91a3be9c7c8568461 100644 (file)
@@ -16,6 +16,7 @@ class ResourceWatcher;
 class resource_load_error: public std::runtime_error
 {
 public:
+       resource_load_error(const std::string &, const std::string &);
        resource_load_error(const std::string &, const std::exception &);
        virtual ~resource_load_error() throw() { }
 };
@@ -31,6 +32,15 @@ public:
                LOAD_MANUALLY
        };
 
+       struct ResourceLocation
+       {
+               DataFile::Collection *collection;
+               std::string name;
+
+               ResourceLocation();
+               ResourceLocation(DataFile::Collection &, const std::string &);
+       };
+
 private:
        struct ManagedResource
        {
@@ -45,8 +55,8 @@ private:
                };
 
                Resource *resource;
-               DataFile::Collection *collection;
-               std::string name;
+               ResourceLocation location;
+               bool load_priority;
                IO::Seekable *io;
                Resource::AsyncLoader *loader;
                State state;
@@ -78,6 +88,8 @@ private:
                unsigned capacity;
                unsigned size;
                std::list<resource_load_error> error_queue;
+               Mutex data_size_mutex;
+               UInt64 loaded_data_size;
                volatile bool done;
 
        public:
@@ -96,6 +108,7 @@ private:
        public:
                bool sync();
                bool needs_work() const { return size<capacity; }
+               UInt64 get_and_reset_loaded_data_size();
 
                void terminate();
        };
@@ -104,8 +117,10 @@ private:
 
        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;
@@ -124,9 +139,16 @@ public:
        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 load_resource(Resource &);
+       bool is_resource_loaded(const Resource &) const;
        void resource_used(const Resource &);
        void remove_resource(Resource &);
 
@@ -139,7 +161,7 @@ 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 *);