Skip to content

Commit

Permalink
libcore: Querying current event loop frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 18, 2017
1 parent 373d231 commit 0653ff9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doomsday/sdk/libcore/include/de/core/loop.h
Expand Up @@ -58,7 +58,9 @@ class DENG2_PUBLIC Loop : public QObject
*
* @param freqHz Frequency in Hz.
*/
void setRate(int freqHz);
void setRate(double freqHz);

double rate() const;

/**
* Starts the loop.
Expand Down
7 changes: 6 additions & 1 deletion doomsday/sdk/libcore/src/core/loop.cpp
Expand Up @@ -62,12 +62,17 @@ DENG2_AUDIENCE_METHOD(Loop, Iteration)
Loop::Loop() : d(new Impl(this))
{}

void Loop::setRate(int freqHz)
void Loop::setRate(double freqHz)
{
d->interval = 1.0 / freqHz;
d->timer->setInterval(de::max(1, int(d->interval.asMilliSeconds())));
}

double Loop::rate() const
{
return 1.0 / d->interval;
}

void Loop::start()
{
d->running = true;
Expand Down

0 comments on commit 0653ff9

Please sign in to comment.