Skip to content

Commit

Permalink
Windows|Fixed: Application refresh loop behavior, LegacyWidget/BusyWi…
Browse files Browse the repository at this point in the history
…dget issues

It seems that on Windows the only way to run the app refresh loop is to
use a QTimer (and not singleshot calls). Also corrected issues related to busy
widget drawing/update during transitions between normal and busy mode. View
resizing is also ignored if the engine is shutting down.
  • Loading branch information
skyjake committed Mar 1, 2013
1 parent 44841db commit 5f45516
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/src/busymode.cpp
Expand Up @@ -426,6 +426,8 @@ static void BusyMode_Exit(void)
*/
void BusyMode_Loop(void)
{
if(!busyTask) return;

boolean canUpload = !(busyTask->mode & BUSYF_NO_UPLOADS);
timespan_t oldTime;

Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -197,6 +197,7 @@ void ClientApp::postFrame()
S_EndFrame();

Garbage_Recycle();
loop().resume();
}

ClientApp &ClientApp::app()
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/busywidget.cpp
Expand Up @@ -40,11 +40,13 @@ BusyWidget::~BusyWidget()

void BusyWidget::update()
{
DENG_ASSERT(BusyMode_Active());
BusyMode_Loop();
}

void BusyWidget::draw()
{
DENG_ASSERT(BusyMode_Active());
BusyVisual_Render();
}

Expand Down
6 changes: 5 additions & 1 deletion doomsday/client/src/ui/legacywidget.cpp
Expand Up @@ -61,7 +61,7 @@ LegacyWidget::~LegacyWidget()

void LegacyWidget::viewResized()
{
if(isDisabled()) return;
if(isDisabled() || Sys_IsShuttingDown()) return;

LOG_AS("LegacyWidget");
LOG_DEBUG("View resized to ") << root().viewSize().asText();
Expand All @@ -84,6 +84,8 @@ void LegacyWidget::update()
{
if(isDisabled()) return;

//LOG_DEBUG("Legacy update");

DENG2_ASSERT(!BusyMode_Active());

// We may be performing GL operations.
Expand Down Expand Up @@ -117,6 +119,8 @@ void LegacyWidget::draw()

if(isDisabled()) return;

//LOG_DEBUG("Legacy draw");

if(drawGame)
{
if(App_GameLoaded())
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/window.cpp
Expand Up @@ -58,6 +58,7 @@
#include <QWidget>
#include <QDesktopWidget>
#include "ui/canvaswindow.h"
#include "clientapp.h"
#include <de/Config>
#include <de/Record>
#include <de/NumberValue>
Expand Down Expand Up @@ -1294,6 +1295,8 @@ void Window_Draw(Window* win)
assert(win);
assert(win->widget);

ClientApp::app().loop().pause();

// The canvas needs to be recreated when the GL format has changed
// (e.g., multisampling).
if(win->needRecreateCanvas)
Expand Down Expand Up @@ -1498,6 +1501,8 @@ boolean Window_IsMouseTrapped(const Window* wnd)

boolean Window_ShouldRepaintManually(const Window* wnd)
{
//return false;

// When the pointer is not grabbed, allow the system to regulate window
// updates (e.g., for window manipulation).
if(Window_IsFullscreen(wnd)) return true;
Expand Down
6 changes: 5 additions & 1 deletion doomsday/libdeng2/include/de/core/loop.h
Expand Up @@ -72,7 +72,11 @@ class DENG2_PUBLIC Loop : public QObject
*/
void stop();

protected slots:
void pause();

void resume();

public slots:
void nextLoopIteration();

private:
Expand Down
24 changes: 17 additions & 7 deletions doomsday/libdeng2/src/core/loop.cpp
Expand Up @@ -29,13 +29,12 @@ DENG2_PIMPL(Loop)
{
TimeDelta interval;
bool running;
QTimer *timer;

Instance(Public *i) : Base(i), interval(0), running(false) {}

void schedule()
Instance(Public *i) : Base(i), interval(0), running(false)
{
QTimer::singleShot(de::max(duint64(1), interval.asMilliSeconds()),
thisPublic, SLOT(nextLoopIteration()));
timer = new QTimer(thisPublic);
QObject::connect(timer, SIGNAL(timeout()), thisPublic, SLOT(nextLoopIteration()));
}
};

Expand All @@ -50,24 +49,35 @@ Loop::~Loop()
void Loop::setRate(int freqHz)
{
d->interval = 1.0 / freqHz;
d->timer->setInterval(de::max(duint64(1), d->interval.asMilliSeconds()));
}

void Loop::start()
{
d->running = true;
d->schedule();
d->timer->start();
}

void Loop::stop()
{
d->running = false;
d->timer->stop();
}

void Loop::pause()
{
d->timer->stop();
}

void Loop::resume()
{
d->timer->start();
}

void Loop::nextLoopIteration()
{
if(d->running)
{
d->schedule();
DENG2_FOR_AUDIENCE(Iteration, i) i->loopIteration();
}
}
Expand Down
2 changes: 2 additions & 0 deletions doomsday/libgui/src/guiapp.cpp
Expand Up @@ -93,6 +93,8 @@ Loop &GuiApp::loop()

void GuiApp::loopIteration()
{
//LOG_DEBUG("GuiApp loopIteration @ ") << Time().asText();

// Update the clock time. de::App listens to this clock and will inform
// subsystems in the order they've been added.
Clock::appClock().setTime(Time());
Expand Down

0 comments on commit 5f45516

Please sign in to comment.