Fix idle anim rate not being saved properly (fixes #8613)
(cherry picked from commit cd6f3fade7
)
This commit is contained in:
parent
d39ceb1aa3
commit
a3c1bc17cc
3 changed files with 23 additions and 18 deletions
|
@ -522,14 +522,14 @@ void set_idle_anim(const bool ison)
|
||||||
prefs["idle_anim"] = ison;
|
prefs["idle_anim"] = ison;
|
||||||
}
|
}
|
||||||
|
|
||||||
double idle_anim_rate()
|
int idle_anim_rate()
|
||||||
{
|
{
|
||||||
return prefs["idle_anim_rate"].to_double(1.0);
|
return prefs["idle_anim_rate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_idle_anim_rate(const int rate)
|
void set_idle_anim_rate(int rate)
|
||||||
{
|
{
|
||||||
prefs["idle_anim_rate"] = std::pow(2.0, -rate / 10.0);
|
prefs["idle_anim_rate"] = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string language()
|
std::string language()
|
||||||
|
|
|
@ -112,8 +112,8 @@ namespace preferences {
|
||||||
bool idle_anim();
|
bool idle_anim();
|
||||||
void set_idle_anim(const bool ison);
|
void set_idle_anim(const bool ison);
|
||||||
|
|
||||||
double idle_anim_rate();
|
int idle_anim_rate();
|
||||||
void set_idle_anim_rate(const int rate);
|
void set_idle_anim_rate(int rate);
|
||||||
|
|
||||||
std::string language();
|
std::string language();
|
||||||
void set_language(const std::string& s);
|
void set_language(const std::string& s);
|
||||||
|
|
|
@ -26,6 +26,21 @@
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int get_next_idle_time()
|
||||||
|
{
|
||||||
|
if(!preferences::idle_anim()) {
|
||||||
|
return INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// I really don't know why this negates the saved rate first
|
||||||
|
const double rate = std::pow(2.0, -preferences::idle_anim_rate() / 10.0);
|
||||||
|
return get_current_animation_tick()
|
||||||
|
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * rate);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
const unit_animation* unit_animation_component::choose_animation(const map_location& loc,const std::string& event,
|
const unit_animation* unit_animation_component::choose_animation(const map_location& loc,const std::string& event,
|
||||||
const map_location& second_loc,const int value,const strike_result::type hit,
|
const map_location& second_loc,const int value,const strike_result::type hit,
|
||||||
const_attack_ptr attack, const_attack_ptr second_attack, int swing_num)
|
const_attack_ptr attack, const_attack_ptr second_attack, int swing_num)
|
||||||
|
@ -110,12 +125,7 @@ void unit_animation_component::start_animation (int start_time, const unit_anima
|
||||||
anim_->start_animation(real_start_time, u_.loc_, u_.loc_.get_direction(u_.facing_),
|
anim_->start_animation(real_start_time, u_.loc_, u_.loc_.get_direction(u_.facing_),
|
||||||
text, text_color, accelerate);
|
text, text_color, accelerate);
|
||||||
frame_begin_time_ = anim_->get_begin_time() -1;
|
frame_begin_time_ = anim_->get_begin_time() -1;
|
||||||
if (preferences::idle_anim()) {
|
next_idling_ = get_next_idle_time();
|
||||||
next_idling_ = get_current_animation_tick()
|
|
||||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * preferences::idle_anim_rate());
|
|
||||||
} else {
|
|
||||||
next_idling_ = INT_MAX;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unit_animation_component::refresh()
|
void unit_animation_component::refresh()
|
||||||
|
@ -134,12 +144,7 @@ void unit_animation_component::refresh()
|
||||||
if (get_current_animation_tick() > next_idling_ + 1000)
|
if (get_current_animation_tick() > next_idling_ + 1000)
|
||||||
{
|
{
|
||||||
// prevent all units animating at the same time
|
// prevent all units animating at the same time
|
||||||
if (preferences::idle_anim()) {
|
next_idling_ = get_next_idle_time();
|
||||||
next_idling_ = get_current_animation_tick()
|
|
||||||
+ static_cast<int>(randomness::rng::default_instance().get_random_int(20000, 39999) * preferences::idle_anim_rate());
|
|
||||||
} else {
|
|
||||||
next_idling_ = INT_MAX;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
set_idling();
|
set_idling();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue