shithub: qk1

Download patch

ref: 21b8680c21fd7ba41b2c289a1240bf0b8125cca7
parent: 7fe32763fd14abdf54bcfc38b24acd905ba199f3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Oct 22 12:41:41 EDT 2024

move to SDL3

--- a/cross/i686-w64-mingw32.static.txt
+++ b/cross/i686-w64-mingw32.static.txt
@@ -5,7 +5,6 @@
 [binaries]
 c = prefix + 'gcc'
 pkg-config = prefix + 'pkg-config'
-sdl2-config = prefix + 'sdl2-config'
 strip = prefix + 'strip'
 windres = prefix + 'windres'
 
--- a/cross/x86_64-w64-mingw32.static.txt
+++ b/cross/x86_64-w64-mingw32.static.txt
@@ -5,7 +5,6 @@
 [binaries]
 c = prefix + 'gcc'
 pkg-config = prefix + 'pkg-config'
-sdl2-config = prefix + 'sdl2-config'
 strip = prefix + 'strip'
 windres = prefix + 'windres'
 
--- a/in_sdl.c
+++ b/in_sdl.c
@@ -1,10 +1,10 @@
 #include "quakedef.h"
-#include <SDL.h>
+#include <SDL3/SDL.h>
 
 static cvar_t m_windowed = {"m_windowed", "1", true};
 static cvar_t m_filter = {"m_filter", "0", true};
 static cvar_t m_raw = {"m_raw", "1", true};
-static int mouseon, oldmwin, focuslost;
+static bool mouseon, focuslost = true;
 static float dx, dy, olddx, olddy;
 
 static int mbuttons[] = {
@@ -26,48 +26,42 @@
 
 	if(cls.state == ca_dedicated)
 		return;
-	if(oldmwin != (int)m_windowed.value){
-		oldmwin = (int)m_windowed.value;
-		IN_Grabm(oldmwin);
-	}
 
 	while(SDL_PollEvent(&event)){
 		switch(event.type){
-		case SDL_QUIT:
+		case SDL_EVENT_QUIT:
 			Cbuf_AddText("menu_quit\n");
 			break;
-		case SDL_WINDOWEVENT:
-			switch(event.window.event){
-			case SDL_WINDOWEVENT_RESIZED:
-				vid.resized = true;
-				break;
-			case SDL_WINDOWEVENT_CLOSE:
-				Cbuf_AddText("menu_quit\n");
-				break;
-			case SDL_WINDOWEVENT_LEAVE:
-				focuslost = mouseon;
-				IN_Grabm(0);
-				break;
-			case SDL_WINDOWEVENT_ENTER:
-				IN_Grabm(focuslost);
-				break;
-			}
+		case SDL_EVENT_WINDOW_RESIZED:
+			vid.resized = true;
 			break;
-		case SDL_MOUSEMOTION:
+		case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
+			Cbuf_AddText("menu_quit\n");
+			break;
+		case SDL_EVENT_WINDOW_MOUSE_LEAVE:
+			focuslost = mouseon;
+			IN_Grabm(false);
+			break;
+		case SDL_EVENT_WINDOW_MOUSE_ENTER:
+			IN_Grabm(focuslost);
+			break;
+		case SDL_EVENT_MOUSE_MOTION:
 			if(mouseon){
 				dx += event.motion.xrel;
 				dy += event.motion.yrel;
 			}
 			break;
-		case SDL_MOUSEBUTTONDOWN:
-		case SDL_MOUSEBUTTONUP:
+		case SDL_EVENT_MOUSE_BUTTON_DOWN:
+		case SDL_EVENT_MOUSE_BUTTON_UP:
 			if((b = event.button.button-1) >= 0 && b < nelem(mbuttons))
-				Key_Event(mbuttons[b], event.type == SDL_MOUSEBUTTONDOWN);
+				Key_Event(mbuttons[b], event.type == SDL_EVENT_MOUSE_BUTTON_DOWN);
 			break;
-		case SDL_KEYDOWN:
-		case SDL_KEYUP:
-			switch(key = event.key.keysym.sym){
-			case SDLK_BACKQUOTE: key = '~'; break;
+		case SDL_EVENT_KEY_DOWN:
+		case SDL_EVENT_KEY_UP:
+			if(event.key.repeat)
+				break;
+			switch(key = event.key.key){
+			case SDLK_GRAVE: key = '~'; break;
 			case SDLK_DELETE: key = K_DEL; break;
 			case SDLK_BACKSPACE: key = K_BACKSPACE; break;
 			case SDLK_F1: key = K_F1; break;
@@ -99,7 +93,7 @@
 				break;
 			}
 			if(key > 0)
-				Key_Event(key, event.key.state);
+				Key_Event(key, event.key.down);
 			break;
 		}
 	}
@@ -153,21 +147,22 @@
 }
 
 void
-IN_Grabm(int on)
+IN_Grabm(bool on)
 {
-	SDL_SetRelativeMouseMode(mouseon = on);
+	extern SDL_Window *win;
+	SDL_SetWindowRelativeMouseMode(win, mouseon = on);
 }
 
 void
 IN_Shutdown(void)
 {
-	IN_Grabm(0);
+	IN_Grabm(false);
 }
 
 void
 IN_Init(void)
 {
-	SDL_SetHint(SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP, "0");
+	SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0");
 	m_raw.cb = m_raw_cb;
 	Cvar_RegisterVariable(&m_windowed);
 	Cvar_RegisterVariable(&m_filter);
--- a/input.h
+++ b/input.h
@@ -13,5 +13,5 @@
 void IN_ClearStates (void);
 // restores all button and position states to defaults
 
-void IN_Grabm (int on);
+void IN_Grabm (bool on);
 // grab or ungrab mouse
--- a/menu.c
+++ b/menu.c
@@ -211,7 +211,7 @@
 	if(key_dest == key_console)
 		Con_ToggleConsole_f(nil);
 	else{
-		IN_Grabm(0);
+		IN_Grabm(false);
 		M_Menu_Main_f(nil);
 	}
 }
@@ -265,7 +265,7 @@
 		if(cls.state != ca_connected && !cls.demoplayback && cls.demonum != -1)
 			CL_NextDemo();
 		if(cls.state == ca_connected || cls.demoplayback)
-			IN_Grabm(1);
+			IN_Grabm(true);
 		break;
 
 	case K_DOWNARROW:
--- a/meson.build
+++ b/meson.build
@@ -138,7 +138,7 @@
 	]
 else
 	audio = dependency('openal')
-	video = dependency('sdl2')
+	video = dependency('sdl3')
 	src_sys += [
 		'in_sdl.c',
 		'parg.c',
--- a/sv_main.c
+++ b/sv_main.c
@@ -1306,7 +1306,7 @@
 		if (host_client->active)
 			SV_SendServerinfo (host_client);
 
-	IN_Grabm(1);
+	IN_Grabm(true);
 	Con_DPrintf("server spawned\n");
 }
 
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1,10 +1,10 @@
 #include "quakedef.h"
 #include "colormatrix.h"
-#include <SDL.h>
+#include <SDL3/SDL.h>
 
+SDL_Window *win;
 static SDL_Renderer *rend;
 static SDL_Texture *fbi;
-static SDL_Window *win;
 static pixel_t *vidbuffer;
 extern pixel_t *r_warpbuffer;
 
@@ -16,9 +16,7 @@
 {
 	Uint32 fl;
 
-	fl = (win != nil ? SDL_GetWindowFlags(win) : 0) & (SDL_WINDOW_FULLSCREEN_DESKTOP|SDL_WINDOW_FULLSCREEN);
-	if(fl == SDL_WINDOW_FULLSCREEN_DESKTOP)
-		return 2;
+	fl = (win != nil ? SDL_GetWindowFlags(win) : 0) & SDL_WINDOW_FULLSCREEN;
 	if(fl == SDL_WINDOW_FULLSCREEN)
 		return 1;
 
@@ -28,8 +26,6 @@
 static int
 cvarwinflags(void)
 {
-	if(v_fullscreen.value >= 2)
-		return SDL_WINDOW_FULLSCREEN_DESKTOP;
 	if(v_fullscreen.value >= 1)
 		return SDL_WINDOW_FULLSCREEN;
 	return 0;
@@ -46,7 +42,7 @@
 	/* lower than 320x240 doesn't really make sense,
 	 * but at least this prevents a crash, beyond that
 	 * it's your funeral */
-	SDL_GetRendererOutputSize(rend, &vid.width, &vid.height);
+	SDL_GetCurrentRenderOutputSize(rend, &vid.width, &vid.height);
 	vid.width /= v_scale.value;
 	vid.height /= v_scale.value;
 	vid.width = clamp(vid.width, 320, MAXWIDTH);
@@ -64,7 +60,7 @@
 
 	if(fbi != nil)
 		SDL_DestroyTexture(fbi);
-	fbi = SDL_CreateTexture(rend, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, vid.width, vid.height);
+	fbi = SDL_CreateTexture(rend, SDL_PIXELFORMAT_XRGB8888, SDL_TEXTUREACCESS_STATIC, vid.width, vid.height);
 	if(fbi == NULL)
 		fatal("SDL_CreateTexture: %s", SDL_GetError());
 	SDL_SetTextureBlendMode(fbi, SDL_BLENDMODE_NONE);
@@ -107,7 +103,7 @@
 	cmprocess(cm, vidbuffer, vid.width*vid.height);
 
 	SDL_UpdateTexture(fbi, nil, vidbuffer, vid.width*4);
-	SDL_RenderCopy(rend, fbi, nil, nil);
+	SDL_RenderTexture(rend, fbi, nil, nil);
 	SDL_RenderPresent(rend);
 }
 
@@ -141,8 +137,8 @@
 static void
 hints(void)
 {
-	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
 	SDL_SetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1");
+	SDL_SetHint(SDL_HINT_WINDOWS_CLOSE_ON_ALT_F4, "0");
 	SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "1");
 	SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_PING, "0");
 	SDL_SetHint(SDL_HINT_RENDER_VSYNC, v_sync.value ? "1" : "0");
@@ -171,16 +167,10 @@
 		SDL_DestroyWindow(win);
 
 	hints();
-	win = SDL_CreateWindow("quake", x, y, w, h, cvarwinflags() | SDL_WINDOW_RESIZABLE);
-	if(win == nil)
+	if(!SDL_CreateWindowAndRenderer("quake", w, h, cvarwinflags() | SDL_WINDOW_RESIZABLE, &win, &rend))
 		fatal("SDL_CreateWindow: %s", SDL_GetError());
-	SDL_SetWindowResizable(win, SDL_TRUE);
+	SDL_SetWindowResizable(win, true);
 	SDL_SetWindowMinimumSize(win, 320, 240);
-	rend = SDL_CreateRenderer(win, -1,
-		(v_sync.value ? SDL_RENDERER_PRESENTVSYNC : 0)
-	);
-	if(rend == nil)
-		fatal("SDL_CreateRenderer: %s", SDL_GetError());
 	SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
 	SDL_RenderClear(rend);
 	SDL_RenderPresent(rend);
@@ -213,11 +203,11 @@
 	torgbx(host_colormap, vid.colormap, 256*64);
 	vid.fullbright = 256 - LittleLong(*((int *)vid.colormap + 2048));
 
-	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0)
+	if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
 		fatal("SDL_Init: %s", SDL_GetError());
 	makewindow();
 	resetfb();
-	IN_Grabm(1);
+	IN_Grabm(true);
 
 	Cvar_RegisterVariable(&v_fullscreen);
 	v_fullscreen.cb = v_fullscreen_cb;