Skip to content

Commit

Permalink
Merge pull request #6701 from bencsikandrei/various_fixes_animated_h_cpp
Browse files Browse the repository at this point in the history
Remove some dead code (maybe a merge defect?)
  • Loading branch information
Vultraz committed May 13, 2022
2 parents e5dbbf6 + 4476ee4 commit b6519cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/animated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ template<typename T>
class animated
{
public:
animated(int start_time = 0);
virtual ~animated() {}

typedef std::pair<int, T> frame_description;
typedef std::vector<frame_description> anim_description;
animated(const std::vector<frame_description>& cfg, int start_time = 0, bool force_change = false);

animated(int start_time = 0);
explicit animated(const std::vector<frame_description>& cfg, int start_time = 0, bool force_change = false);

virtual ~animated() = default;

/** Adds a frame to an animation. */
void add_frame(int duration, const T& value, bool force_change = false);
Expand Down Expand Up @@ -107,10 +108,12 @@ class animated

protected:
friend class unit_animation;
int starting_frame_time_;

void remove_frames_until(int starting_time);
void set_end_time(int ending_time);

int starting_frame_time_;

private:
struct frame
{
Expand Down
17 changes: 7 additions & 10 deletions src/animated.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ inline void animated<T>::start_animation(int start_time, bool cycles)
started_ = true;
last_update_tick_ = get_current_animation_tick();
acceleration_ = 1.0; // assume acceleration is 1, this will be fixed at first update_last_draw_time
start_tick_ = last_update_tick_ + static_cast<int>((starting_frame_time_ - start_time) / acceleration_);

start_tick_ = last_update_tick_ + (starting_frame_time_ - start_time);
cycles_ = cycles;
if(acceleration_ <= 0) {
acceleration_ = 1;
}
current_frame_key_ = 0;
force_next_update_ = !frames_.empty();
}
Expand Down Expand Up @@ -129,8 +125,9 @@ inline void animated<T>::update_last_draw_time(double acceleration)
}
}

if(get_current_frame_end_time() < get_animation_time() && // catch up
get_current_frame_end_time() < get_end_time()) { // don't go after the end
const int current_frame_end_time = get_current_frame_end_time();
// catch up && don't go after the end
if(current_frame_end_time < get_animation_time() && current_frame_end_time < get_end_time()) {
current_frame_key_++;
}
}
Expand Down Expand Up @@ -223,7 +220,7 @@ inline int animated<T>::get_animation_time() const
}

int time = tick_to_time(last_update_tick_);
if (time > max_animation_time_ && max_animation_time_ > 0) {
if(time > max_animation_time_ && max_animation_time_ > 0) {
return max_animation_time_;
}
return time;
Expand Down Expand Up @@ -386,8 +383,8 @@ 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();
while(last_start_time < new_ending_time && current_frame != frames_.end()) {
auto current_frame = frames_.cbegin();
while(last_start_time < new_ending_time && current_frame != frames_.cend()) {
last_start_time += current_frame->duration_;
++current_frame;
}
Expand Down

0 comments on commit b6519cc

Please sign in to comment.