mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [SDL2] Split Start() in a few more functions
This makes it a bit easier to follow what is going on, and allow future subdrivers to hook into a few of these functions. Reworked the code slighly while at it, to return early where possible.pull/8729/head
parent
86c309ea75
commit
6098811b49
|
@ -673,28 +673,40 @@ int VideoDriver_SDL::PollEvent()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *VideoDriver_SDL::Start(const StringList &parm)
|
static const char *InitializeSDL()
|
||||||
{
|
{
|
||||||
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
|
|
||||||
|
|
||||||
/* Explicitly disable hardware acceleration. Enabling this causes
|
/* Explicitly disable hardware acceleration. Enabling this causes
|
||||||
* UpdateWindowSurface() to update the window's texture instead of
|
* UpdateWindowSurface() to update the window's texture instead of
|
||||||
* its surface. */
|
* its surface. */
|
||||||
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
|
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
|
||||||
SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1");
|
SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1");
|
||||||
|
|
||||||
/* Just on the offchance the audio subsystem started before the video system,
|
/* Check if the video-driver is already initialized. */
|
||||||
* check whether any part of SDL has been initialised before getting here.
|
if (SDL_WasInit(SDL_INIT_VIDEO) != 0) return nullptr;
|
||||||
* Slightly duplicated with sound/sdl_s.cpp */
|
|
||||||
int ret_code = 0;
|
|
||||||
if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
|
|
||||||
ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO);
|
|
||||||
}
|
|
||||||
if (ret_code < 0) return SDL_GetError();
|
|
||||||
|
|
||||||
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) return SDL_GetError();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *VideoDriver_SDL::Initialize()
|
||||||
|
{
|
||||||
this->UpdateAutoResolution();
|
this->UpdateAutoResolution();
|
||||||
|
|
||||||
|
const char *error = InitializeSDL();
|
||||||
|
if (error != nullptr) return error;
|
||||||
|
|
||||||
FindResolutions();
|
FindResolutions();
|
||||||
|
DEBUG(driver, 2, "Resolution for display: %ux%u", _cur_resolution.width, _cur_resolution.height);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *VideoDriver_SDL::Start(const StringList &parm)
|
||||||
|
{
|
||||||
|
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
|
||||||
|
|
||||||
|
const char *error = this->Initialize();
|
||||||
|
if (error != nullptr) return error;
|
||||||
|
|
||||||
this->startup_display = FindStartupDisplay(GetDriverParamInt(parm, "display", -1));
|
this->startup_display = FindStartupDisplay(GetDriverParamInt(parm, "display", -1));
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
void MainLoopCleanup();
|
void MainLoopCleanup();
|
||||||
bool CreateMainSurface(uint w, uint h, bool resize);
|
bool CreateMainSurface(uint w, uint h, bool resize);
|
||||||
bool CreateMainWindow(uint w, uint h);
|
bool CreateMainWindow(uint w, uint h);
|
||||||
|
const char *Initialize();
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
/* Convert a constant pointer back to a non-constant pointer to a member function. */
|
/* Convert a constant pointer back to a non-constant pointer to a member function. */
|
||||||
|
|
Loading…
Reference in New Issue