19 pending_remove_.clear();
21 for (
auto entity : ui_flagged_) {
23 n->anim_override_ = 0;
34 pending_remove_.push_back(entity);
41 f32 tweenDelta = deltaTime;
43 if (tween.delay > 0.0f) {
44 tween.delay -= deltaTime;
45 if (tween.delay > 0.0f) {
52 applyValue(registry, tween, tween.from_value);
55 tweenDelta = -tween.delay;
59 tween.elapsed =
static_cast<f32>(std::min(
60 static_cast<double>(tween.elapsed) + tweenDelta,
61 static_cast<double>(std::numeric_limits<f32>::max())));
62 if (tween.loop_mode !=
LoopMode::None && tween.duration > 0.0f && tween.elapsed > tween.duration) {
63 const double elapsed = tween.elapsed;
64 const double duration = tween.duration;
65 const double remainder = std::fmod(elapsed, duration);
66 double skipped = std::floor(elapsed / duration) - (remainder == 0.0 ? 1.0 : 0.0);
67 bool reverse = (std::fmod(elapsed, duration * 2.0) >= duration) != (remainder == 0.0);
68 if (tween.loops_remaining > 0 && skipped >= tween.loops_remaining) {
69 skipped = tween.loops_remaining - 1;
70 reverse =
static_cast<i32>(skipped) % 2 != 0;
71 tween.elapsed = tween.duration;
74 tween.elapsed =
static_cast<f32>(remainder == 0.0 ? duration : remainder);
76 if (tween.loops_remaining > 0) tween.loops_remaining -=
static_cast<i32>(skipped);
78 std::swap(tween.from_value, tween.to_value);
81 f32 rawT = (tween.duration > 0.0f)
82 ? glm::clamp(tween.elapsed / tween.duration, 0.0f, 1.0f)
84 f32 easedT = evaluateEasing(tween, rawT);
85 f32 value = glm::mix(tween.from_value, tween.to_value, easedT);
87 applyValue(registry, tween, value);
92 pending_remove_.push_back(entity);
95 if (tween.loops_remaining > 0) {
96 tween.loops_remaining--;
97 if (tween.loops_remaining == 0) {
99 pending_remove_.push_back(entity);
103 tween.elapsed = 0.0f;
104 std::swap(tween.from_value, tween.to_value);
105 if (tween.loops_remaining > 0) {
106 tween.loops_remaining--;
107 if (tween.loops_remaining == 0) {
109 pending_remove_.push_back(entity);
123 for (
auto entity : pending_remove_) {
134 tween.target_property = property;
135 tween.from_value = from;
137 tween.duration = duration;
138 tween.easing = easing;
144 applyValue(registry, tween, from);
191 std::vector<Entity>& flagged) {
193 if (n->anim_override_ == 0) flagged.push_back(entity);
194 n->anim_override_ |= flag;
200 std::vector<Entity>& flagged) {
208 c->position.x = value;
214 c->position.y = value;
235 f32 h = value * 0.5f;
236 c->rotation = glm::quat(std::cos(h), 0.0f, 0.0f, std::sin(h));
282void TweenSystem::applyValue(
ecs::Registry& registry,
const TweenData& tween,
f32 value) {
283 Entity target = tween.target_entity;
284 if (!registry.
valid(target)) {
287 applyTweenValue(registry, target, tween.target_property, value, ui_flagged_);
292 return cubicBezier(t, tween.bezier_p1x, tween.bezier_p1y,
293 tween.bezier_p2x, tween.bezier_p2y);
Camera component for rendering viewpoints.
2D sprite rendering component
void resumeTween(ecs::Registry ®istry, Entity tweenEntity)
void pauseTween(ecs::Registry ®istry, Entity tweenEntity)
Entity createTween(ecs::Registry ®istry, Entity targetEntity, TweenTarget property, f32 from, f32 to, f32 duration, EasingType easing=EasingType::Linear)
void cancelTween(ecs::Registry ®istry, Entity tweenEntity)
void update(ecs::Registry ®istry, f32 deltaTime)
void cancelAllTweens(ecs::Registry ®istry, Entity targetEntity)
Central container for all entities and components.
bool isEntityActive(Entity e) const
T & get(Entity entity)
Gets a component from an entity (must exist).
void markChanged(Entity entity)
Says entity's T was written, through a reference held from before.
bool valid(Entity entity) const
Checks if an entity is currently valid.
void destroy(Entity entity)
Destroys an entity and removes all its components.
Entity create()
Creates a new entity.
T * tryGet(Entity entity)
Tries to get a component from an entity.
T & emplace(Entity entity, Args &&... args)
Adds a component to an entity with in-place construction.
View< Components... > view()
Creates a view for iterating entities with specific components.
static void applyTweenValue(ecs::Registry ®istry, Entity entity, TweenTarget target, f32 value, std::vector< Entity > &flagged)
EasingFn getEasingFunction(EasingType type)
static void markUIAnimOverride(ecs::Registry ®istry, Entity entity, u8 flag, std::vector< Entity > &flagged)
f32 cubicBezier(f32 t, f32 p1x, f32 p1y, f32 p2x, f32 p2y)
void invalidateTransformComposition()
Say that composed world transforms are stale.
std::int32_t i32
Signed 32-bit integer.
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
std::uint8_t u8
Unsigned 8-bit integer.
float f32
32-bit floating point
Entity identifier with packed index + generation.
Camera component for rendering viewpoints.
UINode — the CSS box-model layout input (the CSS/Flex primary layout model).
static constexpr u8 ANIM_SCALE_X
static constexpr u8 ANIM_ROT_Z
static constexpr u8 ANIM_POS_X
static constexpr u8 ANIM_POS_Y
static constexpr u8 ANIM_SCALE_Y