Exemple #1
0
int ControlsCapSampleRate (void)
{
//	DEFTIME

if (gameStates.limitFPS.bControls) {
	// check elapsed time since last call to ControlsReadAll
	// if less than 25 ms (i.e. 40 fps) return
	if (gameOpts->legacy.bMouse) 
		gameStates.input.kcPollTime = gameData.time.xFrame;
	else {
		if (gameData.app.bGamePaused)
			GetSlowTicks ();
		kcFrameCount++;
		gameStates.input.kcPollTime += gameData.time.xFrame;
		if (!gameStates.app.tick40fps.bTick)
			return 1;
		}
	}
else
	gameStates.input.kcPollTime = gameData.time.xFrame;
gameStates.input.kcFrameTime = (float) gameStates.input.kcPollTime / kcFrameCount;
#if 1
nMaxTurnRate = (int) gameStates.input.kcFrameTime;
#else
nMaxTurnRate = (int) (gameStates.input.kcFrameTime * (1.0f - X2F (gameData.pig.ship.player->maxRotThrust)));
#endif
if (CheckGameConfig ())
	SDL_Delay (gameData.app.nFrameCount % 100);
return 0;
}
void CalcFrameTime (void)
{
if (gameData.app.bGamePaused) {
	gameData.time.xLast = TimerGetFixedSeconds ();
	gameData.time.xFrame = 0;
	gameData.time.xRealFrame = 0;
	return;
	}

fix 	timerValue,
		xLastFrameTime = gameData.time.xFrame;
GetSlowTicks ();

#if EXACT_FRAME_TIME

	static float fSlack = 0;

	int	nFrameTime, nMinFrameTime, nDeltaTime;

if (MAXFPS <= 1) 
	nDeltaTime = 0;
else {
#ifdef RELEASE
	if (!gameOpts->app.bExpertMode && (gameOpts->render.nMaxFPS > 1))
		gameOpts->render.nMaxFPS = MAX_FRAMERATE;
#endif
	if (!gameData.time.tLast)
		nDeltaTime = 0;
	else {
		nFrameTime = gameStates.app.nSDLTicks - gameData.time.tLast;
		nMinFrameTime = 1000 / MAXFPS;
		nDeltaTime = nMinFrameTime - nFrameTime;
		fSlack += 1000.0f / MAXFPS - nMinFrameTime;
		if (fSlack >= 1) {
			nDeltaTime += int (fSlack);
			fSlack -= int (fSlack);
			}
		if (0 < nDeltaTime)
			G3_SLEEP (nDeltaTime);
		}
	}
timerValue = MSEC2X (gameStates.app.nSDLTicks);

#else

fix xMinFrameTime = ((MAXFPS > 1) ? I2X (1) / MAXFPS : 1);
do {
	timerValue = TimerGetFixedSeconds ();
   gameData.time.xFrame = timerValue - gameData.time.xLast;
	if (MAXFPS < 2)
		break;
	G3_SLEEP (1);
	} while (gameData.time.xFrame < xMinFrameTime);

#endif

gameData.time.xFrame = timerValue - gameData.time.xLast;
gameData.time.xRealFrame = gameData.time.xFrame;
if (gameStates.app.cheats.bTurboMode)
	gameData.time.xFrame *= 2;
gameData.time.xLast = timerValue;

#if EXACT_FRAME_TIME

gameData.time.tLast = gameStates.app.nSDLTicks;
if (nDeltaTime > 0)
	gameData.time.tLast += nDeltaTime;

#else

gameData.time.tLast = SDL_GetTicks ();

#endif

if (gameData.time.xFrame < 0)						//if bogus frametimed:\temp\dm_test.
	gameData.time.xFrame = xLastFrameTime;		//d:\temp\dm_test.then use time from last frame
#if Arcade_mode
gameData.time.xFrame /= 2;
#endif
#if defined (TIMER_TEST) && defined (_DEBUG)
gameData.time.xStops = gameData.time.xStarts = 0;
#endif
//	Set value to determine whether homing missile can see target.
//	The lower frametime is, the more likely that it can see its target.
if (gameStates.limitFPS.bHomers)
	xMinTrackableDot = MIN_TRACKABLE_DOT;
else if (gameData.time.xFrame <= I2X (1)/64)
	xMinTrackableDot = MIN_TRACKABLE_DOT;	// -- 3* (I2X (1) - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
else if (gameData.time.xFrame < I2X (1)/32)
	xMinTrackableDot = MIN_TRACKABLE_DOT + I2X (1)/64 - 2*gameData.time.xFrame;	// -- FixMul (I2X (1) - MIN_TRACKABLE_DOT, I2X (1)-4*gameData.time.xFrame) + MIN_TRACKABLE_DOT;
else if (gameData.time.xFrame < I2X (1)/4)
	xMinTrackableDot = MIN_TRACKABLE_DOT + I2X (1)/64 - I2X (1)/16 - gameData.time.xFrame;	// -- FixMul (I2X (1) - MIN_TRACKABLE_DOT, I2X (1)-4*gameData.time.xFrame) + MIN_TRACKABLE_DOT;
else
	xMinTrackableDot = MIN_TRACKABLE_DOT + I2X (1)/64 - I2X (1)/8;
}