]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_win.c
Borland C++ compile fixes.
[divverent/darkplaces.git] / sys_win.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // sys_win.c -- Win32 system interface code
21
22 #include "quakedef.h"
23 #include "winquake.h"
24 #include "errno.h"
25 #include "resource.h"
26 #include "conproc.h"
27 #include "direct.h"
28
29 // LordHavoc: raised min to 24mb (was 8.5mb)
30 #define MINIMUM_WIN_MEMORY              0x1800000
31 // LordHavoc: raised max to 24mb (was 16mb)
32 #define MAXIMUM_WIN_MEMORY              0x1800000
33
34 #define CONSOLE_ERROR_TIMEOUT   60.0    // # of seconds to wait on Sys_Error running
35                                                                                 //  dedicated before exiting
36 #define PAUSE_SLEEP             50                              // sleep time on pause or minimization
37 #define NOT_FOCUS_SLEEP 20                              // sleep time when not focus
38
39 int                     starttime;
40 qboolean        ActiveApp, Minimized;
41 qboolean        WinNT;
42
43 static double           pfreq;
44 static double           curtime = 0.0;
45 static double           lastcurtime = 0.0;
46 static int                      lowshift;
47 qboolean                        isDedicated;
48 static qboolean         sc_return_on_enter = false;
49 HANDLE                          hinput, houtput;
50
51 static char                     *tracking_tag = "Clams & Mooses";
52
53 static HANDLE   tevent;
54 static HANDLE   hFile;
55 static HANDLE   heventParent;
56 static HANDLE   heventChild;
57
58 void MaskExceptions (void);
59 void Sys_InitFloatTime (void);
60 void Sys_PushFPCW_SetHigh (void);
61 void Sys_PopFPCW (void);
62
63 volatile int                                    sys_checksum;
64
65
66 /*
67 ================
68 Sys_PageIn
69 ================
70 */
71 void Sys_PageIn (void *ptr, int size)
72 {
73         byte    *x;
74         int             m, n;
75
76 // touch all the memory to make sure it's there. The 16-page skip is to
77 // keep Win 95 from thinking we're trying to page ourselves in (we are
78 // doing that, of course, but there's no reason we shouldn't)
79         x = (byte *)ptr;
80
81         for (n=0 ; n<4 ; n++)
82         {
83                 for (m=0 ; m<(size - 16 * 0x1000) ; m += 4)
84                 {
85                         sys_checksum += *(int *)&x[m];
86                         sys_checksum += *(int *)&x[m + 16 * 0x1000];
87                 }
88         }
89 }
90
91
92 /*
93 ===============================================================================
94
95 FILE IO
96
97 ===============================================================================
98 */
99
100 // LordHavoc: 256 pak files (was 10)
101 #define MAX_HANDLES             256
102 FILE    *sys_handles[MAX_HANDLES];
103
104 int             findhandle (void)
105 {
106         int             i;
107         
108         for (i=1 ; i<MAX_HANDLES ; i++)
109                 if (!sys_handles[i])
110                         return i;
111         Sys_Error ("out of handles");
112         return -1;
113 }
114
115 /*
116 ================
117 filelength
118 ================
119 */
120 int filelength (FILE *f)
121 {
122         int             pos;
123         int             end;
124         int             t;
125
126         t = VID_ForceUnlockedAndReturnState ();
127
128         pos = ftell (f);
129         fseek (f, 0, SEEK_END);
130         end = ftell (f);
131         fseek (f, pos, SEEK_SET);
132
133         VID_ForceLockState (t);
134
135         return end;
136 }
137
138 int Sys_FileOpenRead (char *path, int *hndl)
139 {
140         FILE    *f;
141         int             i, retval;
142         int             t;
143
144         t = VID_ForceUnlockedAndReturnState ();
145
146         i = findhandle ();
147
148         f = fopen(path, "rb");
149
150         if (!f)
151         {
152                 *hndl = -1;
153                 retval = -1;
154         }
155         else
156         {
157                 sys_handles[i] = f;
158                 *hndl = i;
159                 retval = filelength(f);
160         }
161
162         VID_ForceLockState (t);
163
164         return retval;
165 }
166
167 int Sys_FileOpenWrite (char *path)
168 {
169         FILE    *f;
170         int             i;
171         int             t;
172
173         t = VID_ForceUnlockedAndReturnState ();
174         
175         i = findhandle ();
176
177         f = fopen(path, "wb");
178         if (!f)
179                 Host_Error ("Error opening %s: %s", path,strerror(errno));
180         sys_handles[i] = f;
181         
182         VID_ForceLockState (t);
183
184         return i;
185 }
186
187 void Sys_FileClose (int handle)
188 {
189         int             t;
190
191         t = VID_ForceUnlockedAndReturnState ();
192         fclose (sys_handles[handle]);
193         sys_handles[handle] = NULL;
194         VID_ForceLockState (t);
195 }
196
197 void Sys_FileSeek (int handle, int position)
198 {
199         int             t;
200
201         t = VID_ForceUnlockedAndReturnState ();
202         fseek (sys_handles[handle], position, SEEK_SET);
203         VID_ForceLockState (t);
204 }
205
206 int Sys_FileRead (int handle, void *dest, int count)
207 {
208         int             t, x;
209
210         t = VID_ForceUnlockedAndReturnState ();
211         x = fread (dest, 1, count, sys_handles[handle]);
212         VID_ForceLockState (t);
213         return x;
214 }
215
216 int Sys_FileWrite (int handle, void *data, int count)
217 {
218         int             t, x;
219
220         t = VID_ForceUnlockedAndReturnState ();
221         x = fwrite (data, 1, count, sys_handles[handle]);
222         VID_ForceLockState (t);
223         return x;
224 }
225
226 int     Sys_FileTime (char *path)
227 {
228         FILE    *f;
229         int             t, retval;
230
231         t = VID_ForceUnlockedAndReturnState ();
232         
233         f = fopen(path, "rb");
234
235         if (f)
236         {
237                 fclose(f);
238                 retval = 1;
239         }
240         else
241         {
242                 retval = -1;
243         }
244         
245         VID_ForceLockState (t);
246         return retval;
247 }
248
249 void Sys_mkdir (char *path)
250 {
251         _mkdir (path);
252 }
253
254
255 /*
256 ===============================================================================
257
258 SYSTEM IO
259
260 ===============================================================================
261 */
262
263 /*
264 ================
265 Sys_MakeCodeWriteable
266 ================
267 */
268 void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
269 {
270         DWORD  flOldProtect;
271
272         if (!VirtualProtect((LPVOID)startaddr, length, PAGE_READWRITE, &flOldProtect))
273                 Sys_Error("Protection change failed\n");
274 }
275
276
277 //#ifndef _M_IX86
278
279 void Sys_SetFPCW (void)
280 {
281 }
282
283 void Sys_PushFPCW_SetHigh (void)
284 {
285 }
286
287 void Sys_PopFPCW (void)
288 {
289 }
290
291 void MaskExceptions (void)
292 {
293 }
294
295 //#endif
296
297 /*
298 ================
299 Sys_Init
300 ================
301 */
302 void Sys_Init (void)
303 {
304         LARGE_INTEGER   PerformanceFreq;
305         unsigned int    lowpart, highpart;
306         OSVERSIONINFO   vinfo;
307
308         MaskExceptions ();
309         Sys_SetFPCW ();
310
311         if (!QueryPerformanceFrequency (&PerformanceFreq))
312                 Sys_Error ("No hardware timer available");
313
314 // get 32 out of the 64 time bits such that we have around
315 // 1 microsecond resolution
316         lowpart = (unsigned int)PerformanceFreq.LowPart;
317         highpart = (unsigned int)PerformanceFreq.HighPart;
318         lowshift = 0;
319
320         while (highpart || (lowpart > 2000000.0))
321         {
322                 lowshift++;
323                 lowpart >>= 1;
324                 lowpart |= (highpart & 1) << 31;
325                 highpart >>= 1;
326         }
327
328         pfreq = 1.0 / (double)lowpart;
329
330         Sys_InitFloatTime ();
331
332         vinfo.dwOSVersionInfoSize = sizeof(vinfo);
333
334         if (!GetVersionEx (&vinfo))
335                 Sys_Error ("Couldn't get OS info");
336
337         if ((vinfo.dwMajorVersion < 4) ||
338                 (vinfo.dwPlatformId == VER_PLATFORM_WIN32s))
339         {
340                 Sys_Error ("WinQuake requires at least Win95 or NT 4.0");
341         }
342
343         if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
344                 WinNT = true;
345         else
346                 WinNT = false;
347 }
348
349
350 void Sys_Error (char *error, ...)
351 {
352         va_list         argptr;
353         char            text[1024], text2[1024];
354         char            *text3 = "Press Enter to exit\n";
355         char            *text4 = "***********************************\n";
356         char            *text5 = "\n";
357         DWORD           dummy;
358         double          starttime;
359         static int      in_sys_error0 = 0;
360         static int      in_sys_error1 = 0;
361         static int      in_sys_error2 = 0;
362         static int      in_sys_error3 = 0;
363
364         if (!in_sys_error3)
365         {
366                 in_sys_error3 = 1;
367                 VID_ForceUnlockedAndReturnState ();
368         }
369
370         va_start (argptr, error);
371         vsprintf (text, error, argptr);
372         va_end (argptr);
373
374         if (isDedicated)
375         {
376                 va_start (argptr, error);
377                 vsprintf (text, error, argptr);
378                 va_end (argptr);
379
380                 sprintf (text2, "ERROR: %s\n", text);
381                 WriteFile (houtput, text5, strlen (text5), &dummy, NULL);
382                 WriteFile (houtput, text4, strlen (text4), &dummy, NULL);
383                 WriteFile (houtput, text2, strlen (text2), &dummy, NULL);
384                 WriteFile (houtput, text3, strlen (text3), &dummy, NULL);
385                 WriteFile (houtput, text4, strlen (text4), &dummy, NULL);
386
387
388                 starttime = Sys_FloatTime ();
389                 sc_return_on_enter = true;      // so Enter will get us out of here
390
391                 while (!Sys_ConsoleInput () &&
392                                 ((Sys_FloatTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
393                 {
394                 }
395         }
396         else
397         {
398         // switch to windowed so the message box is visible, unless we already
399         // tried that and failed
400                 if (!in_sys_error0)
401                 {
402                         in_sys_error0 = 1;
403                         VID_SetDefaultMode ();
404                         MessageBox(NULL, text, "Quake Error",
405                                            MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
406                 }
407                 else
408                 {
409                         MessageBox(NULL, text, "Double Quake Error",
410                                            MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
411                 }
412         }
413
414         if (!in_sys_error1)
415         {
416                 in_sys_error1 = 1;
417                 Host_Shutdown ();
418         }
419
420 // shut down QHOST hooks if necessary
421         if (!in_sys_error2)
422         {
423                 in_sys_error2 = 1;
424                 DeinitConProc ();
425         }
426
427         exit (1);
428 }
429
430 void Sys_Printf (char *fmt, ...)
431 {
432         va_list         argptr;
433         char            text[1024];
434         DWORD           dummy;
435         
436         if (isDedicated)
437         {
438                 va_start (argptr,fmt);
439                 vsprintf (text, fmt, argptr);
440                 va_end (argptr);
441
442                 WriteFile(houtput, text, strlen (text), &dummy, NULL);  
443         }
444 }
445
446 void Sys_Quit (void)
447 {
448
449         VID_ForceUnlockedAndReturnState ();
450
451         Host_Shutdown();
452
453         if (tevent)
454                 CloseHandle (tevent);
455
456         if (isDedicated)
457                 FreeConsole ();
458
459 // shut down QHOST hooks if necessary
460         DeinitConProc ();
461
462         exit (0);
463 }
464
465
466 /*
467 ================
468 Sys_FloatTime
469 ================
470 */
471 double Sys_FloatTime (void)
472 {
473         static int                      sametimecount;
474         static unsigned int     oldtime;
475         static int                      first = 1;
476         LARGE_INTEGER           PerformanceCount;
477         unsigned int            temp, t2;
478         double                          time;
479
480         Sys_PushFPCW_SetHigh ();
481
482         QueryPerformanceCounter (&PerformanceCount);
483
484         temp = ((unsigned int)PerformanceCount.LowPart >> lowshift) |
485                    ((unsigned int)PerformanceCount.HighPart << (32 - lowshift));
486
487         if (first)
488         {
489                 oldtime = temp;
490                 first = 0;
491         }
492         else
493         {
494         // check for turnover or backward time
495                 if ((temp <= oldtime) && ((oldtime - temp) < 0x10000000))
496                 {
497                         oldtime = temp; // so we can't get stuck
498                 }
499                 else
500                 {
501                         t2 = temp - oldtime;
502
503                         time = (double)t2 * pfreq;
504                         oldtime = temp;
505
506                         curtime += time;
507
508                         if (curtime == lastcurtime)
509                         {
510                                 sametimecount++;
511
512                                 if (sametimecount > 100000)
513                                 {
514                                         curtime += 1.0;
515                                         sametimecount = 0;
516                                 }
517                         }
518                         else
519                         {
520                                 sametimecount = 0;
521                         }
522
523                         lastcurtime = curtime;
524                 }
525         }
526
527         Sys_PopFPCW ();
528
529     return curtime;
530 }
531
532
533 /*
534 ================
535 Sys_InitFloatTime
536 ================
537 */
538 void Sys_InitFloatTime (void)
539 {
540         int             j;
541
542         Sys_FloatTime ();
543
544         j = COM_CheckParm("-starttime");
545
546         if (j)
547         {
548                 curtime = (double) (atof(com_argv[j+1]));
549         }
550         else
551         {
552                 curtime = 0.0;
553         }
554
555         lastcurtime = curtime;
556 }
557
558
559 char *Sys_ConsoleInput (void)
560 {
561         static char     text[256];
562         static int              len;
563         INPUT_RECORD    recs[1024];
564         int             dummy;
565         int             ch, numread, numevents;
566
567         if (!isDedicated)
568                 return NULL;
569
570
571         for ( ;; )
572         {
573                 if (!GetNumberOfConsoleInputEvents (hinput, &numevents))
574                         Sys_Error ("Error getting # of console events");
575
576                 if (numevents <= 0)
577                         break;
578
579                 if (!ReadConsoleInput(hinput, recs, 1, &numread))
580                         Sys_Error ("Error reading console input");
581
582                 if (numread != 1)
583                         Sys_Error ("Couldn't read console input");
584
585                 if (recs[0].EventType == KEY_EVENT)
586                 {
587                         if (!recs[0].Event.KeyEvent.bKeyDown)
588                         {
589                                 ch = recs[0].Event.KeyEvent.uChar.AsciiChar;
590
591                                 switch (ch)
592                                 {
593                                         case '\r':
594                                                 WriteFile(houtput, "\r\n", 2, &dummy, NULL);    
595
596                                                 if (len)
597                                                 {
598                                                         text[len] = 0;
599                                                         len = 0;
600                                                         return text;
601                                                 }
602                                                 else if (sc_return_on_enter)
603                                                 {
604                                                 // special case to allow exiting from the error handler on Enter
605                                                         text[0] = '\r';
606                                                         len = 0;
607                                                         return text;
608                                                 }
609
610                                                 break;
611
612                                         case '\b':
613                                                 WriteFile(houtput, "\b \b", 3, &dummy, NULL);   
614                                                 if (len)
615                                                 {
616                                                         len--;
617                                                 }
618                                                 break;
619
620                                         default:
621                                                 if (ch >= ' ')
622                                                 {
623                                                         WriteFile(houtput, &ch, 1, &dummy, NULL);       
624                                                         text[len] = ch;
625                                                         len = (len + 1) & 0xff;
626                                                 }
627
628                                                 break;
629
630                                 }
631                         }
632                 }
633         }
634
635         return NULL;
636 }
637
638 void Sys_Sleep (void)
639 {
640         Sleep (1);
641 }
642
643
644 void Sys_SendKeyEvents (void)
645 {
646     MSG        msg;
647
648         while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
649         {
650         // we always update if there are any event, even if we're paused
651                 scr_skipupdate = 0;
652
653                 if (!GetMessage (&msg, NULL, 0, 0))
654                         Sys_Quit ();
655
656         TranslateMessage (&msg);
657         DispatchMessage (&msg);
658         }
659 }
660
661
662 /*
663 ==============================================================================
664
665  WINDOWS CRAP
666
667 ==============================================================================
668 */
669
670
671 /*
672 ==================
673 WinMain
674 ==================
675 */
676 void SleepUntilInput (int time)
677 {
678
679         MsgWaitForMultipleObjects(1, &tevent, FALSE, time, QS_ALLINPUT);
680 }
681
682
683 /*
684 ==================
685 WinMain
686 ==================
687 */
688 HINSTANCE       global_hInstance;
689 int                     global_nCmdShow;
690 char            *argv[MAX_NUM_ARGVS];
691 static char     *empty_string = "";
692 HWND            hwnd_dialog;
693
694
695 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
696 {
697         quakeparms_t    parms;
698         double                  time, oldtime, newtime/*, timediff*/;
699         MEMORYSTATUS    lpBuffer;
700         static  char    cwd[1024];
701         int                             t;
702         RECT                    rect;
703
704     /* previous instances do not exist in Win32 */
705     if (hPrevInstance)
706         return 0;
707
708         global_hInstance = hInstance;
709         global_nCmdShow = nCmdShow;
710
711         lpBuffer.dwLength = sizeof(MEMORYSTATUS);
712         GlobalMemoryStatus (&lpBuffer);
713
714         if (!GetCurrentDirectory (sizeof(cwd), cwd))
715                 Sys_Error ("Couldn't determine current directory");
716
717         if (cwd[strlen(cwd)-1] == '/')
718                 cwd[strlen(cwd)-1] = 0;
719
720         parms.basedir = cwd;
721         parms.cachedir = NULL;
722
723         parms.argc = 1;
724         argv[0] = empty_string;
725
726         while (*lpCmdLine && (parms.argc < MAX_NUM_ARGVS))
727         {
728                 while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
729                         lpCmdLine++;
730
731                 if (*lpCmdLine)
732                 {
733                         argv[parms.argc] = lpCmdLine;
734                         parms.argc++;
735
736                         while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
737                                 lpCmdLine++;
738
739                         if (*lpCmdLine)
740                         {
741                                 *lpCmdLine = 0;
742                                 lpCmdLine++;
743                         }
744                         
745                 }
746         }
747
748         parms.argv = argv;
749
750         COM_InitArgv (parms.argc, parms.argv);
751
752         parms.argc = com_argc;
753         parms.argv = com_argv;
754
755         isDedicated = (COM_CheckParm ("-dedicated") != 0);
756
757         if (!isDedicated)
758         {
759                 hwnd_dialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, NULL);
760
761                 if (hwnd_dialog)
762                 {
763                         if (GetWindowRect (hwnd_dialog, &rect))
764                         {
765                                 if (rect.left > (rect.top * 2))
766                                 {
767                                         SetWindowPos (hwnd_dialog, 0,
768                                                 (rect.left / 2) - ((rect.right - rect.left) / 2),
769                                                 rect.top, 0, 0,
770                                                 SWP_NOZORDER | SWP_NOSIZE);
771                                 }
772                         }
773
774                         ShowWindow (hwnd_dialog, SW_SHOWDEFAULT);
775                         UpdateWindow (hwnd_dialog);
776                         SetForegroundWindow (hwnd_dialog);
777                 }
778         }
779
780 // take the greater of all the available memory or half the total memory,
781 // but at least 8 Mb and no more than 16 Mb, unless they explicitly
782 // request otherwise
783         parms.memsize = lpBuffer.dwAvailPhys;
784
785         if (parms.memsize < MINIMUM_WIN_MEMORY)
786                 parms.memsize = MINIMUM_WIN_MEMORY;
787
788         if (parms.memsize < (lpBuffer.dwTotalPhys >> 1))
789                 parms.memsize = lpBuffer.dwTotalPhys >> 1;
790
791         if (parms.memsize > MAXIMUM_WIN_MEMORY)
792                 parms.memsize = MAXIMUM_WIN_MEMORY;
793
794         if (COM_CheckParm ("-heapsize"))
795         {
796                 t = COM_CheckParm("-heapsize") + 1;
797
798                 if (t < com_argc)
799                         parms.memsize = atoi (com_argv[t]) * 1024;
800         }
801
802         if (COM_CheckParm ("-mem"))
803         {
804                 t = COM_CheckParm("-mem") + 1;
805
806                 if (t < com_argc)
807                         parms.memsize = atoi (com_argv[t]) * 1048576;
808         }
809
810         if (COM_CheckParm ("-winmem"))
811         {
812                 t = COM_CheckParm("-winmem") + 1;
813
814                 if (t < com_argc)
815                         parms.memsize = atoi (com_argv[t]) * 1048576;
816         }
817
818         parms.membase = malloc (parms.memsize);
819
820         if (!parms.membase)
821                 Sys_Error ("Not enough memory free; check disk space\n");
822
823         Sys_PageIn (parms.membase, parms.memsize);
824
825         tevent = CreateEvent(NULL, FALSE, FALSE, NULL);
826
827         if (!tevent)
828                 Sys_Error ("Couldn't create event");
829
830         if (isDedicated)
831         {
832                 if (!AllocConsole ())
833                 {
834                         Sys_Error ("Couldn't create dedicated server console");
835                 }
836
837                 hinput = GetStdHandle (STD_INPUT_HANDLE);
838                 houtput = GetStdHandle (STD_OUTPUT_HANDLE);
839
840         // give QHOST a chance to hook into the console
841                 if ((t = COM_CheckParm ("-HFILE")) > 0)
842                 {
843                         if (t < com_argc)
844                                 hFile = (HANDLE)atoi (com_argv[t+1]);
845                 }
846                         
847                 if ((t = COM_CheckParm ("-HPARENT")) > 0)
848                 {
849                         if (t < com_argc)
850                                 heventParent = (HANDLE)atoi (com_argv[t+1]);
851                 }
852                         
853                 if ((t = COM_CheckParm ("-HCHILD")) > 0)
854                 {
855                         if (t < com_argc)
856                                 heventChild = (HANDLE)atoi (com_argv[t+1]);
857                 }
858
859                 InitConProc (hFile, heventParent, heventChild);
860         }
861
862         Sys_Init ();
863
864 // because sound is off until we become active
865         S_BlockSound ();
866
867         Sys_Printf ("Host_Init\n");
868         Host_Init (&parms);
869
870         oldtime = Sys_FloatTime ();
871
872     /* main window message loop */
873         while (1)
874         {
875                 if (isDedicated)
876                 {
877                         newtime = Sys_FloatTime ();
878                         time = newtime - oldtime;
879
880                         while (time < sys_ticrate.value )
881                         {
882                                 Sys_Sleep();
883                                 newtime = Sys_FloatTime ();
884                                 time = newtime - oldtime;
885                         }
886                 }
887                 else
888                 {
889                 // yield the CPU for a little while when paused, minimized, or not the focus
890                         if ((cl.paused && (!ActiveApp && !DDActive)) || Minimized)
891                         {
892                                 SleepUntilInput (PAUSE_SLEEP);
893                                 scr_skipupdate = 1;             // no point in bothering to draw
894                         }
895                         else if (!ActiveApp && !DDActive)
896                         {
897                                 SleepUntilInput (NOT_FOCUS_SLEEP);
898                         }
899                         /*
900                         else if (!cls.timedemo && time < (timediff = 1.0 / maxfps.value))
901                         {
902                                 newtime = Sys_FloatTime ();
903                                 time = newtime - oldtime;
904
905                                 while (time < timediff)
906                                 {
907                                         Sys_Sleep();
908                                         newtime = Sys_FloatTime ();
909                                         time = newtime - oldtime;
910                                 }
911                         }
912                         */
913
914                         newtime = Sys_FloatTime ();
915                         time = newtime - oldtime;
916                 }
917
918                 Host_Frame (time);
919                 oldtime = newtime;
920         }
921
922     /* return success of application */
923     return TRUE;
924 }
925