#pragma once #include #include #include #include #include #include namespace extra2d { // ============================================================================ // FrameRenderer - 帧渲染器 // 单渲染器 + SpriteFrame 引用策略,替代 N帧=N个Sprite 的旧设计 // 负责预加载帧的 SpriteFrame、渲染当前帧、处理混合模式 // ============================================================================ class FrameRenderer { public: FrameRenderer() = default; // ------ 预加载 ------ // 解析所有帧的 SpriteFrame(通过 SpriteFrameCache) bool preloadFrames(const std::vector &frames); void releaseFrames(); // ------ 渲染当前帧 ------ void renderFrame(RenderBackend &renderer, const AnimationFrame &frame, size_t frameIndex, const Vec2 &position, float nodeOpacity, const Color &tintColor, bool flipX, bool flipY); // ------ 渲染插值帧 ------ void renderInterpolated(RenderBackend &renderer, const AnimationFrame &fromFrame, size_t fromIndex, const InterpolatedProperties &props, const Vec2 &position, float nodeOpacity, const Color &tintColor, bool flipX, bool flipY); // ------ 混合模式映射 ------ static BlendMode mapBlendMode(const FramePropertySet &props); // ------ 查询 ------ Ptr getSpriteFrame(size_t frameIndex) const; Size getMaxFrameSize() const { return maxFrameSize_; } bool isLoaded() const { return !spriteFrames_.empty(); } private: std::vector> spriteFrames_; Size maxFrameSize_; void drawSpriteFrame(RenderBackend &renderer, Ptr sf, const Vec2 &position, const Vec2 &offset, const Vec2 &scale, float rotation, float opacity, const Color &tint, bool flipX, bool flipY, BlendMode blend); }; } // namespace extra2d