X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=sys_sdl.c;h=d7ed9179f717e3f73231ba240cd7474897ad81c8;hb=873252304e74ca61e2572542bf58400399cecc80;hp=4187d529ed9c07792b04465463688eb7be037a31;hpb=7403ba135fe27515470bfc6a7f8980869ccfee76;p=xonotic%2Fdarkplaces.git diff --git a/sys_sdl.c b/sys_sdl.c index 4187d529..d7ed9179 100644 --- a/sys_sdl.c +++ b/sys_sdl.c @@ -1,5 +1,7 @@ +#include "quakedef.h" #ifdef WIN32 +#include #include "conio.h" #else #include @@ -9,8 +11,6 @@ #include -#include "quakedef.h" - #include // ======================================================================= @@ -49,7 +49,22 @@ void Sys_Error (const char *error, ...) void Sys_PrintToTerminal(const char *text) { - fprintf(stdout, "%s", text); +#ifndef WIN32 + // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0). + int origflags = fcntl (1, F_GETFL, 0); + fcntl (1, F_SETFL, origflags & ~FNDELAY); +#endif + while(*text) + { + int written = (int)write(1, text, (int)strlen(text)); + if(written <= 0) + break; // sorry, I cannot do anything about this error - without an output + text += written; + } +#ifndef WIN32 + fcntl (1, F_SETFL, origflags); +#endif + //fprintf(stdout, "%s", text); } double Sys_DoubleTime (void) @@ -139,11 +154,11 @@ char *Sys_ConsoleInput(void) return NULL; } -void Sys_Sleep(int milliseconds) +void Sys_Sleep(int microseconds) { - if (milliseconds < 1) - milliseconds = 1; - SDL_Delay(milliseconds); + if (microseconds < 1000) + microseconds = 1000; + SDL_Delay(microseconds / 1000); } char *Sys_GetClipboardData (void) @@ -160,8 +175,10 @@ char *Sys_GetClipboardData (void) { if ((cliptext = GlobalLock (hClipboardData)) != 0) { - data = malloc (GlobalSize(hClipboardData)+1); - strcpy (data, cliptext); + size_t allocsize; + allocsize = GlobalSize (hClipboardData) + 1; + data = Z_Malloc (allocsize); + strlcpy (data, cliptext, allocsize); GlobalUnlock (hClipboardData); } } @@ -183,8 +200,6 @@ void Sys_Init_Commands (void) int main (int argc, char *argv[]) { - double frameoldtime, framenewtime; - signal(SIGFPE, SIG_IGN); com_argc = argc; @@ -194,17 +209,10 @@ int main (int argc, char *argv[]) fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY); #endif - Host_Init(); + // we don't know which systems we'll want to init, yet... + SDL_Init(0); - frameoldtime = Sys_DoubleTime () - 0.1; - while (1) - { - // find time spent rendering last frame - framenewtime = Sys_DoubleTime (); - - Host_Frame (framenewtime - frameoldtime); + Host_Main(); - frameoldtime = framenewtime; - } return 0; }