Skip to content

Commit

Permalink
Hopefully make macOS port compatible with SDL3
Browse files Browse the repository at this point in the history
.. 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.
  • Loading branch information
DanielGibson committed Oct 9, 2024
1 parent 6181f24 commit cf720c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 4 additions & 5 deletions neo/sys/osx/DOOMController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
#include <fenv.h>
#include <mach/thread_status.h>
#include <AppKit/AppKit.h>

#include <SDL_main.h>

#include "sys/platform.h"

#include <sys/types.h>
Expand Down Expand Up @@ -194,13 +191,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';
Expand Down
10 changes: 9 additions & 1 deletion neo/sys/osx/SDLMain.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 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>
Expand Down

0 comments on commit cf720c5

Please sign in to comment.