12 #include <android/log.h>
21 #pragma comment(lib, "sdl2.lib")
22 #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 static qboolean nocrashdialog;
47 void Sys_Error (const char *error, ...)
50 char string[MAX_INPUTLINE];
52 // change stdin to non blocking
54 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
57 va_start (argptr,error);
58 dpvsnprintf (string, sizeof (string), error, argptr);
61 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
64 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
70 void Sys_PrintToTerminal(const char *text)
73 if (developer.integer > 0)
75 __android_log_write(ANDROID_LOG_DEBUG, sys.argv[0], text);
81 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
82 // this is because both go to /dev/tty by default!
84 int origflags = fcntl (sys.outfd, F_GETFL, 0);
85 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
92 fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
94 break; // sorry, I cannot do anything about this error - without an output
98 fcntl (sys.outfd, F_SETFL, origflags);
101 //fprintf(stdout, "%s", text);
105 char *Sys_ConsoleInput(void)
107 // if (cls.state == ca_dedicated)
109 static char text[MAX_INPUTLINE];
140 if (len == sizeof (text))
145 struct timeval timeout;
147 FD_SET(0, &fdset); // stdin
150 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
152 len = read (0, text, sizeof(text));
155 // rip off the \n and terminate
165 char *Sys_GetClipboardData (void)
170 cliptext = SDL_GetClipboardText();
171 if (cliptext != NULL) {
173 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
174 data = (char *)Z_Malloc (allocsize);
175 strlcpy (data, cliptext, allocsize);
182 void Sys_InitConsole (void)
186 int main (int argc, char *argv[])
188 signal(SIGFPE, SIG_IGN);
191 Sys_AllowProfiling(true);
196 sys.argv = (const char **)argv;
198 // Sys_Error this early in startup might screw with automated
199 // workflows or something if we show the dialog by default.
200 nocrashdialog = true;
204 // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes
205 if(!Sys_CheckParm("-nocrashdialog"))
206 nocrashdialog = false;
207 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
208 if(Sys_CheckParm("-noterminal"))
210 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
211 else if(Sys_CheckParm("-stderr"))
217 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
220 // we don't know which systems we'll want to init, yet...
223 // used by everything
233 qboolean sys_supportsdlgetticks = true;
234 unsigned int Sys_SDL_GetTicks (void)
236 return SDL_GetTicks();
238 void Sys_SDL_Delay (unsigned int milliseconds)
240 SDL_Delay(milliseconds);