diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-08 18:04:36 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-08 18:04:36 +0100 |
commit | ba713ba89127e3b4a24f204f67bccaa9c2972916 (patch) | |
tree | 1a1c501ac96ffa80d72f93596098b462a798600a /src/crepe/facade/SDLContext.h | |
parent | 91a277c69fd5f8ba814adc1006a49c7415ff65be (diff) |
Made it RAII
Diffstat (limited to 'src/crepe/facade/SDLContext.h')
-rw-r--r-- | src/crepe/facade/SDLContext.h | 17 |
1 files changed, 13 insertions, 4 deletions
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 <SDL2/SDL_keycode.h> #include <SDL2/SDL_render.h> #include <SDL2/SDL_video.h> +#include <memory> #include <string> #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<SDL_Window, WindowDeleter> game_window; + //! renderer for the crepe engine - SDL_Renderer * game_renderer = nullptr; + std::unique_ptr<SDL_Renderer, RendererDeleter> game_renderer; //! viewport for the camera window SDL_Rect viewport = {0, 0, 640, 480}; |