Animated: simplified template stuff
Just... why was T_void_value a thing.
This commit is contained in:
parent
8a00056a22
commit
7241561554
2 changed files with 60 additions and 70 deletions
|
@ -27,16 +27,6 @@ void new_animation_frame();
|
|||
int get_current_animation_tick();
|
||||
|
||||
template<typename T>
|
||||
class void_value
|
||||
{
|
||||
public:
|
||||
const T operator()() const
|
||||
{
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename T_void_value = void_value<T>>
|
||||
class animated
|
||||
{
|
||||
public:
|
||||
|
|
120
src/animated.tpp
120
src/animated.tpp
|
@ -17,11 +17,11 @@
|
|||
* Templates related to animations.
|
||||
*/
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
const T animated<T, T_void_value>::void_value_ = T_void_value()();
|
||||
template<typename T>
|
||||
const T animated<T>::void_value_ = T();
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline animated<T, T_void_value>::animated(int start_time)
|
||||
template<typename T>
|
||||
inline animated<T>::animated(int start_time)
|
||||
: starting_frame_time_(start_time)
|
||||
, does_not_change_(true)
|
||||
, started_(false)
|
||||
|
@ -36,8 +36,8 @@ inline animated<T, T_void_value>::animated(int start_time)
|
|||
{
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline animated<T, T_void_value>::animated(const std::vector<std::pair<int, T>>& cfg, int start_time, bool force_change)
|
||||
template<typename T>
|
||||
inline animated<T>::animated(const std::vector<std::pair<int, T>>& cfg, int start_time, bool force_change)
|
||||
: starting_frame_time_(start_time)
|
||||
, does_not_change_(true)
|
||||
, started_(false)
|
||||
|
@ -56,8 +56,8 @@ inline animated<T, T_void_value>::animated(const std::vector<std::pair<int, T>>&
|
|||
}
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::add_frame(int duration, const T& value, bool force_change)
|
||||
template<typename T>
|
||||
inline void animated<T>::add_frame(int duration, const T& value, bool force_change)
|
||||
{
|
||||
// NOTE: We cannot use emplace_back here, because the value may be a reference into the same vector,
|
||||
// which case emplace_back could invalidate it before the new frame is constructed.
|
||||
|
@ -70,8 +70,8 @@ inline void animated<T, T_void_value>::add_frame(int duration, const T& value, b
|
|||
}
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::start_animation(int start_time, bool cycles)
|
||||
template<typename T>
|
||||
inline void animated<T>::start_animation(int start_time, bool cycles)
|
||||
{
|
||||
started_ = true;
|
||||
last_update_tick_ = get_current_animation_tick();
|
||||
|
@ -86,8 +86,8 @@ inline void animated<T, T_void_value>::start_animation(int start_time, bool cycl
|
|||
force_next_update_ = !frames_.empty();
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::update_last_draw_time(double acceleration)
|
||||
template<typename T>
|
||||
inline void animated<T>::update_last_draw_time(double acceleration)
|
||||
{
|
||||
if(acceleration > 0 && acceleration_ != acceleration) {
|
||||
int tmp = tick_to_time(last_update_tick_);
|
||||
|
@ -133,8 +133,8 @@ inline void animated<T, T_void_value>::update_last_draw_time(double acceleration
|
|||
}
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline bool animated<T, T_void_value>::need_update() const
|
||||
template<typename T>
|
||||
inline bool animated<T>::need_update() const
|
||||
{
|
||||
if(force_next_update_) {
|
||||
return true;
|
||||
|
@ -159,8 +159,8 @@ inline bool animated<T, T_void_value>::need_update() const
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline bool animated<T, T_void_value>::animation_finished_potential() const
|
||||
template<typename T>
|
||||
inline bool animated<T>::animation_finished_potential() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return true;
|
||||
|
@ -181,8 +181,8 @@ inline bool animated<T, T_void_value>::animation_finished_potential() const
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline bool animated<T, T_void_value>::animation_finished() const
|
||||
template<typename T>
|
||||
inline bool animated<T>::animation_finished() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return true;
|
||||
|
@ -203,8 +203,8 @@ inline bool animated<T, T_void_value>::animation_finished() const
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_animation_time_potential() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_animation_time_potential() const
|
||||
{
|
||||
if(!started_ && start_tick_ == 0) {
|
||||
return starting_frame_time_;
|
||||
|
@ -213,8 +213,8 @@ inline int animated<T, T_void_value>::get_animation_time_potential() const
|
|||
return tick_to_time(get_current_animation_tick());
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_animation_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_animation_time() const
|
||||
{
|
||||
if(!started_ && start_tick_ == 0) {
|
||||
return starting_frame_time_;
|
||||
|
@ -227,8 +227,8 @@ inline int animated<T, T_void_value>::get_animation_time() const
|
|||
return time;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::set_animation_time(int time)
|
||||
template<typename T>
|
||||
inline void animated<T>::set_animation_time(int time)
|
||||
{
|
||||
start_tick_ = last_update_tick_ + static_cast<int>((starting_frame_time_ - time) / acceleration_);
|
||||
|
||||
|
@ -236,20 +236,20 @@ inline void animated<T, T_void_value>::set_animation_time(int time)
|
|||
force_next_update_ = true;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::set_max_animation_time(int time)
|
||||
template<typename T>
|
||||
inline void animated<T>::set_max_animation_time(int time)
|
||||
{
|
||||
max_animation_time_ = time;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_animation_duration() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_animation_duration() const
|
||||
{
|
||||
return get_end_time() - get_begin_time();
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline const T& animated<T, T_void_value>::get_current_frame() const
|
||||
template<typename T>
|
||||
inline const T& animated<T>::get_current_frame() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return void_value_;
|
||||
|
@ -258,8 +258,8 @@ inline const T& animated<T, T_void_value>::get_current_frame() const
|
|||
return frames_[current_frame_key_].value_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_current_frame_begin_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_current_frame_begin_time() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return starting_frame_time_;
|
||||
|
@ -268,8 +268,8 @@ inline int animated<T, T_void_value>::get_current_frame_begin_time() const
|
|||
return frames_[current_frame_key_].start_time_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_current_frame_end_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_current_frame_end_time() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return starting_frame_time_;
|
||||
|
@ -278,8 +278,8 @@ inline int animated<T, T_void_value>::get_current_frame_end_time() const
|
|||
return get_current_frame_begin_time() + get_current_frame_duration();
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_current_frame_duration() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_current_frame_duration() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return 0;
|
||||
|
@ -288,8 +288,8 @@ inline int animated<T, T_void_value>::get_current_frame_duration() const
|
|||
return frames_[current_frame_key_].duration_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_current_frame_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_current_frame_time() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return 0;
|
||||
|
@ -299,8 +299,8 @@ inline int animated<T, T_void_value>::get_current_frame_time() const
|
|||
return std::max<int>(0, get_animation_time() - get_current_frame_begin_time());
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline const T& animated<T, T_void_value>::get_first_frame() const
|
||||
template<typename T>
|
||||
inline const T& animated<T>::get_first_frame() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return void_value_;
|
||||
|
@ -309,8 +309,8 @@ inline const T& animated<T, T_void_value>::get_first_frame() const
|
|||
return frames_[0].value_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline const T& animated<T, T_void_value>::get_frame(std::size_t n) const
|
||||
template<typename T>
|
||||
inline const T& animated<T>::get_frame(std::size_t n) const
|
||||
{
|
||||
if(n >= frames_.size()) {
|
||||
return void_value_;
|
||||
|
@ -319,8 +319,8 @@ inline const T& animated<T, T_void_value>::get_frame(std::size_t n) const
|
|||
return frames_[n].value_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline const T& animated<T, T_void_value>::get_last_frame() const
|
||||
template<typename T>
|
||||
inline const T& animated<T>::get_last_frame() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return void_value_;
|
||||
|
@ -329,20 +329,20 @@ inline const T& animated<T, T_void_value>::get_last_frame() const
|
|||
return frames_.back().value_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline std::size_t animated<T, T_void_value>::get_frames_count() const
|
||||
template<typename T>
|
||||
inline std::size_t animated<T>::get_frames_count() const
|
||||
{
|
||||
return frames_.size();
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_begin_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_begin_time() const
|
||||
{
|
||||
return starting_frame_time_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::time_to_tick(int animation_time) const
|
||||
template<typename T>
|
||||
inline int animated<T>::time_to_tick(int animation_time) const
|
||||
{
|
||||
if(!started_ && start_tick_ == 0) {
|
||||
return 0;
|
||||
|
@ -351,8 +351,8 @@ inline int animated<T, T_void_value>::time_to_tick(int animation_time) const
|
|||
return start_tick_ + static_cast<int>((animation_time - starting_frame_time_) / acceleration_);
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::tick_to_time(int animation_tick) const
|
||||
template<typename T>
|
||||
inline int animated<T>::tick_to_time(int animation_tick) const
|
||||
{
|
||||
if(!started_ && start_tick_ == 0) {
|
||||
return 0;
|
||||
|
@ -361,8 +361,8 @@ inline int animated<T, T_void_value>::tick_to_time(int animation_tick) const
|
|||
return static_cast<int>((static_cast<double>(animation_tick - start_tick_) * acceleration_) + starting_frame_time_);
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline int animated<T, T_void_value>::get_end_time() const
|
||||
template<typename T>
|
||||
inline int animated<T>::get_end_time() const
|
||||
{
|
||||
if(frames_.empty()) {
|
||||
return starting_frame_time_;
|
||||
|
@ -371,8 +371,8 @@ inline int animated<T, T_void_value>::get_end_time() const
|
|||
return frames_.back().start_time_ + frames_.back().duration_;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
void animated<T, T_void_value>::remove_frames_until(int new_starting_time)
|
||||
template<typename T>
|
||||
void animated<T>::remove_frames_until(int new_starting_time)
|
||||
{
|
||||
while(starting_frame_time_ < new_starting_time && !frames_.empty()) {
|
||||
starting_frame_time_ += frames_[0].duration_;
|
||||
|
@ -380,8 +380,8 @@ void animated<T, T_void_value>::remove_frames_until(int new_starting_time)
|
|||
}
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::set_end_time(int new_ending_time)
|
||||
template<typename T>
|
||||
inline void animated<T>::set_end_time(int new_ending_time)
|
||||
{
|
||||
int last_start_time = starting_frame_time_;
|
||||
typename std::vector<frame>::iterator current_frame = frames_.begin();
|
||||
|
@ -396,8 +396,8 @@ inline void animated<T, T_void_value>::set_end_time(int new_ending_time)
|
|||
frames_.back().duration_ += new_ending_time - last_start_time;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
inline void animated<T, T_void_value>::set_begin_time(int new_begin_time)
|
||||
template<typename T>
|
||||
inline void animated<T>::set_begin_time(int new_begin_time)
|
||||
{
|
||||
const int variation = new_begin_time - starting_frame_time_;
|
||||
starting_frame_time_ += variation;
|
||||
|
|
Loading…
Add table
Reference in a new issue