mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
platform, cleanup main emu loop
This commit is contained in:
parent
b38c0ea6f9
commit
b4bc262418
1 changed files with 29 additions and 29 deletions
|
@ -1395,17 +1395,17 @@ static void emu_loop_prep(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* our tick here is 1 us right now */
|
/* our tick here is 1 us right now */
|
||||||
#define ms_to_ticks(x) (int)(x * 1000)
|
#define ms_to_ticks(x) (int)(x * 1000)
|
||||||
#define get_ticks() plat_get_ticks_us()
|
#define get_ticks() plat_get_ticks_us()
|
||||||
#define vsync_delay_x3 3*ms_to_ticks(1)
|
#define vsync_delay ms_to_ticks(1)
|
||||||
|
|
||||||
void emu_loop(void)
|
void emu_loop(void)
|
||||||
{
|
{
|
||||||
int frames_done, frames_shown; /* actual frames for fps counter */
|
int frames_done, frames_shown; /* actual frames for fps counter */
|
||||||
int target_frametime_x3;
|
int target_frametime;
|
||||||
unsigned int timestamp_x3 = 0;
|
unsigned int timestamp = 0;
|
||||||
unsigned int timestamp_aim_x3 = 0;
|
unsigned int timestamp_aim = 0;
|
||||||
unsigned int timestamp_fps_x3 = 0;
|
unsigned int timestamp_fps = 0;
|
||||||
char *notice_msg = NULL;
|
char *notice_msg = NULL;
|
||||||
char fpsbuff[24];
|
char fpsbuff[24];
|
||||||
int fskip_cnt = 0;
|
int fskip_cnt = 0;
|
||||||
|
@ -1420,9 +1420,9 @@ void emu_loop(void)
|
||||||
|
|
||||||
/* number of ticks per frame */
|
/* number of ticks per frame */
|
||||||
if (Pico.m.pal)
|
if (Pico.m.pal)
|
||||||
target_frametime_x3 = 3 * ms_to_ticks(1000) / 50;
|
target_frametime = ms_to_ticks(1000) / 50;
|
||||||
else
|
else
|
||||||
target_frametime_x3 = 3 * ms_to_ticks(1000) / 60;
|
target_frametime = ms_to_ticks(1000) / 60;
|
||||||
|
|
||||||
reset_timing = 1;
|
reset_timing = 1;
|
||||||
frames_done = frames_shown = 0;
|
frames_done = frames_shown = 0;
|
||||||
|
@ -1438,22 +1438,22 @@ void emu_loop(void)
|
||||||
if (reset_timing) {
|
if (reset_timing) {
|
||||||
reset_timing = 0;
|
reset_timing = 0;
|
||||||
plat_video_wait_vsync();
|
plat_video_wait_vsync();
|
||||||
timestamp_aim_x3 = get_ticks() * 3;
|
timestamp_aim = get_ticks();
|
||||||
timestamp_fps_x3 = timestamp_aim_x3;
|
timestamp_fps = timestamp_aim;
|
||||||
fskip_cnt = 0;
|
fskip_cnt = 0;
|
||||||
}
|
}
|
||||||
else if (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) {
|
else if (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) {
|
||||||
timestamp_aim_x3 = get_ticks() * 3;
|
timestamp_aim = get_ticks();
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp_x3 = get_ticks() * 3;
|
timestamp = get_ticks();
|
||||||
|
|
||||||
// show notice_msg message?
|
// show notice_msg message?
|
||||||
if (notice_msg_time != 0)
|
if (notice_msg_time != 0)
|
||||||
{
|
{
|
||||||
static int noticeMsgSum;
|
static int noticeMsgSum;
|
||||||
if (timestamp_x3 - ms_to_ticks(notice_msg_time) * 3
|
if (timestamp - ms_to_ticks(notice_msg_time)
|
||||||
> ms_to_ticks(STATUS_MSG_TIMEOUT) * 3)
|
> ms_to_ticks(STATUS_MSG_TIMEOUT))
|
||||||
{
|
{
|
||||||
notice_msg_time = 0;
|
notice_msg_time = 0;
|
||||||
notice_msg = NULL;
|
notice_msg = NULL;
|
||||||
|
@ -1470,7 +1470,7 @@ void emu_loop(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// second changed?
|
// second changed?
|
||||||
if (timestamp_x3 - timestamp_fps_x3 >= ms_to_ticks(1000) * 3)
|
if (timestamp - timestamp_fps >= ms_to_ticks(1000))
|
||||||
{
|
{
|
||||||
#ifdef BENCHMARK
|
#ifdef BENCHMARK
|
||||||
static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
|
static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];
|
||||||
|
@ -1488,13 +1488,13 @@ void emu_loop(void)
|
||||||
snprintf(fpsbuff, 8, "%02i/%02i ", frames_shown, frames_done);
|
snprintf(fpsbuff, 8, "%02i/%02i ", frames_shown, frames_done);
|
||||||
#endif
|
#endif
|
||||||
frames_shown = frames_done = 0;
|
frames_shown = frames_done = 0;
|
||||||
timestamp_fps_x3 += ms_to_ticks(1000) * 3;
|
timestamp_fps += ms_to_ticks(1000);
|
||||||
}
|
}
|
||||||
#ifdef PFRAMES
|
#ifdef PFRAMES
|
||||||
sprintf(fpsbuff, "%i", Pico.m.frame_count);
|
sprintf(fpsbuff, "%i", Pico.m.frame_count);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
diff = timestamp_aim_x3 - timestamp_x3;
|
diff = timestamp_aim - timestamp;
|
||||||
|
|
||||||
if (currentConfig.Frameskip >= 0) // frameskip enabled (or 0)
|
if (currentConfig.Frameskip >= 0) // frameskip enabled (or 0)
|
||||||
{
|
{
|
||||||
|
@ -1506,7 +1506,7 @@ void emu_loop(void)
|
||||||
fskip_cnt = 0;
|
fskip_cnt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (diff < -target_frametime_x3)
|
else if (diff < -target_frametime)
|
||||||
{
|
{
|
||||||
/* no time left for this frame - skip */
|
/* no time left for this frame - skip */
|
||||||
/* limit auto frameskip to max_skip */
|
/* limit auto frameskip to max_skip */
|
||||||
|
@ -1521,14 +1521,14 @@ void emu_loop(void)
|
||||||
fskip_cnt = 0;
|
fskip_cnt = 0;
|
||||||
|
|
||||||
// don't go in debt too much
|
// don't go in debt too much
|
||||||
while (diff < -target_frametime_x3 * 3) {
|
while (diff < -target_frametime * 3) {
|
||||||
timestamp_aim_x3 += target_frametime_x3;
|
timestamp_aim += target_frametime;
|
||||||
diff = timestamp_aim_x3 - timestamp_x3;
|
diff = timestamp_aim - timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
emu_update_input();
|
emu_update_input();
|
||||||
if (skip) {
|
if (skip) {
|
||||||
int do_audio = diff > -target_frametime_x3 * 2;
|
int do_audio = diff > -target_frametime * 2;
|
||||||
PicoIn.skipFrame = do_audio ? 1 : 2;
|
PicoIn.skipFrame = do_audio ? 1 : 2;
|
||||||
PicoFrame();
|
PicoFrame();
|
||||||
PicoIn.skipFrame = 0;
|
PicoIn.skipFrame = 0;
|
||||||
|
@ -1539,7 +1539,7 @@ void emu_loop(void)
|
||||||
frames_shown++;
|
frames_shown++;
|
||||||
}
|
}
|
||||||
frames_done++;
|
frames_done++;
|
||||||
timestamp_aim_x3 += target_frametime_x3;
|
timestamp_aim += target_frametime;
|
||||||
|
|
||||||
if (!skip && !flip_after_sync)
|
if (!skip && !flip_after_sync)
|
||||||
plat_video_flip();
|
plat_video_flip();
|
||||||
|
@ -1549,18 +1549,18 @@ void emu_loop(void)
|
||||||
&& !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT)))
|
&& !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT)))
|
||||||
{
|
{
|
||||||
unsigned int timestamp = get_ticks();
|
unsigned int timestamp = get_ticks();
|
||||||
diff = timestamp_aim_x3 - timestamp * 3;
|
diff = timestamp_aim - timestamp;
|
||||||
|
|
||||||
// sleep or vsync if we are still too fast
|
// sleep or vsync if we are still too fast
|
||||||
if (diff > target_frametime_x3 + vsync_delay_x3 && (currentConfig.EmuOpt & EOPT_VSYNC)) {
|
if (diff > target_frametime + vsync_delay && (currentConfig.EmuOpt & EOPT_VSYNC)) {
|
||||||
// we are too fast
|
// we are too fast
|
||||||
plat_video_wait_vsync();
|
plat_video_wait_vsync();
|
||||||
timestamp = get_ticks();
|
timestamp = get_ticks();
|
||||||
diff = timestamp_aim_x3 - timestamp * 3;
|
diff = timestamp_aim - timestamp;
|
||||||
}
|
}
|
||||||
if (diff > target_frametime_x3 + vsync_delay_x3) {
|
if (diff > target_frametime + vsync_delay) {
|
||||||
// still too fast
|
// still too fast
|
||||||
plat_wait_till_us(timestamp + (diff - target_frametime_x3) / 3);
|
plat_wait_till_us(timestamp + (diff - target_frametime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue