From f5c3b2d1c016f33db0f9f05301639385e9891428 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 6 Feb 2011 14:03:45 +0000 Subject: [PATCH] Fixing issues with very small timeouts in network games. --- src/gui/qt/gametable/mytimeoutlabel.cpp | 57 +++++++++++++------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/gui/qt/gametable/mytimeoutlabel.cpp b/src/gui/qt/gametable/mytimeoutlabel.cpp index 0f45b96e..38b77fb1 100644 --- a/src/gui/qt/gametable/mytimeoutlabel.cpp +++ b/src/gui/qt/gametable/mytimeoutlabel.cpp @@ -31,37 +31,40 @@ MyTimeoutLabel::~MyTimeoutLabel() void MyTimeoutLabel::startTimeOutAnimation(int secs, bool beep) { - isBeepPlayed = FALSE; - isBeep = beep; + if (secs >= 4) // smaller timeouts may lead to errors/endless loops below + { + isBeepPlayed = FALSE; + isBeep = beep; - timeOutValue = secs; - timeOutFrame = 1; - timeOutAnimationWidth = 52; - - int preTimerIntervall = ((timeOutValue-3) * 1000)/timeOutAnimationWidth; - - timerIntervall = preTimerIntervall; + timeOutValue = secs; + timeOutFrame = 1; + timeOutAnimationWidth = 52; - //save gfx ressources and never play more the 10 pps - while(timerIntervall < 100) { - if(secs <= 9 && secs >= 6) { - //fix inaccuracies caused by integer division - timerIntervall = timerIntervall + preTimerIntervall + 5; - } - else { - timerIntervall = timerIntervall + preTimerIntervall; + int preTimerIntervall = ((timeOutValue-3) * 1000)/timeOutAnimationWidth; + + timerIntervall = preTimerIntervall; + + //save gfx ressources and never play more the 10 pps + while(timerIntervall < 100) { + if(secs <= 9 && secs >= 6) { + //fix inaccuracies caused by integer division + timerIntervall = timerIntervall + preTimerIntervall + 5; + } + else { + timerIntervall = timerIntervall + preTimerIntervall; + } } + + waitFrames = 3000/timerIntervall; + + //start the real timer + realTimer.reset(); + realTimer.start(); + + // std::cout << timerIntervall << endl; + timeOutAnimation = TRUE; + timeOutAnimationTimer->start(timerIntervall); } - - waitFrames = 3000/timerIntervall; - - //start the real timer - realTimer.reset(); - realTimer.start(); - -// std::cout << timerIntervall << endl; - timeOutAnimation = TRUE; - timeOutAnimationTimer->start(timerIntervall); } void MyTimeoutLabel::startTimeOutAnimationNow() {