Skip to content

Commit

Permalink
Fixed Native timer issue (tentative to use SDL again)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiensanglard committed Dec 12, 2012
1 parent c7e4c75 commit 6b9299b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 109 deletions.
1 change: 1 addition & 0 deletions Engine/src/macos_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@

#define stricmp strcasecmp


#endif
81 changes: 64 additions & 17 deletions Engine/src/sdl_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 ... */

92 changes: 0 additions & 92 deletions Game/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<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?
Expand Down
4 changes: 4 additions & 0 deletions Game/src/funct.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------

#ifndef FUNCT_H
#define FUNCT_H

extern void sendscore(char *s);
//#line "sounds.c" 25
extern void SoundStartup(void );
Expand Down Expand Up @@ -586,3 +589,4 @@ extern void moveactors(void );
//#line "actors.c" 6005
extern void moveexplosions(void );

#endif

0 comments on commit 6b9299b

Please sign in to comment.