aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-08 20:21:36 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-08 20:21:36 +0100
commit506de66aaecc9b82415dde46058b848e46bc7258 (patch)
treea3f2427b0882d07f2d960b7214170533ad241830 /src/crepe/facade
parent7817c85e84560933a33ad86ec3f9ca3d48d327d5 (diff)
nitpicks (merge #27)
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp33
-rw-r--r--src/crepe/facade/SDLContext.h95
2 files changed, 67 insertions, 61 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 5b9ca71..c4c96e2 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -46,11 +46,11 @@ SDLContext::SDLContext() {
<< SDL_GetError() << std::endl;
return;
}
- this->game_window = {tmp_window, [](SDL_Window* window) { SDL_DestroyWindow(window); }};
+ this->game_window
+ = {tmp_window, [](SDL_Window * window) { SDL_DestroyWindow(window); }};
-
- SDL_Renderer* tmp_renderer = SDL_CreateRenderer(this->game_window.get(), -1,
- SDL_RENDERER_ACCELERATED);
+ SDL_Renderer * tmp_renderer = SDL_CreateRenderer(
+ this->game_window.get(), -1, SDL_RENDERER_ACCELERATED);
if (!tmp_renderer) {
// FIXME: throw exception
std::cerr << "Renderer could not be created! SDL_Error: "
@@ -59,7 +59,9 @@ SDLContext::SDLContext() {
return;
}
- this->game_renderer = {tmp_renderer, [](SDL_Renderer* renderer) { SDL_DestroyRenderer(renderer); }};
+ this->game_renderer = {tmp_renderer, [](SDL_Renderer * renderer) {
+ SDL_DestroyRenderer(renderer);
+ }};
int img_flags = IMG_INIT_PNG;
if (!(IMG_Init(img_flags) & img_flags)) {
@@ -150,27 +152,32 @@ void SDLContext::camera(const Camera & cam) {
cam.bg_color.g, cam.bg_color.b, cam.bg_color.a);
}
-const uint64_t SDLContext::get_ticks() const { return SDL_GetTicks64(); }
+uint64_t SDLContext::get_ticks() const { return SDL_GetTicks64(); }
-std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> SDLContext::texture_from_path(const std::string & path) {
+std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>>
+SDLContext::texture_from_path(const std::string & path) {
SDL_Surface * tmp = IMG_Load(path.c_str());
- if (tmp == nullptr) {
+ if (tmp == nullptr) {
throw Exception("surface cannot be load from %s", path.c_str());
}
- std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>> img_surface;
- img_surface = {tmp, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }};
+ std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>>
+ img_surface;
+ img_surface
+ = {tmp, [](SDL_Surface * surface) { SDL_FreeSurface(surface); }};
SDL_Texture * tmp_texture = SDL_CreateTextureFromSurface(
this->game_renderer.get(), img_surface.get());
- if ( tmp_texture == nullptr) {
+ if (tmp_texture == nullptr) {
throw Exception("Texture cannot be load from %s", path.c_str());
}
- std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> img_texture;
- img_texture = {tmp_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }};
+ std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>>
+ img_texture;
+ img_texture = {tmp_texture,
+ [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }};
return img_texture;
}
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 93166f2..e358c21 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -11,13 +11,15 @@
#include "../api/Transform.h"
#include "api/Camera.h"
-//FIXME: this needs to be removed
+// FIXME: this needs to be removed
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
namespace crepe {
-//TODO: Wouter will fix this. cause user cannot this at the moment
+// TODO: SDL_Keycode is defined in a header not distributed with crepe, which
+// means this typedef is unusable when crepe is packaged. Wouter will fix this
+// later.
typedef SDL_Keycode CREPE_KEYCODES;
class Texture;
@@ -34,9 +36,9 @@ class SDLContext {
public:
/**
- * \brief Gets the singleton instance of SDLContext.
- * \return Reference to the SDLContext instance.
- */
+ * \brief Gets the singleton instance of SDLContext.
+ * \return Reference to the SDLContext instance.
+ */
static SDLContext & get_instance();
SDLContext(const SDLContext &) = delete;
@@ -48,9 +50,9 @@ private:
//! will only use handle_events
friend class LoopManager;
/**
- * \brief Handles SDL events such as window close and input.
- * \param running Reference to a boolean flag that controls the main loop.
- */
+ * \brief Handles SDL events such as window close and input.
+ * \param running Reference to a boolean flag that controls the main loop.
+ */
void handle_events(bool & running);
private:
@@ -58,22 +60,22 @@ private:
friend class AnimatorSystem;
/**
- * \brief Gets the current SDL ticks since the program started.
- * \return Current ticks in milliseconds as a constant uint64_t.
- */
- const uint64_t get_ticks() const;
+ * \brief Gets the current SDL ticks since the program started.
+ * \return Current ticks in milliseconds as a constant uint64_t.
+ */
+ uint64_t get_ticks() const;
private:
/**
- * \brief Constructs an SDLContext instance.
- * Initializes SDL, creates a window and renderer.
- */
+ * \brief Constructs an SDLContext instance.
+ * Initializes SDL, creates a window and renderer.
+ */
SDLContext();
/**
- * \brief Destroys the SDLContext instance.
- * Cleans up SDL resources, including the window and renderer.
- */
+ * \brief Destroys the SDLContext instance.
+ * Cleans up SDL resources, including the window and renderer.
+ */
~SDLContext();
private:
@@ -84,23 +86,24 @@ private:
friend class Animator;
/**
- * \brief Loads a texture from a file path.
- * \param path Path to the image file.
- * \return Pointer to the created SDL_Texture.
- */
- std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture_from_path(const std::string & path);
+ * \brief Loads a texture from a file path.
+ * \param path Path to the image file.
+ * \return Pointer to the created SDL_Texture.
+ */
+ std::unique_ptr<SDL_Texture, std::function<void(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.
- */
+ * \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;
/**
- * \brief Gets the height of a texture.
- * \param texture Reference to the Texture object.
- * \return Height of the texture as an integer.
- */
+ * \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;
private:
@@ -108,37 +111,33 @@ private:
friend class RenderSystem;
/**
- * \brief Draws a sprite to the screen using the specified transform and camera.
- * \param sprite Reference to the Sprite to draw.
- * \param transform Reference to the Transform for positioning.
- * \param camera Reference to the Camera for view adjustments.
- */
+ * \brief Draws a sprite to the screen using the specified transform and camera.
+ * \param sprite Reference to the Sprite to draw.
+ * \param transform Reference to the Transform for positioning.
+ * \param camera Reference to the Camera for view adjustments.
+ */
void draw(const Sprite & sprite, const Transform & transform,
const Camera & camera);
- /**
- * \brief Clears the screen, preparing for a new frame.
- */
+ //! Clears the screen, preparing for a new frame.
void clear_screen();
- /**
- * \brief Presents the rendered frame to the screen.
- */
+ //! Presents the rendered frame to the screen.
void present_screen();
/**
- * \brief Sets the current camera for rendering.
- * \param camera Reference to the Camera object.
- */
+ * \brief Sets the current camera for rendering.
+ * \param camera Reference to the Camera object.
+ */
void camera(const Camera & camera);
private:
-
//! sdl Window
- std::unique_ptr<SDL_Window, std::function<void(SDL_Window*) >> game_window;
+ std::unique_ptr<SDL_Window, std::function<void(SDL_Window *)>> game_window;
//! renderer for the crepe engine
- std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer*)>> game_renderer;
+ std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>>
+ game_renderer;
//! viewport for the camera window
SDL_Rect viewport = {0, 0, 640, 480};