Added generic way to do periodic updates of OS X startup window

It's used to avoid updating of window (progress bar in particular) too often
Most of time were spent on UI events processing but not on data loading
This commit is contained in:
alexey.lysiuk 2016-02-28 10:58:50 +02:00 committed by Christoph Oelckers
parent 0fba6563c7
commit c687394f72

View file

@ -192,6 +192,39 @@ void FConsoleWindow::ShowFatalError(const char* const message)
} }
static const unsigned int THIRTY_FPS = 33; // milliseconds per update
template <typename Function, unsigned int interval = THIRTY_FPS>
struct TimedUpdater
{
explicit TimedUpdater(const Function& function)
{
const unsigned int currentTime = I_MSTime();
if (currentTime - m_previousTime > interval)
{
m_previousTime = currentTime;
function();
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}
}
static unsigned int m_previousTime;
};
template <typename Function, unsigned int interval>
unsigned int TimedUpdater<Function, interval>::m_previousTime;
template <typename Function, unsigned int interval = THIRTY_FPS>
static void UpdateTimed(const Function& function)
{
TimedUpdater<Function, interval> dummy(function);
}
void FConsoleWindow::AddText(const char* message) void FConsoleWindow::AddText(const char* message)
{ {
PalEntry color(223, 223, 223); PalEntry color(223, 223, 223);
@ -376,18 +409,11 @@ void FConsoleWindow::Progress(const int current, const int maximum)
return; return;
} }
static unsigned int previousTime = I_MSTime(); UpdateTimed([&]()
unsigned int currentTime = I_MSTime();
if (currentTime - previousTime > 33) // approx. 30 FPS
{ {
previousTime = currentTime;
[m_progressBar setMaxValue:maximum]; [m_progressBar setMaxValue:maximum];
[m_progressBar setDoubleValue:current]; [m_progressBar setDoubleValue:current];
});
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}
} }