Hopefully make macOS port compatible with SDL3

.. mostly by not making it use SDL_main.h, because it implements its
own SDL main functionality anyway.

However, I have no way to test this code and as long as SDL3 is not in
homebrew testing it in the CI build isn't easy either.
This commit is contained in:
Daniel Gibson 2024-10-09 18:42:26 +02:00
parent 6181f24c44
commit 3a6210b154
2 changed files with 18 additions and 6 deletions

View file

@ -32,9 +32,6 @@ If you have questions concerning this license or the applicable additional terms
#include <fenv.h>
#include <mach/thread_status.h>
#include <AppKit/AppKit.h>
#include <SDL_main.h>
#include "sys/platform.h"
#include <sys/types.h>
@ -45,6 +42,11 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/posix/posix_public.h"
// usually the following would be from SDL_main.h,
// but this way we should be able to avoid that header
// for better compatibility between SDL1.2 to SDL3
extern "C" int SDL_main( int argc, char *argv[] );
static char base_path[MAXPATHLEN];
static char exe_path[MAXPATHLEN];
static char save_path[MAXPATHLEN];
@ -194,13 +196,15 @@ int SDL_main( int argc, char *argv[] ) {
Sys_Error("Could not access application resources");
// DG: set exe_path so Posix_InitSignalHandlers() can call Posix_GetExePath()
SDL_strlcpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cStringUsingEncoding:NSUTF8StringEncoding ], sizeof(exe_path));
strncpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cStringUsingEncoding:NSUTF8StringEncoding ], sizeof(exe_path)-1);
exe_path[sizeof(exe_path)-1] = '\0';
// same for save_path for Posix_GetSavePath()
D3_snprintfC99(save_path, sizeof(save_path), "%s/Library/Application Support/dhewm3", [NSHomeDirectory() cStringUsingEncoding:NSUTF8StringEncoding]);
// and preinitializing basepath is easy enough so do that as well
{
char* snap;
SDL_strlcpy(base_path, exe_path, sizeof(base_path));
strncpy(base_path, exe_path, sizeof(base_path)-1);
base_path[sizeof(base_path)-1] = '\0';
snap = strrchr(base_path, '/');
if (snap)
*snap = '\0';

View file

@ -10,7 +10,15 @@
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "SDL.h"
#ifdef D3_SDL3
#include <SDL3/SDL.h>
// as SDL.h doesn't implicitly include SDL_main.h anymore,
// declare SDL_main() here. I think it's the only part of SDL_main.h we used,
// we implement it in DOOMController.mm an call it here in applicationDidFinishLaunching
extern "C" int SDL_main( int argc, char *argv[] );
#else // SDL2 and SDL1.2
#include "SDL.h"
#endif
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>