aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp17
-rw-r--r--src/crepe/facade/SDLContext.h49
2 files changed, 26 insertions, 40 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 9a2d15a..cedb7b8 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -7,6 +7,7 @@
#include <cmath>
#include <cstddef>
#include <iostream>
+#include <string>
#include "../api/Sprite.h"
#include "../api/Texture.h"
@@ -98,13 +99,15 @@ void SDLContext::handle_events(bool & running) {
*/
}
-void SDLContext::clear_screen() const { SDL_RenderClear(this->game_renderer); }
-void SDLContext::present_screen() const { SDL_RenderPresent(this->game_renderer); }
+void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer); }
+void SDLContext::present_screen() {
+ SDL_RenderPresent(this->game_renderer);
+}
void SDLContext::draw(const Sprite & sprite, const Transform & transform,
- const Camera & cam) const {
+ const Camera & cam) {
- static SDL_RendererFlip render_flip
+ SDL_RendererFlip render_flip
= (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x)
| (SDL_FLIP_VERTICAL * sprite.flip.flip_y));
@@ -147,10 +150,10 @@ void SDLContext::camera(const Camera & cam) {
const uint64_t SDLContext::get_ticks() const { return SDL_GetTicks64(); }
-SDL_Texture * SDLContext::texture_from_path(const char * path) const {
- dbg_trace();
+//TODO: make this RAII
+SDL_Texture * SDLContext::texture_from_path(const std::string & path) {
- SDL_Surface * tmp = IMG_Load(path);
+ SDL_Surface * tmp = IMG_Load(path.c_str());
if (!tmp) {
std::cerr << "Error surface " << IMG_GetError << std::endl;
}
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 3396697..80b76dd 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -3,18 +3,18 @@
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_video.h>
+#include <string>
#include "../api/Sprite.h"
#include "../api/Transform.h"
#include "api/Camera.h"
-typedef SDL_Keycode CREPE_KEYCODES;
-
//FIXME: this needs to be removed
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
namespace crepe {
+typedef SDL_Keycode CREPE_KEYCODES;
class Texture;
class LoopManager;
@@ -35,29 +35,13 @@ public:
*/
static SDLContext & get_instance();
- /**
- * \brief Deleted copy constructor.
- */
SDLContext(const SDLContext &) = delete;
-
- /**
- * \brief Deleted move constructor.
- */
SDLContext(SDLContext &&) = delete;
-
- /**
- * \brief Deleted copy assignment operator.
- * \return Reference to the SDLContext instance.
- */
SDLContext & operator=(const SDLContext &) = delete;
-
- /**
- * \brief Deleted move assignment operator.
- * \return Reference to the SDLContext instance.
- */
SDLContext & operator=(SDLContext &&) = delete;
private:
+ //! will only use handle_events
friend class LoopManager;
/**
* \brief Handles SDL events such as window close and input.
@@ -65,8 +49,8 @@ private:
*/
void handle_events(bool & running);
-
private:
+ //! Will only use get_ticks
friend class AnimatorSystem;
/**
@@ -75,7 +59,6 @@ private:
*/
const uint64_t get_ticks() const;
-
private:
/**
* \brief Constructs an SDLContext instance.
@@ -87,13 +70,13 @@ private:
* \brief Destroys the SDLContext instance.
* Cleans up SDL resources, including the window and renderer.
*/
- virtual ~SDLContext();
-
-
+ ~SDLContext();
private:
-
+ //! Will use the funtions: texture_from_path, get_width,get_height.
friend class Texture;
+
+ //! Will use the funtions: texture_from_path, get_width,get_height.
friend class Animator;
/**
@@ -101,25 +84,24 @@ private:
* \param path Path to the image file.
* \return Pointer to the created SDL_Texture.
*/
- SDL_Texture * texture_from_path(const char * path) const;
+ SDL_Texture * texture_from_path(const std::string & path);
/**
* \brief Gets the width of a texture.
* \param texture Reference to the Texture object.
* \return Width of the texture as an integer.
*/
- int get_width(const Texture & ) const ;
+ int get_width(const Texture &) const;
/**
* \brief Gets the height of a texture.
* \param texture Reference to the Texture object.
* \return Height of the texture as an integer.
*/
- int get_height(const Texture &) const ;
-
+ int get_height(const Texture &) const;
private:
-
+ //! Will use draw,clear_screen, present_screen, camera.
friend class RenderSystem;
/**
@@ -129,17 +111,17 @@ private:
* \param camera Reference to the Camera for view adjustments.
*/
void draw(const Sprite & sprite, const Transform & transform,
- const Camera & camera) const;
+ const Camera & camera);
/**
* \brief Clears the screen, preparing for a new frame.
*/
- void clear_screen() const ;
+ void clear_screen();
/**
* \brief Presents the rendered frame to the screen.
*/
- void present_screen() const ;
+ void present_screen();
/**
* \brief Sets the current camera for rendering.
@@ -148,6 +130,7 @@ private:
void camera(const Camera & camera);
private:
+ //TODO: Make this RAII
//! sdl window
SDL_Window * game_window = nullptr;
//! renderer for the crepe engine