NW4F Snd
Loading...
Searching...
No Matches
snd_MoveValue.h
Go to the documentation of this file.
1#ifndef NW_SND_MOVE_VALUE_H_
2#define NW_SND_MOVE_VALUE_H_
3
4namespace nw { namespace snd { namespace internal {
5
6template <typename ValueType, typename CountType>
8{
9public:
11 : m_Origin(0)
12 , m_Target(0)
13 , m_Frame(0)
14 , m_Counter(0)
15 {
16 }
17
18 void InitValue(ValueType value)
19 {
20 m_Origin = value;
21 m_Target = value;
22 m_Frame = 0;
23 m_Counter = 0;
24 }
25
26 void SetTarget(ValueType targetValue, CountType frames)
27 {
29 m_Target = targetValue;
30 m_Frame = frames;
31 m_Counter = 0;
32 }
33
34 ValueType GetTarget() const
35 {
36 return m_Target;
37 }
38
39 ValueType GetValue() const
40 {
41 if (IsFinished())
42 return m_Target;
43
44 return static_cast<ValueType>(
45 m_Origin + (m_Target - m_Origin) * ValueType(m_Counter) / ValueType(m_Frame)
46 );
47 }
48
49 void Update()
50 {
51 if (m_Counter < m_Frame)
52 ++m_Counter;
53 }
54
55 bool IsFinished() const
56 {
57 return m_Counter >= m_Frame;
58 }
59
60 CountType GetRemainingCount() const
61 {
62 if (IsFinished())
63 return static_cast<CountType>(0);
64
65 return m_Frame - m_Counter;
66 }
67
68private:
69 ValueType m_Origin;
70 ValueType m_Target;
71 CountType m_Frame;
72 CountType m_Counter;
73};
74
75} } } // namespace nw::snd::internal
76
77#endif // NW_SND_MOVE_VALUE_H_
Definition snd_MoveValue.h:8
void Update()
Definition snd_MoveValue.h:49
CountType GetRemainingCount() const
Definition snd_MoveValue.h:60
CountType m_Counter
Definition snd_MoveValue.h:72
ValueType GetValue() const
Definition snd_MoveValue.h:39
void SetTarget(ValueType targetValue, CountType frames)
Definition snd_MoveValue.h:26
void InitValue(ValueType value)
Definition snd_MoveValue.h:18
ValueType GetTarget() const
Definition snd_MoveValue.h:34
bool IsFinished() const
Definition snd_MoveValue.h:55
CountType m_Frame
Definition snd_MoveValue.h:71
ValueType m_Target
Definition snd_MoveValue.h:70
ValueType m_Origin
Definition snd_MoveValue.h:69
MoveValue()
Definition snd_MoveValue.h:10
Definition snd_BasicSound.cpp:3
Definition snd_BasicSound.cpp:3