From ba713ba89127e3b4a24f204f67bccaa9c2972916 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Fri, 8 Nov 2024 18:04:36 +0100 Subject: Made it RAII --- src/crepe/facade/SDLContext.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/crepe/facade/SDLContext.h') diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 80b76dd..0a8dbcf 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "../api/Sprite.h" @@ -130,11 +131,19 @@ private: void camera(const Camera & camera); private: - //TODO: Make this RAII - //! sdl window - SDL_Window * game_window = nullptr; + struct WindowDeleter { + void operator()(SDL_Window * window) { SDL_DestroyWindow(window); } + }; + + struct RendererDeleter { + void operator()(SDL_Renderer * renderer) { SDL_DestroyRenderer(renderer); } + }; + + //! sdl Window + std::unique_ptr game_window; + //! renderer for the crepe engine - SDL_Renderer * game_renderer = nullptr; + std::unique_ptr game_renderer; //! viewport for the camera window SDL_Rect viewport = {0, 0, 640, 480}; -- cgit v1.2.3