1 #include "darkplaces.h"
13 #include <android/log.h>
22 #pragma comment(lib, "sdl2.lib")
23 #pragma comment(lib, "sdl2main.lib")
29 // =======================================================================
31 // =======================================================================
33 void Sys_Shutdown (void)
36 Sys_AllowProfiling(false);
39 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
45 static qbool nocrashdialog;
46 void Sys_Error (const char *error, ...)
49 char string[MAX_INPUTLINE];
51 // change stdin to non blocking
53 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
56 va_start (argptr,error);
57 dpvsnprintf (string, sizeof (string), error, argptr);
60 Con_Printf(CON_ERROR "Engine Error: %s\n", string);
63 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Engine Error", string, NULL);
69 void Sys_PrintToTerminal(const char *text)
72 if (developer.integer > 0)
74 __android_log_write(ANDROID_LOG_DEBUG, sys.argv[0], text);
80 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
81 // this is because both go to /dev/tty by default!
83 int origflags = fcntl (sys.outfd, F_GETFL, 0);
84 fcntl (sys.outfd, F_SETFL, origflags & ~O_NONBLOCK);
91 fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
93 break; // sorry, I cannot do anything about this error - without an output
97 fcntl (sys.outfd, F_SETFL, origflags);
100 //fprintf(stdout, "%s", text);
104 char *Sys_ConsoleInput(void)
106 static char text[MAX_INPUTLINE];
137 if (len == sizeof (text))
142 struct timeval timeout;
144 FD_SET(0, &fdset); // stdin
147 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
149 len = read (0, text, sizeof(text));
152 // rip off the \n and terminate
161 char *Sys_GetClipboardData (void)
166 cliptext = SDL_GetClipboardText();
167 if (cliptext != NULL) {
169 allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
170 data = (char *)Z_Malloc (allocsize);
171 strlcpy (data, cliptext, allocsize);
178 void Sys_InitConsole (void)
182 int main (int argc, char *argv[])
184 signal(SIGFPE, SIG_IGN);
187 Sys_AllowProfiling(true);
192 sys.argv = (const char **)argv;
194 // Sys_Error this early in startup might screw with automated
195 // workflows or something if we show the dialog by default.
196 nocrashdialog = true;
200 // COMMANDLINEOPTION: -nocrashdialog disables "Engine Error" crash dialog boxes
201 if(!Sys_CheckParm("-nocrashdialog"))
202 nocrashdialog = false;
203 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
204 if(Sys_CheckParm("-noterminal"))
206 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
207 else if(Sys_CheckParm("-stderr"))
213 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
216 // we don't know which systems we'll want to init, yet...
219 // used by everything
229 qbool sys_supportsdlgetticks = true;
230 unsigned int Sys_SDL_GetTicks (void)
232 return SDL_GetTicks();
234 void Sys_SDL_Delay (unsigned int milliseconds)
236 SDL_Delay(milliseconds);