2 #include <io.h> // Include this BEFORE darkplaces.h because it uses strncpy which trips DP_STATIC_ASSERT
11 #include <android/log.h>
17 * Include this BEFORE darkplaces.h because it breaks wrapping
18 * _Static_assert. Cloudwalk has no idea how or why so don't ask.
22 #include "darkplaces.h"
26 #pragma comment(lib, "sdl2.lib")
27 #pragma comment(lib, "sdl2main.lib")
33 // =======================================================================
35 // =======================================================================
37 void Sys_Shutdown (void)
40 Sys_AllowProfiling(false);
43 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
49 static qbool nocrashdialog;
50 void Sys_Error (const char *error, ...)
53 char string[MAX_INPUTLINE];
55 // change stdin to non blocking
57 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
60 va_start (argptr,error);
61 dpvsnprintf (string, sizeof (string), error, argptr);
64 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
66 // don't want a dead window left blocking the OS UI or the crash dialog
70 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
75 void Sys_Print(const char *text)
78 if (developer.integer > 0)
80 __android_log_write(ANDROID_LOG_DEBUG, sys.argv[0], text);
86 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
87 // this is because both go to /dev/tty by default!
89 int origflags = fcntl (sys.outfd, F_GETFL, 0);
90 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
97 fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
99 break; // sorry, I cannot do anything about this error - without an output
103 fcntl (sys.outfd, F_SETFL, origflags);
106 //fprintf(stdout, "%s", text);
110 char *Sys_ConsoleInput(void)
112 static char text[MAX_INPUTLINE];
143 if (len == sizeof (text))
148 struct timeval timeout;
150 FD_SET(0, &fdset); // stdin
153 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
155 len = read (0, text, sizeof(text));
158 // rip off the \n and terminate
167 char *Sys_GetClipboardData (void)
172 cliptext = SDL_GetClipboardText();
173 if (cliptext != NULL) {
175 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
176 data = (char *)Z_Malloc (allocsize);
177 strlcpy (data, cliptext, allocsize);
184 int main (int argc, char *argv[])
186 signal(SIGFPE, SIG_IGN);
189 Sys_AllowProfiling(true);
194 sys.argv = (const char **)argv;
196 // Sys_Error this early in startup might screw with automated
197 // workflows or something if we show the dialog by default.
198 nocrashdialog = true;
202 // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes
203 if(!Sys_CheckParm("-nocrashdialog"))
204 nocrashdialog = false;
205 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
206 if(Sys_CheckParm("-noterminal"))
208 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
209 else if(Sys_CheckParm("-stderr"))
215 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
218 // we don't know which systems we'll want to init, yet...
221 // used by everything
231 qbool sys_supportsdlgetticks = true;
232 unsigned int Sys_SDL_GetTicks (void)
234 return SDL_GetTicks();
236 void Sys_SDL_Delay (unsigned int milliseconds)
238 SDL_Delay(milliseconds);