]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/material.h
Rearrange type specification in material datafiles
[libs/gl.git] / source / materials / material.h
index 2f8f38ab7ce183c40492b3d75f2b11c2904939a6..278fc4dc0ee8ba7da8ce27fcd392d5c4bf0c2b46 100644 (file)
@@ -62,31 +62,32 @@ public:
        {
        private:
                template<typename T>
-               struct AddType
+               struct CreateMaterial
                {
-                       void operator()(const std::string &kw, GenericLoader &ldr) const { ldr.add(kw, &GenericLoader::typed_material<T>); }
+                       void operator()(const std::string &, GenericLoader &) const;
                };
 
                DataFile::Collection *coll;
-               RefPtr<Material> material;
+               Material *material;
+               Loader *mat_loader;
 
                static ActionMap shared_actions;
 
        public:
                GenericLoader(DataFile::Collection * = 0);
+               ~GenericLoader();
 
-               Material *get_material() { return material.release(); }
+               Material *get_material() { Material *m = material; material = 0; return m; }
        private:
                virtual void init_actions();
 
-               template<typename T>
-               void typed_material();
+               void type(const DataFile::Symbol &);
 
                friend class Material;
        };
 
 private:
-       typedef TypeRegistry<GenericLoader::AddType, GenericLoader &> MaterialRegistry;
+       typedef TypeRegistry<GenericLoader::CreateMaterial, GenericLoader &> MaterialRegistry;
 
 protected:
        const Sampler *sampler;
@@ -194,16 +195,18 @@ void Material::PropertyLoader<C>::property_texture(void (C::*set_texture)(const
 
 
 template<typename T>
-void Material::GenericLoader::typed_material()
+void Material::GenericLoader::CreateMaterial<T>::operator()(const std::string &, GenericLoader &ldr) const
 {
-       if(material)
-               throw std::logic_error("Material was already loaded");
-       RefPtr<T> mat = new T;
-       if(coll)
-               load_sub(*mat, *coll);
+       if(ldr.material)
+               throw std::logic_error("Material type was already specified");
+
+       T *mat = new T;
+       ldr.material = mat;
+       if(ldr.coll)
+               ldr.mat_loader = new typename T::Loader(*mat, *ldr.coll);
        else
-               load_sub(*mat);
-       material = mat;
+               ldr.mat_loader = new typename T::Loader(*mat);
+       ldr.add_auxiliary_loader(*ldr.mat_loader);
 }
 
 } // namespace GL