forked from kdx/jtmm2-old
[WIP] FPS limit doesn't work, ask for help
This commit is contained in:
parent
65ceff3971
commit
5abe1d6828
|
@ -0,0 +1,9 @@
|
|||
#define UPS 32
|
||||
#define FPS 32
|
||||
|
||||
#ifdef FX9860G
|
||||
#define SCALE 1
|
||||
#endif /* FX9860G */
|
||||
#ifdef FXCG50
|
||||
#define SCALE 2
|
||||
#endif /* FXCG50 */
|
|
@ -4,5 +4,7 @@
|
|||
#include "input.h"
|
||||
|
||||
int play_level(int level_id);
|
||||
/* callback used for FPS control */
|
||||
int callback(volatile void *arg);
|
||||
void step_event(Player *player, Level *level, Camera *camera, Input *input);
|
||||
void draw_event(Player *player, Level *level, Camera *camera, Input *input);
|
||||
|
|
32
src/main.c
32
src/main.c
|
@ -1,8 +1,11 @@
|
|||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/timer.h>
|
||||
#include <gint/clock.h>
|
||||
#include <gint/std/string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "conf.h"
|
||||
#include "main.h"
|
||||
#include "debug.h"
|
||||
#include "init.h"
|
||||
|
@ -42,12 +45,7 @@ int play_level(int level_id)
|
|||
Camera camera = {
|
||||
.pos = {DWIDTH * VEC_PRECISION, DHEIGHT * VEC_PRECISION},
|
||||
.target = &player.pos,
|
||||
#ifdef FX9860G
|
||||
.speed = 0.0005
|
||||
#endif /* FX9860G */
|
||||
#ifdef FXCG50
|
||||
.speed = 0.05
|
||||
#endif /* FXCG50 */
|
||||
};
|
||||
|
||||
/* create input manager */
|
||||
|
@ -57,16 +55,36 @@ int play_level(int level_id)
|
|||
input.keys[K_UP] = KEY_UP;
|
||||
input.keys[K_DOWN] = KEY_DOWN;
|
||||
|
||||
//vec_cpy(&camera.pos, player.pos);
|
||||
/* FPS control */
|
||||
volatile int has_ticked = 1;
|
||||
timer_setup(TIMER_ANY, 1000000/FPS, callback, &has_ticked);
|
||||
timer_start(0);
|
||||
|
||||
while (camera.pos.x / VEC_PRECISION != player.pos.x / VEC_PRECISION ||
|
||||
camera.pos.y / VEC_PRECISION != player.pos.y / VEC_PRECISION)
|
||||
{
|
||||
step_event(&player, &level, &camera, &input);
|
||||
/* FPS control */
|
||||
while(!has_ticked) sleep();
|
||||
has_ticked = 0;
|
||||
/* repeat step event so the UPS is constant regardless of FPS */
|
||||
for (int i = 0; i < UPS / FPS; ++i)
|
||||
{
|
||||
/* step event is where all the logic happens */
|
||||
step_event(&player, &level, &camera, &input);
|
||||
}
|
||||
/* draw event just draws stuff */
|
||||
draw_event(&player, &level, &camera, &input);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callback(volatile void *arg)
|
||||
{
|
||||
volatile int *has_ticked = arg;
|
||||
*has_ticked = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void step_event(Player *player, Level *level, Camera *camera, Input *input)
|
||||
{
|
||||
//getkey();
|
||||
|
|
Loading…
Reference in New Issue