Skip to content

Commit

Permalink
libdeng2|Loop: Added static accessor for the app's Loop
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 5, 2013
1 parent 5bc7e3d commit 3035731
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/core/loop.h
Expand Up @@ -79,6 +79,8 @@ class DENG2_PUBLIC Loop : public QObject
*/
static void timer(TimeDelta const &delay, void (*func)(void));

static Loop &appLoop();

public slots:
void nextLoopIteration();

Expand Down
16 changes: 16 additions & 0 deletions doomsday/libdeng2/src/core/loop.cpp
Expand Up @@ -29,6 +29,8 @@

namespace de {

static Loop *loopSingleton = 0;

DENG2_PIMPL(Loop)
{
TimeDelta interval;
Expand All @@ -37,9 +39,17 @@ DENG2_PIMPL(Loop)

Instance(Public *i) : Base(i), interval(0), running(false)
{
DENG2_ASSERT(!loopSingleton);
loopSingleton = i;

timer = new QTimer(thisPublic);
QObject::connect(timer, SIGNAL(timeout()), thisPublic, SLOT(nextLoopIteration()));
}

~Instance()
{
loopSingleton = 0;
}
};

Loop::Loop() : d(new Instance(this))
Expand Down Expand Up @@ -80,6 +90,12 @@ void Loop::timer(TimeDelta const &delay, void (*func)(void))
timer->start(delay.asMilliSeconds());
}

Loop &Loop::appLoop()
{
DENG2_ASSERT(loopSingleton != 0);
return *loopSingleton;
}

void Loop::nextLoopIteration()
{
try
Expand Down

0 comments on commit 3035731

Please sign in to comment.