mirror of https://git.sr.ht/~kikoodx/momento
Automatic frameskip
This commit is contained in:
parent
f9df721d54
commit
b63bbd3148
|
@ -7,8 +7,7 @@
|
|||
#define TILE_WIDTH 16
|
||||
#define TILE_HEIGHT 16
|
||||
#define TILESET_WIDTH 16
|
||||
#define TARGET_FPS 30
|
||||
#define TARGET_UPS 60
|
||||
#define TARGET_FPS 60
|
||||
#define LVL_PER_PACK 4
|
||||
#define ACC_GND 0.1
|
||||
#define ACC_AIR 0.025
|
||||
|
|
24
src/main.c
24
src/main.c
|
@ -43,13 +43,15 @@ extern char *fatal_error_msg;
|
|||
|
||||
extern const font_t font_main;
|
||||
|
||||
static int callback(volatile void *arg);
|
||||
static int callback(volatile int *arg);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
int timer;
|
||||
int player_return_code;
|
||||
int frameskip = 0;
|
||||
int toskip = 0;
|
||||
/* int level_pack_beaten; */
|
||||
enum TransitionMode transition_previous_mode;
|
||||
enum GameState game_state = TitleScreen;
|
||||
|
@ -74,7 +76,7 @@ int main(void)
|
|||
PANIC(fatal_error_msg);
|
||||
/* timer setup */
|
||||
timer =
|
||||
timer_setup(TIMER_ANY, 1000000 / TARGET_UPS, callback, &has_ticked);
|
||||
timer_setup(TIMER_ANY, 1000000 / TARGET_FPS, callback, &has_ticked);
|
||||
if (timer == -1)
|
||||
PANIC("timer_setup failed");
|
||||
timer_start(timer);
|
||||
|
@ -84,13 +86,19 @@ int main(void)
|
|||
|
||||
/* main game loop */
|
||||
while (!keydown(KEY_EXIT)) {
|
||||
/* do x updates per frame, x being ups/fps */
|
||||
i = TARGET_UPS / TARGET_FPS;
|
||||
/* skip render frames */
|
||||
i = 1 + frameskip;
|
||||
toskip = frameskip;
|
||||
while (i-- > 0) {
|
||||
/* frameskip adjustement */
|
||||
if (has_ticked - 1 > frameskip)
|
||||
frameskip = has_ticked - 1;
|
||||
|
||||
/* speed limiter */
|
||||
while (!has_ticked)
|
||||
sleep();
|
||||
has_ticked = 0;
|
||||
while (has_ticked)
|
||||
has_ticked = 0;
|
||||
|
||||
/* update */
|
||||
input_update(&input);
|
||||
|
@ -204,6 +212,7 @@ int main(void)
|
|||
case Playing:
|
||||
level_draw();
|
||||
particles_draw();
|
||||
trail_draw();
|
||||
player_draw(player);
|
||||
transition_draw(transition);
|
||||
break;
|
||||
|
@ -222,9 +231,8 @@ int main(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int callback(volatile void *arg)
|
||||
static int callback(volatile int *arg)
|
||||
{
|
||||
volatile int *has_ticked = arg;
|
||||
*has_ticked = 1;
|
||||
*arg += 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue