Mercurial > repos > blastem
comparison render_sdl.c @ 342:13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 16 May 2013 09:37:53 -0700 |
parents | 58a085cfc6bd |
children | 15dd6418fe67 |
comparison
equal
deleted
inserted
replaced
341:6ad8e36de685 | 342:13f994c88c34 |
---|---|
12 | 12 |
13 int32_t color_map[1 << 12]; | 13 int32_t color_map[1 << 12]; |
14 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255}; | 14 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255}; |
15 | 15 |
16 uint32_t min_delay; | 16 uint32_t min_delay; |
17 uint32_t frame_delay = 1000/60; | |
17 | 18 |
18 void render_init(int width, int height, char * title) | 19 void render_init(int width, int height, char * title) |
19 { | 20 { |
20 if (SDL_Init(SDL_INIT_VIDEO) < 0) { | 21 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
21 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); | 22 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); |
227 #define BUTTON_A 0x10 | 228 #define BUTTON_A 0x10 |
228 #define BUTTON_B 0x10 | 229 #define BUTTON_B 0x10 |
229 #define BUTTON_START 0x20 | 230 #define BUTTON_START 0x20 |
230 #define BUTTON_C 0x20 | 231 #define BUTTON_C 0x20 |
231 | 232 |
232 #define FRAME_DELAY 16 | |
233 #define MIN_DELAY 5 | |
234 uint32_t frame_counter = 0; | 233 uint32_t frame_counter = 0; |
235 uint32_t start = 0; | 234 uint32_t start = 0; |
236 int wait_render_frame(vdp_context * context, int frame_limit) | 235 int wait_render_frame(vdp_context * context, int frame_limit) |
237 { | 236 { |
238 FILE * outfile; | 237 FILE * outfile; |
360 } | 359 } |
361 } | 360 } |
362 if (frame_limit) { | 361 if (frame_limit) { |
363 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS | 362 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS |
364 uint32_t current = SDL_GetTicks(); | 363 uint32_t current = SDL_GetTicks(); |
365 uint32_t desired = last_frame + FRAME_DELAY; | 364 uint32_t desired = last_frame + frame_delay; |
366 if (current < desired) { | 365 if (current < desired) { |
367 uint32_t delay = last_frame + FRAME_DELAY - current; | 366 uint32_t delay = last_frame + frame_delay - current; |
368 //TODO: Calculate MIN_DELAY at runtime | 367 if (delay > min_delay) { |
369 if (delay > MIN_DELAY) { | 368 SDL_Delay((delay/min_delay)*min_delay); |
370 SDL_Delay((delay/MIN_DELAY)*MIN_DELAY); | |
371 } | 369 } |
372 while ((desired) >= SDL_GetTicks()) { | 370 while ((desired) >= SDL_GetTicks()) { |
373 } | 371 } |
374 } | 372 } |
375 } | 373 } |
387 frame_counter = 0; | 385 frame_counter = 0; |
388 }*/ | 386 }*/ |
389 return ret; | 387 return ret; |
390 } | 388 } |
391 | 389 |
392 | 390 void render_fps(uint32_t fps) |
391 { | |
392 frame_delay = 1000/fps; | |
393 } | |
394 | |
395 |