Removed time delta, as it's leading to poor frame pacing.

This commit is contained in:
Steve 2018-04-30 08:12:48 +01:00
parent 2db4b4171d
commit 9ae3e4bfc0
3 changed files with 74 additions and 77 deletions

View File

@ -22,10 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void handleMissionArgs(int argc, char *argv[]); static void handleMissionArgs(int argc, char *argv[]);
static void handleLoggingArgs(int argc, char *argv[]); static void handleLoggingArgs(int argc, char *argv[]);
static long capFrameRate(const long then);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
float td;
long then, lastFrameTime, frames; long then, lastFrameTime, frames;
long expireTextTimer; long expireTextTimer;
SDL_Event event; SDL_Event event;
@ -56,95 +56,81 @@ int main(int argc, char *argv[])
handleMissionArgs(argc, argv); handleMissionArgs(argc, argv);
dev.fps = frames = td = 0; dev.fps = frames = 0;
then = SDL_GetTicks(); then = SDL_GetTicks();
lastFrameTime = SDL_GetTicks() + 1000; lastFrameTime = SDL_GetTicks() + 1000;
expireTextTimer = SDL_GetTicks() + (1000 * 10); expireTextTimer = SDL_GetTicks() + (1000 * 10);
while (1) while (1)
{ {
td += (SDL_GetTicks() - then); then = capFrameRate(then);
then = SDL_GetTicks(); while (SDL_PollEvent(&event))
while (td >= LOGIC_RATE)
{ {
while (SDL_PollEvent(&event)) switch (event.type)
{ {
switch (event.type) case SDL_MOUSEMOTION:
{ doMouseMotion(&event.motion);
case SDL_MOUSEMOTION: break;
doMouseMotion(&event.motion);
break; case SDL_MOUSEWHEEL:
doMouseWheel(&event.wheel);
case SDL_MOUSEWHEEL: break;
doMouseWheel(&event.wheel);
break; case SDL_MOUSEBUTTONDOWN:
doMouseDown(&event.button);
case SDL_MOUSEBUTTONDOWN: break;
doMouseDown(&event.button);
break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
doMouseUp(&event.button); doMouseUp(&event.button);
break; break;
case SDL_KEYDOWN:
doKeyDown(&event.key);
break;
case SDL_KEYDOWN: case SDL_KEYUP:
doKeyDown(&event.key); doKeyUp(&event.key);
break; break;
case SDL_KEYUP:
doKeyUp(&event.key);
break;
case SDL_QUIT: case SDL_QUIT:
exit(0); exit(0);
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (event.window.event) switch (event.window.event)
{ {
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
musicSetPlaying(1); musicSetPlaying(1);
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
musicSetPlaying(0); musicSetPlaying(0);
break; break;
} }
break; break;
}
} }
if (app.modalDialog.type != MD_NONE)
{
doModalDialog();
}
/* let the delegate decide during logic() */
app.doTrophyAlerts = 0;
app.delegate.logic();
td -= LOGIC_RATE;
if (app.doTrophyAlerts)
{
doTrophyAlerts();
}
if (app.resetTimeDelta)
{
td = 0;
then = SDL_GetTicks();
app.resetTimeDelta = 0;
}
game.stats[STAT_TIME]++;
/* always zero the mouse motion */
app.mouse.dx = app.mouse.dy = 0;
} }
if (app.modalDialog.type != MD_NONE)
{
doModalDialog();
}
/* let the delegate decide during logic() */
app.doTrophyAlerts = 0;
app.delegate.logic();
if (app.doTrophyAlerts)
{
doTrophyAlerts();
}
game.stats[STAT_TIME]++;
/* always zero the mouse motion */
app.mouse.dx = app.mouse.dy = 0;
prepareScene(); prepareScene();
app.delegate.draw(); app.delegate.draw();
@ -204,6 +190,20 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
static long capFrameRate(const long then)
{
long wait;
wait = 16 - (SDL_GetTicks() - then);
if (wait > 0)
{
SDL_Delay(wait);
}
return SDL_GetTicks();
}
static void handleLoggingArgs(int argc, char *argv[]) static void handleLoggingArgs(int argc, char *argv[])
{ {
int i; int i;

View File

@ -484,7 +484,6 @@ typedef struct {
} Mouse; } Mouse;
typedef struct { typedef struct {
int resetTimeDelta;
char saveDir[MAX_FILENAME_LENGTH]; char saveDir[MAX_FILENAME_LENGTH];
int saveGame; int saveGame;
int winWidth; int winWidth;

View File

@ -43,6 +43,4 @@ void endSectionTransition(void)
{ {
SDL_Delay(elasped); SDL_Delay(elasped);
} }
app.resetTimeDelta = 1;
} }