• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

This is a fork of Zandronum for Mac Os (Silicon and Intel)


Commit MetaInfo

Revisiónd7f03c3afd90bfaf1d7e3a8ca341c670cbe6271f (tree)
Tiempo2023-01-23 18:48:43
AutorJoshua Surace <doomjoshuaboy@live...>
CommiterJoshua Surace

Log Message

SDL Fixes

Cambiar Resumen

Diferencia incremental

diff -r c1f472a776fa -r d7f03c3afd90 src/sdl/crashcatcher.c
--- a/src/sdl/crashcatcher.c Mon Jan 23 20:43:01 2023 +1100
+++ b/src/sdl/crashcatcher.c Mon Jan 23 20:48:43 2023 +1100
@@ -10,6 +10,15 @@
1010 #include <errno.h>
1111 #include <limits.h>
1212
13+// [EP] Header for the timestamp appending to crash log filename.
14+#include <time.h>
15+
16+// Solaris doesn't have SA_ONESHOT
17+// According to the Linux header this is the same.
18+#ifndef SA_ONESHOT
19+#define SA_ONESHOT SA_RESETHAND
20+#endif
21+
1322 #ifdef __linux__
1423 #include <sys/prctl.h>
1524 #ifndef PR_SET_PTRACER
@@ -137,6 +146,7 @@
137146 "shell echo \"\"\n"
138147 "shell echo \"* Backtrace\"\n"
139148 "thread apply all backtrace full\n"
149+ "gcore\n" // [EP] try to create a core dump ...
140150 "detach\n"
141151 "quit\n", pid);
142152 fclose(f);
@@ -170,6 +180,15 @@
170180 putchar('\n');
171181 fflush(stdout);
172182 #endif
183+ // [BB] Also log the gdb version.
184+ FILE *IN = popen ( "gdb --version", "r" );
185+ if ( IN ) {
186+ char gdbversion[1024];
187+ if ( fgets(gdbversion, 1024, IN) )
188+ puts(gdbversion);
189+
190+ pclose(IN);
191+ }
173192 }
174193
175194
@@ -265,6 +284,9 @@
265284 const char *sigdesc = "";
266285 int i;
267286
287+ // [EP/TP] Will contain the new log filename if necessary.
288+ char newLogfile[64];
289+
268290 if(fread(&crash_info, sizeof(crash_info), 1, stdin) != 1)
269291 {
270292 fprintf(stderr, "!!! Failed to retrieve info from crashed process\n");
@@ -337,6 +359,23 @@
337359
338360 if(logfile)
339361 {
362+ // [EP/TP] Append the timestamp and the process id to the crash log filename.
363+ time_t timestamp;
364+
365+ time( &timestamp );
366+ char *bufferEnd = newLogfile + sizeof( newLogfile );
367+ snprintf( newLogfile, sizeof( newLogfile ), "%s", logfile );
368+
369+ char *appendPoint = strchr( newLogfile, '.' );
370+ if ( appendPoint == NULL )
371+ appendPoint = newLogfile + strlen( newLogfile );
372+
373+ appendPoint += strftime( appendPoint, bufferEnd - appendPoint, "-%m_%d_%Y-%H_%M_%S", localtime( &timestamp ) );
374+
375+ snprintf( appendPoint, bufferEnd - appendPoint, ".%d.log", (int)crash_info.pid );
376+
377+ logfile = (const char *)newLogfile;
378+
340379 /* Create crash log file and redirect shell output to it */
341380 if(freopen(logfile, "wa", stdout) != stdout)
342381 {
@@ -365,6 +404,7 @@
365404 kill(crash_info.pid, SIGKILL);
366405 }
367406
407+#ifndef SERVER_ONLY // [BB] The Linux server doesn't have a GUI, so don't bother it with a window.
368408 if(logfile)
369409 {
370410 const char *str;
@@ -379,6 +419,7 @@
379419
380420 system(buf);
381421 }
422+#endif
382423 exit(0);
383424 }
384425
diff -r c1f472a776fa -r d7f03c3afd90 src/sdl/i_input.cpp
--- a/src/sdl/i_input.cpp Mon Jan 23 20:43:01 2023 +1100
+++ b/src/sdl/i_input.cpp Mon Jan 23 20:48:43 2023 +1100
@@ -256,32 +256,32 @@
256256
257257 static void I_CheckNativeMouse ()
258258 {
259- bool focus = SDL_GetKeyboardFocus() != NULL;
260- bool fs = screen->IsFullscreen();
261-
262- bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !inGame());
259+ bool focus = SDL_GetKeyboardFocus() != NULL;
260+ bool fs = screen->IsFullscreen();
261+
262+ bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !inGame());
263263
264- if (wantNative != NativeMouse)
265- {
266- NativeMouse = wantNative;
267- SDL_ShowCursor (wantNative);
268- if (wantNative)
269- I_ReleaseMouseCapture ();
270- else
271- I_SetMouseCapture ();
272- }
264+ if (wantNative != NativeMouse)
265+ {
266+ NativeMouse = wantNative;
267+ SDL_ShowCursor (wantNative);
268+ if (wantNative)
269+ I_ReleaseMouseCapture ();
270+ else
271+ I_SetMouseCapture ();
272+ }
273273 }
274274
275275 void MessagePump (const SDL_Event &sev)
276276 {
277- static int lastx = 0, lasty = 0;
278- int x, y;
279- event_t event = { 0,0,0,0,0,0,0 };
280-
281- switch (sev.type)
282- {
283- case SDL_QUIT:
284- exit (0);
277+ static int lastx = 0, lasty = 0;
278+ int x, y;
279+ event_t event = { 0,0,0,0,0,0,0 };
280+
281+ switch (sev.type)
282+ {
283+ case SDL_QUIT:
284+ exit (0);
285285
286286
287287 case SDL_WINDOWEVENT:
@@ -293,211 +293,219 @@
293293 break;
294294 }
295295 break;
296-
297-
298- case SDL_MOUSEBUTTONDOWN:
299- case SDL_MOUSEBUTTONUP:
300- case SDL_MOUSEMOTION:
301- if (!GUICapture || sev.button.button == 4 || sev.button.button == 5)
302- {
303- if(sev.type != SDL_MOUSEMOTION)
304- {
305- event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
306- /* These button mappings work with my Gentoo system using the
307- * evdev driver and a Logitech MX510 mouse. Whether or not they
308- * carry over to other Linux systems, I have no idea, but I sure
309- * hope so. (Though buttons 11 and 12 are kind of useless, since
310- * they also trigger buttons 4 and 5.)
311- */
312- switch (sev.button.button)
313- {
314- case SDL_BUTTON_LEFT: event.data1 = KEY_MOUSE1; break;
315- case SDL_BUTTON_MIDDLE: event.data1 = KEY_MOUSE3; break;
316- case SDL_BUTTON_RIGHT: event.data1 = KEY_MOUSE2; break;
317- case 8: event.data1 = KEY_MOUSE4; break; // For whatever reason my side mouse buttons are here.
318- case 9: event.data1 = KEY_MOUSE5; break;
319- case SDL_BUTTON_X1: event.data1 = KEY_MOUSE6; break; // And these don't exist
320- case SDL_BUTTON_X2: event.data1 = KEY_MOUSE7; break;
321- case 6: event.data1 = KEY_MOUSE8; break;
322- default: printf("SDL mouse button %s %d\n",
323- sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break;
324- }
325- if (event.data1 != 0)
326- {
327- D_PostEvent(&event);
328- }
329- }
330- }
331- else if (sev.type == SDL_MOUSEMOTION || (sev.button.button >= 1 && sev.button.button <= 3))
332- {
333- int x, y;
334- SDL_GetMouseState (&x, &y);
335-
336- event.data1 = x;
337- event.data2 = y;
338-
339- screen->ScaleCoordsFromWindow(event.data1, event.data2);
340-
341- event.type = EV_GUI_Event;
342- if(sev.type == SDL_MOUSEMOTION)
343- event.subtype = EV_GUI_MouseMove;
344- else
345- {
346- event.subtype = sev.type == SDL_MOUSEBUTTONDOWN ? EV_GUI_LButtonDown : EV_GUI_LButtonUp;
347- event.subtype += (sev.button.button - 1) * 3;
348- }
349- D_PostEvent(&event);
350- }
351- break;
352-
353- case SDL_MOUSEWHEEL:
354- if (GUICapture)
355- {
356- event.type = EV_GUI_Event;
357- event.subtype = sev.wheel.y > 0 ? EV_GUI_WheelUp : EV_GUI_WheelDown;
358- D_PostEvent (&event);
359- }
360- else
361- {
362- event.type = EV_KeyDown;
363- event.data1 = sev.wheel.y > 0 ? KEY_MWHEELUP : KEY_MWHEELDOWN;
364- D_PostEvent (&event);
365- event.type = EV_KeyUp;
366- D_PostEvent (&event);
367- }
368- break;
369-
370- case SDL_KEYDOWN:
371- case SDL_KEYUP:
372- if (!GUICapture)
373- {
374- event.type = sev.type == SDL_KEYDOWN ? EV_KeyDown : EV_KeyUp;
375-
376- // Try to look up our key mapped key for conversion to DirectInput.
377- // If that fails, then we'll do a lookup against the scan code,
378- // which may not return the right key, but at least the key should
379- // work in the game.
380- if (const BYTE *dik = KeySymToDIK.CheckKey (sev.key.keysym.sym))
381- event.data1 = *dik;
382- else if (const BYTE *dik = KeyScanToDIK.CheckKey (sev.key.keysym.scancode))
383- event.data1 = *dik;
384296
385- if (event.data1)
386- {
387- if (sev.key.keysym.sym < 256)
388- {
389- event.data2 = sev.key.keysym.sym;
390- }
391- D_PostEvent (&event);
392- }
393- }
394- else
395- {
396- event.type = EV_GUI_Event;
397- event.subtype = sev.type == SDL_KEYDOWN ? EV_GUI_KeyDown : EV_GUI_KeyUp;
398- event.data3 = ((sev.key.keysym.mod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
399- ((sev.key.keysym.mod & KMOD_CTRL) ? GKM_CTRL : 0) |
400- ((sev.key.keysym.mod & KMOD_ALT) ? GKM_ALT : 0);
401-
402- if (event.subtype == EV_GUI_KeyDown)
403- {
404- if (DownState[sev.key.keysym.scancode])
405- {
406- event.subtype = EV_GUI_KeyRepeat;
407- }
408- DownState[sev.key.keysym.scancode] = 1;
409- }
410- else
411- {
412- DownState[sev.key.keysym.scancode] = 0;
413- }
297+ case SDL_MOUSEBUTTONDOWN:
298+ case SDL_MOUSEBUTTONUP:
299+ case SDL_MOUSEMOTION:
300+ if (!GUICapture || sev.button.button == 4 || sev.button.button == 5)
301+ {
302+ if(sev.type != SDL_MOUSEMOTION)
303+ {
304+ event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
305+ /* These button mappings work with my Gentoo system using the
306+ * evdev driver and a Logitech MX510 mouse. Whether or not they
307+ * carry over to other Linux systems, I have no idea, but I sure
308+ * hope so. (Though buttons 11 and 12 are kind of useless, since
309+ * they also trigger buttons 4 and 5.)
310+ */
311+ switch (sev.button.button)
312+ {
313+ case SDL_BUTTON_LEFT: event.data1 = KEY_MOUSE1; break;
314+ case SDL_BUTTON_MIDDLE: event.data1 = KEY_MOUSE3; break;
315+ case SDL_BUTTON_RIGHT: event.data1 = KEY_MOUSE2; break;
316+ case 8: event.data1 = KEY_MOUSE4; break; // For whatever reason my side mouse buttons are here.
317+ case 9: event.data1 = KEY_MOUSE5; break;
318+ case SDL_BUTTON_X1: event.data1 = KEY_MOUSE6; break; // And these don't exist
319+ case SDL_BUTTON_X2: event.data1 = KEY_MOUSE7; break;
320+ case 6: event.data1 = KEY_MOUSE8; break;
321+ default: printf("SDL mouse button %s %d\n",
322+ sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break;
323+ }
324+ if (event.data1 != 0)
325+ {
326+ D_PostEvent(&event);
327+ }
328+ }
329+ }
330+ else if (sev.type == SDL_MOUSEMOTION || (sev.button.button >= 1 && sev.button.button <= 3))
331+ {
332+ int x, y;
333+ SDL_GetMouseState (&x, &y);
414334
415- switch (sev.key.keysym.sym)
416- {
417- case SDLK_KP_ENTER: event.data1 = GK_RETURN; break;
418- case SDLK_PAGEUP: event.data1 = GK_PGUP; break;
419- case SDLK_PAGEDOWN: event.data1 = GK_PGDN; break;
420- case SDLK_END: event.data1 = GK_END; break;
421- case SDLK_HOME: event.data1 = GK_HOME; break;
422- case SDLK_LEFT: event.data1 = GK_LEFT; break;
423- case SDLK_RIGHT: event.data1 = GK_RIGHT; break;
424- case SDLK_UP: event.data1 = GK_UP; break;
425- case SDLK_DOWN: event.data1 = GK_DOWN; break;
426- case SDLK_DELETE: event.data1 = GK_DEL; break;
427- case SDLK_ESCAPE: event.data1 = GK_ESCAPE; break;
428- case SDLK_F1: event.data1 = GK_F1; break;
429- case SDLK_F2: event.data1 = GK_F2; break;
430- case SDLK_F3: event.data1 = GK_F3; break;
431- case SDLK_F4: event.data1 = GK_F4; break;
432- case SDLK_F5: event.data1 = GK_F5; break;
433- case SDLK_F6: event.data1 = GK_F6; break;
434- case SDLK_F7: event.data1 = GK_F7; break;
435- case SDLK_F8: event.data1 = GK_F8; break;
436- case SDLK_F9: event.data1 = GK_F9; break;
437- case SDLK_F10: event.data1 = GK_F10; break;
438- case SDLK_F11: event.data1 = GK_F11; break;
439- case SDLK_F12: event.data1 = GK_F12; break;
440- default:
441- if (sev.key.keysym.sym < 256)
442- {
443- event.data1 = sev.key.keysym.sym;
444- }
445- break;
446- }
447- if (event.data1 < 128)
448- {
449- event.data1 = toupper(event.data1);
450- D_PostEvent (&event);
451- }
452- }
453- break;
335+ event.data1 = x;
336+ event.data2 = y;
454337
455- case SDL_TEXTINPUT:
456- if (GUICapture)
457- {
458- event.type = EV_GUI_Event;
459- event.subtype = EV_GUI_Char;
460- event.data1 = sev.text.text[0];
461- D_PostEvent (&event);
462- }
463- break;
338+ screen->ScaleCoordsFromWindow(event.data1, event.data2);
464339
465- case SDL_JOYBUTTONDOWN:
466- case SDL_JOYBUTTONUP:
467- if (!GUICapture)
468- {
469- event.type = sev.type == SDL_JOYBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
470- event.data1 = KEY_FIRSTJOYBUTTON + sev.jbutton.button;
471- if(event.data1 != 0)
472- D_PostEvent(&event);
473- }
474- break;
475- }
340+ event.type = EV_GUI_Event;
341+ if(sev.type == SDL_MOUSEMOTION)
342+ event.subtype = EV_GUI_MouseMove;
343+ else
344+ {
345+ event.subtype = sev.type == SDL_MOUSEBUTTONDOWN ? EV_GUI_LButtonDown : EV_GUI_LButtonUp;
346+ event.subtype += (sev.button.button - 1) * 3;
347+ }
348+
349+ SDL_Keymod kmod = SDL_GetModState();
350+ event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
351+ ((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
352+ ((kmod & KMOD_ALT) ? GKM_ALT : 0);
353+
354+ D_PostEvent(&event);
355+ }
356+ break;
357+
358+ case SDL_MOUSEWHEEL:
359+ if (GUICapture)
360+ {
361+ event.type = EV_GUI_Event;
362+ event.subtype = sev.wheel.y > 0 ? EV_GUI_WheelUp : EV_GUI_WheelDown;
363+ SDL_Keymod kmod = SDL_GetModState();
364+ event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
365+ ((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
366+ ((kmod & KMOD_ALT) ? GKM_ALT : 0);
367+ D_PostEvent (&event);
368+ }
369+ else
370+ {
371+ event.type = EV_KeyDown;
372+ event.data1 = sev.wheel.y > 0 ? KEY_MWHEELUP : KEY_MWHEELDOWN;
373+ D_PostEvent (&event);
374+ event.type = EV_KeyUp;
375+ D_PostEvent (&event);
376+ }
377+ break;
378+
379+ case SDL_KEYDOWN:
380+ case SDL_KEYUP:
381+ if (!GUICapture)
382+ {
383+ if (sev.key.repeat)
384+ {
385+ break;
386+ }
387+
388+ event.type = sev.type == SDL_KEYDOWN ? EV_KeyDown : EV_KeyUp;
389+
390+ // Try to look up our key mapped key for conversion to DirectInput.
391+ // If that fails, then we'll do a lookup against the scan code,
392+ // which may not return the right key, but at least the key should
393+ // work in the game.
394+ if (const uint8_t *dik = KeySymToDIK.CheckKey (sev.key.keysym.sym))
395+ event.data1 = *dik;
396+ else if (const uint8_t *dik = KeyScanToDIK.CheckKey (sev.key.keysym.scancode))
397+ event.data1 = *dik;
398+
399+ if (event.data1)
400+ {
401+ if (sev.key.keysym.sym < 256)
402+ {
403+ event.data2 = sev.key.keysym.sym;
404+ }
405+ D_PostEvent (&event);
406+ }
407+ }
408+ else
409+ {
410+ event.type = EV_GUI_Event;
411+ event.subtype = sev.type == SDL_KEYDOWN ? EV_GUI_KeyDown : EV_GUI_KeyUp;
412+ SDL_Keymod kmod = SDL_GetModState();
413+ event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
414+ ((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
415+ ((kmod & KMOD_ALT) ? GKM_ALT : 0);
416+
417+ if (event.subtype == EV_GUI_KeyDown && sev.key.repeat)
418+ {
419+ event.subtype = EV_GUI_KeyRepeat;
420+ }
421+
422+ switch (sev.key.keysym.sym)
423+ {
424+ case SDLK_KP_ENTER: event.data1 = GK_RETURN; break;
425+ case SDLK_PAGEUP: event.data1 = GK_PGUP; break;
426+ case SDLK_PAGEDOWN: event.data1 = GK_PGDN; break;
427+ case SDLK_END: event.data1 = GK_END; break;
428+ case SDLK_HOME: event.data1 = GK_HOME; break;
429+ case SDLK_LEFT: event.data1 = GK_LEFT; break;
430+ case SDLK_RIGHT: event.data1 = GK_RIGHT; break;
431+ case SDLK_UP: event.data1 = GK_UP; break;
432+ case SDLK_DOWN: event.data1 = GK_DOWN; break;
433+ case SDLK_DELETE: event.data1 = GK_DEL; break;
434+ case SDLK_ESCAPE: event.data1 = GK_ESCAPE; break;
435+ case SDLK_F1: event.data1 = GK_F1; break;
436+ case SDLK_F2: event.data1 = GK_F2; break;
437+ case SDLK_F3: event.data1 = GK_F3; break;
438+ case SDLK_F4: event.data1 = GK_F4; break;
439+ case SDLK_F5: event.data1 = GK_F5; break;
440+ case SDLK_F6: event.data1 = GK_F6; break;
441+ case SDLK_F7: event.data1 = GK_F7; break;
442+ case SDLK_F8: event.data1 = GK_F8; break;
443+ case SDLK_F9: event.data1 = GK_F9; break;
444+ case SDLK_F10: event.data1 = GK_F10; break;
445+ case SDLK_F11: event.data1 = GK_F11; break;
446+ case SDLK_F12: event.data1 = GK_F12; break;
447+ default:
448+ if (sev.key.keysym.sym < 256)
449+ {
450+ event.data1 = sev.key.keysym.sym;
451+ }
452+ break;
453+ }
454+ if (event.data1 < 128)
455+ {
456+ event.data1 = toupper(event.data1);
457+ D_PostEvent (&event);
458+ }
459+ }
460+ break;
461+
462+ case SDL_TEXTINPUT:
463+ if (GUICapture)
464+ {
465+ event.type = EV_GUI_Event;
466+ event.subtype = EV_GUI_Char;
467+ event.data1 = sev.text.text[0];
468+ event.data2 = !!(SDL_GetModState() & KMOD_ALT);
469+ D_PostEvent (&event);
470+ }
471+ break;
472+
473+ case SDL_JOYBUTTONDOWN:
474+ case SDL_JOYBUTTONUP:
475+ if (!GUICapture)
476+ {
477+ event.type = sev.type == SDL_JOYBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
478+ event.data1 = KEY_FIRSTJOYBUTTON + sev.jbutton.button;
479+ if(event.data1 != 0)
480+ D_PostEvent(&event);
481+ }
482+ break;
483+ }
476484 }
477485
478486 void I_GetEvent ()
479487 {
480- SDL_Event sev;
481-
482- while (SDL_PollEvent (&sev))
483- {
484- MessagePump (sev);
485- }
486- if (use_mouse)
487- {
488- MouseRead ();
489- }
488+ SDL_Event sev;
489+
490+ while (SDL_PollEvent (&sev))
491+ {
492+ MessagePump (sev);
493+ }
494+ if (use_mouse)
495+ {
496+ MouseRead ();
497+ }
490498 }
491499
492500 void I_StartTic ()
493501 {
494- I_CheckGUICapture ();
495- I_CheckNativeMouse ();
496- I_GetEvent ();
502+ I_CheckGUICapture ();
503+ I_CheckNativeMouse ();
504+ I_GetEvent ();
497505 }
498506
499507 void I_ProcessJoysticks ();
500508 void I_StartFrame ()
501509 {
502- I_ProcessJoysticks();
503-}
510+ I_ProcessJoysticks();
511+}
\ No newline at end of file
diff -r c1f472a776fa -r d7f03c3afd90 src/sdl/i_main.cpp
--- a/src/sdl/i_main.cpp Mon Jan 23 20:43:01 2023 +1100
+++ b/src/sdl/i_main.cpp Mon Jan 23 20:48:43 2023 +1100
@@ -68,7 +68,7 @@
6868 // MACROS ------------------------------------------------------------------
6969
7070 // The maximum number of functions that can be registered with atterm.
71-#define MAX_TERMS 64
71+#define MAX_TERMS 64
7272
7373 // TYPES -------------------------------------------------------------------
7474
@@ -259,9 +259,10 @@
259259 // Note that the LANG environment variable is overridden by LC_*
260260 setenv ("LC_NUMERIC", "C", 1);
261261
262-#ifndef NO_GTK
263- GtkAvailable = gtk_init_check (&argc, &argv);
264-#endif
262+// [BB] Patch from icculus for SDL 1.2 compatibility.
263+// #ifndef NO_GTK
264+// GtkAvailable = gtk_init_check (&argc, &argv);
265+// #endif
265266
266267 setlocale (LC_ALL, "C");
267268
diff -r c1f472a776fa -r d7f03c3afd90 src/sdl/sdlglvideo.cpp
--- a/src/sdl/sdlglvideo.cpp Mon Jan 23 20:43:01 2023 +1100
+++ b/src/sdl/sdlglvideo.cpp Mon Jan 23 20:48:43 2023 +1100
@@ -174,223 +174,218 @@
174174 PalEntry flashColor;
175175 // int flashAmount;
176176
177- if (old != NULL)
178- { // Reuse the old framebuffer if its attributes are the same
179- SDLGLFB *fb = static_cast<SDLGLFB *> (old);
180- if (fb->Width == width &&
181- fb->Height == height)
182- {
183- bool fsnow = (SDL_GetWindowFlags (fb->Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
184-
185- if (fsnow != fullscreen)
186- {
187- SDL_SetWindowFullscreen (fb->Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
188- }
189- return old;
190- }
191-// old->GetFlash (flashColor, flashAmount);
192- delete old;
193- }
194- else
195- {
196- flashColor = 0;
197-// flashAmount = 0;
198- }
199-
200- SDLGLFB *fb = new OpenGLFrameBuffer (0, width, height, 32, 60, fullscreen);
201- retry = 0;
202-
203- // If we could not create the framebuffer, try again with slightly
204- // different parameters in this order:
205- // 1. Try with the closest size
206- // 2. Try in the opposite screen mode with the original size
207- // 3. Try in the opposite screen mode with the closest size
208- // This is a somewhat confusing mass of recursion here.
177+ if (old != NULL)
178+ { // Reuse the old framebuffer if its attributes are the same
179+ SDLGLFB *fb = static_cast<SDLGLFB *> (old);
180+ if (fb->Width == width &&
181+ fb->Height == height)
182+ {
183+ bool fsnow = (SDL_GetWindowFlags (fb->Screen) & SDL_WINDOW_FULLSCREEN) != 0;
184+
185+ if (fsnow != fullscreen)
186+ {
187+ SDL_SetWindowFullscreen(fb->Screen, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
188+ }
189+ return old;
190+ }
191+// old->GetFlash (flashColor, flashAmount);
192+ delete old;
193+ }
194+ else
195+ {
196+ flashColor = 0;
197+// flashAmount = 0;
198+ }
199+
200+ SDLGLFB *fb = new OpenGLFrameBuffer (0, width, height, 32, 60, fullscreen);
201+ retry = 0;
202+
203+ // If we could not create the framebuffer, try again with slightly
204+ // different parameters in this order:
205+ // 1. Try with the closest size
206+ // 2. Try in the opposite screen mode with the original size
207+ // 3. Try in the opposite screen mode with the closest size
208+ // This is a somewhat confusing mass of recursion here.
209209
210- while (fb == NULL || !fb->IsValid ())
211- {
212- if (fb != NULL)
213- {
214- delete fb;
215- }
216-
217- switch (retry)
218- {
219- case 0:
220- owidth = width;
221- oheight = height;
222- case 2:
223- // Try a different resolution. Hopefully that will work.
224- I_ClosestResolution (&width, &height, 8);
225- break;
210+ while (fb == NULL || !fb->IsValid ())
211+ {
212+ if (fb != NULL)
213+ {
214+ delete fb;
215+ }
226216
227- case 1:
228- // Try changing fullscreen mode. Maybe that will work.
229- width = owidth;
230- height = oheight;
231- fullscreen = !fullscreen;
232- break;
233-
234- default:
235- // I give up!
236- I_FatalError ("Could not create new screen (%d x %d)", owidth, oheight);
217+ switch (retry)
218+ {
219+ case 0:
220+ owidth = width;
221+ oheight = height;
222+ case 2:
223+ // Try a different resolution. Hopefully that will work.
224+ I_ClosestResolution (&width, &height, 8);
225+ break;
237226
238- fprintf( stderr, "!!! [SDLGLVideo::CreateFrameBuffer] Got beyond I_FatalError !!!" );
239- return NULL; //[C] actually this shouldn't be reached; probably should be replaced with an ASSERT
240- }
227+ case 1:
228+ // Try changing fullscreen mode. Maybe that will work.
229+ width = owidth;
230+ height = oheight;
231+ fullscreen = !fullscreen;
232+ break;
241233
242- ++retry;
243- fb = static_cast<SDLGLFB *>(CreateFrameBuffer (width, height, fullscreen, NULL));
244- }
234+ default:
235+ // I give up!
236+ I_FatalError ("Could not create new screen (%d x %d)", owidth, oheight);
245237
246-// fb->SetFlash (flashColor, flashAmount);
247- return fb;
238+ fprintf( stderr, "!!! [SDLGLVideo::CreateFrameBuffer] Got beyond I_FatalError !!!" );
239+ return NULL; //[C] actually this shouldn't be reached; probably should be replaced with an ASSERT
240+ }
241+
242+ ++retry;
243+ fb = static_cast<SDLGLFB *>(CreateFrameBuffer (width, height, fullscreen, NULL));
244+ }
245+
246+// fb->SetFlash (flashColor, flashAmount);
247+ return fb;
248248 }
249249
250-
251250 void SDLGLVideo::SetWindowedScale (float scale)
252251 {
253252 }
254253
255254 bool SDLGLVideo::SetResolution (int width, int height, int bits)
256255 {
257- // FIXME: Is it possible to do this without completely destroying the old
258- // interface?
256+ // FIXME: Is it possible to do this without completely destroying the old
257+ // interface?
259258 #ifndef NO_GL
260259
261- if (GLRenderer != NULL) GLRenderer->FlushTextures();
262- I_ShutdownGraphics();
260+ if (GLRenderer != NULL) GLRenderer->FlushTextures();
261+ I_ShutdownGraphics();
263262
264- Video = new SDLGLVideo(0);
265- if (Video == NULL) I_FatalError ("Failed to initialize display");
263+ Video = new SDLGLVideo(0);
264+ if (Video == NULL) I_FatalError ("Failed to initialize display");
266265
267266 #if (defined(WINDOWS)) || defined(WIN32)
268- bits=32;
267+ bits=32;
269268 #else
270- bits=24;
269+ bits=24;
271270 #endif
272-
273- V_DoModeSetup(width, height, bits);
271+
272+ V_DoModeSetup(width, height, bits);
274273 #endif
275- return true; // We must return true because the old video context no longer exists.
274+ return true; // We must return true because the old video context no longer exists.
276275 }
277276
278277 //==========================================================================
279278 //
280-//
279+//
281280 //
282281 //==========================================================================
283282
284283 bool SDLGLVideo::SetupPixelFormat(bool allowsoftware, int multisample)
285284 {
286- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
287- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
288- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
289- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
290- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
291- SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
292- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
293- if (multisample > 0) {
294- SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
295- SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample );
296- }
285+ SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
286+ SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
287+ SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
288+ SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
289+ SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
290+ SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
291+ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
292+ if (multisample > 0) {
293+ SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
294+ SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample );
295+ }
297296 return true;
298297 }
299298
300299 //==========================================================================
301300 //
302-//
301+//
303302 //
304303 //==========================================================================
305304
306305 bool SDLGLVideo::InitHardware (bool allowsoftware, int multisample)
307306 {
308- if (!SetupPixelFormat(allowsoftware, multisample))
309- {
310- Printf ("R_OPENGL: Reverting to software mode...\n");
311- return false;
312- }
313- return true;
307+ if (!SetupPixelFormat(allowsoftware, multisample))
308+ {
309+ Printf ("R_OPENGL: Reverting to software mode...\n");
310+ return false;
311+ }
312+ return true;
314313 }
315314
316315
317316 // FrameBuffer implementation -----------------------------------------------
318317
319318 SDLGLFB::SDLGLFB (void *, int width, int height, int, int, bool fullscreen)
320- : DFrameBuffer (width, height)
319+ : DFrameBuffer (width, height)
321320 {
322- static int localmultisample=-1;
323-
324- if (localmultisample<0) localmultisample=gl_vid_multisample;
325-
326- int i;
327-
328- m_Lock=0;
321+ int i;
322+
323+ m_Lock=0;
329324
330- UpdatePending = false;
331-
332- if (!static_cast<SDLGLVideo*>(Video)->InitHardware(false, localmultisample))
333- {
334- vid_renderer = 0;
335- return;
336- }
325+ UpdatePending = false;
326+
327+ if (!static_cast<SDLGLVideo*>(Video)->InitHardware(false, 0))
328+ {
329+ vid_renderer = 0;
330+ return;
331+ }
337332
338- FString caption;
339- caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
340- Screen = SDL_CreateWindow (caption,
341- SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
342- width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)|SDL_WINDOW_OPENGL);
333+ FString caption;
334+ caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime());
335+ Screen = SDL_CreateWindow (caption,
336+ SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter),
337+ width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN : 0)|SDL_WINDOW_OPENGL);
343338
344- if (Screen == NULL)
345- return;
339+ if (Screen == NULL)
340+ return;
346341
347- GLContext = SDL_GL_CreateContext(Screen);
348- if (GLContext == NULL)
349- return;
342+ GLContext = SDL_GL_CreateContext(Screen);
343+ if (GLContext == NULL)
344+ return;
350345
351- m_supportsGamma = -1 != SDL_GetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]);
346+ m_supportsGamma = -1 != SDL_GetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]);
352347 }
353348
354349 SDLGLFB::~SDLGLFB ()
355350 {
356- if (Screen)
357- {
351+ if (Screen)
352+ {
358353 if (m_supportsGamma)
359354 {
360355 SDL_SetWindowGammaRamp(Screen, m_origGamma[0], m_origGamma[1], m_origGamma[2]);
361356 }
362357
363- if (GLContext)
364- {
365- SDL_GL_DeleteContext(GLContext);
366- }
358+ if (GLContext)
359+ {
360+ SDL_GL_DeleteContext(GLContext);
361+ }
367362
368- SDL_DestroyWindow(Screen);
369- }
363+ SDL_DestroyWindow(Screen);
364+ }
370365 }
371366
372367
373368
374369
375-void SDLGLFB::InitializeState()
370+void SDLGLFB::InitializeState()
376371 {
377372 }
378373
379374 bool SDLGLFB::CanUpdate ()
380375 {
381- if (m_Lock != 1)
382- {
383- if (m_Lock > 0)
384- {
385- UpdatePending = true;
386- --m_Lock;
387- }
388- return false;
389- }
390- return true;
376+ if (m_Lock != 1)
377+ {
378+ if (m_Lock > 0)
379+ {
380+ UpdatePending = true;
381+ --m_Lock;
382+ }
383+ return false;
384+ }
385+ return true;
391386 }
392387
393-void SDLGLFB::SetGammaTable(WORD *tbl)
388+void SDLGLFB::SetGammaTable(uint16_t *tbl)
394389 {
395390 SDL_SetWindowGammaRamp(Screen, &tbl[0], &tbl[256], &tbl[512]);
396391 }
@@ -426,20 +421,30 @@
426421
427422 bool SDLGLFB::IsFullscreen ()
428423 {
429- return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
424+ return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN) != 0;
430425 }
431426
432427
433428 bool SDLGLFB::IsValid ()
434429 {
435- return DFrameBuffer::IsValid() && Screen != NULL;
430+ return DFrameBuffer::IsValid() && Screen != NULL;
436431 }
437432
438433 void SDLGLFB::SetVSync( bool vsync )
439434 {
440435 #if defined (__APPLE__)
441- const GLint value = vsync ? 1 : 0;
442- CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &value );
436+ const GLint value = vsync ? 1 : 0;
437+ CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval, &value );
438+#else
439+ if (vsync)
440+ {
441+ if (SDL_GL_SetSwapInterval(-1) == -1)
442+ SDL_GL_SetSwapInterval(1);
443+ }
444+ else
445+ {
446+ SDL_GL_SetSwapInterval(0);
447+ }
443448 #endif
444449 }
445450
@@ -449,8 +454,27 @@
449454
450455 void SDLGLFB::SwapBuffers()
451456 {
452- SDL_GL_SwapWindow (Screen);
457+#ifndef __APPLE__
458+ if (vid_maxfps && !cl_capfps)
459+ {
460+ SEMAPHORE_WAIT(FPSLimitSemaphore)
461+ }
462+#endif
463+
464+ SDL_GL_SwapWindow (Screen);
453465 }
454466
467+int SDLGLFB::GetClientWidth()
468+{
469+ int width = 0;
470+ SDL_GL_GetDrawableSize(Screen, &width, nullptr);
471+ return width;
472+}
455473
456-#endif
474+int SDLGLFB::GetClientHeight()
475+{
476+ int height = 0;
477+ SDL_GL_GetDrawableSize(Screen, nullptr, &height);
478+ return height;
479+}
480+#endif //NO_GL
\ No newline at end of file
diff -r c1f472a776fa -r d7f03c3afd90 src/sdl/sdlglvideo.h
--- a/src/sdl/sdlglvideo.h Mon Jan 23 20:43:01 2023 +1100
+++ b/src/sdl/sdlglvideo.h Mon Jan 23 20:48:43 2023 +1100
@@ -58,8 +58,8 @@
5858
5959 friend class SDLGLVideo;
6060
61-//[C]
62- int GetTrueHeight() { return GetHeight();}
61+ int GetClientWidth();
62+ int GetClientHeight();
6363
6464 protected:
6565 bool CanUpdate();