From: Mikko Rasa Date: Tue, 5 Oct 2021 10:18:52 +0000 (+0300) Subject: Remove collection-less constructor overloads from most loaders X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=ae45c0397e2cb8f0a01f2f31d01c95ff3870271e Remove collection-less constructor overloads from most loaders These classes are extremely likely to require references to other objects, and requiring a collection makes the code more straightforward. --- diff --git a/source/builders/font.cpp b/source/builders/font.cpp index 1ede612a..4fb64352 100644 --- a/source/builders/font.cpp +++ b/source/builders/font.cpp @@ -143,8 +143,8 @@ Font::Glyph::Glyph(): { } -Font::Loader::Loader(Font &f, Collection *c): - DataFile::CollectionObjectLoader(f, c) +Font::Loader::Loader(Font &f, Collection &c): + DataFile::CollectionObjectLoader(f, &c) { add("native_size", &Font::native_size); add("ascent", &Font::ascent); diff --git a/source/builders/font.h b/source/builders/font.h index af65da8a..f46a2870 100644 --- a/source/builders/font.h +++ b/source/builders/font.h @@ -21,11 +21,9 @@ public: class Loader: public DataFile::CollectionObjectLoader { 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); diff --git a/source/builders/sequencetemplate.cpp b/source/builders/sequencetemplate.cpp index c125823e..5d7f4d0b 100644 --- a/source/builders/sequencetemplate.cpp +++ b/source/builders/sequencetemplate.cpp @@ -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(p, c) +SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c): + DataFile::CollectionObjectLoader(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 lightn = new Lighting; - load_sub(*lightn); + load_sub(*lightn, get_collection()); get_collection().add(inline_base_name+".lightn", lightn.get()); obj.lighting = lightn.release(); } diff --git a/source/builders/sequencetemplate.h b/source/builders/sequencetemplate.h index bf1e8be1..52c42bb1 100644 --- a/source/builders/sequencetemplate.h +++ b/source/builders/sequencetemplate.h @@ -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: diff --git a/source/materials/basicmaterial.cpp b/source/materials/basicmaterial.cpp index 49a74764..3a4b7487 100644 --- a/source/materials/basicmaterial.cpp +++ b/source/materials/basicmaterial.cpp @@ -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 >(m) -{ - set_actions(shared_actions); -} - BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c): DerivedObjectLoader >(m, c) { diff --git a/source/materials/basicmaterial.h b/source/materials/basicmaterial.h index a5a8a43f..bf1b0e8c 100644 --- a/source/materials/basicmaterial.h +++ b/source/materials/basicmaterial.h @@ -15,7 +15,6 @@ public: static ActionMap shared_actions; public: - Loader(BasicMaterial &); Loader(BasicMaterial &, Collection &); private: diff --git a/source/materials/lighting.cpp b/source/materials/lighting.cpp index 11373504..c1b2e2aa 100644 --- a/source/materials/lighting.cpp +++ b/source/materials/lighting.cpp @@ -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(l, 0) -{ - set_actions(shared_actions); -} - Lighting::Loader::Loader(Lighting &l, Collection &c): CollectionObjectLoader(l, &c) { diff --git a/source/materials/lighting.h b/source/materials/lighting.h index 9dc93b24..658d7476 100644 --- a/source/materials/lighting.h +++ b/source/materials/lighting.h @@ -24,7 +24,6 @@ public: static ActionMap shared_actions; public: - Loader(Lighting &); Loader(Lighting &, Collection &); private: diff --git a/source/materials/material.cpp b/source/materials/material.cpp index b7dd767e..71610c7c 100644 --- a/source/materials/material.cpp +++ b/source/materials/material.cpp @@ -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; diff --git a/source/materials/material.h b/source/materials/material.h index 4f8e23cc..ea02df6b 100644 --- a/source/materials/material.h +++ b/source/materials/material.h @@ -19,7 +19,6 @@ private: class Loader: public DataFile::CollectionObjectLoader { protected: - Loader(Material &); Loader(Material &, Collection &); virtual void init_actions(); @@ -42,7 +41,6 @@ protected: class PropertyLoader: public DataFile::DerivedObjectLoader { protected: - PropertyLoader(C &m): DerivedObjectLoader(m) { } PropertyLoader(C &m, Collection &c): DerivedObjectLoader(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::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); } diff --git a/source/materials/pbrmaterial.cpp b/source/materials/pbrmaterial.cpp index ad36159a..ed94bf79 100644 --- a/source/materials/pbrmaterial.cpp +++ b/source/materials/pbrmaterial.cpp @@ -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 >(m) -{ - set_actions(shared_actions); -} - PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c): DerivedObjectLoader >(m, c) { diff --git a/source/materials/pbrmaterial.h b/source/materials/pbrmaterial.h index 0204451b..9669bc35 100644 --- a/source/materials/pbrmaterial.h +++ b/source/materials/pbrmaterial.h @@ -17,7 +17,6 @@ public: static ActionMap shared_actions; public: - Loader(PbrMaterial &); Loader(PbrMaterial &, Collection &); private: diff --git a/source/materials/rendermethod.cpp b/source/materials/rendermethod.cpp index 2c36cd6f..35c24c1f 100644 --- a/source/materials/rendermethod.cpp +++ b/source/materials/rendermethod.cpp @@ -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(p, 0) -{ - set_actions(shared_actions); -} - RenderMethod::Loader::Loader(RenderMethod &p, Collection &c): DataFile::CollectionObjectLoader(p, &c) { diff --git a/source/materials/rendermethod.h b/source/materials/rendermethod.h index 11c7e858..bf35aac5 100644 --- a/source/materials/rendermethod.h +++ b/source/materials/rendermethod.h @@ -30,7 +30,6 @@ public: static ActionMap shared_actions; public: - Loader(RenderMethod &); Loader(RenderMethod &, Collection &); private: virtual void init_actions(); diff --git a/source/materials/technique.cpp b/source/materials/technique.cpp index 268149f8..60eba997 100644 --- a/source/materials/technique.cpp +++ b/source/materials/technique.cpp @@ -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(t, 0) -{ - set_actions(shared_actions); -} - Technique::Loader::Loader(Technique &t, Collection &c): DataFile::CollectionObjectLoader(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"); diff --git a/source/materials/technique.h b/source/materials/technique.h index 4e6b908d..716c57cd 100644 --- a/source/materials/technique.h +++ b/source/materials/technique.h @@ -25,7 +25,6 @@ public: static ActionMap shared_actions; public: - Loader(Technique &); Loader(Technique &, Collection &); private: virtual void init_actions(); diff --git a/source/materials/unlitmaterial.cpp b/source/materials/unlitmaterial.cpp index 21f2b2f3..d5d99c01 100644 --- a/source/materials/unlitmaterial.cpp +++ b/source/materials/unlitmaterial.cpp @@ -52,12 +52,6 @@ void UnlitMaterial::set_vertex_color(bool vc) DataFile::Loader::ActionMap UnlitMaterial::Loader::shared_actions; -UnlitMaterial::Loader::Loader(UnlitMaterial &m): - DerivedObjectLoader >(m) -{ - set_actions(shared_actions); -} - UnlitMaterial::Loader::Loader(UnlitMaterial &m, Collection &c): DerivedObjectLoader >(m, c) { diff --git a/source/materials/unlitmaterial.h b/source/materials/unlitmaterial.h index dc027f1f..4481d5f9 100644 --- a/source/materials/unlitmaterial.h +++ b/source/materials/unlitmaterial.h @@ -15,7 +15,6 @@ public: static ActionMap shared_actions; public: - Loader(UnlitMaterial &); Loader(UnlitMaterial &, Collection &); private: diff --git a/source/render/object.cpp b/source/render/object.cpp index b6343474..ccc7b97e 100644 --- a/source/render/object.cpp +++ b/source/render/object.cpp @@ -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(o, c), +Object::LodLoader::LodLoader(Object &o, unsigned i, Collection &c): + DataFile::CollectionObjectLoader(o, &c), index(i), lod(obj.get_lod(index, "Object::LodLoader::LodLoader")) { diff --git a/source/render/object.h b/source/render/object.h index dea389e4..80a73cba 100644 --- a/source/render/object.h +++ b/source/render/object.h @@ -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);