12 #include <android/log.h>
15 #define FNDELAY O_NDELAY
25 #pragma comment(lib, "sdl2.lib")
26 #pragma comment(lib, "sdl2main.lib")
32 // =======================================================================
34 // =======================================================================
36 void Sys_Shutdown (void)
39 Sys_AllowProfiling(false);
42 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
48 static qboolean nocrashdialog;
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) & ~FNDELAY);
59 va_start (argptr,error);
60 dpvsnprintf (string, sizeof (string), error, argptr);
63 Con_Errorf ("Engine Error: %s\n", string);
66 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
73 void Sys_PrintToTerminal(const char *text)
76 if (developer.integer > 0)
78 __android_log_write(ANDROID_LOG_DEBUG, com_argv[0], text);
84 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
85 // this is because both go to /dev/tty by default!
87 int origflags = fcntl (outfd, F_GETFL, 0);
88 fcntl (outfd, F_SETFL, origflags & ~FNDELAY);
95 fs_offset_t written = (fs_offset_t)write(outfd, text, (int)strlen(text));
97 break; // sorry, I cannot do anything about this error - without an output
101 fcntl (outfd, F_SETFL, origflags);
104 //fprintf(stdout, "%s", text);
108 char *Sys_ConsoleInput(void)
110 // if (cls.state == ca_dedicated)
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
168 char *Sys_GetClipboardData (void)
173 cliptext = SDL_GetClipboardText();
174 if (cliptext != NULL) {
176 allocsize = strlen(cliptext) + 1;
177 data = (char *)Z_Malloc (allocsize);
178 strlcpy (data, cliptext, allocsize);
185 void Sys_InitConsole (void)
189 int main (int argc, char *argv[])
191 signal(SIGFPE, SIG_IGN);
194 Sys_AllowProfiling(true);
198 com_argv = (const char **)argv;
200 // Sys_Error this early in startup might screw with automated
201 // workflows or something if we show the dialog by default.
202 nocrashdialog = true;
206 // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes
207 if(!COM_CheckParm("-nocrashdialog"))
208 nocrashdialog = false;
209 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
210 if(COM_CheckParm("-noterminal"))
212 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
213 else if(COM_CheckParm("-stderr"))
219 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
222 // we don't know which systems we'll want to init, yet...
230 qboolean sys_supportsdlgetticks = true;
231 unsigned int Sys_SDL_GetTicks (void)
233 return SDL_GetTicks();
235 void Sys_SDL_Delay (unsigned int milliseconds)
237 SDL_Delay(milliseconds);