载入中...
搜索中...
未找到
Tween.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Time.h"
6
7#include <string>
8#include <unordered_map>
9#include <vector>
10
11namespace eve::animation {
12
13class Animation;
14
26public:
28 explicit Tween(float duration = 1.f);
30 ~Tween();
31
32 Tween(const Tween &) = delete;
33 Tween &operator=(const Tween &) = delete;
34
36 void setFrom(const std::string &name, float value);
38 void setTo(const std::string &name, float value);
40 void setDelta(const std::string &name, float delta);
41
43 void setFromAngle(const std::string &name, float radians);
45 void setToAngle(const std::string &name, float radians);
47 void setDeltaAngle(const std::string &name, float deltaRadians);
48
50 bool has(const std::string &name) const;
52 float get(const std::string &name) const;
54 float getFrom(const std::string &name) const;
56 float getTo(const std::string &name) const;
58 float getDelta(const std::string &name) const;
59
61 void setDuration(float seconds);
63 float getDuration() const { return duration_; }
65 void setDelay(float seconds);
67 float getDelay() const { return delay_; }
69 void setEase(const std::string &kind);
71 std::string getEase() const { return ease_; }
72
77 void setRepeat(int count);
79 int getRepeat() const { return repeat_; }
81 void setYoyo(bool enabled) { yoyo_ = enabled; }
83 bool getYoyo() const { return yoyo_; }
84
86 void start();
88 void pause();
90 void resume();
92 void stop();
94 void reset();
95
97 bool isRunning() const { return state_ == State::Running; }
99 bool isPaused() const { return state_ == State::Paused; }
101 bool isFinished() const { return state_ == State::Finished; }
103 bool isStopped() const { return state_ == State::Idle || state_ == State::Stopped; }
105 bool isDelayed() const { return state_ == State::Delayed; }
107 bool isActive() const {
108 return state_ == State::Delayed || state_ == State::Running || state_ == State::Paused;
109 }
110
112 float getElapsed() const { return elapsed_; }
114 float getProgress() const;
116 float getEasedProgress() const;
117
119 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
121 [[nodiscard]] bool hasCurrentTick() const noexcept { return hasLastTick_; }
123 [[nodiscard]] eve::SimulationTick currentTick() const noexcept { return lastTick_; }
125 bool update(float dt);
126
128 float evaluate(const std::string &name, float t) const;
129
131 int getPropertyCount() const { return static_cast<int>(order_.size()); }
133 std::string getPropertyName(int index) const;
134
135private:
136 friend class Animation;
137
138 enum class State { Idle, Delayed, Running, Paused, Finished, Stopped };
139
140 enum class EndMode { Absolute, Delta };
141
142 struct Track {
143 float from = 0.f;
144 float to = 0.f;
145 float delta = 0.f;
146 float current = 0.f;
147 bool hasFrom = false;
148 EndMode endMode = EndMode::Absolute;
149 bool isAngle = false;
150 bool resolved = false;
151 };
152
153 void setOwner(Animation *owner) { owner_ = owner; }
154 Animation *owner() const { return owner_; }
155 Track &ensureTrack(const std::string &name);
156 const Track *findTrack(const std::string &name) const;
157 void resolveTracks();
158 void applyProgress(float linearT);
159 void finishCycle();
160 static float ease(float t, const std::string &kind);
161 static float lerpAngle(float a, float b, float t);
162 static float clamp01(float t);
163
164 Animation *owner_ = nullptr;
165 float duration_ = 1.f;
166 float delay_ = 0.f;
167 float delayLeft_ = 0.f;
168 float elapsed_ = 0.f;
169 int repeat_ = 1;
170 int played_ = 0;
171 bool yoyo_ = false;
172 bool reverse_ = false;
173 std::string ease_ = "linear";
174 State state_ = State::Idle;
175 std::unordered_map<std::string, Track> tracks_;
176 std::vector<std::string> order_;
178 bool hasLastTick_ = false;
179
180 bool updateUnchecked(float dt);
181};
182
183} // namespace eve::animation
double value
Duration start
float duration
std::string from
#define EVENGINE_API_WORLD
Definition Export.h:109
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
TokenKind kind
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float t
double current
std::uint32_t count
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
Property tween — interpolates named float properties from → to over time.
Definition Tween.h:25
bool isFinished() const
True when finished.
Definition Tween.h:101
bool isRunning() const
True when running.
Definition Tween.h:97
int getRepeat() const
Returns the repeat.
Definition Tween.h:79
bool getYoyo() const
Returns the yoyo.
Definition Tween.h:83
int getPropertyCount() const
Names of all property tracks (stable order = insertion order).
Definition Tween.h:131
float getDuration() const
Returns the duration.
Definition Tween.h:63
bool hasCurrentTick() const noexcept
Whether this tween has consumed a scheduler step.
Definition Tween.h:121
bool isPaused() const
True when paused.
Definition Tween.h:99
void setYoyo(bool enabled)
Sets the yoyo.
Definition Tween.h:81
bool isDelayed() const
True when delayed.
Definition Tween.h:105
bool isActive() const
True when active.
Definition Tween.h:107
float getDelay() const
Returns the delay.
Definition Tween.h:67
eve::SimulationTick currentTick() const noexcept
Last scheduler tick consumed by this tween.
Definition Tween.h:123
std::string getEase() const
Returns the ease.
Definition Tween.h:71
Tween(const Tween &)=delete
float getElapsed() const
Elapsed time in the current cycle (excludes delay).
Definition Tween.h:112
bool isStopped() const
True when stopped.
Definition Tween.h:103
Tween & operator=(const Tween &)=delete
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
State
Lifecycle state of a generic transaction plan.
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158