From 6b9299bd6526aea844933b56ae6879e794a655b7 Mon Sep 17 00:00:00 2001 From: Fabien Sanglard Date: Wed, 12 Dec 2012 13:30:34 -0500 Subject: [PATCH] Fixed Native timer issue (tentative to use SDL again) --- Engine/src/macos_compat.h | 1 + Engine/src/sdl_driver.c | 81 ++++++++++++++++++++++++++-------- Game/src/config.c | 92 --------------------------------------- Game/src/funct.h | 4 ++ 4 files changed, 69 insertions(+), 109 deletions(-) diff --git a/Engine/src/macos_compat.h b/Engine/src/macos_compat.h index cf81380..eec76e1 100644 --- a/Engine/src/macos_compat.h +++ b/Engine/src/macos_compat.h @@ -48,4 +48,5 @@ #define stricmp strcasecmp + #endif diff --git a/Engine/src/sdl_driver.c b/Engine/src/sdl_driver.c index 12c1d6b..6c7fcbc 100644 --- a/Engine/src/sdl_driver.c +++ b/Engine/src/sdl_driver.c @@ -2267,11 +2267,27 @@ void limitrate(void) } /* 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 @@ void (*installusertimercallback(void (*callback)(void)))(void) } -// -// 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,8 +2371,8 @@ void sampletimer(void) 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) { @@ -2362,14 +2384,14 @@ void sampletimer(void) } -// -// 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 @@ void uninitkeys(void) // 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 ... */ diff --git a/Game/src/config.c b/Game/src/config.c index d75c91e..fad6578 100644 --- a/Game/src/config.c +++ b/Game/src/config.c @@ -101,99 +101,7 @@ void CONFIG_GetSetupFilename( void ) 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\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()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