Adding support for variable throttle

This commit is contained in:
Nathan Woods 2014-02-02 12:54:03 +00:00
parent a2da57f494
commit 45b241e53b
2 changed files with 12 additions and 9 deletions

View File

@ -85,7 +85,7 @@ video_manager::video_manager(running_machine &machine)
m_overall_real_ticks(0),
m_overall_emutime(attotime::zero),
m_overall_valid_counter(0),
m_throttle(machine.options().throttle()),
m_throttle_rate(machine.options().throttle() ? 1.0f : 0.0f),
m_fastforward(false),
m_seconds_to_run(machine.options().seconds_to_run()),
m_auto_frameskip(machine.options().auto_frameskip()),
@ -718,7 +718,7 @@ void video_manager::update_throttle(attotime emutime)
// compute conversion factors up front
osd_ticks_t ticks_per_second = osd_ticks_per_second();
attoseconds_t attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second;
attoseconds_t attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second * m_throttle_rate;
// if we're paused, emutime will not advance; instead, we subtract a fixed
// amount of time (1/60th of a second) from the emulated time that was passed in,
@ -872,9 +872,12 @@ void video_manager::update_frameskip()
// if we're throttling and autoframeskip is on, adjust
if (effective_throttle() && effective_autoframeskip() && m_frameskip_counter == 0)
{
// calibrate the "adjusted speed" based on the target
double adjusted_speed_percent = m_speed_percent / m_throttle_rate;
// if we're too fast, attempt to increase the frameskip
double speed = m_speed * 0.001;
if (m_speed_percent >= 0.995 * speed)
if (adjusted_speed_percent >= 0.995 * speed)
{
// but only after 3 consecutive frames where we are too fast
if (++m_frameskip_adjust >= 3)
@ -889,7 +892,7 @@ void video_manager::update_frameskip()
else
{
// if below 80% speed, be more aggressive
if (m_speed_percent < 0.80 * speed)
if (adjusted_speed_percent < 0.80 * speed)
m_frameskip_adjust -= (0.90 * speed - m_speed_percent) / 0.05;
// if we're close, only force it up to frameskip 8
@ -1280,5 +1283,5 @@ bool video_assert_out_of_range_pixels(running_machine &machine, bitmap_ind16 &bi
void video_manager::toggle_throttle()
{
set_throttled(!throttled());
set_throttle_rate(throttled() ? 0.0f : 1.0f);
}

View File

@ -61,14 +61,14 @@ public:
bool skip_this_frame() const { return m_skipping_this_frame; }
int speed_factor() const { return m_speed; }
int frameskip() const { return m_auto_frameskip ? -1 : m_frameskip_level; }
bool throttled() const { return m_throttle; }
bool throttled() const { return throttle_rate() != 0; }
float throttle_rate() const { return m_throttle_rate; }
bool fastforward() const { return m_fastforward; }
bool is_recording() const { return (m_mngfile != NULL || m_avifile != NULL); }
// setters
void set_speed_factor(int speed) { m_speed = speed; }
void set_frameskip(int frameskip);
void set_throttled(bool throttled = true) { m_throttle = throttled; }
void set_throttle_rate(float throttle_rate) { m_throttle_rate = throttle_rate; }
void set_fastforward(bool ffwd = true) { m_fastforward = ffwd; }
void set_output_changed() { m_output_changed = true; }
@ -141,7 +141,7 @@ private:
UINT32 m_overall_valid_counter; // number of consecutive valid time periods
// configuration
bool m_throttle; // flag: TRUE if we're currently throttled
float m_throttle_rate; // target rate for throttling (0 = no throttle)
bool m_fastforward; // flag: TRUE if we're currently fast-forwarding
UINT32 m_seconds_to_run; // number of seconds to run before quitting
bool m_auto_frameskip; // flag: TRUE if we're automatically frameskipping