diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-05-16 16:54:55 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-05-16 16:54:55 +0000 |
commit | 0f5e2c1f67d6f9b7d6ee3dd55b8c7cd903881bd6 (patch) | |
tree | 4615062f7f0a4268d04c00196aa64381ae0f3e50 /src/main.c | |
parent | 096e588e4f2e93e51a2791258f3e6c4a7f7a78ae (diff) |
Reshuffle lots of things
Basic environment mapping stuff
Remove OBJ file stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@19 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -45,6 +45,7 @@ int main(int argc, char *argv[]) { int c; Uint32 video_flags; ScreenResolution res; + Uint32 t; res = RES_VGA; video_flags = SDL_OPENGL; @@ -113,7 +114,14 @@ int main(int argc, char *argv[]) { /* Main loop */ finished = 0; + t = SDL_GetTicks(); while ( !finished ) { + + /* Timer advances only when game is not paused */ + if ( !game->paused ) { + t = SDL_GetTicks(); + } + SDL_PollEvent(&event); switch ( event.type ) { case SDL_KEYDOWN : @@ -139,29 +147,38 @@ 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); + if ( game->paused ) render_draw(game, t); break; case SDL_QUIT : finished = 1; break; } if ( !game->paused ) { - physics_step(game); - render_draw(game); + physics_step(game, t); + render_draw(game, t); } - printf("%+7.4f %+7.4f %+7.4f %+5.1f deg %+7.5f %+7.5f %+7.5f %2i %2i %2i %3i %3i fps\r", + printf("%+7.4f %+7.4f %+7.4f %+5.1f deg %+7.5f %+7.5f %+7.5f %2i %2i %2i %3i fps\r", game->lander->x, game->lander->y, game->lander->z, rad2deg(game->lander->yaw), game->lander->vx, game->lander->vy, game->lander->vz, - game->cur_room_x, game->cur_room_y, game->cur_room_z, game->num_rooms, game->render->fps); + game->cur_room_x, game->cur_room_y, game->cur_room_z, game->fps); fflush(stdout); + /* 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; + game->frames = 0; + game->frame_delay_fiddled = 0; + } + /* Attempt to hold output FPS close to some target value */ - if ( (!game->frame_delay_fiddled) && (game->render->fps < 30) ) { + if ( (!game->frame_delay_fiddled) && (game->fps < 30) ) { game->frame_delay -= game->frame_delay/20; game->frame_delay_fiddled = 1; } - if ( (!game->frame_delay_fiddled) && (game->render->fps > 50) ) { + if ( (!game->frame_delay_fiddled) && (game->fps > 50) ) { game->frame_delay += game->frame_delay/20; game->frame_delay_fiddled = 1; } |