Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
AnimationBindings.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
18#include "AnimationBindings.hpp"
19
20#include "ActiveContext.hpp"
22
23namespace esengine {
24
25// The active context, spelled as every other binding TU spells it.
26static EstellaContext& ctx() { return activeCtx(); }
27
28u32 anim_createTween(ecs::Registry& registry, u32 entity, u32 targetProp,
29 f32 from, f32 to, f32 duration,
30 u32 easing, f32 delay,
31 u32 loopMode, i32 loopCount) {
32 auto* sys = ctx().tryGet<animation::TweenSystem>();
33 if (!sys) {
34 return INVALID_ENTITY.id();
35 }
36 auto tweenEntity = sys->createTween(
37 registry, Entity::fromRaw(entity),
38 static_cast<animation::TweenTarget>(targetProp),
39 from, to, duration,
40 static_cast<animation::EasingType>(easing));
41
42 auto& tween = registry.get<animation::TweenData>(tweenEntity);
43 tween.delay = delay;
44 tween.loop_mode = static_cast<animation::LoopMode>(loopMode);
45 tween.loop_count = loopCount;
46 tween.loops_remaining = loopCount;
47 return tweenEntity.id();
48}
49
50void anim_cancelTween(ecs::Registry& registry, u32 tweenEntity) {
51 if (auto* sys = ctx().tryGet<animation::TweenSystem>()) {
52 sys->cancelTween(registry, Entity::fromRaw(tweenEntity));
53 }
54}
55
56void anim_cancelAllTweens(ecs::Registry& registry, u32 targetEntity) {
57 if (auto* sys = ctx().tryGet<animation::TweenSystem>()) {
58 sys->cancelAllTweens(registry, Entity::fromRaw(targetEntity));
59 }
60}
61
62void anim_pauseTween(ecs::Registry& registry, u32 tweenEntity) {
63 if (auto* sys = ctx().tryGet<animation::TweenSystem>()) {
64 sys->pauseTween(registry, Entity::fromRaw(tweenEntity));
65 }
66}
67
68void anim_resumeTween(ecs::Registry& registry, u32 tweenEntity) {
69 if (auto* sys = ctx().tryGet<animation::TweenSystem>()) {
70 sys->resumeTween(registry, Entity::fromRaw(tweenEntity));
71 }
72}
73
74void anim_setTweenBezier(ecs::Registry& registry, u32 tweenEntity,
75 f32 p1x, f32 p1y, f32 p2x, f32 p2y) {
76 if (auto* tween = registry.tryGet<animation::TweenData>(Entity::fromRaw(tweenEntity))) {
78 tween->bezier_p1x = p1x;
79 tween->bezier_p1y = p1y;
80 tween->bezier_p2x = p2x;
81 tween->bezier_p2y = p2y;
82 }
83}
84
85void anim_setSequenceNext(ecs::Registry& registry, u32 tweenEntity, u32 nextEntity) {
86 if (auto* tween = registry.tryGet<animation::TweenData>(Entity::fromRaw(tweenEntity))) {
87 tween->sequence_next = Entity::fromRaw(nextEntity);
88 }
89}
90
91void anim_updateTweens(ecs::Registry& registry, f32 deltaTime) {
92 if (auto* sys = ctx().tryGet<animation::TweenSystem>()) {
93 sys->update(registry, deltaTime);
94 }
95}
96
97i32 anim_getTweenState(ecs::Registry& registry, u32 tweenEntity) {
98 if (auto* tween = registry.tryGet<animation::TweenData>(Entity::fromRaw(tweenEntity))) {
99 return static_cast<i32>(tween->state);
100 }
101 return static_cast<i32>(animation::TweenState::Completed);
102}
103
104} // namespace esengine
The tween entry points, declared once for both registration layers.
Entity createTween(ecs::Registry &registry, Entity targetEntity, TweenTarget property, f32 from, f32 to, f32 duration, EasingType easing=EasingType::Linear)
Central container for all entities and components.
Definition Registry.hpp:73
T & get(Entity entity)
Gets a component from an entity (must exist).
Definition Registry.hpp:649
T * tryGet(Entity entity)
Tries to get a component from an entity.
Definition Registry.hpp:670
void anim_resumeTween(ecs::Registry &registry, u32 tweenEntity)
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
void anim_updateTweens(ecs::Registry &registry, f32 deltaTime)
i32 anim_getTweenState(ecs::Registry &registry, u32 tweenEntity)
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
Definition Types.hpp:174
void anim_setSequenceNext(ecs::Registry &registry, u32 tweenEntity, u32 nextEntity)
void anim_cancelTween(ecs::Registry &registry, u32 tweenEntity)
void anim_setTweenBezier(ecs::Registry &registry, u32 tweenEntity, f32 p1x, f32 p1y, f32 p2x, f32 p2y)
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
void anim_cancelAllTweens(ecs::Registry &registry, u32 targetEntity)
u32 anim_createTween(ecs::Registry &registry, u32 entity, u32 targetProp, f32 from, f32 to, f32 duration, u32 easing, f32 delay, u32 loopMode, i32 loopCount)
static EstellaContext & ctx()
EstellaContext & activeCtx()
The engine context every binding routes through — single source of truth.
void anim_pauseTween(ecs::Registry &registry, u32 tweenEntity)
float f32
32-bit floating point
Definition Types.hpp:59
static constexpr Entity fromRaw(u32 v)
Reconstructs an Entity from a raw packed value.
Definition Types.hpp:162