JugiMap Framework
jmTimelineAnimationInstance.h
1 #ifndef JUGIMAP_TIMELINE_ANIMATION_INSTANCE_H
2 #define JUGIMAP_TIMELINE_ANIMATION_INSTANCE_H
3 
4 
5 #include "jmMap.h"
6 #include "jmTimelineAnimation.h"
7 
8 
9 
10 namespace jugimap{
11 
12 
13 
14 
15 class SourceSprite;
16 class Sprite;
17 class VectorShape;
18 
19 
20 class TimelineAnimation;
21 class AnimationQueuePlayer;
22 class FrameAnimationInstance;
23 class AnimationMemberState;
24 class TimelineAnimationInstance;
25 
26 
27 
28 
29 class AnimationTrackState
30 {
31 public:
32 
33  AnimationTrackState(AnimationTrack* _tAnimation, AnimationMemberState* _tAnimationsStatesSet);
34  virtual ~AnimationTrackState();
35 
36 
37  bool Empty(){ return (activeStartKey==nullptr && activeEndKey==nullptr); }
38  AnimationTrackKind GetKind();
39 
40  AnimationTrack* GetAnimationTrack(){ return animationTrack; }
41  AnimationKey* GetStateKey(){ return stateKey; }
42  AnimationKey* GetActiveStartKey(){ return activeStartKey; }
43  AnimationKey* GetActiveEndKey(){ return activeEndKey; }
44  AnimationKey* GetActiveKey(){ return (activeStartKey!=nullptr)? activeStartKey : activeEndKey;}
45 
46  VectorShape * GetPath(){ return path; }
47  AnimationQueuePlayer* GetTimelineAnimationQueuePlayer(){ return timelineAnimationPlayer; }
48  AnimationQueuePlayer* GetFrameAnimationPlayer(){ return frameAnimationPlayer; }
49  AnimationTrackParameters &GetTrackParameters(){ return tp; };
50 
51  bool IsDisabled(){ return disabled; }
52  void SetDisabled(bool _disabled){ disabled = _disabled; }
53 
54  int Update(int _animationTime, int _flags);
55 
56  void _ClearLinkPointers(VectorShape* _shape);
57 
58 private:
60 
61  AnimationMemberState * animationMemberState = nullptr; // LINK to owner
62  AnimationTrack* animationTrack = nullptr; // LINK to related tAnimation object
63  AnimationKey* activeStartKey = nullptr; // LINK to a key in tAnimation
64  AnimationKey* activeEndKey = nullptr; // LINK to a key in tAnimation
65 
66  //---
67  AnimationKey *stateKey = nullptr; // OWNED
68 
69  AnimationQueuePlayer *frameAnimationPlayer = nullptr; // OWNED, sub-player
70  std::vector<FrameAnimationInstance*>*frameAnimationInstances = nullptr; // OWNED, instances for sub-player
71  //EFrameAnimationInstance* activeFrameAnimationInstance = nullptr;
72 
73  AnimationQueuePlayer* timelineAnimationPlayer = nullptr; // OWNED, sub-player
74  std::vector<TimelineAnimationInstance*>*timelineAnimationInstances = nullptr; // OWNED, instances for sub-player
75  //ETimelineAnimationInstance* activeTimelineAnimationInstance = nullptr; // LINK
76 
77  AnimationTrackParameters tp; // OWNED
78 
79  //---
80  VectorShape *path = nullptr; // LINK, stored pointer for quicker access
81  SourceSprite* sourceObject = nullptr; // LINK, stored pointer for quicker access
82 
83  bool disabled = false;
84 
85 
86  void SetActiveKeys(int _animationTime);
87  int ManageSubTimelineAnimation();
88  int ManageSubFrameAnimation();
89  void FindSourceObject();
90  Map* FindMap();
91 
92  TimelineAnimationInstance* FindTimelineAnimationInstance(const std::string& _name);
93  TimelineAnimationInstance* CreateAndStoreTimelineAnimationInstance(const std::string& _name);
94 
95  FrameAnimationInstance* FindFrameAnimationInstance(const std::string& _name);
96  FrameAnimationInstance* CreateAndStoreFrameAnimationInstance(const std::string& _name);
97 
98 };
99 
100 
101 //================================================================
102 
103 
104 class AnimationMemberState
105 {
106 public:
107  friend class AnimationTrackState;
108  friend class TimelineAnimationInstance;
109 
110 
111  AnimationMember *GetAnimationMember(){ return animationMember; }
112  std::vector<AnimationTrackState*> &GetAnimationTrackStates(){ return animationsTrackStates; }
113  Sprite* _GetSprite(){ return sprite;}
114  std::vector<Sprite*>* _GetSprites(){ return sprites;}
115 
116  bool IsDisabled(){ return disabled; }
117  void SetDisabled(bool _disabled){ disabled = _disabled; }
118 
119 
120 private:
121 
122  AnimationMemberState(AnimationMember *_animationMember);
123  AnimationMemberState(const AnimationMember &_animationMember) = delete;
124  AnimationMemberState& operator=(const AnimationMember &_animationMember) = delete;
125  ~AnimationMemberState();
126 
127 
128  int Update(int msTimePoint, int _flags);
129  void StopSubPlayers();
130  void PauseSubPlayers();
131  void ResumeSubPlayers();
132  void ResetAnimatedProperties();
133 
134 
135  AnimationMember * animationMember = nullptr; //LINK
136  std::vector<AnimationTrackState*>animationsTrackStates;
137 
138  Sprite* sprite = nullptr; // LINK
139  std::vector<Sprite*>*sprites = nullptr; // vector OWNED, sprites LINKS
140  AnimatedProperties ap;
141  bool disabled = false;
142 
143  TimelineAnimationInstance* animationInstance = nullptr; // LINK
144 
145 
146  int UpdateAnimatedProperties(AnimationTrackState & _ats);
147  void ResetSpritesAnimatedProperties();
148  void UpdateAnimatedSprites();
149 
150 };
151 
152 
153 
154 //================================================================
155 
156 
160 {
161 public:
162 
163  //friend class AnimationQueuePlayer;
164 
165 
169  TimelineAnimationInstance(TimelineAnimation *_timelineAnimation, Sprite *_sprite);
170 
171 
176  TimelineAnimationInstance(TimelineAnimation *_timelineAnimation, std::vector<Sprite*>&_sprites);
177 
178 
180  ~TimelineAnimationInstance() override;
181 
182 
184  Sprite* GetSprite(){ return animationsMemberStates.front()->_GetSprite();}
185 
186 
190  std::vector<Sprite*>* GetSprites(){ return animationsMemberStates.front()->_GetSprites();}
191 
192 
194  std::vector<AnimationMemberState*>& GetAnimationsMemberStates(){ return animationsMemberStates;}
195 
196 
198  AnimationTrackState* GetMetaAnimationTrackState(){ return metaAnimationTrackState;}
199 
200 
201 
202  int Update(int msTimePoint, int _flags) override;
203  void StopSubPlayers();
204  void PauseSubPlayers();
205  void ResumeSubPlayers();
206 
207  void UpdateAnimatedSprites(bool _resetSpriteAnimatedProperties) override;
208  void ResetAnimatedProperties() override;
209 
210  void ClearLinkPointers(VectorShape* _shape);
211 
212 
214  AnimationMemberState* FindAnimationMemberState(AnimationMember* _animationMember);
215 
216 
219  AnimationTrackState* FindAnimationTrackState(AnimationTrackKind _animationTrackKind, const std::string &_memberName="");
220 
221 
223  AnimationTrackState* FindAnimationTrackState(AnimationTrack* _animationTrack);
224 
225 
226 private:
227  std::vector<AnimationMemberState*>animationsMemberStates; // OWNED
228  AnimationTrackState* metaAnimationTrackState = nullptr; // OWNED
229 
231  TimelineAnimationInstance(const TimelineAnimationInstance &src) = delete;
232  TimelineAnimationInstance& operator=(const TimelineAnimationInstance &src) = delete;
233 };
234 
235 
236 
237 
238 
239 }
240 
241 
242 
243 
244 #endif
jugimap::TimelineAnimationInstance::GetAnimationsMemberStates
std::vector< AnimationMemberState * > & GetAnimationsMemberStates()
Returns a reference to the vector of animation members.
Definition: jmTimelineAnimationInstance.h:194
jugimap::TimelineAnimationInstance::UpdateAnimatedSprites
void UpdateAnimatedSprites(bool _resetSpriteAnimatedProperties) override
Update the animated sprites.
Definition: jmTimelineAnimationInstance.cpp:905
jugimap::TimelineAnimation
The TimelineAnimation class represents the sprite timeline animation from JugiMap Editor.
Definition: jmTimelineAnimation.h:481
jugimap::TimelineAnimationInstance::GetSprites
std::vector< Sprite * > * GetSprites()
Returns a pointer to the vector of assigned sprites; if one sprite has been assigned it returns nullp...
Definition: jmTimelineAnimationInstance.h:190
jugimap::TimelineAnimationInstance::FindAnimationMemberState
AnimationMemberState * FindAnimationMemberState(AnimationMember *_animationMember)
Returns a pointer to animation member state object of the given *_animationMember*....
Definition: jmTimelineAnimationInstance.cpp:987
jugimap::AnimationTrackKind
AnimationTrackKind
The kinds of animation track. Used as identifier for AnimationTrack and AnimationKey classes.
Definition: jmGlobal.h:157
jugimap::AnimationInstance
The base animation instance class.
Definition: jmAnimationCommon.h:163
jugimap::Sprite
The Sprite is the base sprite class.
Definition: jmSprites.h:32
jugimap::TimelineAnimationInstance::~TimelineAnimationInstance
~TimelineAnimationInstance() override
Destructor.
Definition: jmTimelineAnimationInstance.cpp:890
jugimap::TimelineAnimationInstance::GetSprite
Sprite * GetSprite()
Returns the assigned sprite; if a vector of sprites has been assigned it returns nullptr!
Definition: jmTimelineAnimationInstance.h:184
jugimap::TimelineAnimationInstance::FindAnimationTrackState
AnimationTrackState * FindAnimationTrackState(AnimationTrackKind _animationTrackKind, const std::string &_memberName="")
Returns a pointer to animation track state object of the given AnimationTrackKind within the member w...
Definition: jmTimelineAnimationInstance.cpp:1001
jugimap::TimelineAnimationInstance
A class for using timeline animations in animation players.
Definition: jmTimelineAnimationInstance.h:159
jugimap::TimelineAnimationInstance::Update
int Update(int msTimePoint, int _flags) override
Update the animation state for the given msTimePoint.
Definition: jmTimelineAnimationInstance.cpp:919
jugimap::AnimationTrackKind::NOT_DEFINED
Not defined.
jugimap::VectorShape
The VectorShape class defines the vector shape from JugiMap Editor.
Definition: jmVectorShapes.h:206
jugimap::TimelineAnimationInstance::GetMetaAnimationTrackState
AnimationTrackState * GetMetaAnimationTrackState()
Returns a pointer to meta track state. If the animation has no meta track returns nullptr.
Definition: jmTimelineAnimationInstance.h:198