| 12 | inline constexpr float AnimationSpeedUnit = AnimationFPS * AnimationDivisor; |
| 13 | |
| 14 | template <Concepts::Drawable T> class Animation { |
| 15 | T _drawable; |
| 16 | double _frameTime; |
| 17 | uint32_t _frameIdx; |
| 18 | double _animationSpeed; |
| 19 | |
| 20 | public: |
| 21 | explicit Animation(std::string_view path) : _drawable(path), _frameTime(), _frameIdx(), _animationSpeed(0.5 * (AnimationSpeedUnit)) {} |
| 22 | void draw(int x, int y) { _drawable.draw(_frameIdx, x, y); } |
| 23 | |
| 24 | void update(const std::chrono::duration<double> deltaTime) { |
| 25 | _frameTime += deltaTime.count(); |
| 26 | const auto framesToAdd = static_cast<uint32_t>(_frameTime / _animationSpeed); |
| 27 | _frameTime -= framesToAdd * _animationSpeed; |
| 28 | _frameIdx += framesToAdd; |
| 29 | _frameIdx %= _drawable.getFrameCount(); |
| 30 | } |
| 31 | |
| 32 | void setPalette(const Abyss::DataTypes::Palette &palette) { _drawable.setPalette(palette); } |
| 33 | |
| 34 | void setBlendMode(Enums::BlendMode blendMode) { _drawable.setBlendMode(blendMode); } |
| 35 | }; |
| 36 | |
| 37 | } // namespace Abyss::Common |
nothing calls this directly
no outgoing calls
no test coverage detected