]> git.tdb.fi Git - libs/gl.git/commitdiff
Use constructor delegation instead of init functions when possible
authorMikko Rasa <tdb@tdb.fi>
Fri, 1 Oct 2021 19:09:54 +0000 (22:09 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 1 Oct 2021 19:09:54 +0000 (22:09 +0300)
22 files changed:
source/animation/animation.cpp
source/animation/animation.h
source/animation/keyframe.cpp
source/animation/keyframe.h
source/builders/font.cpp
source/builders/font.h
source/builders/grid.cpp
source/builders/grid.h
source/builders/sequencetemplate.cpp
source/builders/sequencetemplate.h
source/core/framebuffer.cpp
source/core/framebuffer.h
source/core/mesh.cpp
source/core/mesh.h
source/core/texture.cpp
source/core/texture.h
source/effects/environmentmap.cpp
source/effects/environmentmap.h
source/render/object.cpp
source/render/object.h
source/render/scene.cpp
source/render/scene.h

index a9278e3de00836b3eb9e2ebe56ff908e2da207ed..98cfdc87f5398f2813252fb9c0688fdbd69be65a 100644 (file)
@@ -489,23 +489,12 @@ Matrix Animation::Iterator::get_pose_matrix(unsigned link) const
 }
 
 
-Animation::Loader::Loader(Animation &a):
-       DataFile::CollectionObjectLoader<Animation>(a, 0)
+Animation::Loader::Loader(Animation &a, Collection *c):
+       DataFile::CollectionObjectLoader<Animation>(a, c),
+       start_slope(1),
+       end_slope(1),
+       slopes_set(0)
 {
-       init();
-}
-
-Animation::Loader::Loader(Animation &a, Collection &c):
-       DataFile::CollectionObjectLoader<Animation>(a, &c)
-{
-       init();
-}
-
-void Animation::Loader::init()
-{
-       start_slope = 1;
-       end_slope = 1;
-       slopes_set = 0;
        add("armature", &Animation::armature);
        add("control_keyframe", &Loader::control_keyframe);
        add("control_keyframe", &Loader::control_keyframe_inline);
index 3d247cf5f74bc0821481fc9a2cdbf10f24a0e8ca..eb5911c32a4d08a6c441cabddbd56231aa05f56d 100644 (file)
@@ -31,10 +31,10 @@ public:
                int slopes_set;
 
        public:
-               Loader(Animation &);
-               Loader(Animation &, Collection &);
+               Loader(Animation &a): Loader(a, 0) { }
+               Loader(Animation &a, Collection &c): Loader(a, &c) { }
        private:
-               void init();
+               Loader(Animation &, Collection *);
                virtual void finish();
 
                void check_slopes_and_control(bool, bool);
index 6cb8ce6ad1b5d9d5260115bae32821f62961c426..3f3dea28f0d1412d0a0414cfc9384e1ef5993c9a 100644 (file)
@@ -47,19 +47,8 @@ KeyFrame::AnimatedUniform::AnimatedUniform(unsigned s, float v0, float v1, float
 }
 
 
-KeyFrame::Loader::Loader(KeyFrame &k):
-       DataFile::CollectionObjectLoader<KeyFrame>(k, 0)
-{
-       init();
-}
-
-KeyFrame::Loader::Loader(KeyFrame &k, Collection &c):
-       DataFile::CollectionObjectLoader<KeyFrame>(k, &c)
-{
-       init();
-}
-
-void KeyFrame::Loader::init()
+KeyFrame::Loader::Loader(KeyFrame &k, Collection *c):
+       DataFile::CollectionObjectLoader<KeyFrame>(k, c)
 {
        add("pose", &Loader::pose);
        add("pose", &Loader::pose_inline);
index 7a96447e656d5ef533a381b099a9e39e17abc44d..26d18534496b755ceac151601b886b589fad8da3 100644 (file)
@@ -23,10 +23,10 @@ public:
                std::string inline_base_name;
 
        public:
-               Loader(KeyFrame &);
-               Loader(KeyFrame &, Collection &);
+               Loader(KeyFrame &k): Loader(k, 0) { }
+               Loader(KeyFrame &k, Collection &c): Loader(k, &c) { }
        private:
-               void init();
+               Loader(KeyFrame &, Collection *);
 
        public:
                void set_inline_base_name(const std::string &);
index f46475bcae69c84bc5497f9bd397669ddeefb48a..1ede612a1dec64e9ab2e671a5a9398fc44e8f6dc 100644 (file)
@@ -143,19 +143,8 @@ Font::Glyph::Glyph():
 { }
 
 
-Font::Loader::Loader(Font &f):
-       DataFile::CollectionObjectLoader<Font>(f, 0)
-{
-       init();
-}
-
-Font::Loader::Loader(Font &f, Collection &c):
-       DataFile::CollectionObjectLoader<Font>(f, &c)
-{
-       init();
-}
-
-void Font::Loader::init()
+Font::Loader::Loader(Font &f, Collection *c):
+       DataFile::CollectionObjectLoader<Font>(f, c)
 {
        add("native_size", &Font::native_size);
        add("ascent",      &Font::ascent);
index 2bb61f750783aa6e179ea7a21c7989dee883ff21..af65da8af9ae15d160482397fccdac70d8429d5d 100644 (file)
@@ -21,11 +21,11 @@ public:
        class Loader: public DataFile::CollectionObjectLoader<Font>
        {
        public:
-               Loader(Font &);
-               Loader(Font &, Collection &);
-
+               Loader(Font &f): Loader(f, 0) { }
+               Loader(Font &f, Collection &c): Loader(f, &c) { }
        private:
-               void init();
+               Loader(Font &, Collection *);
+
                void glyph(unsigned);
                void kerning(unsigned, unsigned, float);
                void ligature(unsigned, unsigned, unsigned);
index d812a2c2558656212f086cffe96ef11564d2bc25..f452c438fa5f3932281e919ae9e0c615bcf9c788 100644 (file)
@@ -8,62 +8,32 @@ namespace Msp {
 namespace GL {
 
 GridBuilder::GridBuilder(float w, float h, unsigned u, unsigned v):
-       origin(-w/2, -h/2, 0),
-       side1(w, 0, 0),
-       side2(0, h, 0),
-       norm(0, 0, 1),
-       binorm(0, 1, 0),
-       u_div(u),
-       v_div(v)
-{
-       init(false);
-}
+       GridBuilder(Vector3(-w/2, -h/2, 0), Vector3(w, 0, 0), Vector3(0, h, 0), u, v)
+{ }
 
 GridBuilder::GridBuilder(const Vector3 &o, const Vector3 &s, unsigned u, unsigned v):
-       origin(o),
-       u_div(u),
-       v_div(v)
-{
-       if(abs(s.z)<abs(s.x) && abs(s.z)<abs(s.y))
-       {
-               side1 = Vector3(s.x, 0, 0);
-               side2 = Vector3(0, s.y, 0);
-       }
-       else if(abs(s.y)<abs(s.x))
-       {
-               side1 = Vector3(0, 0, s.z);
-               side2 = Vector3(s.x, 0, 0);
-       }
-       else
-       {
-               side1 = Vector3(0, s.y, 0);
-               side2 = Vector3(0, 0, s.z);
-       }
-       init(true);
-}
+       GridBuilder(o, get_side(s, 0), get_side(s, 1), u, v)
+{ }
 
 GridBuilder::GridBuilder(const Vector3 &o, const Vector3 &s1, const Vector3 &s2, unsigned u, unsigned v):
        origin(o),
        side1(s1),
        side2(s2),
-       u_div(u),
-       v_div(v)
+       u_div(max(u, 1U)),
+       v_div(max(v, 1U))
 {
-       init(true);
+       norm = normalize(cross(side1, side2));
+       binorm = normalize(cross(norm, side1));
 }
 
-void GridBuilder::init(bool compute_normals)
+Vector3 GridBuilder::get_side(const Vector3 &size, unsigned index)
 {
-       if(u_div<1)
-               u_div = 1;
-       if(v_div<1)
-               v_div = 1;
-
-       if(compute_normals)
-       {
-               norm = normalize(cross(side1, side2));
-               binorm = normalize(cross(norm, side1));
-       }
+       if(!size.x)
+               return Vector3(0, (index==0 ? size.y : 0), (index==1 ? size.z : 0));
+       else if(!size.y)
+               return Vector3((index==0 ? size.x : 0), 0, (index==1 ? size.z : 0));
+       else
+               return Vector3((index==0 ? size.x : 0), (index==1 ? size.z : 0), 0);
 }
 
 void GridBuilder::build(PrimitiveBuilder &builder) const
index ed22ce7d6c939fdf71b7e4d1a35a065807bb9ae5..a66051277f02e32e967e4338338408a2c0ea120c 100644 (file)
@@ -23,7 +23,7 @@ public:
        GridBuilder(const Vector3 &, const Vector3 &, unsigned = 4, unsigned = 4);
        GridBuilder(const Vector3 &, const Vector3 &, const Vector3 &, unsigned = 4, unsigned = 4);
 private:
-       void init(bool);
+       Vector3 get_side(const Vector3 &, unsigned);
 
 public:
        using GeometryBuilder::build;
index 67fb4d91d1988cf0cac5e3461d4ac67d05adccfb..c125823eb8344da53d4013a6137a44f6897b5f46 100644 (file)
@@ -160,19 +160,8 @@ void SequenceTemplate::ClearLoader::stencil(int s)
 }
 
 
-SequenceTemplate::Step::Loader::Loader(Step &p):
-       DataFile::CollectionObjectLoader<Step>(p, 0)
-{
-       init();
-}
-
-SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
-       DataFile::CollectionObjectLoader<Step>(p, &c)
-{
-       init();
-}
-
-void SequenceTemplate::Step::Loader::init()
+SequenceTemplate::Step::Loader::Loader(Step &p, Collection *c):
+       DataFile::CollectionObjectLoader<Step>(p, c)
 {
        add("blend", &Loader::blend);
        add("blend", &Loader::blend_factors);
index c49b2d43dfa95c8ea30a56c521863430f4332348..bf1e8be185e086efc6b3597139f827630e672536 100644 (file)
@@ -70,9 +70,10 @@ public:
                        std::string inline_base_name;
 
                public:
-                       Loader(Step &);
-                       Loader(Step &, Collection &);
+                       Loader(Step &s): Loader(s, 0) { }
+                       Loader(Step &s, Collection &c): Loader(s, &c) { }
                private:
+                       Loader(Step &, Collection *);
                        void init();
 
                public:
index 167b403aec18e142548c9f02f775e453e71e6cb0..613277233a84d78258fe40c2c585cbca24cf41bb 100644 (file)
@@ -27,32 +27,24 @@ Framebuffer::Framebuffer(bool s):
 }
 
 Framebuffer::Framebuffer():
-       FramebufferBackend(false)
-{
-       init();
-}
+       FramebufferBackend(false),
+       width(0),
+       height(0),
+       dirty(0)
+{ }
 
 Framebuffer::Framebuffer(FrameAttachment fa):
-       FramebufferBackend(false)
+       Framebuffer()
 {
-       init();
        set_format(fa);
 }
 
 Framebuffer::Framebuffer(const FrameFormat &f):
-       FramebufferBackend(false)
+       Framebuffer()
 {
-       init();
        set_format(f);
 }
 
-void Framebuffer::init()
-{
-       width = 0;
-       height = 0;
-       dirty = 0;
-}
-
 void Framebuffer::set_format(const FrameFormat &fmt)
 {
        if(!format.empty() || !id)
index 18e48f2022b6b1197129a6de6c57ee8a37cf38b3..0b9af1efd167e47addd3572eff9db4e80b87d3e1 100644 (file)
@@ -68,10 +68,6 @@ public:
        /** Creates a framebuffer and sets its format. */
        Framebuffer(const FrameFormat &);
 
-private:
-       void init();
-
-public:
        /** Sets the format of the framebuffer.  Once the format is set, it can't
        be changed. */
        void set_format(const FrameFormat &);
index 029c16e0fac6b04d35f1847faf2590fafd320c1f..981a59e8002c46585f498887da1c32f00429b7ce 100644 (file)
@@ -9,29 +9,23 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Mesh::Mesh(ResourceManager *rm)
+Mesh::Mesh(ResourceManager *rm):
+       vbuf(0),
+       ibuf(0),
+       dirty(0),
+       disallow_rendering(false),
+       face_winding(NON_MANIFOLD)
 {
-       init(rm);
+       if(rm)
+               set_manager(rm);
 }
 
-Mesh::Mesh(const VertexFormat &f, ResourceManager *rm)
+Mesh::Mesh(const VertexFormat &f, ResourceManager *rm):
+       Mesh(rm)
 {
-       init(rm);
        storage(f);
 }
 
-void Mesh::init(ResourceManager *rm)
-{
-       vbuf = 0;
-       ibuf = 0;
-       dirty = 0;
-       disallow_rendering = false;
-       face_winding = NON_MANIFOLD;
-
-       if(rm)
-               set_manager(rm);
-}
-
 Mesh::~Mesh()
 {
        set_manager(0);
index 010289b04aa667eeea23b652a2088d26f81a8636..39bf55b22d5129f0725f11a44233f48be28556d9 100644 (file)
@@ -77,9 +77,6 @@ private:
 public:
        Mesh(ResourceManager * = 0);
        Mesh(const VertexFormat &, ResourceManager * = 0);
-private:
-       void init(ResourceManager *);
-public:
        ~Mesh();
 
        void storage(const VertexFormat &);
index 4968e2e678bd6103c239103828cc1c78b0ff4b2b..85f5fb5836ebdcdb56af17191343a9c2f21be9ea 100644 (file)
@@ -65,22 +65,10 @@ void Texture::load_image(const string &fn, unsigned lv)
 }
 
 
-Texture::Loader::Loader(Texture &t):
-       DataFile::CollectionObjectLoader<Texture>(t, 0)
+Texture::Loader::Loader(Texture &t, Collection *c):
+       CollectionObjectLoader<Texture>(t, c),
+       levels(0)
 {
-       init();
-}
-
-Texture::Loader::Loader(Texture &t, Collection &c):
-       DataFile::CollectionObjectLoader<Texture>(t, &c)
-{
-       init();
-}
-
-void Texture::Loader::init()
-{
-       levels = 0;
-
        add("external_image", &Loader::external_image);
        add("external_image_srgb", &Loader::external_image_srgb);
        add("generate_mipmap", &Loader::generate_mipmap);
index 6073cdcb2fcb5e071145731e4c1c88abbf1d02b0..2f647b90cae721837f441a59c4c67e5c5f3f31fd 100644 (file)
@@ -30,10 +30,10 @@ protected:
                unsigned levels;
 
        public:
-               Loader(Texture &);
-               Loader(Texture &, Collection &);
+               Loader(Texture &t): Loader(t, 0) { }
+               Loader(Texture &t, Collection &c): Loader(t, &c) { }
        private:
-               void init();
+               Loader(Texture &, Collection *);
 
                virtual void finish();
 
index 2291a2023471ca4c960b1dd922bbff6896b0aa98..315390b1ca81664c47a2a5c940ef445ee94faa97 100644 (file)
@@ -12,16 +12,8 @@ namespace Msp {
 namespace GL {
 
 EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, Renderable &r, Renderable &e):
-       Effect(r),
-       environment(e),
-       irradiance_shprog(Resources::get_global().get<Program>("_envmap_irradiance.glsl.shader")),
-       specular_shprog(Resources::get_global().get<Program>("_envmap_specular.glsl.shader")),
-       fullscreen_mesh(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
-       sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
-       mip_sampler(Resources::get_global().get<Sampler>("_mip_clamp.samp"))
-{
-       init(s, f, 1);
-}
+       EnvironmentMap(s, f, 1, r, e)
+{ }
 
 EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable &r, Renderable &e):
        Effect(r),
@@ -31,11 +23,6 @@ EnvironmentMap::EnvironmentMap(unsigned s, PixelFormat f, unsigned l, Renderable
        fullscreen_mesh(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
        sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
        mip_sampler(Resources::get_global().get<Sampler>("_mip_clamp.samp"))
-{
-       init(s, f, l);
-}
-
-void EnvironmentMap::init(unsigned s, PixelFormat f, unsigned l)
 {
        if(!l || (1U<<(l-1))>=s)
                throw invalid_argument("EnvironmentMap::EnvironmentMap");
index 98328488580a563182e7fee0eedc4cde0bc6f3b1..bf6fbaf0f2b77081ffea4638400554837b91775c 100644 (file)
@@ -57,10 +57,7 @@ private:
 public:
        EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
        EnvironmentMap(unsigned size, PixelFormat, unsigned, Renderable &rend, Renderable &env);
-private:
-       void init(unsigned, PixelFormat, unsigned);
 
-public:
        void set_depth_clip(float, float);
 
        /** Sets the interval in frames between environment map updates.  A value of
index 98eb05f7cdb53deb5eb9e7703f48a5aebfdde0cf..34eebec782472880484179df7cf2175303086bab 100644 (file)
@@ -188,19 +188,8 @@ void Object::resource_removed(Resource &res)
 }
 
 
-Object::Loader::Loader(Object &o):
-       LodLoader(o, 0, 0)
-{
-       init();
-}
-
-Object::Loader::Loader(Object &o, Collection &c):
-       LodLoader(o, 0, &c)
-{
-       init();
-}
-
-void Object::Loader::init()
+Object::Loader::Loader(Object &o, Collection *c):
+       LodLoader(o, 0, c)
 {
        add("bounding_sphere_hint", &Loader::bounding_sphere_hint);
        add("level_of_detail", &Loader::level_of_detail);
index 0fbcf3830331cd893dbd5bc4b0f6f46dc72a9381..ac62c702b4e1e2f9c6033c40e95e2db812b84735 100644 (file)
@@ -50,10 +50,10 @@ public:
        class Loader: public LodLoader
        {
        public:
-               Loader(Object &);
-               Loader(Object &, Collection &);
+               Loader(Object &o): Loader(o, 0) { }
+               Loader(Object &o, Collection &c): Loader(o, &c) { }
        private:
-               void init();
+               Loader(Object &, Collection *);
                virtual void finish();
 
                void bounding_sphere_hint(float, float, float, float);
index 87d8c423852ac749ec29a45e9af7331c5f214031..229588679af54726cb3a203ed3d8b21a1e4330c9 100644 (file)
@@ -89,24 +89,11 @@ Scene::SceneRegistry &Scene::get_scene_registry()
 }
 
 
-Scene::Loader::Loader(Scene &s, Collection &c):
+Scene::Loader::Loader(Scene &s, Collection &c, ContentMap *m):
        DataFile::CollectionObjectLoader<Scene>(s, &c),
-       content(0)
+       content(m),
+       inst_counter(0)
 {
-       init();
-}
-
-Scene::Loader::Loader(Scene &s, Collection &c, ContentMap &m):
-       DataFile::CollectionObjectLoader<Scene>(s, &c),
-       content(&m)
-{
-       init();
-}
-
-void Scene::Loader::init()
-{
-       inst_counter = 0;
-
        add("object", &Loader::object);
        add("object", &Loader::object_tagged);
        add("scene", &Loader::scene);
index b68953446d72df4c735440a9700f827b29191a79..e4f5ecdfd070ff81b499696a8f643a5ce61adb00 100644 (file)
@@ -28,10 +28,10 @@ protected:
                unsigned inst_counter;
 
        public:
-               Loader(Scene &, Collection &);
-               Loader(Scene &, Collection &, ContentMap &);
+               Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
+               Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { }
        private:
-               void init();
+               Loader(Scene &, Collection &, ContentMap *);
 
                void object(const std::string &);
                void object_tagged(const std::string &, const std::string &);