From 30ad3556dda304838dc497dee57846ebd9403c5a Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 16 Dec 2025 05:18:24 +0500 Subject: [PATCH] engine: small refactorings in sdl2 support, enable messagebox and timer in sdl3 backend back --- common/defaults.h | 4 ++-- engine/client/vid_common.h | 20 +++++++++++++++++--- engine/platform/sdl2/platform_sdl2.h | 3 --- engine/platform/sdl2/s_sdl2.c | 4 ---- engine/platform/sdl2/vid_sdl2.c | 13 +++++-------- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/common/defaults.h b/common/defaults.h index 161e6278..2e97ca2c 100644 --- a/common/defaults.h +++ b/common/defaults.h @@ -56,7 +56,7 @@ SETUP BACKENDS DEFINITIONS // select messagebox implementation // #ifndef XASH_MESSAGEBOX - #if XASH_SDL == 2 && !XASH_NSWITCH // SDL2 messageboxes are not available on NSW + #if XASH_SDL >= 2 && !XASH_NSWITCH // SDL2 messageboxes are not available on NSW #define XASH_MESSAGEBOX MSGBOX_SDL #elif XASH_WIN32 #define XASH_MESSAGEBOX MSGBOX_WIN32 @@ -73,7 +73,7 @@ SETUP BACKENDS DEFINITIONS // no timer - no xash // #ifndef XASH_TIMER - #if XASH_SDL == 2 + #if XASH_SDL >= 2 #define XASH_TIMER TIMER_SDL #elif XASH_WIN32 #define XASH_TIMER TIMER_WIN32 diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index 6643fa65..04507f64 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -1,7 +1,22 @@ -#pragma once +/* +vid_common.h - common implementation of platform-specific vid component +Copyright (C) 2025 Xash3D FWGS contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +*/ #ifndef VID_COMMON #define VID_COMMON +#include "ref_api.h" + typedef struct vidmode_s { const char *desc; @@ -12,8 +27,7 @@ typedef struct vidmode_s typedef struct { void *context; // handle to GL rendering context - int safe; - int desktopBitsPixel; + ref_safegl_context_t safe; qboolean software; } glwstate_t; diff --git a/engine/platform/sdl2/platform_sdl2.h b/engine/platform/sdl2/platform_sdl2.h index b6898a85..c44fe747 100644 --- a/engine/platform/sdl2/platform_sdl2.h +++ b/engine/platform/sdl2/platform_sdl2.h @@ -22,9 +22,6 @@ GNU General Public License for more details. // window management void VID_RestoreScreenResolution( window_mode_t window_mode ); -qboolean VID_CreateWindow( int width, int height, window_mode_t window_mode ); -void VID_DestroyWindow( void ); -void GL_InitExtensions( void ); void VID_SaveWindowSize( int width, int height ); // diff --git a/engine/platform/sdl2/s_sdl2.c b/engine/platform/sdl2/s_sdl2.c index 5197c41f..fad8885f 100644 --- a/engine/platform/sdl2/s_sdl2.c +++ b/engine/platform/sdl2/s_sdl2.c @@ -15,8 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "platform.h" -#if XASH_SOUND == SOUND_SDL - #include "sound.h" #include "voice.h" @@ -344,5 +342,3 @@ void VoiceCapture_Shutdown( void ) SDL_CloseAudioDevice( in_dev ); in_dev = 0; } - -#endif // XASH_SOUND == SOUND_SDL diff --git a/engine/platform/sdl2/vid_sdl2.c b/engine/platform/sdl2/vid_sdl2.c index 82b44ede..9ce894fb 100644 --- a/engine/platform/sdl2/vid_sdl2.c +++ b/engine/platform/sdl2/vid_sdl2.c @@ -488,7 +488,8 @@ static qboolean VID_GetDisplayBounds( int display_index, SDL_Window *hWnd, SDL_R return true; } - else if( SDL_GetDisplayBounds( display_index, rect ) == 0 ) + + if( SDL_GetDisplayBounds( display_index, rect ) == 0 ) { rect->x += 100; rect->y += 100; @@ -566,7 +567,6 @@ static qboolean VID_SetScreenResolution( int width, int height, window_mode_t wi { int display_index = VID_GetDisplayIndex( __func__, NULL ); SDL_Rect bounds; - int xpos, ypos; if( VID_GetDisplayBounds( display_index, host.hWnd, &bounds )) { @@ -721,7 +721,7 @@ static qboolean RectFitsInDisplay( const SDL_Rect *rect, const SDL_Rect *display VID_CreateWindow ================= */ -qboolean VID_CreateWindow( int input_width, int input_height, window_mode_t window_mode ) +static qboolean VID_CreateWindow( const int input_width, const int input_height, window_mode_t window_mode ) { Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_MOUSE_FOCUS; SDL_Rect rect = { window_xpos.value, window_ypos.value, input_width, input_height }; @@ -1001,7 +1001,6 @@ R_Init_Video qboolean R_Init_Video( const int type ) { string safe; - qboolean retval; SDL_DisplayMode displayMode; const SDL_Point point = { window_xpos.value, window_ypos.value }; @@ -1048,10 +1047,8 @@ qboolean R_Init_Video( const int type ) break; } - if( !(retval = VID_SetMode()) ) - { - return retval; - } + if( !VID_SetMode( )) + return false; switch( type ) {