Eliminats mètodes sense callers: - Sprite::getRect() (DEAD-04) - Sprite::incX / incY (DEAD-05) - AnimatedSprite::getCurrentAnimationSize() (DEAD-07) - Surface::getSurfaceData() (DEAD-08) Sprite::update passa a ser virtual amb cos buit inline al header, en lloc de la definició a .cpp amb (void)delta_time; desapareix una línia de "parxejament" sense alterar la polimorfia (Player::update, heretat via AnimatedSprite/MovingSprite, continua fent override correctament). Això tanca DEAD-10 i PATCH-04 alhora. Els ctors per defecte Sprite()/MovingSprite() s'apunten com WONTFIX al document: són necessaris per a la cadena de construcció base d'Animated Sprite (que no delega explícitament al ctor parametritzat). Build + smoke 5s xvfb OK (exit 124). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
2.0 KiB
C++
53 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
class Surface;
|
|
|
|
class Sprite {
|
|
public:
|
|
Sprite();
|
|
Sprite(std::shared_ptr<Surface> surface, float x, float y, float w, float h);
|
|
Sprite(std::shared_ptr<Surface> surface, SDL_FRect rect);
|
|
explicit Sprite(std::shared_ptr<Surface> surface);
|
|
|
|
virtual ~Sprite() = default;
|
|
|
|
// Hook d'actualització per frame. Base buida (no hi ha Sprite pur a
|
|
// actualitzar); les subclasses mòbils/animades fan override.
|
|
virtual void update(float /*delta_time*/) {}
|
|
virtual void render();
|
|
// Renderitza substituint l'índex source_color per target_color (ús típic:
|
|
// la classe Text, que recolora glifs monocroms per paràmetre).
|
|
virtual void render(Uint8 source_color, Uint8 target_color);
|
|
virtual void clear();
|
|
|
|
[[nodiscard]] auto getX() const -> float { return pos_.x; }
|
|
[[nodiscard]] auto getY() const -> float { return pos_.y; }
|
|
[[nodiscard]] auto getWidth() const -> float { return pos_.w; }
|
|
[[nodiscard]] auto getHeight() const -> float { return pos_.h; }
|
|
[[nodiscard]] auto getPosition() const -> SDL_FRect { return pos_; }
|
|
[[nodiscard]] auto getClip() const -> SDL_FRect { return clip_; }
|
|
[[nodiscard]] auto getSurface() const -> std::shared_ptr<Surface> { return surface_; }
|
|
|
|
void setX(float x) { pos_.x = x; }
|
|
void setY(float y) { pos_.y = y; }
|
|
void setWidth(float w) { pos_.w = w; }
|
|
void setHeight(float h) { pos_.h = h; }
|
|
void setPosition(float x, float y);
|
|
void setPosition(SDL_FPoint p);
|
|
void setPosition(SDL_FRect r) { pos_ = r; }
|
|
|
|
void setClip(SDL_FRect rect) { clip_ = rect; }
|
|
void setClip(float x, float y, float w, float h) { clip_ = SDL_FRect{.x = x, .y = y, .w = w, .h = h}; }
|
|
void setSurface(std::shared_ptr<Surface> surface) { surface_ = std::move(surface); }
|
|
|
|
protected:
|
|
std::shared_ptr<Surface> surface_{nullptr};
|
|
SDL_FRect pos_{.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
|
|
SDL_FRect clip_{.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
|
|
};
|