Otclient  14/8/2020
animator.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22 
23 #ifndef ANIMATOR_H
24 #define ANIMATOR_H
25 
26 #include "declarations.h"
27 
29 
31 {
35 };
36 
38 {
41 };
42 
44 {
45 public:
46  Animator();
47 
48  void unserialize(int animationPhases, const FileStreamPtr& fin);
49  void serialize(const FileStreamPtr& fin);
50 
51  void setPhase(int phase);
52  int getPhase();
53  int getPhaseAt(ticks_t time);
54 
55  int getStartPhase();
56  int getAnimationPhases() { return m_animationPhases; }
57  bool isAsync() { return m_async; }
58  bool isComplete() { return m_isComplete; }
59 
61 
62  void resetAnimation();
63 
64 private:
65  int getPingPongPhase();
66  int getLoopPhase();
67  int getPhaseDuration(int phase);
68  void calculateSynchronous();
69 
70  int m_animationPhases;
71  int m_startPhase;
72  int m_loopCount;
73  bool m_async;
74  std::vector< std::tuple<int, int> > m_phaseDurations;
75 
76  int m_currentDuration;
77  AnimationDirection m_currentDirection;
78  int m_currentLoop;
79 
80  ticks_t m_lastPhaseTicks;
81  bool m_isComplete;
82 
83  int m_phase;
84 };
85 
86 #endif
AnimDirBackward
@ AnimDirBackward
Definition: animator.h:40
Animator::isComplete
bool isComplete()
Definition: animator.h:58
Animator::unserialize
void unserialize(int animationPhases, const FileStreamPtr &fin)
Definition: animator.cpp:43
Animator::getTotalDuration
ticks_t getTotalDuration()
Definition: animator.cpp:219
ticks_t
int64 ticks_t
Definition: types.h:43
Animator::getAnimationPhases
int getAnimationPhases()
Definition: animator.h:56
AnimDirForward
@ AnimDirForward
Definition: animator.h:39
Animator::serialize
void serialize(const FileStreamPtr &fin)
Definition: animator.cpp:62
stdext::time
ticks_t time()
Definition: time.cpp:33
Animator::getPhaseAt
int getPhaseAt(ticks_t time)
Definition: animator.cpp:126
declarations.h
declarations.h
AnimPhaseAutomatic
@ AnimPhaseAutomatic
Definition: animator.h:32
AnimationPhase
AnimationPhase
Definition: animator.h:30
AnimationDirection
AnimationDirection
Definition: animator.h:37
Animator::isAsync
bool isAsync()
Definition: animator.h:57
stdext::shared_object_ptr< FileStream >
Animator::Animator
Animator()
Definition: animator.cpp:29
AnimPhaseAsync
@ AnimPhaseAsync
Definition: animator.h:34
int16
int16_t int16
Definition: types.h:40
Animator::getStartPhase
int getStartPhase()
Definition: animator.cpp:144
Animator
Definition: animator.h:43
stdext::shared_object
Definition: shared_object.h:41
AnimPhaseRandom
@ AnimPhaseRandom
Definition: animator.h:33
uint8
uint8_t uint8
Definition: types.h:37
Animator::resetAnimation
void resetAnimation()
Definition: animator.cpp:151
Animator::getPhase
int getPhase()
Definition: animator.cpp:96
Animator::setPhase
void setPhase(int phase)
Definition: animator.cpp:74