add cleaner framerate management
This commit is contained in:
parent
a071d0373e
commit
4ce6ed3969
BIN
SuperCbr.g1a
BIN
SuperCbr.g1a
Binary file not shown.
Binary file not shown.
Binary file not shown.
1072
build-fx/map
1072
build-fx/map
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
build-fx/src/framerate.c.o: src/framerate.c
|
Binary file not shown.
|
@ -1,6 +1,7 @@
|
|||
build-fx/src/levelchanger.c.o: src/levelchanger.c include/levelchanger.h \
|
||||
include/keyboard.h include/mario.h include/box.h include/world.h \
|
||||
include/score.h include/level.h include/save.h include/config.h
|
||||
include/score.h include/level.h include/save.h include/config.h \
|
||||
include/framerate.h
|
||||
|
||||
include/levelchanger.h:
|
||||
|
||||
|
@ -19,3 +20,5 @@ include/level.h:
|
|||
include/save.h:
|
||||
|
||||
include/config.h:
|
||||
|
||||
include/framerate.h:
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
#ifndef FRAMERATE_H
|
||||
#define FRAMERATE_H
|
||||
|
||||
// Defined to 20 FPS, constant
|
||||
|
||||
void init_refresh();
|
||||
|
||||
void quit_refresh();
|
||||
|
||||
void wait_next_frame();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,36 @@
|
|||
#include <gint/timer.h>
|
||||
#include <gint/clock.h>
|
||||
|
||||
static volatile int has_ticked = 0;
|
||||
|
||||
int callback(volatile void *arg)
|
||||
{
|
||||
volatile int *has_ticked = arg;
|
||||
*has_ticked = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_refresh()
|
||||
{
|
||||
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
|
||||
timer_start(0);
|
||||
}
|
||||
|
||||
void quit_refresh()
|
||||
{
|
||||
timer_stop(0);
|
||||
}
|
||||
|
||||
void wait_next_frame()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (has_ticked)
|
||||
{
|
||||
has_ticked=0;
|
||||
return;
|
||||
}
|
||||
sleep();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
#include <level.h>
|
||||
#include <save.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <framerate.h>
|
||||
|
||||
static void levelchanger(int w)
|
||||
{
|
||||
|
@ -237,21 +237,10 @@ void launch_ui()
|
|||
|
||||
|
||||
int frame_id;
|
||||
int callback(volatile void *arg)
|
||||
{
|
||||
volatile int *has_ticked = arg;
|
||||
*has_ticked = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int play_level(int w, int l)
|
||||
{
|
||||
volatile int has_ticked = 1;
|
||||
timer_setup(0, timer_delay(0, 50000), timer_Po_4, callback, &has_ticked);
|
||||
timer_start(0);
|
||||
init_refresh();
|
||||
|
||||
//int finish_status=0; // FAil
|
||||
finish_level=0; mario_dead=0;
|
||||
|
@ -267,57 +256,48 @@ int play_level(int w, int l)
|
|||
|
||||
while(global_quit==0)
|
||||
{
|
||||
if (has_ticked)
|
||||
{
|
||||
has_ticked=0;
|
||||
frame_id++;
|
||||
wait_next_frame();
|
||||
|
||||
frame_id++;
|
||||
//mario_move();
|
||||
|
||||
world_move();
|
||||
dclear(C_WHITE);
|
||||
world_draw(mario.p.x,mario.p.y);
|
||||
score_display();
|
||||
world_move();
|
||||
dclear(C_WHITE);
|
||||
world_draw(mario.p.x,mario.p.y);
|
||||
score_display();
|
||||
|
||||
dupdate();
|
||||
if (mario_dead)
|
||||
dupdate();
|
||||
if (mario_dead)
|
||||
{
|
||||
mario_immunity=0;
|
||||
int i=6;
|
||||
while(mario.p.y>=0)
|
||||
{
|
||||
mario_immunity=0;
|
||||
int i=6;
|
||||
while(mario.p.y>=0)
|
||||
{
|
||||
if (has_ticked)
|
||||
{
|
||||
has_ticked=0;
|
||||
mario.p.y+=i;
|
||||
dclear(C_WHITE);
|
||||
world_draw(mario.p.x,mario.p.y);
|
||||
mario_draw();
|
||||
score_display();
|
||||
wait_next_frame();
|
||||
mario.p.y+=i;
|
||||
dclear(C_WHITE);
|
||||
world_draw(mario.p.x,mario.p.y);
|
||||
mario_draw();
|
||||
score_display();
|
||||
|
||||
dupdate();
|
||||
i--;
|
||||
}
|
||||
else
|
||||
sleep_ms(3,1);
|
||||
}
|
||||
sleep_ms(3,1000);
|
||||
|
||||
timer_stop(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (finish_level)
|
||||
{
|
||||
timer_stop(0);
|
||||
// TODO ajouter temps au score etc
|
||||
if (finish_level==1)
|
||||
sleep_ms(3,3000);
|
||||
return finish_level;
|
||||
dupdate();
|
||||
i--;
|
||||
}
|
||||
sleep_ms(3,1000);
|
||||
|
||||
quit_refresh();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
sleep_ms(3,1);
|
||||
if (finish_level)
|
||||
{
|
||||
quit_refresh();
|
||||
// TODO ajouter temps au score etc
|
||||
if (finish_level==1)
|
||||
sleep_ms(3,3000);
|
||||
return finish_level;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue