aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-14 12:25:05 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-14 12:25:05 +0000
commit2b3e32981c358ff308f3a5e05f3865a299d9dd28 (patch)
tree414b7ed24fe06d36f5dc6b019cee53d5945f13e3 /src/main.c
parent386384955ed68b7671f152a0ab4f30c2170e3e54 (diff)
Hold FPS at around 100
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@10 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 36de2a3..db6b260 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include "game.h"
#include "render.h"
#include "physics.h"
+#include "utils.h"
int main(int argc, char *argv[]) {
@@ -42,7 +43,8 @@ int main(int argc, char *argv[]) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
width = 1680; height = 1050;
- screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL | SDL_FULLSCREEN);
+ width=640;height=480;
+ screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL);// | SDL_FULLSCREEN);
if ( screen == NULL ) {
width = 1280; height = 1024;
screen = SDL_SetVideoMode(width, height, 16, SDL_OPENGL | SDL_FULLSCREEN);
@@ -99,8 +101,24 @@ int main(int argc, char *argv[]) {
render_draw(game);
}
- /* Sleep for around 8ms to avoid hogging the CPU. This value gives about 100fps on my (rather modest) machine. */
- usleep(8000);
+ printf("%+7.4f %+7.4f %+7.4f %+5.1f deg %+7.5f %+7.5f %+7.5f %2i %2i %2i %3i %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);
+ fflush(stdout);
+
+ /* Attempt to hold output FPS close to 100 */
+ if ( (!game->frame_delay_fiddled) && (game->render->fps < 90) ) {
+ game->frame_delay -= game->frame_delay/20;
+ game->frame_delay_fiddled = 1;
+ }
+ if ( (!game->frame_delay_fiddled) && (game->render->fps > 110) ) {
+ game->frame_delay += game->frame_delay/20;
+ game->frame_delay_fiddled = 1;
+ }
+
+ /* Sleep for a bit to avoid hogging the CPU. */
+ usleep(game->frame_delay);
}