mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
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:
parent
0fba6563c7
commit
c687394f72
1 changed files with 35 additions and 9 deletions
|
@ -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)
|
||||
{
|
||||
PalEntry color(223, 223, 223);
|
||||
|
@ -376,18 +409,11 @@ void FConsoleWindow::Progress(const int current, const int maximum)
|
|||
return;
|
||||
}
|
||||
|
||||
static unsigned int previousTime = I_MSTime();
|
||||
unsigned int currentTime = I_MSTime();
|
||||
|
||||
if (currentTime - previousTime > 33) // approx. 30 FPS
|
||||
UpdateTimed([&]()
|
||||
{
|
||||
previousTime = currentTime;
|
||||
|
||||
[m_progressBar setMaxValue:maximum];
|
||||
[m_progressBar setDoubleValue:current];
|
||||
|
||||
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue