From 31317175d72c62994b98a93e1b827633b4de9cb2 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 1 Aug 2017 23:47:35 +0100 Subject: Fixing constructors and destructors --- include/YAGE/Math/matrix.hpp | 9 --------- include/YAGE/Physics/body.hpp | 2 -- include/YAGE/Physics/collider.hpp | 3 --- include/YAGE/camera2d.hpp | 1 - include/YAGE/glslprogram.hpp | 21 +++++++++++++-------- include/YAGE/sprite.hpp | 5 +++++ include/YAGE/spritebatch.hpp | 23 ++++++++++++++--------- include/YAGE/texturecache.hpp | 1 - include/YAGE/window.hpp | 23 +++++++++++++---------- 9 files changed, 45 insertions(+), 43 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 388e9535..2aca04db 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -183,15 +183,6 @@ public: return detail::Row((Matrix*)this, row); } - Matrix& operator=(const Matrix &other) - { - if(this!=&other) - { - data_=other.data_; - } - return *this; - } - Matrix& operator+=(const Matrix &rhs) { std::vector out; diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index 8fb7aaf6..b0869779 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -39,8 +39,6 @@ protected: Vector2d force_=Vector2d(0, 0); public: - virtual ~Body(); - // apply force to the object and update the velocity virtual void applyForce(const Vector2d &force)=0; virtual void update()=0; diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp index fc5d38d5..716b7d4c 100644 --- a/include/YAGE/Physics/collider.hpp +++ b/include/YAGE/Physics/collider.hpp @@ -28,9 +28,6 @@ protected: public: Collider(const glm::vec2 &position, const glm::vec2 &size) : position_(position), size_(size) {} - // virtual deconstructor for classes that inherits - virtual ~Collider() {} - // function that checks if two colliders are colliding virtual bool collides(const Collider &collider) const=0; diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp index 400cfe02..4c44ccaf 100644 --- a/include/YAGE/camera2d.hpp +++ b/include/YAGE/camera2d.hpp @@ -28,7 +28,6 @@ private: public: Camera2D(int screen_width=1280, int screen_height=720); - virtual ~Camera2D(); // update camera location void update(GlslProgram &program); diff --git a/include/YAGE/glslprogram.hpp b/include/YAGE/glslprogram.hpp index 28222ede..70f30b73 100644 --- a/include/YAGE/glslprogram.hpp +++ b/include/YAGE/glslprogram.hpp @@ -19,19 +19,24 @@ namespace yage class GlslProgram { private: - // compiled shader program id - GLuint program_id_ = 0; - GLuint vertex_shader_id_ = 0; - GLuint fragment_shader_id_ = 0; - int attribute_index_ = 0; + /// compiled shader program id + GLuint program_id_=0; + GLuint vertex_shader_id_=0; + GLuint fragment_shader_id_=0; + int attribute_index_=0; - // compiles one shader + /// compiles one shader void compileShader(const GLuint &shader, const std::string &file_path); public: - GlslProgram(); + GlslProgram()=default; + GlslProgram(const GlslProgram&)=delete; + GlslProgram(GlslProgram&&)=delete; ~GlslProgram(); - // compiles vertex and fragment shader + GlslProgram& operator=(const GlslProgram&)=delete; + GlslProgram& operator=(GlslProgram&&)=delete; + + /// compiles vertex and fragment shader void compileShaders(const std::string &vertex_shader_path, const std::string &fragment_shader_path); void linkShaders(); void addAttribute(const std::string &attribute_name); diff --git a/include/YAGE/sprite.hpp b/include/YAGE/sprite.hpp index 9e5aca8b..cddc0e26 100644 --- a/include/YAGE/sprite.hpp +++ b/include/YAGE/sprite.hpp @@ -29,8 +29,13 @@ private: Texture texture_; public: Sprite(); + Sprite(const Sprite&)=delete; + Sprite(Sprite&&)=delete; ~Sprite(); + Sprite& operator=(const Sprite&)=delete; + Sprite& operator=(Sprite&&)=delete; + void init(float x, float y, float width, float height, const std::string &texture_path); void draw(); }; diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index 61efd0aa..a3007bbf 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -36,12 +36,12 @@ private: public: Glyph(GLuint texture, float depth, const Vertex &top_left, const Vertex &top_right, const Vertex &bottom_right, const Vertex &bottom_left); - inline GLuint texture() const { return texture_; } - inline float depth() const { return depth_; } - inline Vertex top_left() const { return top_left_; } - inline Vertex top_right() const { return top_right_; } - inline Vertex bottom_right() const { return bottom_right_; } - inline Vertex bottom_left() const { return bottom_left_; } + GLuint texture() const { return texture_; } + float depth() const { return depth_; } + Vertex top_left() const { return top_left_; } + Vertex top_right() const { return top_right_; } + Vertex bottom_right() const { return bottom_right_; } + Vertex bottom_left() const { return bottom_left_; } }; class RenderBatch @@ -58,9 +58,9 @@ public: RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); // getters - inline GLint offset() const { return offset_; } - inline GLsizei num_vertices() const { return num_vertices_; } - inline GLuint texture() const { return texture_; } + GLint offset() const { return offset_; } + GLsizei num_vertices() const { return num_vertices_; } + GLuint texture() const { return texture_; } }; class SpriteBatch @@ -78,8 +78,13 @@ private: // member functions public: SpriteBatch(); + SpriteBatch(const SpriteBatch&)=delete; + SpriteBatch(SpriteBatch&&)=delete; ~SpriteBatch(); + SpriteBatch& operator=(const SpriteBatch&)=delete; + SpriteBatch& operator=(SpriteBatch&&)=delete; + // initialize vaos and vbos void init(); void begin(); diff --git a/include/YAGE/texturecache.hpp b/include/YAGE/texturecache.hpp index 158f81ee..ac318230 100644 --- a/include/YAGE/texturecache.hpp +++ b/include/YAGE/texturecache.hpp @@ -22,7 +22,6 @@ private: std::unordered_map texture_map_; public: TextureCache(); - ~TextureCache(); Texture getTexture(const std::string &texture_path); }; diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp index 98ba2592..beefae3d 100644 --- a/include/YAGE/window.hpp +++ b/include/YAGE/window.hpp @@ -28,25 +28,28 @@ enum WindowFlags : unsigned // window wrapper around SDL_Window pointer class Window { -public: // member variables private: - // window handle + /// window handle SDL_Window *window_=nullptr; -public: // member functions +public: Window(); - // destroys the window handle - ~Window(); + Window(const Window&)=delete; + Window(Window&&)=delete; + /// destroys the window handle + ~Window(); - // create the window, initialize the handle and update the width and height + Window& operator=(const Window&)=delete; + Window& operator=(Window&&)=delete; + + /// create the window, initialize the handle and update the width and height void create(const std::string &window_name, int width, int height, unsigned flags=WindowFlags::SHOWN); - // swap the buffer + /// swap the buffer void swapBuffer(); - // clear buffer + /// clear buffer void clearBuffer(); -private: }; -} // yage +} // namespace yage #endif -- cgit