qxLib
easing_sequence.h
Go to the documentation of this file.
1 /**
2 
3  @file easing_sequence.h
4  @author Khrapov
5  @date 4.05.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/macros/common.h>
13 
14 #include <vector>
15 
16 namespace qx
17 {
18 
19 /**
20 
21  @class base_easing_sequence
22  @brief qx::base_easing_element queue
23  @tparam T - floating point ish value
24  @author Khrapov
25  @date 04.05.2021
26 
27 **/
28 template<class T>
30 {
31 public:
33  using type = T;
34 
35 public:
36  /**
37  @brief Add easing element to queue
38  @param element - easing element
39  **/
40  void push_back(easing_element_type element) noexcept;
41 
42  /**
43  @brief Add easing element to queue by constructing in-place
44  @tparam args_t - template parameter pack type
45  @param args - arguments for constructing
46  **/
47  template<class... args_t>
48  void emplace_back(args_t&&... args) noexcept;
49 
50  /**
51  @brief Clear elements queue
52  **/
53  void clear() noexcept;
54 
55  /**
56  @brief Start easing element sequence playing
57  **/
58  void start() noexcept;
59 
60  /**
61  @brief Pause easing element sequence playing
62  **/
63  void pause() noexcept;
64 
65  /**
66  @brief Resume easing element sequence playing
67  **/
68  void resume() noexcept;
69 
70  /**
71  @brief Skip current element
72  **/
73  void skip() noexcept;
74 
75  /**
76  @brief Reset sequence
77  **/
78  void reset() noexcept;
79 
80  /**
81  @brief Update easing element sequence
82  @param fDeltaTime - delta time
83  **/
84  void update(T fDeltaTime) noexcept;
85 
86  /**
87  @brief Set loop state
88  @param bLooped - true if loop
89  **/
90  void set_looped(bool bLooped) noexcept;
91 
92  /**
93  @brief Set updating speed value
94  @param fSpeed - speed
95  **/
96  void set_speed(T fSpeed) noexcept;
97 
98  /**
99  @brief Get value of current sequence element
100  @retval - value of current sequence element
101  **/
102  T get() const noexcept;
103 
104  /**
105  @brief Get a fraction indicating how much of the sequence has played
106  @retval - fraction [0.0, 1.0]
107  **/
108  T get_fraction() const noexcept;
109 
110  /**
111  @brief Get updating speed value
112  @retval - speed
113  **/
114  T get_speed() const noexcept;
115 
116  /**
117  @brief Is sequence not started
118  @retval - true if sequence is not started
119  **/
120  bool is_not_started() const noexcept;
121 
122  /**
123  @brief Is sequence started
124  @retval - true if sequence is started
125  **/
126  bool is_started() const noexcept;
127 
128  /**
129  @brief Is sequence paused
130  @retval - true if sequence is paused
131  **/
132  bool is_paused() const noexcept;
133 
134  /**
135  @brief Is sequence finished
136  @retval - true if sequence is finished
137  **/
138  bool is_finished() const noexcept;
139 
140  /**
141  @brief Is sequence looped
142  @retval - true if sequence is looped
143  **/
144  bool is_looped() const noexcept;
145 
146 private:
147  /**
148  @brief Get current element pointer or nullptr if no elements
149  @retval - current element pointer or nullptr if no elements
150  **/
151  easing_element_type* get_current_element() noexcept;
152 
153  /**
154  @brief Get current element pointer or nullptr if no elements
155  @retval - current element pointer or nullptr if no elements
156  **/
157  const easing_element_type* get_current_element() const noexcept;
158 
159  /**
160  @brief Update total time by adding time from last element
161  **/
162  void update_total_time() noexcept;
163 
164 private:
165  std::vector<easing_element_type> m_ElementsSequence;
166  size_t m_nCurrentElement = 0;
167  T m_fTotalTime = T(0.f);
168  T m_fCurrentTime = T(0.f);
169  T m_fSpeed = T(1.f);
170  bool m_bLoop = false;
171 };
172 
174 
175 } // namespace qx
176 
An updatable element representing the value of the easing function at a given time.
qx::base_easing_element queue
bool is_started() const noexcept
Is sequence started.
T get_speed() const noexcept
Get updating speed value.
void update(T fDeltaTime) noexcept
Update easing element sequence.
void start() noexcept
Start easing element sequence playing.
void clear() noexcept
Clear elements queue.
void pause() noexcept
Pause easing element sequence playing.
void skip() noexcept
Skip current element.
bool is_paused() const noexcept
Is sequence paused.
bool is_finished() const noexcept
Is sequence finished.
T get_fraction() const noexcept
Get a fraction indicating how much of the sequence has played.
void resume() noexcept
Resume easing element sequence playing.
void emplace_back(args_t &&... args) noexcept
Add easing element to queue by constructing in-place.
T get() const noexcept
Get value of current sequence element.
void set_looped(bool bLooped) noexcept
Set loop state.
void reset() noexcept
Reset sequence.
bool is_not_started() const noexcept
Is sequence not started.
void set_speed(T fSpeed) noexcept
Set updating speed value.
bool is_looped() const noexcept
Is sequence looped.
void push_back(easing_element_type element) noexcept
Add easing element to queue.