载入中...
搜索中...
未找到
SpineAnim.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Time.h"
5
6#include <string>
7#include <vector>
9
10namespace eve::graphics {
11struct DrawItem2D;
12class Texture;
13} // namespace eve::graphics
14
15#include <string>
16#include <vector>
17
18namespace eve::graphics {
19class Graphics;
20}
21
22namespace eve::animation {
23
24class Animation;
25class SpineAtlas;
26class SpineSkeleton;
27
36public:
38 explicit SpineAnim(SpineSkeleton *skeleton);
40 ~SpineAnim();
41
42 SpineAnim(const SpineAnim &) = delete;
43 SpineAnim &operator=(const SpineAnim &) = delete;
44
46 SpineSkeleton *getSkeleton() const { return skeleton_; }
47
49 void setAtlas(SpineAtlas *atlas);
51 SpineAtlas *getAtlas() const { return atlas_; }
52
54 void setPageTexture(int pageIndex, graphics::Texture *texture);
56 void setPageTextureByName(const std::string &pageName, graphics::Texture *texture);
58 graphics::Texture *getPageTexture(int pageIndex) const;
59
61 bool play(const std::string &animationName);
63 void stop();
65 void pause();
67 void resume();
68
70 void setSpeed(float speed);
72 float getSpeed() const { return speed_; }
74 void setTime(float seconds);
76 float getTime() const { return time_; }
78 void setLoop(bool loop) { loop_ = loop; }
80 bool getLoop() const { return loop_; }
81
83 void setFlipY(bool flip) { flipY_ = flip; }
85 bool getFlipY() const { return flipY_; }
86
88 void setPosition(float x, float y);
90 float getX() const { return x_; }
92 float getY() const { return y_; }
94 void setScale(float sx, float sy);
96 float getScaleX() const { return scaleX_; }
98 float getScaleY() const { return scaleY_; }
100 void setLayer(int layer) { layer_ = layer; }
102 int getLayer() const { return layer_; }
104 void setColor(float r, float g, float b, float a = 1.f);
105
107 bool isPlaying() const { return playing_ && !paused_; }
109 bool isPaused() const { return paused_; }
111 bool isFinished() const { return finished_; }
113 std::string getAnimation() const { return animName_; }
115 float getAnimationDuration() const;
116
118 void apply();
119
121 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
123 [[nodiscard]] bool hasCurrentTick() const noexcept { return hasLastTick_; }
125 [[nodiscard]] eve::SimulationTick currentTick() const noexcept { return lastTick_; }
127 bool update(float dt);
128
130 void collectDrawItems(std::vector<graphics::DrawItem2D> &out);
132 void draw(graphics::Graphics *gfx);
133
138 int getDrawSlotCount() const;
140 float getDrawSlotX(int index) const;
142 float getDrawSlotY(int index) const;
144 float getDrawSlotWidth(int index) const;
146 float getDrawSlotHeight(int index) const;
148 float getDrawSlotRotation(int index) const;
150 int getDrawSlotPage(int index) const;
152 std::string getDrawSlotRegion(int index) const;
153
154private:
155 friend class Animation;
156
157 struct DrawSlot {
158 float x = 0.f, y = 0.f;
159 float w = 0.f, h = 0.f;
160 float rotation = 0.f;
161 int page = 0;
162 int region = -1;
163 int order = 0; // slot draw order (back-to-front)
164 bool rotated = false; // atlas region packed rotated (90°)
165 std::string regionName;
166 float u0 = 0.f, v0 = 0.f, u1 = 1.f, v1 = 1.f;
167 };
168
169 void setOwner(Animation *owner) { owner_ = owner; }
170 Animation *owner() const { return owner_; }
171
172 void rebuildDrawSlots();
173 void checkDrawSlot(int index) const;
174
175 static float sampleFloat(const std::vector<SpineSkeletonData::FloatKey> &keys, float time,
176 float fallback);
177 static void sampleTranslate(const std::vector<SpineSkeletonData::TranslateKey> &keys,
178 float time, float &x, float &y);
179 static void sampleScale(const std::vector<SpineSkeletonData::ScaleKey> &keys, float time,
180 float &x, float &y);
181 static std::string sampleAttachment(const std::vector<SpineSkeletonData::AttachmentKey> &keys,
182 float time, const std::string &fallback);
183
184 Animation *owner_ = nullptr;
185 SpineSkeleton *skeleton_ = nullptr;
186 SpineAtlas *atlas_ = nullptr;
187 std::vector<graphics::Texture *> pageTextures_;
188 int animIndex_ = -1;
189 std::string animName_;
190 float speed_ = 1.f;
191 float time_ = 0.f;
192 bool loop_ = true;
193 bool playing_ = false;
194 bool paused_ = false;
195 bool finished_ = false;
196 bool flipY_ = true;
197 float x_ = 0.f, y_ = 0.f;
198 float scaleX_ = 1.f, scaleY_ = 1.f;
199 int layer_ = 0;
200 float r_ = 1.f, g_ = 1.f, b_ = 1.f, a_ = 1.f;
201 std::vector<DrawSlot> drawSlots_;
203 bool hasLastTick_ = false;
204
205 bool updateUnchecked(float dt);
206};
207
208} // namespace eve::animation
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
tensor::Graph g
Definition GpuGraph.cpp:7
double r
int h
std::array< float, 4 > rotation
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::vector< std::int32_t > order
MeshVfxBatchedDraw draw
TileLayer * layer
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Animation module — tween factory + 2D sprite-sheet / Spine + 3D skeletal playback (player / state mac...
Definition Animation.h:80
Spine animation player + 2D draw collector (region attachments).
Definition SpineAnim.h:35
SpineAtlas * getAtlas() const
Returns the atlas.
Definition SpineAnim.h:51
bool isPaused() const
True when paused.
Definition SpineAnim.h:109
eve::SimulationTick currentTick() const noexcept
Last scheduler tick consumed by this Spine animation.
Definition SpineAnim.h:125
float getScaleX() const
Returns the scale x.
Definition SpineAnim.h:96
SpineSkeleton * getSkeleton() const
Returns the skeleton.
Definition SpineAnim.h:46
void setLayer(int layer)
Sets the layer.
Definition SpineAnim.h:100
float getX() const
Returns the x.
Definition SpineAnim.h:90
float getY() const
Returns the y.
Definition SpineAnim.h:92
void setLoop(bool loop)
Sets the loop.
Definition SpineAnim.h:78
bool isFinished() const
True when finished.
Definition SpineAnim.h:111
float getSpeed() const
Returns the speed.
Definition SpineAnim.h:72
bool getLoop() const
Returns the loop.
Definition SpineAnim.h:80
SpineAnim(const SpineAnim &)=delete
bool getFlipY() const
Returns the flip y.
Definition SpineAnim.h:85
float getTime() const
Returns the time.
Definition SpineAnim.h:76
void setFlipY(bool flip)
When true (default), Spine Y-up is flipped for screen Y-down draw items.
Definition SpineAnim.h:83
bool hasCurrentTick() const noexcept
Whether this Spine animation has consumed a scheduler step.
Definition SpineAnim.h:123
float getScaleY() const
Returns the scale y.
Definition SpineAnim.h:98
int getLayer() const
Returns the layer.
Definition SpineAnim.h:102
bool isPlaying() const
True when playing.
Definition SpineAnim.h:107
std::string getAnimation() const
Returns the animation.
Definition SpineAnim.h:113
SpineAnim & operator=(const SpineAnim &)=delete
Esoteric Spine .atlas text parser (region rectangles + page metadata). Does not load image pixels — b...
Definition SpineAtlas.h:16
Runtime Spine skeleton pose (local + world bone transforms, slot attachments). Script type: SpineSkel...
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158