aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Animator.cpp2
-rw-r--r--src/crepe/api/Animator.h11
-rw-r--r--src/crepe/api/Sprite.h9
-rw-r--r--src/crepe/facade/SDLContext.cpp7
-rw-r--r--src/crepe/manager/Mediator.h2
-rw-r--r--src/crepe/system/AISystem.cpp3
6 files changed, 23 insertions, 11 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 4c72cc0..123f0e7 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -19,6 +19,8 @@ Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & sing
this->spritesheet.mask.h = single_frame_size.y;
this->spritesheet.mask.x = 0;
this->spritesheet.mask.y = 0;
+
+ this->spritesheet.aspect_ratio = static_cast<float>(single_frame_size.x) / single_frame_size.y;
}
Animator::~Animator() { dbg_trace(); }
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index 9a26bf0..09f0134 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -75,8 +75,9 @@ public:
*
* \param id The unique identifier for the component, typically assigned automatically.
* \param spritesheet the reference to the spritesheet
- * \param max_row maximum of rows inside the given spritesheet
- * \param max_col maximum of columns inside the given spritesheet
+ * \param single_frame_size the width and height in pixels of a single frame inside the
+ * spritesheet
+ * \param max_cell_size the max rows and columns inside the given spritesheet
* \param data extra animation data for more control
*
* This constructor sets up the Animator with the given parameters, and initializes the
@@ -87,15 +88,15 @@ public:
~Animator(); // dbg_trace
public:
- //! The maximum number of rows and columns size
- const uvec2 max_cell_size;
-
Animator::Data data;
private:
//! A reference to the Sprite sheet containing.
Sprite & spritesheet;
+ //! The maximum number of rows and columns size
+ const uvec2 max_cell_size;
+
//! Uses the spritesheet
friend AnimatorSystem;
};
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 7e9812d..14a873b 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -92,6 +92,15 @@ private:
//! Reads the all the variables plus the mask
friend class AnimatorSystem;
+
+ /**
+ * \aspect_ratio the ratio of the sprite image
+ *
+ * - this value will only be set by the \c Animator component for the ratio of the Animation
+ * - if \c Animator component is not added it will not use this ratio (because 0) and will use aspect_ratio of the Asset.
+ */
+ float aspect_ratio = 0;
+
struct Rect {
int w = 0;
int h = 0;
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index a0d7f04..0566ecf 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -233,12 +233,14 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const {
const Sprite::Data & data = ctx.sprite.data;
+ float aspect_ratio = (ctx.sprite.aspect_ratio == 0) ? ctx.texture.get_ratio() : ctx.sprite.aspect_ratio;
+
vec2 size = data.size;
if (data.size.x == 0 && data.size.y != 0) {
- size.x = data.size.y * ctx.texture.get_ratio();
+ size.x = data.size.y * aspect_ratio;
}
if (data.size.y == 0 && data.size.x != 0) {
- size.y = data.size.x / ctx.texture.get_ratio();
+ size.y = data.size.x / aspect_ratio;
}
const CameraValues & cam = ctx.cam;
@@ -273,7 +275,6 @@ void SDLContext::draw(const RenderContext & ctx) {
.img_scale = ctx.scale,
});
- 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/manager/Mediator.h b/src/crepe/manager/Mediator.h
index d5f7e00..628154a 100644
--- a/src/crepe/manager/Mediator.h
+++ b/src/crepe/manager/Mediator.h
@@ -4,8 +4,6 @@
// TODO: remove these singletons:
#include "EventManager.h"
-#include "SaveManager.h"
-#include "api/LoopTimer.h"
namespace crepe {
diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp
index e2e36a5..7f04432 100644
--- a/src/crepe/system/AISystem.cpp
+++ b/src/crepe/system/AISystem.cpp
@@ -12,10 +12,11 @@ using namespace crepe;
void AISystem::update() {
const Mediator & mediator = this->mediator;
ComponentManager & mgr = mediator.component_manager;
+ LoopTimer & timer = mediator.timer;
RefVector<AI> ai_components = mgr.get_components_by_type<AI>();
//TODO: Use fixed loop dt (this is not available at master at the moment)
- double dt = LoopTimer::get_instance().get_delta_time();
+ double dt = timer.get_delta_time();
// Loop through all AI components
for (AI & ai : ai_components) {