载入中...
搜索中...
未找到
MotionBuilder.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5#include <cstdint>
6
7namespace eve::animation {
8namespace {
9
10[[nodiscard]] eve::Diagnostic consumedDiag(const char *api) {
12 std::string(api) + ": builder already consumed");
13}
14
15} // namespace
16
18 : runtime_(runtime) {
19 desc_.from = from;
20 desc_.to = to;
21 desc_.duration = duration;
22}
23
25 desc_.ease = std::move(kind);
26 return *this;
27}
28
30 desc_.delay = seconds;
31 return *this;
32}
33
35 desc_.loops = count;
36 desc_.loopMode = mode;
37 return *this;
38}
39
41 desc_.onUpdate = std::move(cb);
42 return *this;
43}
44
46 desc_.onComplete = std::move(cb);
47 return *this;
48}
49
51 desc_.onCancel = std::move(cb);
52 return *this;
53}
54
59
61 desc_.sink = &sink;
62 return *this;
63}
64
66 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionBuilder.run"));
67 consumed_ = true;
68 desc_.sink = nullptr;
69 return runtime_.spawnFloat(desc_);
70}
71
73 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionBuilder.bind"));
74 consumed_ = true;
75 desc_.sink = &sink;
76 return runtime_.spawnFloat(desc_);
77}
78
80 if (consumed_) return eve::Result<MotionRuntime::FloatDesc>::failure(consumedDiag("MotionBuilder.takeDesc"));
81 consumed_ = true;
83}
84
86 float duration)
87 : runtime_(runtime) {
88 desc_.from = from;
89 desc_.to = to;
90 desc_.duration = duration;
91}
92
94 desc_.ease = std::move(kind);
95 return *this;
96}
97
99 desc_.delay = seconds;
100 return *this;
101}
102
104 desc_.loops = count;
105 desc_.loopMode = mode;
106 return *this;
107}
108
110 desc_.onUpdate = std::move(cb);
111 return *this;
112}
113
115 desc_.onComplete = std::move(cb);
116 return *this;
117}
118
120 desc_.onCancel = std::move(cb);
121 return *this;
122}
123
128
130 desc_.sink = &sink;
131 return *this;
132}
133
135 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionVec2Builder.run"));
136 consumed_ = true;
137 desc_.sink = nullptr;
138 return runtime_.spawnVec2(desc_);
139}
140
142 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionVec2Builder.bind"));
143 consumed_ = true;
144 desc_.sink = &sink;
145 return runtime_.spawnVec2(desc_);
146}
147
149 if (consumed_)
150 return eve::Result<MotionRuntime::Vec2Desc>::failure(consumedDiag("MotionVec2Builder.takeDesc"));
151 consumed_ = true;
152 return eve::Result<MotionRuntime::Vec2Desc>::success(std::move(desc_));
153}
154
156 float duration)
157 : runtime_(runtime) {
158 desc_.from = from;
159 desc_.to = to;
160 desc_.duration = duration;
161}
162
164 desc_.ease = std::move(kind);
165 return *this;
166}
167
169 desc_.delay = seconds;
170 return *this;
171}
172
174 desc_.loops = count;
175 desc_.loopMode = mode;
176 return *this;
177}
178
180 desc_.onUpdate = std::move(cb);
181 return *this;
182}
183
185 desc_.onComplete = std::move(cb);
186 return *this;
187}
188
190 desc_.onCancel = std::move(cb);
191 return *this;
192}
193
198
200 desc_.sink = &sink;
201 return *this;
202}
203
205 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionVec3Builder.run"));
206 consumed_ = true;
207 desc_.sink = nullptr;
208 return runtime_.spawnVec3(desc_);
209}
210
212 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionVec3Builder.bind"));
213 consumed_ = true;
214 desc_.sink = &sink;
215 return runtime_.spawnVec3(desc_);
216}
217
219 if (consumed_)
220 return eve::Result<MotionRuntime::Vec3Desc>::failure(consumedDiag("MotionVec3Builder.takeDesc"));
221 consumed_ = true;
222 return eve::Result<MotionRuntime::Vec3Desc>::success(std::move(desc_));
223}
224
225
227 desc_.style = style;
228 return *this;
229}
231 desc_.frequency = count;
232 return *this;
233}
235 desc_.dampingRatio = ratio;
236 return *this;
237}
239 desc_.seed = value;
240 return *this;
241}
242
244 desc_.style = style;
245 return *this;
246}
248 desc_.frequency = count;
249 return *this;
250}
252 desc_.dampingRatio = ratio;
253 return *this;
254}
256 desc_.seed = value;
257 return *this;
258}
259
261 desc_.style = style;
262 return *this;
263}
265 desc_.frequency = count;
266 return *this;
267}
269 desc_.dampingRatio = ratio;
270 return *this;
271}
273 desc_.seed = value;
274 return *this;
275}
276
278 float duration)
279 : runtime_(runtime) {
280 desc_.from = from;
281 desc_.to = to;
282 desc_.duration = duration;
283}
285 desc_.ease = std::move(kind);
286 return *this;
287}
289 desc_.delay = seconds;
290 return *this;
291}
293 desc_.loops = count;
294 desc_.loopMode = mode;
295 return *this;
296}
298 desc_.onUpdate = std::move(cb);
299 return *this;
300}
302 desc_.onComplete = std::move(cb);
303 return *this;
304}
306 desc_.onCancel = std::move(cb);
307 return *this;
308}
314 desc_.sink = &sink;
315 return *this;
316}
318 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionColorBuilder.run"));
319 consumed_ = true;
320 desc_.sink = nullptr;
321 return runtime_.spawnColor(desc_);
322}
324 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionColorBuilder.bind"));
325 consumed_ = true;
326 desc_.sink = &sink;
327 return runtime_.spawnColor(desc_);
328}
330 if (consumed_)
331 return eve::Result<MotionRuntime::ColorDesc>::failure(consumedDiag("MotionColorBuilder.takeDesc"));
332 consumed_ = true;
333 return eve::Result<MotionRuntime::ColorDesc>::success(std::move(desc_));
334}
335
337 float duration)
338 : runtime_(runtime) {
339 desc_.from = from;
340 desc_.to = to;
341 desc_.duration = duration;
342}
344 desc_.ease = std::move(kind);
345 return *this;
346}
348 desc_.delay = seconds;
349 return *this;
350}
352 desc_.loops = count;
353 desc_.loopMode = mode;
354 return *this;
355}
357 desc_.onUpdate = std::move(cb);
358 return *this;
359}
361 desc_.onComplete = std::move(cb);
362 return *this;
363}
365 desc_.onCancel = std::move(cb);
366 return *this;
367}
373 desc_.sink = &sink;
374 return *this;
375}
377 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionQuatBuilder.run"));
378 consumed_ = true;
379 desc_.sink = nullptr;
380 return runtime_.spawnQuat(desc_);
381}
383 if (consumed_) return eve::Result<MotionHandle>::failure(consumedDiag("MotionQuatBuilder.bind"));
384 consumed_ = true;
385 desc_.sink = &sink;
386 return runtime_.spawnQuat(desc_);
387}
389 if (consumed_)
390 return eve::Result<MotionRuntime::QuatDesc>::failure(consumedDiag("MotionQuatBuilder.takeDesc"));
391 consumed_ = true;
392 return eve::Result<MotionRuntime::QuatDesc>::success(std::move(desc_));
393}
394
395} // namespace eve::animation
double value
float duration
std::string from
Stable, structured diagnostics shared by engine modules.
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
TokenKind kind
Fluent LitMotion-style builder that commits into MotionRuntime.
std::uint32_t count
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Push target for a MotionColor motion.
Push target for a float motion. Lifetime is borrowed by MotionRuntime.
Definition MotionTypes.h:84
Push target for a MotionQuat motion.
Push target for a MotionVec2 motion.
Definition MotionTypes.h:96
Push target for a MotionVec3 motion.
Configure then bind/run a float motion into a MotionRuntime.
MotionBuilder & onUpdate(MotionRuntime::FloatCallback cb)
On update.
eve::Result< MotionRuntime::FloatDesc > takeDesc()
Extract the configured desc for sequence scheduling (consumes builder).
eve::Result< MotionHandle > run()
Start without a sink; read values via MotionRuntime::floatValue.
MotionBuilder & onComplete(MotionRuntime::VoidCallback cb)
On complete.
eve::Result< MotionHandle > bind(IMotionFloatSink &sink)
Start and push each sample into sink (borrowed).
MotionBuilder & ease(std::string kind)
Ease.
MotionBuilder & to(IMotionFloatSink &sink)
Attach a sink without spawning (for MotionSequence).
MotionBuilder & style(MotionStyle style)
Select Tween / Punch / Shake evaluation.
MotionBuilder & dampingRatio(float ratio)
Damping ratio for Punch/Shake (0 = none, 1 = full).
MotionBuilder & cancelOnError(bool enabled)
Cancel on error.
MotionBuilder & frequency(int count)
Oscillation count for Punch/Shake (default 10).
MotionBuilder & onCancel(MotionRuntime::VoidCallback cb)
On cancel.
MotionBuilder & loops(int count, MotionLoopMode mode=MotionLoopMode::Restart)
Loops.
MotionBuilder(MotionRuntime &runtime, float from, float to, float duration)
Motion builder.
MotionBuilder & seed(std::uint32_t value)
Deterministic seed for Shake signs.
MotionBuilder & delay(float seconds)
Delay.
Color fluent builder (Tween / lerp only).
MotionColorBuilder(MotionRuntime &runtime, MotionColor from, MotionColor to, float duration)
Motion color builder.
MotionColorBuilder & delay(float seconds)
Delay.
eve::Result< MotionHandle > run()
Run.
eve::Result< MotionRuntime::ColorDesc > takeDesc()
Take desc.
MotionColorBuilder & onComplete(MotionRuntime::VoidCallback cb)
On complete.
MotionColorBuilder & cancelOnError(bool enabled)
Cancel on error.
MotionColorBuilder & onUpdate(MotionRuntime::ColorCallback cb)
On update.
MotionColorBuilder & to(IMotionColorSink &sink)
To.
MotionColorBuilder & loops(int count, MotionLoopMode mode=MotionLoopMode::Restart)
Loops.
MotionColorBuilder & ease(std::string kind)
Ease.
eve::Result< MotionHandle > bind(IMotionColorSink &sink)
Binds .
MotionColorBuilder & onCancel(MotionRuntime::VoidCallback cb)
On cancel.
Quaternion fluent builder (Tween / slerp only).
MotionQuatBuilder & ease(std::string kind)
Ease.
eve::Result< MotionRuntime::QuatDesc > takeDesc()
Take desc.
MotionQuatBuilder & onComplete(MotionRuntime::VoidCallback cb)
On complete.
MotionQuatBuilder & onUpdate(MotionRuntime::QuatCallback cb)
On update.
MotionQuatBuilder & to(IMotionQuatSink &sink)
To.
MotionQuatBuilder & loops(int count, MotionLoopMode mode=MotionLoopMode::Restart)
Loops.
eve::Result< MotionHandle > bind(IMotionQuatSink &sink)
Binds .
MotionQuatBuilder & onCancel(MotionRuntime::VoidCallback cb)
On cancel.
MotionQuatBuilder(MotionRuntime &runtime, MotionQuat from, MotionQuat to, float duration)
Motion quat builder.
MotionQuatBuilder & cancelOnError(bool enabled)
Cancel on error.
MotionQuatBuilder & delay(float seconds)
Delay.
eve::Result< MotionHandle > run()
Run.
Owns typed motion slots and applies SimulationStep updates.
std::function< void(MotionColor)> ColorCallback
std::function< void(float)> FloatCallback
eve::Result< MotionHandle > spawnColor(const ColorDesc &desc)
eve::Result< MotionHandle > spawnFloat(const FloatDesc &desc)
std::function< void(MotionQuat)> QuatCallback
eve::Result< MotionHandle > spawnVec2(const Vec2Desc &desc)
std::function< void()> VoidCallback
std::function< void(MotionVec2)> Vec2Callback
eve::Result< MotionHandle > spawnVec3(const Vec3Desc &desc)
eve::Result< MotionHandle > spawnQuat(const QuatDesc &desc)
std::function< void(MotionVec3)> Vec3Callback
MotionVec2Builder & onCancel(MotionRuntime::VoidCallback cb)
On cancel.
MotionVec2Builder & cancelOnError(bool enabled)
Cancel on error.
MotionVec2Builder & seed(std::uint32_t value)
Deterministic seed for Shake signs.
MotionVec2Builder & to(IMotionVec2Sink &sink)
To.
eve::Result< MotionHandle > run()
Run.
eve::Result< MotionHandle > bind(IMotionVec2Sink &sink)
Binds .
MotionVec2Builder & style(MotionStyle style)
Select Tween / Punch / Shake evaluation.
MotionVec2Builder & frequency(int count)
Oscillation count for Punch/Shake (default 10).
MotionVec2Builder & delay(float seconds)
Delay.
MotionVec2Builder & ease(std::string kind)
Ease.
MotionVec2Builder & onComplete(MotionRuntime::VoidCallback cb)
On complete.
MotionVec2Builder & dampingRatio(float ratio)
Damping ratio for Punch/Shake (0 = none, 1 = full).
MotionVec2Builder(MotionRuntime &runtime, MotionVec2 from, MotionVec2 to, float duration)
Motion vec 2 builder.
MotionVec2Builder & onUpdate(MotionRuntime::Vec2Callback cb)
On update.
eve::Result< MotionRuntime::Vec2Desc > takeDesc()
Take desc.
MotionVec2Builder & loops(int count, MotionLoopMode mode=MotionLoopMode::Restart)
Loops.
MotionVec3Builder & to(IMotionVec3Sink &sink)
To.
MotionVec3Builder & seed(std::uint32_t value)
Deterministic seed for Shake signs.
MotionVec3Builder(MotionRuntime &runtime, MotionVec3 from, MotionVec3 to, float duration)
Constructs a MotionVec3Builder.
eve::Result< MotionHandle > bind(IMotionVec3Sink &sink)
Binds .
MotionVec3Builder & onUpdate(MotionRuntime::Vec3Callback cb)
On update.
MotionVec3Builder & style(MotionStyle style)
Select Tween / Punch / Shake evaluation.
MotionVec3Builder & onCancel(MotionRuntime::VoidCallback cb)
On cancel.
eve::Result< MotionRuntime::Vec3Desc > takeDesc()
Take desc.
MotionVec3Builder & delay(float seconds)
Delay.
MotionVec3Builder & cancelOnError(bool enabled)
Cancel on error.
MotionVec3Builder & ease(std::string kind)
Ease.
eve::Result< MotionHandle > run()
Run.
MotionVec3Builder & frequency(int count)
Oscillation count for Punch/Shake (default 10).
MotionVec3Builder & onComplete(MotionRuntime::VoidCallback cb)
On complete.
MotionVec3Builder & dampingRatio(float ratio)
Damping ratio for Punch/Shake (0 = none, 1 = full).
MotionVec3Builder & loops(int count, MotionLoopMode mode=MotionLoopMode::Restart)
Loops.
MotionLoopMode
Loop behaviour after a cycle completes.
Definition MotionTypes.h:68
MotionStyle
Evaluation style for a motion slot.
Definition MotionTypes.h:77
bool enabled
Compact RGBA color used by motion adapters.
Definition MotionTypes.h:52
Compact quaternion used by motion adapters (xyzw).
Definition MotionTypes.h:60
int loops
1 = once, N = N cycles, -1 = infinite.
std::uint32_t seed
Deterministic Shake seed.
int frequency
Oscillation count for Punch/Shake.
float dampingRatio
0 = undamped, 1 = fully damped.
std::uint32_t seed
Deterministic Shake seed.
float dampingRatio
0 = undamped, 1 = fully damped.
int frequency
Oscillation count for Punch/Shake.
float dampingRatio
0 = undamped, 1 = fully damped.
int frequency
Oscillation count for Punch/Shake.
std::uint32_t seed
Deterministic Shake seed.
Compact float2 used by motion adapters (avoids graphics math deps).
Definition MotionTypes.h:39
Compact float3 used by motion adapters.
Definition MotionTypes.h:45