Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup fps fixes #412

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/emu/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,10 @@ void screen_device::device_start()
if ((m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0 || !m_scanline_cb.isunset())
m_scanline_timer = timer_alloc(FUNC(screen_device::scanline_tick), this);

#ifdef __LIBRETRO__
screen_configured = 0;
#endif

// configure the screen with the default parameters
configure(m_width, m_height, m_visarea, m_refresh);

Expand Down Expand Up @@ -975,6 +979,14 @@ TIMER_CALLBACK_MEMBER(screen_device::scanline_tick)

void screen_device::configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period)
{
#ifdef __LIBRETRO__
if (screen_configured
&& width == m_width
&& height == m_height
&& floorf(ATTOSECONDS_TO_HZ(frame_period)) == floorf(ATTOSECONDS_TO_HZ(m_frame_period)))
return;
#endif

// validate arguments
assert(width > 0);
assert(height > 0);
Expand Down Expand Up @@ -1029,7 +1041,14 @@ void screen_device::configure(int width, int height, const rectangle &visarea, a
machine().video().update_refresh_speed();

#ifdef __LIBRETRO__
retro_fps = ATTOSECONDS_TO_HZ(frame_period);
float retro_fps_new = ATTOSECONDS_TO_HZ(m_frame_period);
if (!screen_configured
&& retro_fps_new != retro_fps
&& retro_fps_new <= 120.0f
&& retro_fps_new >= 30.0f)
retro_fps = retro_fps_new;

screen_configured++;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/osd/libretro/libretro-internal/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ float view_aspect = 1.0f;
float retro_fps = 60.0f;
float sound_timer = 50.0f; /* default STREAMS_UPDATE_ATTOTIME, changed later to `retro_fps` */
int video_changed = 0;
int screen_configured = 0;

static bool draw_this_frame;
static int cpu_overclock = 100;
Expand Down
4 changes: 4 additions & 0 deletions src/osd/libretro/libretro-internal/libretro_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum
RETRO_SETTING_LIGHTGUN_MODE_LIGHTGUN
};

extern bool retro_load_ok;
extern int video_changed;
extern int retro_pause;
extern int mame_reset;
Expand Down Expand Up @@ -105,6 +106,9 @@ extern float retro_fps;
extern float view_aspect;
extern int rotation_mode;
extern int thread_mode;
extern float sound_timer;
extern int screen_configured;

static const char core[] = "mame";

/* libretro callbacks */
Expand Down
4 changes: 0 additions & 4 deletions src/osd/libretro/osdretro.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

#include "libretro-internal/libretro_shared.h"

extern float sound_timer;
extern float retro_fps;
extern int video_changed;

//============================================================
// Defines
//============================================================
Expand Down
14 changes: 10 additions & 4 deletions src/osd/libretro/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
#include "modules/render/drawretro.h"
#include "modules/monitor/monitor_common.h"

#include "libretro-internal/libretro_shared.h"

extern int max_width;
extern int max_height;
extern int libretro_rotation_allow;
extern int internal_rotation_allow;
extern int norotate;
extern bool retro_load_ok;

//============================================================
// PARAMETERS
Expand Down Expand Up @@ -293,6 +294,9 @@ int retro_window_info::window_init()
// reset sound timer (set in `sound_manager::update` to `retro_fps`)
sound_timer = 0;

// reset screen configuration
screen_configured = 0;

// reset machine aspect (set in `retro_window_info::update()`)
view_aspect = 1;

Expand Down Expand Up @@ -481,11 +485,13 @@ void retro_window_info::update()
/* Update retro_fps */
if (screen)
{
float current_screen_refresh = screen->frame_period().as_hz();
float screen_refresh = screen->frame_period().as_hz();

if (current_screen_refresh != retro_fps)
if (screen_refresh != retro_fps
&& screen_refresh <= 120.0f
&& screen_refresh >= 30.0f)
{
retro_fps = current_screen_refresh;
retro_fps = screen_refresh;
video_changed = 1;
}
}
Expand Down