From ef650a483b4201a1e9727f9a86e59894344d30e8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 7 Oct 2021 11:23:57 +0300 Subject: [PATCH] Use set_manager instead of passing the manager to the constructor This allows always using the parameterless constructor, making some things easier. --- source/backends/opengl/texture2d_backend.cpp | 4 ++-- source/backends/opengl/texture2d_backend.h | 2 +- source/core/mesh.cpp | 11 ++++------- source/core/mesh.h | 4 ++-- source/core/texture.cpp | 7 ++----- source/core/texture.h | 2 +- source/core/texture2d.cpp | 3 +-- source/core/texture2d.h | 2 +- source/resources/resources.cpp | 6 ++++-- 9 files changed, 18 insertions(+), 23 deletions(-) diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index c47600cf..2f7e503b 100644 --- a/source/backends/opengl/texture2d_backend.cpp +++ b/source/backends/opengl/texture2d_backend.cpp @@ -31,8 +31,8 @@ public: }; -OpenGLTexture2D::OpenGLTexture2D(ResourceManager *m): - Texture(GL_TEXTURE_2D, m) +OpenGLTexture2D::OpenGLTexture2D(): + Texture(GL_TEXTURE_2D) { } void OpenGLTexture2D::allocate() diff --git a/source/backends/opengl/texture2d_backend.h b/source/backends/opengl/texture2d_backend.h index 8f2fec59..595c51f5 100644 --- a/source/backends/opengl/texture2d_backend.h +++ b/source/backends/opengl/texture2d_backend.h @@ -13,7 +13,7 @@ class OpenGLTexture2D: public Texture protected: class AsyncLoader; - OpenGLTexture2D(ResourceManager *); + OpenGLTexture2D(); void allocate(); void sub_image(unsigned, int, int, unsigned, unsigned, const void *); diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index 981a59e8..1e811b5b 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -9,19 +9,16 @@ using namespace std; namespace Msp { namespace GL { -Mesh::Mesh(ResourceManager *rm): +Mesh::Mesh(): vbuf(0), ibuf(0), dirty(0), disallow_rendering(false), face_winding(NON_MANIFOLD) -{ - if(rm) - set_manager(rm); -} +{ } -Mesh::Mesh(const VertexFormat &f, ResourceManager *rm): - Mesh(rm) +Mesh::Mesh(const VertexFormat &f): + Mesh() { storage(f); } diff --git a/source/core/mesh.h b/source/core/mesh.h index 39bf55b2..89f51fdd 100644 --- a/source/core/mesh.h +++ b/source/core/mesh.h @@ -75,8 +75,8 @@ private: std::string debug_name; public: - Mesh(ResourceManager * = 0); - Mesh(const VertexFormat &, ResourceManager * = 0); + Mesh(); + Mesh(const VertexFormat &); ~Mesh(); void storage(const VertexFormat &); diff --git a/source/core/texture.cpp b/source/core/texture.cpp index be825e7f..568479a6 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -8,17 +8,14 @@ using namespace std; namespace Msp { namespace GL { -Texture::Texture(unsigned t, ResourceManager *m): +Texture::Texture(unsigned t): TextureBackend(t), format(NO_PIXELFORMAT), storage_fmt(format), swizzle(NO_SWIZZLE), use_srgb_format(false), auto_gen_mipmap(false) -{ - if(m) - set_manager(m); -} +{ } void Texture::set_format(PixelFormat fmt) { diff --git a/source/core/texture.h b/source/core/texture.h index 2f647b90..33e0769d 100644 --- a/source/core/texture.h +++ b/source/core/texture.h @@ -63,7 +63,7 @@ protected: bool use_srgb_format; bool auto_gen_mipmap; - Texture(unsigned, ResourceManager * = 0); + Texture(unsigned); void set_format(PixelFormat); diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 8dc15b1c..01612d73 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -6,8 +6,7 @@ using namespace std; namespace Msp { namespace GL { -Texture2D::Texture2D(ResourceManager *m): - Texture2DBackend(m), +Texture2D::Texture2D(): width(0), height(0) { } diff --git a/source/core/texture2d.h b/source/core/texture2d.h index a2454b76..4f0bde26 100644 --- a/source/core/texture2d.h +++ b/source/core/texture2d.h @@ -37,7 +37,7 @@ private: unsigned levels; public: - Texture2D(ResourceManager * = 0); + Texture2D(); virtual ~Texture2D(); /** Defines storage structure for the texture. If lv is zero, the number diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index fa20a0bf..ec5f431d 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -167,7 +167,8 @@ Mesh *Resources::create_mesh(const string &name) if(RefPtr io = open_raw(name)) { - RefPtr mesh = new Mesh(resource_manager); + RefPtr mesh = new Mesh; + mesh->set_manager(resource_manager); resource_manager->set_resource_location(*mesh, *this, name); return mesh.release(); } @@ -187,7 +188,8 @@ Texture2D *Resources::create_texture2d(const string &name) if(ext==".tex2d") { - tex = new Texture2D(resource_manager); + tex = new Texture2D; + tex->set_manager(resource_manager); DataFile::Parser parser(*io, name); Texture2D::Loader ldr(*tex, *this); ldr.load(parser); -- 2.45.2