diff --git a/src/GameRenderer.cpp b/src/GameRenderer.cpp index 789571d..f958992 100644 --- a/src/GameRenderer.cpp +++ b/src/GameRenderer.cpp @@ -42,16 +42,16 @@ GameRenderer::~GameRenderer() std::unique_ptr GameRenderer::load_sprite(const std::string &file, const int width, const int height) const { - return std::make_unique(Sprite({ renderer, file, width, height })); + return std::make_unique(renderer, file, width, height); } -void GameRenderer::draw_sprite(const Sprite sprite, const int x, const int y) const +void GameRenderer::draw_sprite(const Sprite &sprite, const int x, const int y) const { const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height }; SDL_RenderCopy(renderer, sprite.texture, nullptr, &rect); } -void GameRenderer::draw_sprite_rotated(const Sprite sprite, const int x, const int y, const double angle) const +void GameRenderer::draw_sprite_rotated(const Sprite &sprite, const int x, const int y, const double angle) const { const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height }; SDL_RenderCopyEx(renderer, sprite.texture, nullptr, &rect, angle, nullptr, SDL_FLIP_NONE); diff --git a/src/GameRenderer.hpp b/src/GameRenderer.hpp index 9a43a2e..1e8fd3d 100644 --- a/src/GameRenderer.hpp +++ b/src/GameRenderer.hpp @@ -24,9 +24,9 @@ public: std::unique_ptr load_sprite(const std::string &file, int width, int height) const; - void draw_sprite(Sprite sprite, int x, int y) const; + void draw_sprite(const Sprite &sprite, int x, int y) const; - void draw_sprite_rotated(Sprite sprite, int x, int y, double angle) const; + void draw_sprite_rotated(const Sprite &sprite, int x, int y, double angle) const; void clear_screen(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const; diff --git a/src/Sprite.cpp b/src/Sprite.cpp index 510adaa..bfc71ef 100644 --- a/src/Sprite.cpp +++ b/src/Sprite.cpp @@ -2,22 +2,13 @@ #include #include "Sprite.hpp" #include -#include -#include Sprite::Sprite(SDL_Renderer *renderer, const std::string &file, int width, int height) : width(width), height(height) { texture = IMG_LoadTexture(renderer, file.c_str()); - this->file = std::string(file); } Sprite::~Sprite() { - std::cout << "destruct " << file << std::endl; - - void *array[10]; - size_t size = backtrace(array, 10); - backtrace_symbols_fd(array, size, STDERR_FILENO); - SDL_DestroyTexture(texture); } diff --git a/src/Sprite.hpp b/src/Sprite.hpp index 2316d08..77b4334 100644 --- a/src/Sprite.hpp +++ b/src/Sprite.hpp @@ -9,11 +9,15 @@ public: SDL_Texture *texture; int width; int height; - std::string file; Sprite(SDL_Renderer *renderer, const std::string &file, int width, int height); ~Sprite(); + + Sprite(const Sprite&) = delete; + Sprite operator=(const Sprite&) = delete; + Sprite(Sprite&&) = delete; + Sprite operator=(Sprite&&) = delete; }; #endif