Remove collection-less constructor overloads from most loaders
authorMikko Rasa <tdb@tdb.fi>
Tue, 5 Oct 2021 10:18:52 +0000 (13:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 5 Oct 2021 10:27:59 +0000 (13:27 +0300)
These classes are extremely likely to require references to other
objects, and requiring a collection makes the code more straightforward.

20 files changed:
source/builders/font.cpp
source/builders/font.h
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/materials/basicmaterial.cpp
source/materials/basicmaterial.h
source/materials/lighting.cpp
source/materials/lighting.h
source/materials/material.cpp
source/materials/material.h
source/materials/pbrmaterial.cpp
source/materials/pbrmaterial.h
source/materials/rendermethod.cpp
source/materials/rendermethod.h
source/materials/technique.cpp
source/materials/technique.h
source/materials/unlitmaterial.cpp
source/materials/unlitmaterial.h
source/render/object.cpp
source/render/object.h

index 1ede612a1dec64e9ab2e671a5a9398fc44e8f6dc..4fb643527c83d9ea43058ffb81ead0332a74941e 100644 (file)
@@ -143,8 +143,8 @@ Font::Glyph::Glyph():
 { }
 
 
-Font::Loader::Loader(Font &f, Collection *c):
-       DataFile::CollectionObjectLoader<Font>(f, c)
+Font::Loader::Loader(Font &f, Collection &c):
+       DataFile::CollectionObjectLoader<Font>(f, &c)
 {
        add("native_size", &Font::native_size);
        add("ascent",      &Font::ascent);
index af65da8af9ae15d160482397fccdac70d8429d5d..f46a287092f811a8a6c2b89a73b1aee0eaf97af4 100644 (file)
@@ -21,11 +21,9 @@ public:
        class Loader: public DataFile::CollectionObjectLoader<Font>
        {
        public:
-               Loader(Font &f): Loader(f, 0) { }
-               Loader(Font &f, Collection &c): Loader(f, &c) { }
-       private:
-               Loader(Font &, Collection *);
+               Loader(Font &, Collection &);
 
+       private:
                void glyph(unsigned);
                void kerning(unsigned, unsigned, float);
                void ligature(unsigned, unsigned, unsigned);
index c125823eb8344da53d4013a6137a44f6897b5f46..5d7f4d0b2104caf5474bbd2155677e5bf95c0736 100644 (file)
@@ -123,14 +123,9 @@ void SequenceTemplate::Loader::step_with_slot(const string &tag, const string &r
        Step stp;
        stp.tag = tag;
        stp.slot_name = rend;
-       if(coll)
-       {
-               Step::Loader ldr(stp, *coll);
-               ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
-               load_sub_with(ldr);
-       }
-       else
-               load_sub(stp);
+       Step::Loader ldr(stp, *coll);
+       ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
+       load_sub_with(ldr);
 
        obj.steps.push_back(stp);
 }
@@ -160,8 +155,8 @@ void SequenceTemplate::ClearLoader::stencil(int s)
 }
 
 
-SequenceTemplate::Step::Loader::Loader(Step &p, Collection *c):
-       DataFile::CollectionObjectLoader<Step>(p, c)
+SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
+       DataFile::CollectionObjectLoader<Step>(p, &c)
 {
        add("blend", &Loader::blend);
        add("blend", &Loader::blend_factors);
@@ -202,7 +197,7 @@ void SequenceTemplate::Step::Loader::depth_compare(Predicate c)
 void SequenceTemplate::Step::Loader::lighting_inline()
 {
        RefPtr<Lighting> lightn = new Lighting;
-       load_sub(*lightn);
+       load_sub(*lightn, get_collection());
        get_collection().add(inline_base_name+".lightn", lightn.get());
        obj.lighting = lightn.release();
 }
index bf1e8be185e086efc6b3597139f827630e672536..52c42bb1b18046490ba981cc205da22aac3559ee 100644 (file)
@@ -70,13 +70,8 @@ public:
                        std::string inline_base_name;
 
                public:
-                       Loader(Step &s): Loader(s, 0) { }
-                       Loader(Step &s, Collection &c): Loader(s, &c) { }
-               private:
-                       Loader(Step &, Collection *);
-                       void init();
+                       Loader(Step &, Collection &);
 
-               public:
                        void set_inline_base_name(const std::string &);
 
                private:
index 49a7476489e3f5af42997ee5b0176fd540b50771..3a4b7487ec2fc528fe2cecc54010800a552e3971 100644 (file)
@@ -122,12 +122,6 @@ void BasicMaterial::set_reflectivity_map(const Texture *tex)
 
 DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions;
 
-BasicMaterial::Loader::Loader(BasicMaterial &m):
-       DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m)
-{
-       set_actions(shared_actions);
-}
-
 BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c):
        DerivedObjectLoader<BasicMaterial, Material::PropertyLoader<BasicMaterial> >(m, c)
 {
index a5a8a43f31472c9e9e5f9c4fd320a77cba42e53c..bf1b0e8cdfb1190b114906abe398e4f1376216e4 100644 (file)
@@ -15,7 +15,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(BasicMaterial &);
                Loader(BasicMaterial &, Collection &);
 
        private:
index 113735040ed22ccfa50ea3f71f2448249a857b16..c1b2e2aaf0a02619fb17f9a1e06f456bc27fdd1a 100644 (file)
@@ -99,12 +99,6 @@ void Lighting::set_debug_name(const string &name)
 
 DataFile::Loader::ActionMap Lighting::Loader::shared_actions;
 
-Lighting::Loader::Loader(Lighting &l):
-       CollectionObjectLoader<Lighting>(l, 0)
-{
-       set_actions(shared_actions);
-}
-
 Lighting::Loader::Loader(Lighting &l, Collection &c):
        CollectionObjectLoader<Lighting>(l, &c)
 {
index 9dc93b240c7f0042349a0d0732c6a51251b3a92b..658d7476a794843650188cd6c5ca7a5c7afcc141 100644 (file)
@@ -24,7 +24,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(Lighting &);
                Loader(Lighting &, Collection &);
 
        private:
index b7dd767eaff72dd309f5cb6adc4f4d211cfed4e5..71610c7cd9174957e0bf650f5f50631c2812ddb7 100644 (file)
@@ -69,10 +69,6 @@ Material::MaterialRegistry &Material::get_material_registry()
 }
 
 
-Material::Loader::Loader(Material &m):
-       CollectionObjectLoader(m, 0)
-{ }
-
 Material::Loader::Loader(Material &m, Collection &c):
        CollectionObjectLoader(m, &c)
 { }
@@ -90,20 +86,14 @@ void Material::Loader::sampler(const string &name)
 
 DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
 
-Material::GenericLoader::GenericLoader():
-       coll(0),
+Material::GenericLoader::GenericLoader(DataFile::Collection &c):
+       coll(c),
        material(0),
        mat_loader(0)
 {
        set_actions(shared_actions);
 }
 
-Material::GenericLoader::GenericLoader(DataFile::Collection &c):
-       GenericLoader()
-{
-       coll = &c;
-}
-
 Material::GenericLoader::~GenericLoader()
 {
        delete material;
index 4f8e23ccc972001c892bb6e37a65f9448e3f1c9d..ea02df6b1e00dad8d0dc5275399a55104c5086d5 100644 (file)
@@ -19,7 +19,6 @@ private:
        class Loader: public DataFile::CollectionObjectLoader<Material>
        {
        protected:
-               Loader(Material &);
                Loader(Material &, Collection &);
 
                virtual void init_actions();
@@ -42,7 +41,6 @@ protected:
        class PropertyLoader: public DataFile::DerivedObjectLoader<Material, Loader>
        {
        protected:
-               PropertyLoader(C &m): DerivedObjectLoader<Material, Loader>(m) { }
                PropertyLoader(C &m, Collection &c): DerivedObjectLoader<Material, Loader>(m, c) { }
 
                void add_property(const std::string &, void (C::*)(float), void (C::*)(const Texture *));
@@ -67,14 +65,13 @@ public:
                        void operator()(const std::string &, GenericLoader &) const;
                };
 
-               DataFile::Collection *coll;
+               DataFile::Collection &coll;
                Material *material;
                Loader *mat_loader;
 
                static ActionMap shared_actions;
 
        public:
-               GenericLoader();
                GenericLoader(DataFile::Collection &);
                ~GenericLoader();
 
@@ -200,10 +197,7 @@ void Material::GenericLoader::CreateMaterial<T>::operator()(const std::string &,
 
        T *mat = new T;
        ldr.material = mat;
-       if(ldr.coll)
-               ldr.mat_loader = new typename T::Loader(*mat, *ldr.coll);
-       else
-               ldr.mat_loader = new typename T::Loader(*mat);
+       ldr.mat_loader = new typename T::Loader(*mat, ldr.coll);
        ldr.add_auxiliary_loader(*ldr.mat_loader);
 }
 
index ad36159a6b12c744213d51cfa2605385e8e5d048..ed94bf799f53179e17ad977c782d365272e88edc 100644 (file)
@@ -160,12 +160,6 @@ void PbrMaterial::set_emission_map(const Texture *tex)
 
 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
 
-PbrMaterial::Loader::Loader(PbrMaterial &m):
-       DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
-{
-       set_actions(shared_actions);
-}
-
 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
        DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
 {
index 0204451b63efa0b595f39552e374da2648d819c7..9669bc35a3a1086e117c73cc8aa2e2f4d677d315 100644 (file)
@@ -17,7 +17,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(PbrMaterial &);
                Loader(PbrMaterial &, Collection &);
 
        private:
index 2c36cd6fa1e132e9eeded8a3066320cac582a0b9..35c24c1f080cb3e23fc9908d0d11fcc98852900e 100644 (file)
@@ -124,12 +124,6 @@ void RenderMethod::set_debug_name(const string &name)
 
 DataFile::Loader::ActionMap RenderMethod::Loader::shared_actions;
 
-RenderMethod::Loader::Loader(RenderMethod &p):
-       DataFile::CollectionObjectLoader<RenderMethod>(p, 0)
-{
-       set_actions(shared_actions);
-}
-
 RenderMethod::Loader::Loader(RenderMethod &p, Collection &c):
        DataFile::CollectionObjectLoader<RenderMethod>(p, &c)
 {
index 11c7e8583ecd430f759fe75fb078aac5317700d2..bf35aac57db1177e0a06ee229fe22a3197f64cf2 100644 (file)
@@ -30,7 +30,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(RenderMethod &);
                Loader(RenderMethod &, Collection &);
        private:
                virtual void init_actions();
index 268149f8cb4bff921d9459d2e721e99235fd6257..60eba997c05f2f0cd386039e59acd3c77bef1d45 100644 (file)
@@ -105,12 +105,6 @@ void Technique::set_debug_name(const string &name)
 
 DataFile::Loader::ActionMap Technique::Loader::shared_actions;
 
-Technique::Loader::Loader(Technique &t):
-       DataFile::CollectionObjectLoader<Technique>(t, 0)
-{
-       set_actions(shared_actions);
-}
-
 Technique::Loader::Loader(Technique &t, Collection &c):
        DataFile::CollectionObjectLoader<Technique>(t, &c)
 {
@@ -138,14 +132,9 @@ void Technique::Loader::inherit(const string &n)
 void Technique::Loader::method(const string &n)
 {
        RenderMethod p;
-       if(coll)
-       {
-               RenderMethod::Loader ldr(p, get_collection());
-               ldr.set_inline_base_name(format("%s/%s.method", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n));
-               load_sub_with(ldr);
-       }
-       else
-               load_sub(p);
+       RenderMethod::Loader ldr(p, get_collection());
+       ldr.set_inline_base_name(format("%s/%s.method", (inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name), n));
+       load_sub_with(ldr);
 
        if(!p.get_shader_program())
                throw logic_error("no shader program in method");
index 4e6b908d7847c470a4fc06ec2d5225f57a54aed2..716c57cd0bb5903c71d778038a0eb6ac86248e77 100644 (file)
@@ -25,7 +25,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(Technique &);
                Loader(Technique &, Collection &);
        private:
                virtual void init_actions();
index 21f2b2f3037ed2a1a1eef0f194041727e55fcaf7..d5d99c01f2196a67ca6204ef8d7f9b22a34bebb4 100644 (file)
@@ -52,12 +52,6 @@ void UnlitMaterial::set_vertex_color(bool vc)
 
 DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions;
 
-UnlitMaterial::Loader::Loader(UnlitMaterial &m):
-       DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m)
-{
-       set_actions(shared_actions);
-}
-
 UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c):
        DerivedObjectLoader<UnlitMaterial, Material::PropertyLoader<UnlitMaterial> >(m, c)
 {
index dc027f1f6a79ccc7a400aa5311e1081e056729da..4481d5f988f446d446c048303666803c0af44e46 100644 (file)
@@ -15,7 +15,6 @@ public:
                static ActionMap shared_actions;
 
        public:
-               Loader(UnlitMaterial &);
                Loader(UnlitMaterial &, Collection &);
 
        private:
index b63434742b7ef8a7305a2bbcaed7e3e85a9ba98b..ccc7b97ecdd0086db8f6b6029fc9546e94b82771 100644 (file)
@@ -188,7 +188,7 @@ void Object::resource_removed(Resource &res)
 }
 
 
-Object::Loader::Loader(Object &o, Collection *c):
+Object::Loader::Loader(Object &o, Collection &c):
        LodLoader(o, 0, c)
 {
        add("bounding_sphere_hint", &Loader::bounding_sphere_hint);
@@ -207,13 +207,13 @@ void Object::Loader::bounding_sphere_hint(float x, float y, float z, float r)
 
 void Object::Loader::level_of_detail(unsigned i)
 {
-       LodLoader ldr(obj, i, coll);
+       LodLoader ldr(obj, i, get_collection());
        load_sub_with(ldr);
 }
 
 
-Object::LodLoader::LodLoader(Object &o, unsigned i, Collection *c):
-       DataFile::CollectionObjectLoader<Object>(o, c),
+Object::LodLoader::LodLoader(Object &o, unsigned i, Collection &c):
+       DataFile::CollectionObjectLoader<Object>(o, &c),
        index(i),
        lod(obj.get_lod(index, "Object::LodLoader::LodLoader"))
 {
index dea389e4b8ae4d0d841ccbea333341bbc2a40ef9..80a73cba61e2caf6ac53281af7bb7ded14c303e8 100644 (file)
@@ -37,7 +37,7 @@ private:
                LevelOfDetail &lod;
 
        public:
-               LodLoader(Object &, unsigned, Collection *);
+               LodLoader(Object &, unsigned, Collection &);
 
        private:
                void mesh(const std::string &);
@@ -50,10 +50,8 @@ public:
        class Loader: public LodLoader
        {
        public:
-               Loader(Object &o): Loader(o, 0) { }
-               Loader(Object &o, Collection &c): Loader(o, &c) { }
+               Loader(Object &, Collection &);
        private:
-               Loader(Object &, Collection *);
                virtual void finish();
 
                void bounding_sphere_hint(float, float, float, float);