From: Lockl00p <97256723+Lockl00p@users.noreply.github.com> Date: Thu, 23 May 2024 23:47:34 +0000 (-0500) Subject: Added Nintendo Switch Make target X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=da894e89ae37075f9c8e20c5436f77d0cd45d10e;p=xonotic%2Fdarkplaces.git Added Nintendo Switch Make target This time, it actually works! --- diff --git a/.gitignore b/.gitignore index 4c4c53c9..3e912282 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ obj/ *.o *.i *.s +*.nro # MSVC build objects Debug-darkplaces-sdl2-vs*/ diff --git a/README.md b/README.md index df037d5c..ae5eddd2 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,17 @@ The Release build crashes. The Debug x64 build doesn't crash (but is rather slow To get a build suitable for playing you'll need to use MinGW GCC, or download the autobuild from Xonotic (see above). +### Switch (devkitpro) +Note: This requires a modded switch. +1. Install [devkitpro](https://devkitpro.org/wiki/Getting_Started) +2. Run this command: +``` +(sudo) dkp-pacman -Syu switch-dev switch-sdl switch-libjpeg-turbo switch-zlib +``` +3. Build using `DP_MAKE_TARGET=switch make sdl-release`. +4. Copy `darkplaces-sdl.nro` to your switch's SD Card + +(Basedir is `/switch/darkplaces/(switch username)`) ## Contributing [DarkPlaces Contributing Guidelines](CONTRIBUTING.md) diff --git a/fs.c b/fs.c index 6e425971..bbab3b57 100644 --- a/fs.c +++ b/fs.c @@ -53,6 +53,9 @@ #include "utf8lib.h" #endif +#ifdef __SWITCH__ +#include +#endif // Win32 requires us to add O_BINARY, but the other OSes don't have it #ifndef O_BINARY # define O_BINARY 0 @@ -2193,6 +2196,24 @@ static void FS_Init_Dir (void) } } } +#elif defined(__SWITCH__) + AccountUid userID = {0};; + AccountProfile profile = {0}; + AccountProfileBase profileBase = {0}; + Result result = accountGetPreselectedUser(&userID); + if(R_FAILED(result)){ + StartupError("Unable to get selected user.\nApplet mode is not supported."); + } + accountGetProfile(&profile, userID); + accountProfileGet(&profile,NULL,&profileBase); + + dpsnprintf(fs_basedir, sizeof(fs_basedir), "/switch/darkplaces/%s",profileBase.nickname); + //No idea why I need to make this weird struct to use stat but stackoverflow decreed I must, so I shall. + struct stat sb; + if(stat(fs_basedir,&sb) == -1){ + //Also did not know about mkdir function so thank you stack overflow. + mkdir(fs_basedir,0777); + } #else // use the working directory getcwd(fs_basedir, sizeof(fs_basedir)); diff --git a/makefile b/makefile index b62194cd..619a7c5d 100644 --- a/makefile +++ b/makefile @@ -110,6 +110,43 @@ ifeq ($(DP_MAKE_TARGET), linux) DP_LINK_XMP?=dlopen endif +# Switch configuration +ifeq ($(DP_MAKE_TARGET), switch) + ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") + endif + + CC=$(DEVKITPRO)/devkitA64/bin/aarch64-none-elf-gcc + DP_SSE=0 + + CFLAGS_EXTRA=$(CFLAGS_SWITCH) + OBJ_ICON= + OBJ_ICON_NEXUIZ= + + SYS_OBJ=sys_switch.o + LDFLAGS_SV=$(LDFLAGS_SWITCHSV) + LDFLAGS_SDL=$(LDFLAGS_SWITCHSDL) + SDL_CONFIG=$(DEVKITPRO)/portlibs/switch/bin/sdl2-config + SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) + SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) + SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) + + EXE_SV=$(EXE_UNIXSV) + EXE_SDL=$(EXE_UNIXSDL) + EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ) + EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ) + STRIP=elf2nro + STRIPARGS=$(EXE) $(EXE).nro + + DP_LINK_SDL?=shared + DP_LINK_ZLIB?=shared + DP_LINK_JPEG?=shared + DP_LINK_ODE?= + DP_LINK_CRYPTO?=dlopen + DP_LINK_CRYPTO_RIJNDAEL?=dlopen + DP_LINK_XMP?=dlopen +endif + # Mac OS X configuration ifeq ($(DP_MAKE_TARGET), macosx) OBJ_ICON= diff --git a/makefile.inc b/makefile.inc index 33cbc043..4c5bfe3b 100644 --- a/makefile.inc +++ b/makefile.inc @@ -4,7 +4,7 @@ CHECKLEVEL2 = @if [ "$(LEVEL)" != 2 ]; then $(MAKE) help; false; fi STRIP?=strip - +STRIPARGS?=$(EXE) ###### Sound ##### @@ -126,8 +126,9 @@ OBJ_MENU= \ # note that builddate.c is very intentionally not compiled to a .o before # being linked, because it should be recompiled every time an executable is # built to give the executable a proper date string +SYS_OBJ ?= sys_sdl.o OBJ_SV= builddate.c sys_null.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON) -OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON) +OBJ_SDL= builddate.c $(SYS_OBJ) vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON) # Compilation @@ -227,6 +228,13 @@ LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic $(LDFLAGS_UNIXSDL) +##### Switch specific variables ##### + +CFLAGS_SWITCH= -D__SWITCH__ -I$(DEVKITPRO)/libnx/include -I$(DEVKITPRO)/portlibs/switch/include -fPIE -DNOSUPPORTIPV6 -DDEBUGSDLEVENTS +LDFLAGS_SWITCHSV=-L$(DEVKITPRO)/libnx/lib -L$(DEVKITPRO)/portlibs/switch/lib $(LDFLAGS_UNIXCOMMON) -specs=$(DEVKITPRO)/libnx/switch.specs -g -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE -lm -lnx +LDFLAGS_SWITCHSDL=-L$(DEVKITPRO)/libnx/lib -L$(DEVKITPRO)/portlibs/switch/lib $(LDFLAGS_UNIXCOMMON) -specs=$(DEVKITPRO)/libnx/switch.specs -g -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE $(LDFLAGS_UNIXSDL) -lm -lnx + + ##### Mac OS X specific variables ##### # Link @@ -396,7 +404,7 @@ bin-release : DP_MAKE_TARGET=$(DP_MAKE_TARGET) \ CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE) $(OPTIM_RELEASE)'\ LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2 - $(STRIP) $(EXE) + $(STRIP) $(STRIPARGS) bin-release-profile : $(CHECKLEVEL1) @@ -407,7 +415,7 @@ bin-release-profile : DP_MAKE_TARGET=$(DP_MAKE_TARGET) \ CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE_PROFILE) $(OPTIM_RELEASE)'\ LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2 - $(STRIP) $(EXE) + $(STRIP) $(STRIPARGS) prepare : $(CMD_MKDIR) $(BUILD_DIR) @@ -497,6 +505,7 @@ $(EXE_SDLNEXUIZ): $(OBJ_SDL) $(OBJ_ICON_NEXUIZ) clean: -$(CMD_RM) $(EXE_SV) -$(CMD_RM) $(EXE_SDL) + -$(CMD_RM) $(EXE_SDL).nro -$(CMD_RM) $(EXE_SVNEXUIZ) -$(CMD_RM) $(EXE_SDLNEXUIZ) -$(CMD_RM) *.o diff --git a/sys.h b/sys.h index a5c6b275..a9369090 100644 --- a/sys.h +++ b/sys.h @@ -87,6 +87,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # define DP_OS_NAME "SunOS" # define DP_OS_STR "sunos" # endif +#elif defined(__SWITCH__) +# define DP_OS_NAME "Horizon OS" +# define DP_OS_STR "HOS" #else # define DP_OS_NAME "Unknown" # define DP_OS_STR "unknown" @@ -151,6 +154,8 @@ typedef struct sys_s extern sys_t sys; + + // // DLL management // diff --git a/sys_shared.c b/sys_shared.c index 46cec642..ef8f966d 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -3,9 +3,9 @@ # define _WIN32_WINNT 0x0502 # endif #endif - +#ifndef __SWITCH__ #define SUPPORTDLL - +#endif #ifdef WIN32 # include # include // timeGetTime @@ -26,10 +26,12 @@ # include # include # include +#ifndef __SWITCH__ # ifdef SUPPORTDLL # include # endif #endif +#endif #include @@ -119,7 +121,9 @@ qbool Sys_LoadSelf(dllhandle_t *handle) #ifdef WIN32 dllhandle = LoadLibrary (NULL); #else - dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL); + #ifndef __SWITCH__ + dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL); + #endif #endif *handle = dllhandle; return true; diff --git a/sys_switch.c b/sys_switch.c new file mode 100644 index 00000000..eeac006d --- /dev/null +++ b/sys_switch.c @@ -0,0 +1,91 @@ +/* + * Include this BEFORE darkplaces.h because it breaks wrapping + * _Static_assert. Cloudwalk has no idea how or why so don't ask. + */ +#include + +#include "darkplaces.h" +#include +#include +#include "quakedef.h" +// ======================================================================= +// General routines +// ======================================================================= + +void Sys_SDL_Shutdown(void) +{ + socketExit(); + accountExit(); + SDL_Quit(); +} + +// Sys_Error early in startup might screw with automated +// workflows or something if we show the dialog by default. +static qbool nocrashdialog = true; +void Sys_SDL_Dialog(const char *title, const char *string) +{ + if(!nocrashdialog) + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL); +} + +char *Sys_SDL_GetClipboardData (void) +{ + char *data = NULL; + char *cliptext; + + cliptext = SDL_GetClipboardText(); + if (cliptext != NULL) { + size_t allocsize; + allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1); + data = (char *)Z_Malloc (allocsize); + dp_strlcpy (data, cliptext, allocsize); + SDL_free(cliptext); + } + + return data; +} + +void Sys_SDL_Init(void) +{ + // we don't know which systems we'll want to init, yet... + if (SDL_Init(0) < 0) + Sys_Error("SDL_Init failed: %s\n", SDL_GetError()); + + // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes + if(!Sys_CheckParm("-nocrashdialog")) + nocrashdialog = false; +} + +qbool sys_supportsdlgetticks = true; +unsigned int Sys_SDL_GetTicks (void) +{ + return SDL_GetTicks(); +} +void Sys_SDL_Delay (unsigned int milliseconds) +{ + SDL_Delay(milliseconds); +} + +int StartupError(char message[]){ + consoleInit(NULL); + while(appletMainLoop()){ + printf(message); + printf("\nPlease exit the app"); + consoleUpdate(NULL); + } +} + +int main(int argc, char *argv[]) +{ + + socketInitializeDefault(); + Result result = accountInitialize(AccountServiceType_Application); + if (R_FAILED(result)) + { + StartupError("Unable to initialize account system"); + + + } + + return Sys_Main(argc, argv); +} diff --git a/vid_sdl.c b/vid_sdl.c index 79addbdf..21957a29 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -1123,6 +1123,33 @@ void Sys_SDL_HandleEvents(void) } break; case SDL_JOYBUTTONDOWN: + #ifdef __SWITCH__ + if(event.jbutton.button == 0){ + Key_Event( K_ENTER, 0, true ); + Key_Event( K_ENTER, 0, false ); + } + else if(event.jbutton.button == 13){ + Key_Event( K_UPARROW, 0, true ); + Key_Event( K_UPARROW, 0, false ); + } + else if(event.jbutton.button == 15){ + Key_Event( K_DOWNARROW, 0, true ); + Key_Event( K_DOWNARROW, 0, false ); + } + else if(event.jbutton.button == 12){ + Key_Event( K_LEFTARROW, 0, true ); + Key_Event( K_LEFTARROW, 0, false ); + } + else if(event.jbutton.button == 14){ + Key_Event( K_RIGHTARROW, 0, true ); + Key_Event( K_RIGHTARROW, 0, false ); + } + else if(event.jbutton.button == 10){ + Key_Event( K_ESCAPE, 0, true ); + Key_Event( K_ESCAPE, 0, false ); + } + break; + #endif case SDL_JOYBUTTONUP: case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: