diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-10 16:21:05 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-10 16:21:05 +0100 |
commit | 7b8de90699aea153e73b5f2cee05c69b966b81be (patch) | |
tree | 123f8b71b59a933b2bfcffb9e43e5bea66086d8f | |
parent | 33cd5566909ac089cdf56db38a3d1daf0cb7dd10 (diff) |
implemented feedback wouter, improved animator. however if spritesheet aspect_ratio is not the same as the single frame then the scaling is wrong
-rw-r--r-- | src/crepe/api/Animator.cpp | 18 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 12 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 1 | ||||
-rw-r--r-- | src/crepe/facade/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 4 | ||||
-rw-r--r-- | src/crepe/facade/Texture.cpp (renamed from src/crepe/api/Texture.cpp) | 1 | ||||
-rw-r--r-- | src/crepe/facade/Texture.h (renamed from src/crepe/api/Texture.h) | 5 | ||||
-rw-r--r-- | src/crepe/system/AnimatorSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 5 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 16 |
11 files changed, 27 insertions, 41 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/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt index 4cc53bc..0598e16 100644 --- a/src/crepe/facade/CMakeLists.txt +++ b/src/crepe/facade/CMakeLists.txt @@ -1,5 +1,6 @@ target_sources(crepe PUBLIC Sound.cpp + Texture.cpp SoundContext.cpp SDLContext.cpp DB.cpp @@ -7,6 +8,7 @@ target_sources(crepe PUBLIC target_sources(crepe PUBLIC FILE_SET HEADERS FILES Sound.h + Texture.h SoundContext.h SDLContext.h DB.h diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index ac21d15..a92ec8b 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -19,12 +19,12 @@ #include "../api/Color.h" #include "../api/Config.h" #include "../api/Sprite.h" -#include "../api/Texture.h" #include "../util/Log.h" #include "manager/Manager.h" #include "manager/Mediator.h" #include "SDLContext.h" +#include "Texture.h" #include "types.h" using namespace crepe; @@ -273,7 +273,7 @@ void SDLContext::draw(const RenderContext & ctx) { .img_scale = ctx.scale, }); - cout << dstrect.w << " " << dstrect.h << " " << dstrect.x << " " << dstrect.y << endl; + cout << srcrect->w << " " << srcrect->h << " " << srcrect->x << " " << srcrect->y << endl; double angle = ctx.angle + data.angle_offset; this->set_color_texture(ctx.texture, ctx.sprite.data.color); diff --git a/src/crepe/api/Texture.cpp b/src/crepe/facade/Texture.cpp index b0863cb..7224cb8 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/facade/Texture.cpp @@ -2,7 +2,6 @@ #include "manager/Mediator.h" #include "facade/SDLContext.h" -#include "Asset.h" #include "Resource.h" #include "Texture.h" #include "types.h" diff --git a/src/crepe/api/Texture.h b/src/crepe/facade/Texture.h index c33d9e5..255e14b 100644 --- a/src/crepe/api/Texture.h +++ b/src/crepe/facade/Texture.h @@ -6,13 +6,14 @@ #include <SDL2/SDL_render.h> #include <memory> -#include "Asset.h" -#include "Resource.h" +#include "../Resource.h" + #include "types.h" namespace crepe { class Mediator; +class Asset; /** * \class Texture diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 549c35d..bb22b62 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -23,7 +23,7 @@ void AnimatorSystem::update() { int last_frame = ctx.row; - int cycle_end = (ctx.cycle_end == -1) ? a.max_rows : ctx.cycle_end; + int cycle_end = (ctx.cycle_end == -1) ? a.max_cell_size.x : ctx.cycle_end; int total_frames = cycle_end - ctx.cycle_start; int curr_frame = static_cast<int>(elapsed_time / frame_duration) % total_frames; diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index daf71c5..51340fb 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -10,9 +10,10 @@ #include "../api/Sprite.h" #include "../api/Transform.h" #include "../facade/SDLContext.h" +#include "../facade/Texture.h" #include "../manager/ComponentManager.h" -#include "api/Texture.h" -#include "manager/ResourceManager.h" +#include "../manager/ResourceManager.h" + #include "RenderSystem.h" using namespace crepe; diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index cfc5a84..44bd96a 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -1,5 +1,4 @@ #include "api/Asset.h" -#include "manager/ResourceManager.h" #include <crepe/Component.h> #include <crepe/api/Animator.h> #include <crepe/api/Camera.h> @@ -9,7 +8,6 @@ #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> #include <crepe/api/Sprite.h> -#include <crepe/api/Texture.h> #include <crepe/api/Transform.h> #include <crepe/manager/ComponentManager.h> #include <crepe/manager/Mediator.h> @@ -52,7 +50,7 @@ public: Color color(255, 255, 255, 255); - Asset img{"asset/texture/test_ap43.png"}; + Asset img{"asset/spritesheet/spritesheet_test.png"}; Sprite & test_sprite = game_object.add_component<Sprite>( img, Sprite::Data{ @@ -65,16 +63,8 @@ public: .position_offset = {0, 0}, }); - /* - - auto & anim = game_object.add_component<Animator>(test_sprite, 4, 4, - Animator::Data{ - .fps = 1, - .looping = false, - }); - anim.set_anim(2); - anim.active = false; - */ + auto & anim = game_object.add_component<Animator>(test_sprite,ivec2{32, 64}, uvec2{4,1}, Animator::Data{}); + anim.set_anim(0); auto & cam = game_object.add_component<Camera>(ivec2{1280, 720}, vec2{400, 400}, Camera::Data{ |