CoriEngine
Loading...
Searching...
No Matches
QuadAnimator.cpp
Go to the documentation of this file.
1#include "QuadAnimator.hpp"
3
4namespace Cori {
5 namespace World {
6 namespace Components {
7 namespace Entity {
9 m_ActiveSequence = false;
10
11 SetStopCallback([]{});
13 }
14
16 if (m_Entity.HasComponents<QuadRenderer>()) {
17 auto& renderer = m_Entity.GetComponents<QuadRenderer>();
18 renderer.m_AnimatorBound = false;
19 }
20 }
21
23 m_StopCallBack = std::move(callback);
24 }
25
26 void QuadAnimator::Stop(const bool abruptStop) {
27 if (abruptStop) {
28 m_ActiveSequence = false;
29 m_CurrentFrame = 0;
30 m_CurrentFrameTick = 1;
31 m_StopCallBack();
32 m_EngineCallBack();
33 }
34
35 m_LoopStartIndex = 0xFFFF;
36 }
37
39 if (m_ActiveSequence) {
40 //++m_TicksElapsedSinceStart;
41 auto& [anim, params] = m_AnimationSequence[m_CurrentLoopedSequenceIndex];
42 if (m_CurrentFrame == anim.m_Pack->m_Animations[anim.m_AnimationID].m_Frames.size() - 1 && m_CurrentFrameTick >= anim.m_Pack->m_Animations[anim.m_AnimationID].m_Frames[m_CurrentFrame].m_TickDuration) {
43 if (m_CurrentLoopedSequenceIndex == m_AnimationSequence.size() - 1) {
44 if (m_LoopStartIndex != 0xFFFF) {
45 m_CurrentLoopedSequenceIndex = m_LoopStartIndex;
46 m_CurrentFrame = 0;
47 m_CurrentFrameTick = 1;
48 }
49 else {
50 m_CurrentFrame = 0;
51 m_CurrentFrameTick = 1;
52 Stop(true);
53 m_StopCallBack();
54 m_EngineCallBack();
55 return;
56 }
57 }
58 else {
59 ++m_CurrentLoopedSequenceIndex;
60 m_CurrentFrame = 0;
61 m_CurrentFrameTick = 1;
62 }
63 }
64 else {
65 if (m_CurrentFrameTick < anim.m_Pack->m_Animations[anim.m_AnimationID].m_Frames[m_CurrentFrame].m_TickDuration) {
66 ++m_CurrentFrameTick;
67 }
68 else {
69 m_CurrentFrameTick = 1;
70 ++m_CurrentFrame;
71 }
72 }
73
74 auto& renderer = m_Entity.GetComponents<QuadRenderer>();
75 const auto& [pack, id] = m_AnimationSequence[m_CurrentLoopedSequenceIndex].first;
76 const auto& m_UVs= pack->m_Animations[id].m_Frames[m_CurrentFrame].m_UVs;
77
78 const glm::vec2 animationFrameSize = pack->m_Animations[id].m_FrameSize;
79 if (animationFrameSize != glm::vec2{std::numeric_limits<float>::max(), std::numeric_limits<float>::max()}) {
80 renderer.m_HalfSize = animationFrameSize * m_SizeScale / 2.0f;
81 }
82
83 if (pack->m_Type != Graphics::AnimationPack::CORI_VARYING) {
84 renderer.m_Texture = std::get<std::shared_ptr<Graphics::SpriteAtlas>>(pack->m_TextureOrAtlas)->GetTexture();
85 } else {
86 renderer.m_Texture = std::get<std::shared_ptr<Graphics::Texture2D>>(pack->m_TextureOrAtlas);
87 }
88
89 renderer.m_UVs = m_UVs;
90 }
91 }
92
93 void QuadAnimator::SetSizeScale(const glm::vec2 scale) {
94 m_SizeScale = scale;
95 }
96
97 glm::vec2 QuadAnimator::GetSizeScale() const {
98 return m_SizeScale;
99 }
100
101 //uint64_t QuadAnimator::GetTicksElapsed() const {
102 // return m_TicksElapsedSinceStart;
103 //}
104
106 m_EngineCallBack = std::move(callback);
107 }
108 }
109 }
110 }
111}
void SetStopCallback(StopCallbackFn callback)
Sets a callback that will be fired when any animation sequence stops.
glm::vec2 GetSizeScale() const
Retrieves the current scale modifier.
void Stop(const bool abruptStop)
Stops the current animation.
void SetEngineStopCallback(StopCallbackFn callback)
void SetSizeScale(const glm::vec2 scale)
Changes the size scale.
Components designed to be used with entities.
Components that are used with the WorldSystem (ECS).
Anything connected to WorldSystem (ECS) is in this namespace.
Global engine namespace.