aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
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/api
parent7817c85e84560933a33ad86ec3f9ca3d48d327d5 (diff)
nitpicks (merge #27)
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.cpp4
-rw-r--r--src/crepe/api/Animator.h6
-rw-r--r--src/crepe/api/Camera.cpp9
-rw-r--r--src/crepe/api/Camera.h42
-rw-r--r--src/crepe/api/Color.h4
-rw-r--r--src/crepe/api/Sprite.cpp4
-rw-r--r--src/crepe/api/Sprite.h17
-rw-r--r--src/crepe/api/Texture.cpp4
-rw-r--r--src/crepe/api/Texture.h76
9 files changed, 80 insertions, 86 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 4b4d4be..8b396af 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -3,14 +3,14 @@
#include "util/log.h"
+#include "Animator.h"
#include "Component.h"
#include "Sprite.h"
-#include "Animator.h"
using namespace crepe;
Animator::Animator(uint32_t id, Sprite & ss, int row, int col, int col_animator)
- : Component(id), spritesheet(ss), row(row), col(col){
+ : Component(id), spritesheet(ss), row(row), col(col) {
dbg_trace();
animator_rect = spritesheet.sprite_rect;
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index ae0a896..def0240 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -9,7 +9,6 @@ namespace crepe {
class AnimatorSystem;
class SDLContext;
-
/**
* \brief The Animator component is used to animate sprites by managing the movement
* and frame changes within a sprite sheet.
@@ -39,8 +38,7 @@ public:
Animator(uint32_t id, Sprite & spritesheet, int row, int col,
int col_animate);
-
- ~Animator();
+ ~Animator(); // dbg_trace
Animator(const Animator &) = delete;
Animator(Animator &&) = delete;
Animator & operator=(const Animator &) = delete;
@@ -71,7 +69,7 @@ private:
//! AnimatorSystem adjust the private member parameters of Animator;
friend class AnimatorSystem;
- //! SDLContext reads the Animator member var's
+ //! SDLContext reads the Animator member var's
friend class SDLContext;
};
} // namespace crepe
diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp
index dbbfb32..820a6a8 100644
--- a/src/crepe/api/Camera.cpp
+++ b/src/crepe/api/Camera.cpp
@@ -3,15 +3,14 @@
#include "util/log.h"
-#include "Component.h"
-#include "Color.h"
#include "Camera.h"
+#include "Color.h"
+#include "Component.h"
using namespace crepe;
-Camera::Camera(uint32_t id, const Color & color)
- : Component(id), bg_color(color), aspect_width(640), aspect_height(480),
- zoom(1), x(0), y(0) {
+Camera::Camera(uint32_t id, const Color & bg_color)
+ : Component(id), bg_color(bg_color) {
dbg_trace();
}
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h
index 708a523..ba3a9ef 100644
--- a/src/crepe/api/Camera.h
+++ b/src/crepe/api/Camera.h
@@ -19,41 +19,37 @@ class Camera : public Component {
public:
/**
- * \brief Constructs a Camera with the specified ID and background color.
- * \param id Unique identifier for the camera component.
- * \param bg_color Background color for the camera view.
- */
+ * \brief Constructs a Camera with the specified ID and background color.
+ * \param id Unique identifier for the camera component.
+ * \param bg_color Background color for the camera view.
+ */
Camera(uint32_t id, const Color & bg_color);
-
- /**
- * \brief Destroys the Camera instance.
- */
- ~Camera();
+ ~Camera(); // dbg_trace only
public:
- //! \brief Background color of the camera view.
+ //! Background color of the camera view.
Color bg_color;
- //! \brief Aspect ratio height for the camera.
- double aspect_height;
+ //! Aspect ratio height for the camera.
+ double aspect_height = 480;
- //! \brief Aspect ratio width for the camera.
- double aspect_width;
+ //! Aspect ratio width for the camera.
+ double aspect_width = 640;
- //! \brief X-coordinate of the camera position.
- double x;
+ //! X-coordinate of the camera position.
+ double x = 0.0;
- //! \brief Y-coordinate of the camera position.
- double y;
+ //! Y-coordinate of the camera position.
+ double y = 0.0;
- //! \brief Zoom level of the camera view.
- double zoom;
+ //! Zoom level of the camera view.
+ double zoom = 1.0;
public:
/**
- * \brief Gets the maximum number of camera instances allowed.
- * \return Maximum instance count as an integer.
- */
+ * \brief Gets the maximum number of camera instances allowed.
+ * \return Maximum instance count as an integer.
+ */
virtual int get_instances_max() const { return 10; }
};
} // namespace crepe
diff --git a/src/crepe/api/Color.h b/src/crepe/api/Color.h
index 4ebe3a3..aa47bf4 100644
--- a/src/crepe/api/Color.h
+++ b/src/crepe/api/Color.h
@@ -2,8 +2,9 @@
#include <cstdint>
-namespace crepe{
+namespace crepe {
+// TODO: make Color a struct w/o constructors/destructors
class Color {
// FIXME: can't these colors be defined as a `static constexpr const Color`
@@ -21,6 +22,7 @@ public:
static const Color & get_black();
private:
+ // TODO: why are these private!?
uint8_t r;
uint8_t g;
uint8_t b;
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
index db96c32..f9cd761 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -1,11 +1,11 @@
#include <memory>
-#include "facade/SDLContext.h"
#include "../util/log.h"
+#include "facade/SDLContext.h"
#include "Component.h"
-#include "Texture.h"
#include "Sprite.h"
+#include "Texture.h"
using namespace std;
using namespace crepe;
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 1db32d7..deb3f93 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -4,22 +4,21 @@
#include <memory>
#include "Color.h"
-#include "Texture.h"
#include "Component.h"
-
+#include "Texture.h"
namespace crepe {
struct Rect {
int w = 0;
- int h = 0;
- int x = 0;
- int y = 0;
+ int h = 0;
+ int x = 0;
+ int y = 0;
};
struct FlipSettings {
- bool flip_x = false;
- bool flip_y = false;
+ bool flip_x = false;
+ bool flip_y = false;
};
class SDLContext;
@@ -35,7 +34,6 @@ class AnimatorSystem;
class Sprite : public Component {
public:
-
// TODO: Loek comment in github #27 will be looked another time
// about shared_ptr Texture
/**
@@ -53,10 +51,9 @@ public:
*/
~Sprite();
-
//! Texture used for the sprite
const std::shared_ptr<Texture> sprite_image;
- //! Color tint of the sprite
+ //! Color tint of the sprite
Color color;
//! Flip settings for the sprite
FlipSettings flip;
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
index c31f704..5ebd23d 100644
--- a/src/crepe/api/Texture.cpp
+++ b/src/crepe/api/Texture.cpp
@@ -29,11 +29,11 @@ void Texture::load(unique_ptr<Asset> res) {
this->texture = std::move(ctx.texture_from_path(res->canonical()));
}
-int Texture::get_width() const{
+int Texture::get_width() const {
if (this->texture == nullptr) return 0;
return SDLContext::get_instance().get_width(*this);
}
-int Texture::get_height() const{
+int Texture::get_height() const {
if (this->texture == nullptr) return 0;
return SDLContext::get_instance().get_width(*this);
}
diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h
index 9bda5fe..b89bc17 100644
--- a/src/crepe/api/Texture.h
+++ b/src/crepe/api/Texture.h
@@ -25,51 +25,53 @@ class Animator;
class Texture {
public:
- /**
- * \brief Constructs a Texture from a file path.
- * \param src Path to the image file to be loaded as a texture.
- */
- Texture(const char * src);
-
- /**
- * \brief Constructs a Texture from an Asset resource.
- * \param res Unique pointer to an Asset resource containing texture data.
- */
- Texture(std::unique_ptr<Asset> res);
-
- /**
- * \brief Destroys the Texture instance, freeing associated resources.
- */
- ~Texture();
-
- /**
- * \brief Gets the width of the texture.
- * \return Width of the texture in pixels.
- */
- int get_width() const;
-
- /**
- * \brief Gets the height of the texture.
- * \return Height of the texture in pixels.
- */
- int get_height() const;
+ /**
+ * \brief Constructs a Texture from a file path.
+ * \param src Path to the image file to be loaded as a texture.
+ */
+ Texture(const char * src);
+
+ /**
+ * \brief Constructs a Texture from an Asset resource.
+ * \param res Unique pointer to an Asset resource containing texture data.
+ */
+ Texture(std::unique_ptr<Asset> res);
+
+ /**
+ * \brief Destroys the Texture instance, freeing associated resources.
+ */
+ ~Texture();
+ // FIXME: this constructor shouldn't be necessary because this class doesn't
+ // manage memory
+
+ /**
+ * \brief Gets the width of the texture.
+ * \return Width of the texture in pixels.
+ */
+ int get_width() const;
+
+ /**
+ * \brief Gets the height of the texture.
+ * \return Height of the texture in pixels.
+ */
+ int get_height() const;
private:
- /**
- * \brief Loads the texture from an Asset resource.
- * \param res Unique pointer to an Asset resource to load the texture from.
- */
- void load(std::unique_ptr<Asset> res);
+ /**
+ * \brief Loads the texture from an Asset resource.
+ * \param res Unique pointer to an Asset resource to load the texture from.
+ */
+ void load(std::unique_ptr<Asset> res);
private:
//! The texture of the class from the library
std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture;
- //! Grants SDLContext access to private members.
- friend class SDLContext;
+ //! Grants SDLContext access to private members.
+ friend class SDLContext;
- //! Grants Animator access to private members.
- friend class Animator;
+ //! Grants Animator access to private members.
+ friend class Animator;
};
} // namespace crepe