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>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "core/rendering/sprite/moving_sprite.hpp"
|
|
#include "core/resources/resource_types.hpp"
|
|
|
|
class AnimatedSprite : public MovingSprite {
|
|
public:
|
|
struct AnimationData {
|
|
std::string name;
|
|
std::vector<SDL_FRect> frames;
|
|
std::vector<float> speeds;
|
|
int loop_from{-1};
|
|
bool completed{false};
|
|
int current_frame{0};
|
|
float accumulated_time{0.0F};
|
|
};
|
|
|
|
explicit AnimatedSprite(const AnimationResource& cached_data);
|
|
~AnimatedSprite() override = default;
|
|
|
|
void update(float delta_time) override;
|
|
|
|
auto animationIsCompleted() -> bool;
|
|
|
|
void setCurrentAnimation(const std::string& name = "default");
|
|
void setCurrentAnimation(int index = 0);
|
|
void resetAnimation();
|
|
void setCurrentAnimationFrame(int num);
|
|
void animate(float delta_time);
|
|
|
|
private:
|
|
void buildNameIndex();
|
|
|
|
std::vector<AnimationData> animations_;
|
|
std::unordered_map<std::string, int> animation_index_;
|
|
int current_animation_{0};
|
|
};
|