mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-23 20:24:12 +01:00
Codechange: Pass std::string_view from drivers instead of char *.
This commit is contained in:
committed by
Peter Nelson
parent
a42aa1a086
commit
332cbca36e
@@ -1030,7 +1030,7 @@ void VideoDriver_Win32Base::UnlockVideoBuffer()
|
||||
|
||||
static FVideoDriver_Win32GDI iFVideoDriver_Win32GDI;
|
||||
|
||||
const char *VideoDriver_Win32GDI::Start(const StringList ¶m)
|
||||
std::optional<std::string_view> VideoDriver_Win32GDI::Start(const StringList ¶m)
|
||||
{
|
||||
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
|
||||
|
||||
@@ -1044,7 +1044,7 @@ const char *VideoDriver_Win32GDI::Start(const StringList ¶m)
|
||||
|
||||
this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
|
||||
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void VideoDriver_Win32GDI::Stop()
|
||||
@@ -1237,9 +1237,9 @@ static OGLProc GetOGLProcAddressCallback(const char *proc)
|
||||
/**
|
||||
* Set the pixel format of a window-
|
||||
* @param dc Device context to set the pixel format of.
|
||||
* @return nullptr on success, error message otherwise.
|
||||
* @return std::nullopt on success, error message otherwise.
|
||||
*/
|
||||
static const char *SelectPixelFormat(HDC dc)
|
||||
static std::optional<std::string_view> SelectPixelFormat(HDC dc)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), // Size of this struct.
|
||||
@@ -1265,7 +1265,7 @@ static const char *SelectPixelFormat(HDC dc)
|
||||
if (format == 0) return "No suitable pixel format found";
|
||||
if (!SetPixelFormat(dc, format, &pfd)) return "Can't set pixel format";
|
||||
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/** Bind all WGL extension functions we need. */
|
||||
@@ -1280,7 +1280,7 @@ static void LoadWGLExtensions()
|
||||
HDC dc = GetDC(wnd);
|
||||
|
||||
/* Set pixel format of the window. */
|
||||
if (SelectPixelFormat(dc) == nullptr) {
|
||||
if (SelectPixelFormat(dc) == std::nullopt) {
|
||||
/* Create rendering context. */
|
||||
HGLRC rc = wglCreateContext(dc);
|
||||
if (rc != nullptr) {
|
||||
@@ -1320,7 +1320,7 @@ static void LoadWGLExtensions()
|
||||
|
||||
static FVideoDriver_Win32OpenGL iFVideoDriver_Win32OpenGL;
|
||||
|
||||
const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m)
|
||||
std::optional<std::string_view> VideoDriver_Win32OpenGL::Start(const StringList ¶m)
|
||||
{
|
||||
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
|
||||
|
||||
@@ -1332,8 +1332,8 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m)
|
||||
this->MakeWindow(_fullscreen);
|
||||
|
||||
/* Create and initialize OpenGL context. */
|
||||
const char *err = this->AllocateContext();
|
||||
if (err != nullptr) {
|
||||
auto err = this->AllocateContext();
|
||||
if (err) {
|
||||
this->Stop();
|
||||
_cur_resolution = old_res;
|
||||
return err;
|
||||
@@ -1358,7 +1358,7 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m)
|
||||
|
||||
this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
|
||||
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void VideoDriver_Win32OpenGL::Stop()
|
||||
@@ -1391,12 +1391,12 @@ void VideoDriver_Win32OpenGL::ToggleVsync(bool vsync)
|
||||
}
|
||||
}
|
||||
|
||||
const char *VideoDriver_Win32OpenGL::AllocateContext()
|
||||
std::optional<std::string_view> VideoDriver_Win32OpenGL::AllocateContext()
|
||||
{
|
||||
this->dc = GetDC(this->main_wnd);
|
||||
|
||||
const char *err = SelectPixelFormat(this->dc);
|
||||
if (err != nullptr) return err;
|
||||
auto err = SelectPixelFormat(this->dc);
|
||||
if (err) return err;
|
||||
|
||||
HGLRC rc = nullptr;
|
||||
|
||||
@@ -1438,7 +1438,7 @@ bool VideoDriver_Win32OpenGL::ToggleFullscreen(bool full_screen)
|
||||
if (_screen.dst_ptr != nullptr) this->ReleaseVideoPointer();
|
||||
this->DestroyContext();
|
||||
bool res = this->VideoDriver_Win32Base::ToggleFullscreen(full_screen);
|
||||
res &= this->AllocateContext() == nullptr;
|
||||
res &= this->AllocateContext() == std::nullopt;
|
||||
this->ClientSizeChanged(this->width, this->height, true);
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user