From 773cc212b374b6738cf9f474adcf50d76ad3f097 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sat, 21 Apr 2018 16:04:16 +1100 Subject: [PATCH] Animated: simplified template stuff Just... why was T_void_value a thing. --- src/animated.hpp | 10 ---- src/animated.tpp | 120 +++++++++++++++++++++++------------------------ 2 files changed, 60 insertions(+), 70 deletions(-) diff --git a/src/animated.hpp b/src/animated.hpp index e6f84f4ffdde..6368675bc47e 100644 --- a/src/animated.hpp +++ b/src/animated.hpp @@ -27,16 +27,6 @@ void new_animation_frame(); int get_current_animation_tick(); template -class void_value -{ -public: - const T operator()() const - { - return T(); - } -}; - -template> class animated { public: diff --git a/src/animated.tpp b/src/animated.tpp index a93fb6ec22f5..85f9807b74fb 100644 --- a/src/animated.tpp +++ b/src/animated.tpp @@ -17,11 +17,11 @@ * Templates related to animations. */ -template -const T animated::void_value_ = T_void_value()(); +template +const T animated::void_value_ = T(); -template -inline animated::animated(int start_time) +template +inline animated::animated(int start_time) : starting_frame_time_(start_time) , does_not_change_(true) , started_(false) @@ -36,8 +36,8 @@ inline animated::animated(int start_time) { } -template -inline animated::animated(const std::vector>& cfg, int start_time, bool force_change) +template +inline animated::animated(const std::vector>& cfg, int start_time, bool force_change) : starting_frame_time_(start_time) , does_not_change_(true) , started_(false) @@ -56,8 +56,8 @@ inline animated::animated(const std::vector>& } } -template -inline void animated::add_frame(int duration, const T& value, bool force_change) +template +inline void animated::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::add_frame(int duration, const T& value, b } } -template -inline void animated::start_animation(int start_time, bool cycles) +template +inline void animated::start_animation(int start_time, bool cycles) { started_ = true; last_update_tick_ = get_current_animation_tick(); @@ -86,8 +86,8 @@ inline void animated::start_animation(int start_time, bool cycl force_next_update_ = !frames_.empty(); } -template -inline void animated::update_last_draw_time(double acceleration) +template +inline void animated::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::update_last_draw_time(double acceleration } } -template -inline bool animated::need_update() const +template +inline bool animated::need_update() const { if(force_next_update_) { return true; @@ -159,8 +159,8 @@ inline bool animated::need_update() const return false; } -template -inline bool animated::animation_finished_potential() const +template +inline bool animated::animation_finished_potential() const { if(frames_.empty()) { return true; @@ -181,8 +181,8 @@ inline bool animated::animation_finished_potential() const return false; } -template -inline bool animated::animation_finished() const +template +inline bool animated::animation_finished() const { if(frames_.empty()) { return true; @@ -203,8 +203,8 @@ inline bool animated::animation_finished() const return false; } -template -inline int animated::get_animation_time_potential() const +template +inline int animated::get_animation_time_potential() const { if(!started_ && start_tick_ == 0) { return starting_frame_time_; @@ -213,8 +213,8 @@ inline int animated::get_animation_time_potential() const return tick_to_time(get_current_animation_tick()); } -template -inline int animated::get_animation_time() const +template +inline int animated::get_animation_time() const { if(!started_ && start_tick_ == 0) { return starting_frame_time_; @@ -227,8 +227,8 @@ inline int animated::get_animation_time() const return time; } -template -inline void animated::set_animation_time(int time) +template +inline void animated::set_animation_time(int time) { start_tick_ = last_update_tick_ + static_cast((starting_frame_time_ - time) / acceleration_); @@ -236,20 +236,20 @@ inline void animated::set_animation_time(int time) force_next_update_ = true; } -template -inline void animated::set_max_animation_time(int time) +template +inline void animated::set_max_animation_time(int time) { max_animation_time_ = time; } -template -inline int animated::get_animation_duration() const +template +inline int animated::get_animation_duration() const { return get_end_time() - get_begin_time(); } -template -inline const T& animated::get_current_frame() const +template +inline const T& animated::get_current_frame() const { if(frames_.empty()) { return void_value_; @@ -258,8 +258,8 @@ inline const T& animated::get_current_frame() const return frames_[current_frame_key_].value_; } -template -inline int animated::get_current_frame_begin_time() const +template +inline int animated::get_current_frame_begin_time() const { if(frames_.empty()) { return starting_frame_time_; @@ -268,8 +268,8 @@ inline int animated::get_current_frame_begin_time() const return frames_[current_frame_key_].start_time_; } -template -inline int animated::get_current_frame_end_time() const +template +inline int animated::get_current_frame_end_time() const { if(frames_.empty()) { return starting_frame_time_; @@ -278,8 +278,8 @@ inline int animated::get_current_frame_end_time() const return get_current_frame_begin_time() + get_current_frame_duration(); } -template -inline int animated::get_current_frame_duration() const +template +inline int animated::get_current_frame_duration() const { if(frames_.empty()) { return 0; @@ -288,8 +288,8 @@ inline int animated::get_current_frame_duration() const return frames_[current_frame_key_].duration_; } -template -inline int animated::get_current_frame_time() const +template +inline int animated::get_current_frame_time() const { if(frames_.empty()) { return 0; @@ -299,8 +299,8 @@ inline int animated::get_current_frame_time() const return std::max(0, get_animation_time() - get_current_frame_begin_time()); } -template -inline const T& animated::get_first_frame() const +template +inline const T& animated::get_first_frame() const { if(frames_.empty()) { return void_value_; @@ -309,8 +309,8 @@ inline const T& animated::get_first_frame() const return frames_[0].value_; } -template -inline const T& animated::get_frame(std::size_t n) const +template +inline const T& animated::get_frame(std::size_t n) const { if(n >= frames_.size()) { return void_value_; @@ -319,8 +319,8 @@ inline const T& animated::get_frame(std::size_t n) const return frames_[n].value_; } -template -inline const T& animated::get_last_frame() const +template +inline const T& animated::get_last_frame() const { if(frames_.empty()) { return void_value_; @@ -329,20 +329,20 @@ inline const T& animated::get_last_frame() const return frames_.back().value_; } -template -inline std::size_t animated::get_frames_count() const +template +inline std::size_t animated::get_frames_count() const { return frames_.size(); } -template -inline int animated::get_begin_time() const +template +inline int animated::get_begin_time() const { return starting_frame_time_; } -template -inline int animated::time_to_tick(int animation_time) const +template +inline int animated::time_to_tick(int animation_time) const { if(!started_ && start_tick_ == 0) { return 0; @@ -351,8 +351,8 @@ inline int animated::time_to_tick(int animation_time) const return start_tick_ + static_cast((animation_time - starting_frame_time_) / acceleration_); } -template -inline int animated::tick_to_time(int animation_tick) const +template +inline int animated::tick_to_time(int animation_tick) const { if(!started_ && start_tick_ == 0) { return 0; @@ -361,8 +361,8 @@ inline int animated::tick_to_time(int animation_tick) const return static_cast((static_cast(animation_tick - start_tick_) * acceleration_) + starting_frame_time_); } -template -inline int animated::get_end_time() const +template +inline int animated::get_end_time() const { if(frames_.empty()) { return starting_frame_time_; @@ -371,8 +371,8 @@ inline int animated::get_end_time() const return frames_.back().start_time_ + frames_.back().duration_; } -template -void animated::remove_frames_until(int new_starting_time) +template +void animated::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::remove_frames_until(int new_starting_time) } } -template -inline void animated::set_end_time(int new_ending_time) +template +inline void animated::set_end_time(int new_ending_time) { int last_start_time = starting_frame_time_; typename std::vector::iterator current_frame = frames_.begin(); @@ -396,8 +396,8 @@ inline void animated::set_end_time(int new_ending_time) frames_.back().duration_ += new_ending_time - last_start_time; } -template -inline void animated::set_begin_time(int new_begin_time) +template +inline void animated::set_begin_time(int new_begin_time) { const int variation = new_begin_time - starting_frame_time_; starting_frame_time_ += variation;