aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp35
-rw-r--r--src/crepe/facade/SDLContext.h22
2 files changed, 15 insertions, 42 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 0d42a4c..7317a77 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -109,7 +109,7 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const {
};
}
SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam,
- const double & img_scale) const {
+ const vec2 & cam_pos, const double & img_scale) const {
int width = sprite.height * sprite.aspect_ratio;
int height = sprite.height;
@@ -118,38 +118,25 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, const
height *= img_scale * cam.zoom;
return SDL_Rect{
- .x = static_cast<int>((pos.x - cam.pos.x + (cam.viewport.x / 2) - width / 2)),
- .y = static_cast<int>((pos.y - cam.pos.y + (cam.viewport.y / 2) - height / 2)),
+ .x = static_cast<int>((pos.x - cam_pos.x + (cam.viewport.x / 2) - width / 2)),
+ .y = static_cast<int>((pos.y - cam_pos.y + (cam.viewport.y / 2) - height / 2)),
.w = width,
.h = height,
};
}
-void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle,
- const double & img_scale, const Camera & cam) {
+void SDLContext::draw(const RenderCtx & ctx) {
SDL_RendererFlip render_flip
- = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x)
- | (SDL_FLIP_VERTICAL * sprite.flip.flip_y));
+ = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * ctx.sprite.flip.flip_x)
+ | (SDL_FLIP_VERTICAL * ctx.sprite.flip.flip_y));
- SDL_Rect srcrect = this->get_src_rect(sprite);
- SDL_Rect dstrect = this->get_dst_rect(sprite, pos, cam, img_scale);
+ SDL_Rect srcrect = this->get_src_rect(ctx.sprite);
+ SDL_Rect dstrect
+ = this->get_dst_rect(ctx.sprite, ctx.pos, ctx.cam, ctx.cam_pos, ctx.scale);
- SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect,
- &dstrect, angle, NULL, render_flip);
-}
-
-void SDLContext::draw(const Sprite & sprite, const Transform & transform, const Camera & cam) {
-
- SDL_RendererFlip render_flip
- = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x)
- | (SDL_FLIP_VERTICAL * sprite.flip.flip_y));
-
- SDL_Rect srcrect = this->get_src_rect(sprite);
- SDL_Rect dstrect = this->get_dst_rect(sprite, transform.position, cam, transform.scale);
-
- SDL_RenderCopyEx(this->game_renderer.get(), sprite.sprite_image.texture.get(), &srcrect,
- &dstrect, transform.rotation, NULL, render_flip);
+ SDL_RenderCopyEx(this->game_renderer.get(), ctx.sprite.sprite_image.texture.get(),
+ &srcrect, &dstrect, ctx.angle, NULL, render_flip);
}
void SDLContext::set_camera(const Camera & cam) {
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index 35d667d..7907a0f 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -11,7 +11,6 @@
#include "../api/Camera.h"
#include "../api/Sprite.h"
-#include "../api/Transform.h"
#include "types.h"
@@ -115,23 +114,9 @@ private:
/**
* \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 cam camera of the current scene
+ * \param RenderCtx Reference to rendering data to draw
*/
- void draw(const Sprite & sprite, const Transform & transform, const Camera & cam);
-
- /**
- * \brief Draws a particle to the screen using the specified parameters
- *
- * \param sprite Referenceto the sprite to draw
- * \param pos particle position in world units
- * \param angle particle angle in degrees
- * \param img_scale scalar multiplier to increase image size
- * \param cam camera of the current scene
- */
- void draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle,
- const double & img_scale, const Camera & cam);
+ void draw(const RenderCtx & ctx);
//! Clears the screen, preparing for a new frame.
void clear_screen();
@@ -160,10 +145,11 @@ private:
* \param sprite Reference to the sprite to calculate rectangle
* \param pos the pos in world units
* \param cam the camera of the current scene
+ * \param cam_pos the current postion of the camera
* \param img_scale the image multiplier for increasing img size
* \return sdl rectangle to draw a dst image to draw on the screen
*/
- SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam,
+ SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam, const vec2 & cam_pos,
const double & img_scale) const;
private: