2 #include <io.h> // Include this BEFORE darkplaces.h because it uses strncpy which trips DP_STATIC_ASSERT
10 #include <android/log.h>
14 * Include this BEFORE darkplaces.h because it breaks wrapping
15 * _Static_assert. Cloudwalk has no idea how or why so don't ask.
19 #include "darkplaces.h"
23 #pragma comment(lib, "sdl2.lib")
24 #pragma comment(lib, "sdl2main.lib")
30 // =======================================================================
32 // =======================================================================
34 void Sys_Shutdown (void)
37 Sys_AllowProfiling(false);
40 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
46 // Sys_Error early in startup might screw with automated
47 // workflows or something if we show the dialog by default.
48 static qbool nocrashdialog = true;
49 void Sys_Error (const char *error, ...)
52 char string[MAX_INPUTLINE];
54 // change stdin to non blocking
56 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
59 va_start (argptr,error);
60 dpvsnprintf (string, sizeof (string), error, argptr);
63 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
65 // don't want a dead window left blocking the OS UI or the crash dialog
69 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
74 void Sys_Print(const char *text)
77 if (developer.integer > 0)
79 __android_log_write(ANDROID_LOG_DEBUG, sys.argv[0], text);
85 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
86 // this is because both go to /dev/tty by default!
88 int origflags = fcntl (sys.outfd, F_GETFL, 0);
89 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
96 fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
98 break; // sorry, I cannot do anything about this error - without an output
102 fcntl (sys.outfd, F_SETFL, origflags);
105 //fprintf(stdout, "%s", text);
109 char *Sys_GetClipboardData (void)
114 cliptext = SDL_GetClipboardText();
115 if (cliptext != NULL) {
117 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
118 data = (char *)Z_Malloc (allocsize);
119 strlcpy (data, cliptext, allocsize);
126 void Sys_SDL_Init(void)
128 // we don't know which systems we'll want to init, yet...
130 Sys_Error("SDL_Init failed: %s\n", SDL_GetError());
132 // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes
133 if(!Sys_CheckParm("-nocrashdialog"))
134 nocrashdialog = false;
137 qbool sys_supportsdlgetticks = true;
138 unsigned int Sys_SDL_GetTicks (void)
140 return SDL_GetTicks();
142 void Sys_SDL_Delay (unsigned int milliseconds)
144 SDL_Delay(milliseconds);