mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-15 01:55:09 +00:00
a smoother interface for updating pump_info ticks
This commit is contained in:
parent
de8fb5fb3e
commit
7ac297e25e
@ -342,8 +342,7 @@ void pump()
|
||||
if(event.button.button == SDL_BUTTON_LEFT) {
|
||||
static const int DoubleClickTime = 500;
|
||||
static const int DoubleClickMaxMove = 3;
|
||||
info.ticks = ::SDL_GetTicks();
|
||||
if(last_mouse_down >= 0 && info.ticks - last_mouse_down < DoubleClickTime &&
|
||||
if(last_mouse_down >= 0 && info.ticks() - last_mouse_down < DoubleClickTime &&
|
||||
abs(event.button.x - last_click_x) < DoubleClickMaxMove &&
|
||||
abs(event.button.y - last_click_y) < DoubleClickMaxMove) {
|
||||
SDL_UserEvent user_event;
|
||||
@ -353,7 +352,7 @@ void pump()
|
||||
user_event.data2 = reinterpret_cast<void*>(event.button.y);
|
||||
::SDL_PushEvent(reinterpret_cast<SDL_Event*>(&user_event));
|
||||
}
|
||||
last_mouse_down = info.ticks;
|
||||
last_mouse_down = info.ticks();
|
||||
last_click_x = event.button.x;
|
||||
last_click_y = event.button.y;
|
||||
}
|
||||
@ -483,6 +482,14 @@ int discard(Uint32 event_mask)
|
||||
|
||||
return discard_count;
|
||||
}
|
||||
|
||||
int pump_info::ticks(unsigned *refresh_counter, unsigned refresh_rate) {
|
||||
if(!ticks_ && !(refresh_counter && ++*refresh_counter % refresh_rate)) {
|
||||
ticks_ = ::SDL_GetTicks();
|
||||
}
|
||||
return ticks_;
|
||||
}
|
||||
|
||||
} //end events namespace
|
||||
|
||||
input_blocker::input_blocker()
|
||||
|
@ -82,9 +82,11 @@ struct event_context
|
||||
void pump();
|
||||
|
||||
struct pump_info {
|
||||
pump_info() : ticks(0) {}
|
||||
pump_info() : ticks_(0) {}
|
||||
std::pair<int,int> resize_dimensions;
|
||||
int ticks; //0 if not calculated
|
||||
int ticks(unsigned *refresh_counter=NULL, unsigned refresh_rate=1);
|
||||
private:
|
||||
int ticks_; //0 if not calculated
|
||||
};
|
||||
|
||||
class pump_monitor {
|
||||
|
@ -114,18 +114,15 @@ bool playmp_controller::counting_down() {
|
||||
|
||||
namespace {
|
||||
const int WARNTIME = 10000; //start beeping when 10 seconds are left (10,000ms)
|
||||
int timer_refresh = 0;
|
||||
const int timer_refresh_rate = 50; //prevents calling SDL_GetTicks() too frequently
|
||||
unsigned timer_refresh = 0;
|
||||
const unsigned timer_refresh_rate = 50; //prevents calling SDL_GetTicks() too frequently
|
||||
}
|
||||
|
||||
//make sure we think about countdown even while dialogs are open
|
||||
void playmp_controller::process(events::pump_info &info) {
|
||||
if(playmp_controller::counting_down()) {
|
||||
if(info.ticks == 0 && ++timer_refresh % timer_refresh_rate == 0) {
|
||||
info.ticks = ::SDL_GetTicks();
|
||||
}
|
||||
if(info.ticks != 0) {
|
||||
playmp_controller::think_about_countdown(info.ticks);
|
||||
if(info.ticks(&timer_refresh, timer_refresh_rate)) {
|
||||
playmp_controller::think_about_countdown(info.ticks());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user