12 #include <android/log.h>
15 #define FNDELAY O_NDELAY
25 #pragma comment(lib, "sdl2.lib")
26 #pragma comment(lib, "sdl2main.lib")
34 // =======================================================================
36 // =======================================================================
38 void Sys_Shutdown (void)
41 Sys_AllowProfiling(false);
44 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
50 static qboolean nocrashdialog;
51 void Sys_Error (const char *error, ...)
54 char string[MAX_INPUTLINE];
56 // change stdin to non blocking
58 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
61 va_start (argptr,error);
62 dpvsnprintf (string, sizeof (string), error, argptr);
65 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
68 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
74 void Sys_PrintToTerminal(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 & ~FNDELAY);
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_ConsoleInput(void)
111 // if (cls.state == ca_dedicated)
113 static char text[MAX_INPUTLINE];
144 if (len == sizeof (text))
149 struct timeval timeout;
151 FD_SET(0, &fdset); // stdin
154 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
156 len = read (0, text, sizeof(text));
159 // rip off the \n and terminate
169 char *Sys_GetClipboardData (void)
174 cliptext = SDL_GetClipboardText();
175 if (cliptext != NULL) {
177 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
178 data = (char *)Z_Malloc (allocsize);
179 strlcpy (data, cliptext, allocsize);
186 void Sys_InitConsole (void)
190 int main (int argc, char *argv[])
192 signal(SIGFPE, SIG_IGN);
195 Sys_AllowProfiling(true);
200 sys.argv = (const char **)argv;
202 // Sys_Error this early in startup might screw with automated
203 // workflows or something if we show the dialog by default.
204 nocrashdialog = true;
208 // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes
209 if(!COM_CheckParm("-nocrashdialog"))
210 nocrashdialog = false;
211 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
212 if(COM_CheckParm("-noterminal"))
214 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
215 else if(COM_CheckParm("-stderr"))
221 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
224 // we don't know which systems we'll want to init, yet...
232 qboolean sys_supportsdlgetticks = true;
233 unsigned int Sys_SDL_GetTicks (void)
235 return SDL_GetTicks();
237 void Sys_SDL_Delay (unsigned int milliseconds)
239 SDL_Delay(milliseconds);