Add: [Video] move GameLoop into its own thread
This allows drawing to happen while the GameLoop is doing an iteration too. Sadly, not much drawing currently can be done while the GameLoop is running, as for example PollEvent() or UpdateWindows() can influence the game-state. As such, they first need to acquire a lock on the game-state before they can be called. Currently, the main advantage is the time spend in Paint(), which for non-OpenGL drivers can be a few milliseconds. For OpenGL this is more like 0.05 milliseconds; in these instances this change doesn't add any benefits for now. This is an alternative to the former "draw-thread", which moved the drawing in a thread for some OSes. It has similar performance gain as this does, although this implementation allows for more finer control over what suffers when the GameLoop takes too long: drawing or the next GameLoop. For now they both suffer equally.
This commit is contained in:
committed by
Patric Stout
parent
3a4a15cc93
commit
e56d2c63c3
@@ -570,10 +570,10 @@ bool VideoDriver_SDL::PollEvent()
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *VideoDriver_SDL::Start(const StringList &parm)
|
||||
const char *VideoDriver_SDL::Start(const StringList ¶m)
|
||||
{
|
||||
char buf[30];
|
||||
_use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2);
|
||||
_use_hwpalette = GetDriverParamInt(param, "hw_palette", 2);
|
||||
|
||||
/* Just on the offchance the audio subsystem started before the video system,
|
||||
* check whether any part of SDL has been initialised before getting here.
|
||||
@@ -599,6 +599,8 @@ const char *VideoDriver_SDL::Start(const StringList &parm)
|
||||
MarkWholeScreenDirty();
|
||||
SetupKeyboard();
|
||||
|
||||
this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -647,12 +649,16 @@ void VideoDriver_SDL::InputLoop()
|
||||
|
||||
void VideoDriver_SDL::MainLoop()
|
||||
{
|
||||
this->StartGameThread();
|
||||
|
||||
for (;;) {
|
||||
if (_exit_game) break;
|
||||
|
||||
this->Tick();
|
||||
this->SleepTillNextTick();
|
||||
}
|
||||
|
||||
this->StopGameThread();
|
||||
}
|
||||
|
||||
bool VideoDriver_SDL::ChangeResolution(int w, int h)
|
||||
|
||||
Reference in New Issue
Block a user