aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-10 16:21:05 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-10 16:21:05 +0100
commit7b8de90699aea153e73b5f2cee05c69b966b81be (patch)
tree123f8b71b59a933b2bfcffb9e43e5bea66086d8f /src/crepe/api
parent33cd5566909ac089cdf56db38a3d1daf0cb7dd10 (diff)
implemented feedback wouter, improved animator. however if spritesheet aspect_ratio is not the same as the single frame then the scaling is wrong
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.cpp18
-rw-r--r--src/crepe/api/Animator.h12
-rw-r--r--src/crepe/api/CMakeLists.txt2
-rw-r--r--src/crepe/api/LoopManager.cpp1
-rw-r--r--src/crepe/api/Texture.cpp35
-rw-r--r--src/crepe/api/Texture.h71
6 files changed, 13 insertions, 126 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index ad1778d..4c72cc0 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -7,20 +7,18 @@
using namespace crepe;
-Animator::Animator(game_object_id_t id, Sprite & spritesheet, unsigned int pixel_frame_x,
- unsigned int pixel_frame_y, unsigned int max_row, unsigned int max_col,
- const Animator::Data & data)
+Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size,
+ const uvec2 & max_cell_size, const Animator::Data & data)
: Component(id),
spritesheet(spritesheet),
- max_rows(max_row),
- max_columns(max_col),
+ max_cell_size(max_cell_size),
data(data) {
dbg_trace();
- this->spritesheet.mask.h = this->max_columns * pixel_frame_y;
- this->spritesheet.mask.w /= this->max_rows * pixel_frame_x;
- this->spritesheet.mask.x = this->data.row * this->spritesheet.mask.w;
- this->spritesheet.mask.y = this->data.col * this->spritesheet.mask.h;
+ this->spritesheet.mask.w = single_frame_size.x;
+ this->spritesheet.mask.h = single_frame_size.y;
+ this->spritesheet.mask.x = 0;
+ this->spritesheet.mask.y = 0;
}
Animator::~Animator() { dbg_trace(); }
@@ -51,6 +49,6 @@ void Animator::set_anim(int col) {
void Animator::next_anim() {
Animator::Data & ctx = this->data;
- ctx.row = ctx.row++ % this->max_rows;
+ ctx.row = ctx.row++ % this->max_cell_size.x;
this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w;
}
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index 8ceddad..9a26bf0 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -82,16 +82,14 @@ public:
* This constructor sets up the Animator with the given parameters, and initializes the
* animation system.
*/
- Animator(game_object_id_t id, Sprite & spritesheet, unsigned int pixel_frame_x,
- unsigned int pixel_frame_y, unsigned int max_row, unsigned int max_col,
- const Animator::Data & data);
+ Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size,
+ const uvec2 & max_cell_size, const Animator::Data & data);
~Animator(); // dbg_trace
public:
- //! The maximum number of columns in the sprite sheet.
- const unsigned int max_columns;
- //! The maximum number of rows in the sprite sheet.
- const unsigned int max_rows;
+ //! The maximum number of rows and columns size
+ const uvec2 max_cell_size;
+
Animator::Data data;
private:
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index a163faf..718e497 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -6,7 +6,6 @@ target_sources(crepe PUBLIC
ParticleEmitter.cpp
Transform.cpp
Color.cpp
- Texture.cpp
Sprite.cpp
Config.cpp
Metadata.cpp
@@ -38,7 +37,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Vector2.h
Vector2.hpp
Color.h
- Texture.h
Scene.h
Metadata.h
Camera.h
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 044f096..88243c4 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -65,7 +65,6 @@ void LoopManager::setup() {
this->scene_manager.load_next_scene();
timer.start();
timer.set_fps(200);
- this->scene_manager.load_next_scene();
}
void LoopManager::render() {
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
deleted file mode 100644
index b0863cb..0000000
--- a/src/crepe/api/Texture.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "../util/Log.h"
-#include "manager/Mediator.h"
-#include "facade/SDLContext.h"
-
-#include "Asset.h"
-#include "Resource.h"
-#include "Texture.h"
-#include "types.h"
-
-using namespace crepe;
-using namespace std;
-
-Texture::Texture(const Asset & src, Mediator & mediator) : Resource(src, mediator){
- dbg_trace();
- SDLContext & ctx = mediator.sdl_context;
- this->texture = ctx.texture_from_path(src.get_path());
- this->size = ctx.get_size(*this);
- this->aspect_ratio = static_cast<float>(this->size.x) / this->size.y;
-}
-
-Texture::~Texture() {
- dbg_trace();
- this->texture.reset();
-}
-
-const ivec2 & Texture::get_size() const noexcept{
- return this->size;
-}
-const float & Texture::get_ratio() const noexcept{
- return this->aspect_ratio;
-}
-
-SDL_Texture * Texture::get_img() const noexcept{
- return this->texture.get();
-}
diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h
deleted file mode 100644
index c33d9e5..0000000
--- a/src/crepe/api/Texture.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#pragma once
-
-// FIXME: this header can't be included because this is an API header, and SDL2 development
-// headers won't be bundled with crepe. Why is this facade in the API namespace?
-
-#include <SDL2/SDL_render.h>
-#include <memory>
-
-#include "Asset.h"
-#include "Resource.h"
-#include "types.h"
-
-namespace crepe {
-
-class Mediator;
-
-/**
- * \class Texture
- * \brief Manages texture loading and properties.
- *
- * The Texture class is responsible for loading an image from a source and providing access to
- * its dimensions. Textures can be used for rendering.
- */
-class Texture : public Resource {
-
-public:
- /**
- * \brief Constructs a Texture from an Asset resource.
- * \param src Asset with texture data to load.
- * \param mediator use the SDLContext reference to load the image
- */
- Texture(const Asset & src, Mediator & mediator);
-
- /**
- * \brief Destroys the Texture instance
- */
- ~Texture();
-
- /**
- * \brief get width and height of image in pixels
- * \return pixel size width and height
- *
- */
- const ivec2 & get_size() const noexcept;
-
- /**
- * \brief aspect_ratio of image
- * \return ratio
- *
- */
- const float & get_ratio() const noexcept;
-
- /**
- * \brief get the image texture
- * \return SDL_Texture
- *
- */
- SDL_Texture * get_img() const noexcept;
-
-private:
- //! The texture of the class from the library
- std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture;
-
- // texture size in pixel
- ivec2 size;
-
- //! ratio of image
- float aspect_ratio;
-};
-
-} // namespace crepe