diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -87,7 +87,6 @@ int main(int argc, char *argv[]) { int c; Uint32 video_flags; ScreenResolution res; - Uint32 t = 0; GameOptions gameopts; Uint16 cx, cy; double vyaw_scale, vang_scale; @@ -213,16 +212,21 @@ int main(int argc, char *argv[]) { /* Main loop */ finished = 0; + game->time = 0.0; + game->tlast = SDL_GetTicks(); while ( !finished ) { int mx, my; Uint8 buttons; int mouse_thrust = 0; + int dt; - /* Timer advances only when game is not paused */ + /* Tick size is measured, ... */ + dt = SDL_GetTicks() - game->tlast; + game->tlast = SDL_GetTicks(); + /* ... but timer advances only when game is not paused */ if ( !game->paused ) { - game->tlast = t; - t = SDL_GetTicks(); + game->time += dt; } SDL_PollEvent(&event); @@ -253,7 +257,7 @@ int main(int argc, char *argv[]) { break; case SDL_VIDEOEXPOSE : /* Don't bother redrawing if not paused - not long to wait! */ - if ( game->paused ) render_draw(game, t); + if ( game->paused ) render_draw(game); break; case SDL_QUIT : finished = 1; @@ -270,17 +274,15 @@ int main(int argc, char *argv[]) { mouse_thrust = 1; } if ( !game->paused ) { - physics_step(game, t); - render_draw(game, t); + physics_step(game, dt); + render_draw(game); } if ( mouse_thrust ) game->thrusting = 0; if ( gameopts.status_line ) { - printf("%+7.4f %+7.4f %+7.4f %+6.1f deg %+7.5f %+7.5f %+7.5f %2i %2i %2i %3i fps " - "(r:%6lli p:%6lli) \r", - game->lander->x, game->lander->y, game->lander->z, - rad2deg(game->lander->yaw), game->lander->vx, game->lander->vy, game->lander->vz, + printf("%10lli %+7.5f %+7.5f %+7.5f %2i %2i %2i %3i fps (r:%6lli p:%6lli) \r", + game->time, game->lander->vx, game->lander->vy, game->lander->vz, game->cur_room_x, game->cur_room_y, game->cur_room_z, game->fps, game->time_render, game->time_physics); fflush(stdout); @@ -288,9 +290,9 @@ int main(int argc, char *argv[]) { /* Calculate FPS every half a second */ game->frames++; - if ( t - game->t_fps > 500 ) { - game->fps = (500*game->frames) / (t - game->t_fps); - game->t_fps = t; + if ( game->time - game->t_fps > 500 ) { + game->fps = (500*game->frames) / (game->time - game->t_fps); + game->t_fps = game->time; game->frames = 0; } |