aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-08 19:12:37 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-08 19:12:37 +0100
commitac8a58a2a16118ea4c40fcc533c3420edde45122 (patch)
treef93b591f164c051003788c7edaa55fa9dd50cd82 /src/crepe/api
parentba713ba89127e3b4a24f204f67bccaa9c2972916 (diff)
fixed all the RAII
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.h14
-rw-r--r--src/crepe/api/Texture.cpp2
-rw-r--r--src/crepe/api/Texture.h9
3 files changed, 4 insertions, 21 deletions
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index 42ce957..ae0a896 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -39,23 +39,11 @@ public:
Animator(uint32_t id, Sprite & spritesheet, int row, int col,
int col_animate);
- /**
- * \brief Destroys the Animator object and cleans up any resources.
- *
- * This destructor will handle any necessary cleanup when the Animator component is no longer needed.
- */
- ~Animator();
- //! Deleted copy constructor to prevent copying of the Animator instance.
+ ~Animator();
Animator(const Animator &) = delete;
-
- //! Deleted move constructor to prevent moving of the Animator instance.
Animator(Animator &&) = delete;
-
- //! Deleted copy assignment operator to prevent copying the Animator instance.
Animator & operator=(const Animator &) = delete;
-
- //! Deleted move assignment operator to prevent moving the Animator instance.
Animator & operator=(Animator &&) = delete;
private:
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
index 1eac655..c31f704 100644
--- a/src/crepe/api/Texture.cpp
+++ b/src/crepe/api/Texture.cpp
@@ -26,7 +26,7 @@ Texture::~Texture() {
void Texture::load(unique_ptr<Asset> res) {
SDLContext & ctx = SDLContext::get_instance();
- this->texture.reset(ctx.texture_from_path(res->canonical()));
+ this->texture = std::move(ctx.texture_from_path(res->canonical()));
}
int Texture::get_width() const{
diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h
index 0cacfe5..9bda5fe 100644
--- a/src/crepe/api/Texture.h
+++ b/src/crepe/api/Texture.h
@@ -5,16 +5,14 @@
// API namespace?
#include <SDL2/SDL_render.h>
+#include <functional>
#include <memory>
#include "Asset.h"
namespace crepe {
-//! Forward declaration of SDLContext class.
class SDLContext;
-
-//! Forward declaration of Animator class.
class Animator;
/**
@@ -64,11 +62,8 @@ private:
void load(std::unique_ptr<Asset> res);
private:
- struct TextureDeleter{
- void operator()(SDL_Texture* texture) const { SDL_DestroyTexture(texture);}
- };
//! The texture of the class from the library
- std::unique_ptr<SDL_Texture, TextureDeleter> texture;
+ std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture;
//! Grants SDLContext access to private members.
friend class SDLContext;