*.o
*.i
*.s
+*.nro
# MSVC build objects
Debug-darkplaces-sdl2-vs*/
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)
#include "utf8lib.h"
#endif
+#ifdef __SWITCH__
+#include <switch.h>
+#endif
// Win32 requires us to add O_BINARY, but the other OSes don't have it
#ifndef O_BINARY
# define O_BINARY 0
}
}
}
+#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));
DP_LINK_XMP?=dlopen
endif
+# Switch configuration
+ifeq ($(DP_MAKE_TARGET), switch)
+ ifeq ($(strip $(DEVKITPRO)),)
+$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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=
STRIP?=strip
-
+STRIPARGS?=$(EXE)
###### Sound #####
# 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
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
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)
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)
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
# 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"
extern sys_t sys;
+
+
//
// DLL management
//
# define _WIN32_WINNT 0x0502
# endif
#endif
-
+#ifndef __SWITCH__
#define SUPPORTDLL
-
+#endif
#ifdef WIN32
# include <windows.h>
# include <mmsystem.h> // timeGetTime
# include <fcntl.h>
# include <sys/time.h>
# include <time.h>
+#ifndef __SWITCH__
# ifdef SUPPORTDLL
# include <dlfcn.h>
# endif
#endif
+#endif
#include <signal.h>
#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;
--- /dev/null
+/*
+ * Include this BEFORE darkplaces.h because it breaks wrapping
+ * _Static_assert. Cloudwalk has no idea how or why so don't ask.
+ */
+#include <SDL.h>
+
+#include "darkplaces.h"
+#include <switch.h>
+#include <sys/stat.h>
+#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);
+}
}
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: