shithub: duke3d

Download patch

ref: 6b9299bd6526aea844933b56ae6879e794a655b7
parent: c7e4c757bffdc5058afe16f8c846099bc40b1977
author: Fabien Sanglard <[email protected]>
date: Wed Dec 12 08:30:34 EST 2012

Fixed Native timer issue (tentative to use SDL again)

--- a/Engine/src/macos_compat.h
+++ b/Engine/src/macos_compat.h
@@ -48,4 +48,5 @@
 
 #define stricmp strcasecmp
 
+
 #endif
--- a/Engine/src/sdl_driver.c
+++ b/Engine/src/sdl_driver.c
@@ -2267,11 +2267,27 @@
 } /* limitrate */
 
 
+
+
+
+
+
 //-------------------------------------------------------------------------------------------------
 //  TIMER
 //=================================================================================================
 
-// FIX_00007: game speed corrected. The game speed is now as the real 
+/*
+ FCS: The timer section sadly uses Native high precision calls to implement timer functions.
+ QueryPerformanceFrequency and QueryPerformanceCounter
+ it seems SDL precision was not good enough (or rather using unaccurate OS functions) to replicate
+ a DOS timer.
+ */
+
+int TIMER_GetPlatformTicksInOneSecond(int64_t* t);
+void TIMER_GetPlatformTicks(int64_t* t);
+
+
+// FIX_00007: game speed corrected. The game speed is now as the real
 // DOS duke3d. Unloading a full 200 bullet pistol must take 45.1 sec.
 // SDL timer was not fast/accurate enough and was slowing down the gameplay,
 // so bad
@@ -2298,33 +2314,39 @@
 }
 
 
-//
-// inittimer() -- initialise timer
-//
+/*
+ inittimer() -- initialise timer
+ FCS: The tickspersecond parameter is a ratio value that helps replicating
+      oldschool DOS tick per seconds.
+ 
+      The way the timer work is:
+      float newSystemTickPerSecond = [0,1]
+      tickPerSecond on a DOS system = tickspersecond * newSystemTickPerSecond ;
+*/
+
 int inittimer(int tickspersecond)
 {
 	int64 t;
 	
-    /*
+    
 	if (timerfreq) return 0;	// already installed
 
-	printf("Initialising timer\n");
+	printf("Initialising timer, with tickPerSecond=%d\n",tickspersecond);
 
 	// OpenWatcom seems to want us to query the value into a local variable
 	// instead of the global 'timerfreq' or else it gets pissed with an
 	// access violation
-	if (!QueryPerformanceFrequency((LARGE_INTEGER*)&t)) {
+	if (!TIMER_GetPlatformTicksInOneSecond(&t)) {
 		printf("Failed fetching timer frequency\n");
 		return -1;
 	}
 	timerfreq = t;
 	timerticspersec = tickspersecond;
-	QueryPerformanceCounter((LARGE_INTEGER*)&t);
+	TIMER_GetPlatformTicks(&t);
 	timerlastsample = (long)(t*timerticspersec / timerfreq);
 
 	usertimercallback = NULL;
-    */
-    printf("FCS: Fix the timer.\n");
+    
 	return 0;
 }
 
@@ -2349,9 +2371,9 @@
 	
 	if (!timerfreq) return;
 
-	//QueryPerformanceCounter((LARGE_INTEGER*)&i);
-    printf("FCS: Fix the timer.\n");
+	TIMER_GetPlatformTicks(&i);
     
+    
 	n = (long)(i*timerticspersec / timerfreq) - timerlastsample;
 	if (n>0) {
 		totalclock += n;
@@ -2362,14 +2384,14 @@
 }
 
 
-//
-// getticks() -- returns the windows ticks count
-//
+/*
+   getticks() -- returns the windows ticks count
+   FCS: This seeems to be only used in the multiplayer code
+*/
 unsigned long getticks(void)
 {
 	int64 i;
-	//QueryPerformanceCounter((LARGE_INTEGER*)&i);
-    printf("FCS: Fix the timer.\n");
+	TIMER_GetPlatformTicks(&i);
 	return (unsigned long)(i*(long long)(1000)/timerfreq);
 }
 
@@ -2430,5 +2452,30 @@
 //    return(SDL_GetTicks());
 //} /* getticks */
 
+
+#if PLATFORM_WIN32
+
+int TIMER_GetPlatformTicksInOneSecond(int64_t* t);
+{
+    QueryPerformanceFrequency((LARGE_INTEGER*)t);
+    return 1;
+}
+
+void TIMER_GetPlatformTicks(int64_t* t){
+    QueryPerformanceCounter((LARGE_INTEGER*)t);
+}
+#else
+//FCS: Let's try to use SDL again: Maybe SDL library is accurate enough now.
+int TIMER_GetPlatformTicksInOneSecond(int64_t* t)
+{
+    *t = 1000;
+    return 1;
+}
+    
+void TIMER_GetPlatformTicks(int64_t* t)
+{
+    *t = SDL_GetTicks();
+}
+#endif
 /* end of sdl_driver.c ... */
 
--- a/Game/src/config.c
+++ b/Game/src/config.c
@@ -101,99 +101,7 @@
    int32 numfiles;
    int32 i;
 
-#if 0 //STUB .CFG lookup
-   /*
-   strcpy(setupfilename,SETUPFILENAME);
 
-   // determine extension
-
-   src = setupfilename + strlen(setupfilename) - 1;
-
-   while (*src != '.')
-      {
-      src--;
-      }
-   strcpy (&extension[1],src);
-   extension[0] = '*';
-
-   numfiles=0;
-   if (_dos_findfirst(extension,0,&fblock)==0)
-      {
-      do
-         {
-         // skip timidity.cfg if it exists; it's needed for MIDI playback
-         //  with SDL_mixer, and isn't a Duke configuration file. --ryan.
-         if (strcmpi(fblock.name, "timidity.cfg") != 0)
-            {
-             filenames[numfiles]=SafeMalloc(128);
-             strcpy(filenames[numfiles],fblock.name);
-             numfiles++;
-             if (numfiles == MAXSETUPFILES)
-                break;
-            }
-         }
-      while(!_dos_findnext(&fblock));
-      }
-   i = CheckParm (SETUPNAMEPARM);
-   if (i!=0)
-      {
-      numfiles = 0;
-      strcpy(setupfilename,_argv[i+1]);
-      }
-   if (numfiles>1)
-      {
-      int32 time;
-      int32 oldtime;
-      int32 count;
-
-      printf("\nMultiple Configuration Files Encountered\n");
-      printf("========================================\n");
-      printf("Please choose a configuration file from the following list by pressing its\n");
-      printf("corresponding letter:\n");
-      for (i=0;i<numfiles;i++)
-         {
-         if (strcmpi(filenames[i],SETUPFILENAME))
-            {
-            printf("%c. %s\n",'a'+(char)i,filenames[i]);
-            }
-         else
-            {
-            printf("%c. %s <DEFAULT>\n",'a'+(char)i,filenames[i]);
-            }
-         }
-      printf("\n");
-      printf("(%s will be used if no selection is made within 10 seconds.)\n\n",SETUPFILENAME);
-      KB_FlushKeyboardQueue();
-      KB_ClearKeysDown();
-      count = 9;
-      oldtime = clock();
-      time=clock()+(10*CLOCKS_PER_SEC);
-      while (clock()<time)
-         {
-         if (clock()>oldtime)
-            {
-            printf("%ld seconds left. \r",count);
-            fflush(stdout);
-            oldtime = clock()+CLOCKS_PER_SEC;
-            count--;
-            }
-         if (KB_KeyWaiting())
-            {
-            int32 ch = KB_Getch();
-            ch -='a';
-            if (ch>=0 && ch<numfiles)
-               {
-               strcpy (setupfilename, filenames[ch]);
-               break;
-               }
-            }
-         }
-      printf("\n\n");
-      }
-   if (numfiles==1)
-      strcpy (setupfilename, filenames[0]);
-	  */
-#endif
    setupfilename[0] = '\0';
 
    // Are we trying to load a mod?
--- a/Game/src/funct.h
+++ b/Game/src/funct.h
@@ -24,6 +24,9 @@
 */
 //-------------------------------------------------------------------------
 
+#ifndef FUNCT_H
+#define FUNCT_H
+
 extern void sendscore(char *s);
 //#line "sounds.c" 25
 extern void SoundStartup(void );
@@ -586,3 +589,4 @@
 //#line "actors.c" 6005
 extern void moveexplosions(void );
 
+#endif