mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-27 08:05:41 +00:00
TimingEvents: Use function pointers instead of std::function
This commit is contained in:
parent
8c241ed8de
commit
11992bde4e
|
@ -78,10 +78,14 @@ CDROM::~CDROM() = default;
|
|||
|
||||
void CDROM::Initialize()
|
||||
{
|
||||
m_command_event =
|
||||
TimingEvents::CreateTimingEvent("CDROM Command Event", 1, 1, std::bind(&CDROM::ExecuteCommand, this), false);
|
||||
m_drive_event = TimingEvents::CreateTimingEvent("CDROM Drive Event", 1, 1,
|
||||
std::bind(&CDROM::ExecuteDrive, this, std::placeholders::_2), false);
|
||||
m_command_event = TimingEvents::CreateTimingEvent(
|
||||
"CDROM Command Event", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<CDROM*>(param)->ExecuteCommand(); }, this,
|
||||
false);
|
||||
m_drive_event = TimingEvents::CreateTimingEvent(
|
||||
"CDROM Drive Event", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<CDROM*>(param)->ExecuteDrive(ticks_late); },
|
||||
this, false);
|
||||
|
||||
if (g_settings.cdrom_read_thread)
|
||||
m_reader.StartThread();
|
||||
|
|
|
@ -29,8 +29,10 @@ void DMA::Initialize()
|
|||
m_halt_ticks = g_settings.dma_halt_ticks;
|
||||
|
||||
m_transfer_buffer.resize(32);
|
||||
m_unhalt_event = TimingEvents::CreateTimingEvent("DMA Transfer Unhalt", 1, m_max_slice_ticks,
|
||||
std::bind(&DMA::UnhaltTransfer, this, std::placeholders::_1), false);
|
||||
m_unhalt_event = TimingEvents::CreateTimingEvent(
|
||||
"DMA Transfer Unhalt", 1, m_max_slice_ticks,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<DMA*>(param)->UnhaltTransfer(ticks); }, this,
|
||||
false);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
|
|
@ -31,9 +31,13 @@ bool GPU::Initialize(HostDisplay* host_display)
|
|||
m_force_progressive_scan = g_settings.gpu_disable_interlacing;
|
||||
m_force_ntsc_timings = g_settings.gpu_force_ntsc_timings;
|
||||
m_crtc_tick_event = TimingEvents::CreateTimingEvent(
|
||||
"GPU CRTC Tick", 1, 1, std::bind(&GPU::CRTCTickEvent, this, std::placeholders::_1), true);
|
||||
"GPU CRTC Tick", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<GPU*>(param)->CRTCTickEvent(ticks); }, this,
|
||||
true);
|
||||
m_command_tick_event = TimingEvents::CreateTimingEvent(
|
||||
"GPU Command Tick", 1, 1, std::bind(&GPU::CommandTickEvent, this, std::placeholders::_1), true);
|
||||
"GPU Command Tick", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<GPU*>(param)->CommandTickEvent(ticks); }, this,
|
||||
true);
|
||||
m_fifo_size = g_settings.gpu_fifo_size;
|
||||
m_max_run_ahead = g_settings.gpu_max_run_ahead;
|
||||
m_console_is_pal = System::IsPALRegion();
|
||||
|
|
|
@ -18,8 +18,9 @@ MDEC::~MDEC() = default;
|
|||
|
||||
void MDEC::Initialize()
|
||||
{
|
||||
m_block_copy_out_event =
|
||||
TimingEvents::CreateTimingEvent("MDEC Block Copy Out", 1, 1, std::bind(&MDEC::CopyOutBlock, this), false);
|
||||
m_block_copy_out_event = TimingEvents::CreateTimingEvent(
|
||||
"MDEC Block Copy Out", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<MDEC*>(param)->CopyOutBlock(); }, this, false);
|
||||
m_total_blocks_decoded = 0;
|
||||
Reset();
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ MemoryCard::MemoryCard()
|
|||
{
|
||||
m_FLAG.no_write_yet = true;
|
||||
|
||||
m_save_event = TimingEvents::CreateTimingEvent("Memory Card Host Flush", GetSaveDelayInTicks(), GetSaveDelayInTicks(),
|
||||
std::bind(&MemoryCard::SaveIfChanged, this, true), false);
|
||||
m_save_event = TimingEvents::CreateTimingEvent(
|
||||
"Memory Card Host Flush", GetSaveDelayInTicks(), GetSaveDelayInTicks(),
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<MemoryCard*>(param)->SaveIfChanged(true); },
|
||||
this, false);
|
||||
}
|
||||
|
||||
MemoryCard::~MemoryCard()
|
||||
|
|
|
@ -17,7 +17,9 @@ Pad::~Pad() = default;
|
|||
void Pad::Initialize()
|
||||
{
|
||||
m_transfer_event = TimingEvents::CreateTimingEvent(
|
||||
"Pad Serial Transfer", 1, 1, std::bind(&Pad::TransferEvent, this, std::placeholders::_2), false);
|
||||
"Pad Serial Transfer", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<Pad*>(param)->TransferEvent(ticks_late); },
|
||||
this, false);
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ void SPU::Initialize()
|
|||
// (X * D) / N / 768 -> (X * D) / (N * 768)
|
||||
m_cpu_ticks_per_spu_tick = System::ScaleTicksToOverclock(SYSCLK_TICKS_PER_SPU_TICK);
|
||||
m_cpu_tick_divider = static_cast<TickCount>(g_settings.cpu_overclock_numerator * SYSCLK_TICKS_PER_SPU_TICK);
|
||||
m_tick_event = TimingEvents::CreateTimingEvent("SPU Sample", m_cpu_ticks_per_spu_tick, m_cpu_ticks_per_spu_tick,
|
||||
std::bind(&SPU::Execute, this, std::placeholders::_1), false);
|
||||
m_transfer_event =
|
||||
TimingEvents::CreateTimingEvent("SPU Transfer", TRANSFER_TICKS_PER_HALFWORD, TRANSFER_TICKS_PER_HALFWORD,
|
||||
std::bind(&SPU::ExecuteTransfer, this, std::placeholders::_1), false);
|
||||
m_tick_event = TimingEvents::CreateTimingEvent(
|
||||
"SPU Sample", m_cpu_ticks_per_spu_tick, m_cpu_ticks_per_spu_tick,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<SPU*>(param)->Execute(ticks); }, this, false);
|
||||
m_transfer_event = TimingEvents::CreateTimingEvent(
|
||||
"SPU Transfer", TRANSFER_TICKS_PER_HALFWORD, TRANSFER_TICKS_PER_HALFWORD,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<SPU*>(param)->ExecuteTransfer(ticks); }, this,
|
||||
false);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@ Timers::~Timers() = default;
|
|||
void Timers::Initialize()
|
||||
{
|
||||
m_sysclk_event = TimingEvents::CreateTimingEvent(
|
||||
"Timer SysClk Interrupt", 1, 1, std::bind(&Timers::AddSysClkTicks, this, std::placeholders::_1), false);
|
||||
"Timer SysClk Interrupt", 1, 1,
|
||||
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<Timers*>(param)->AddSysClkTicks(ticks); },
|
||||
this, false);
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ void Shutdown()
|
|||
}
|
||||
|
||||
std::unique_ptr<TimingEvent> CreateTimingEvent(std::string name, TickCount period, TickCount interval,
|
||||
TimingEventCallback callback, bool activate)
|
||||
TimingEventCallback callback, void* callback_param, bool activate)
|
||||
{
|
||||
std::unique_ptr<TimingEvent> event =
|
||||
std::make_unique<TimingEvent>(std::move(name), period, interval, std::move(callback));
|
||||
std::make_unique<TimingEvent>(std::move(name), period, interval, callback, callback_param);
|
||||
if (activate)
|
||||
event->Activate();
|
||||
|
||||
|
@ -291,7 +291,7 @@ void RunEvents()
|
|||
event->m_time_since_last_run = 0;
|
||||
|
||||
// The cycles_late is only an indicator, it doesn't modify the cycles to execute.
|
||||
event->m_callback(ticks_to_execute, ticks_late);
|
||||
event->m_callback(event->m_callback_param, ticks_to_execute, ticks_late);
|
||||
if (event->m_active)
|
||||
SortEvent(event);
|
||||
}
|
||||
|
@ -369,9 +369,10 @@ bool DoState(StateWrapper& sw)
|
|||
|
||||
} // namespace TimingEvents
|
||||
|
||||
TimingEvent::TimingEvent(std::string name, TickCount period, TickCount interval, TimingEventCallback callback)
|
||||
: m_downcount(interval), m_time_since_last_run(0), m_period(period), m_interval(interval),
|
||||
m_callback(std::move(callback)), m_name(std::move(name)), m_active(false)
|
||||
TimingEvent::TimingEvent(std::string name, TickCount period, TickCount interval, TimingEventCallback callback,
|
||||
void* callback_param)
|
||||
: m_downcount(interval), m_time_since_last_run(0), m_period(period), m_interval(interval), m_callback(callback),
|
||||
m_callback_param(callback_param), m_name(std::move(name)), m_active(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -448,7 +449,7 @@ void TimingEvent::InvokeEarly(bool force /* = false */)
|
|||
|
||||
m_downcount = pending_ticks + m_interval;
|
||||
m_time_since_last_run -= ticks_to_execute;
|
||||
m_callback(ticks_to_execute, 0);
|
||||
m_callback(m_callback_param, ticks_to_execute, 0);
|
||||
|
||||
// Since we've changed the downcount, we need to re-sort the events.
|
||||
DebugAssert(TimingEvents::s_current_event != this);
|
||||
|
|
|
@ -9,12 +9,13 @@
|
|||
class StateWrapper;
|
||||
|
||||
// Event callback type. Second parameter is the number of cycles the event was executed "late".
|
||||
using TimingEventCallback = std::function<void(TickCount ticks, TickCount ticks_late)>;
|
||||
using TimingEventCallback = void (*)(void* param, TickCount ticks, TickCount ticks_late);
|
||||
|
||||
class TimingEvent
|
||||
{
|
||||
public:
|
||||
TimingEvent(std::string name, TickCount period, TickCount interval, TimingEventCallback callback);
|
||||
TimingEvent(std::string name, TickCount period, TickCount interval, TimingEventCallback callback,
|
||||
void* callback_param);
|
||||
~TimingEvent();
|
||||
|
||||
ALWAYS_INLINE const std::string& GetName() const { return m_name; }
|
||||
|
@ -59,14 +60,16 @@ public:
|
|||
TimingEvent* prev = nullptr;
|
||||
TimingEvent* next = nullptr;
|
||||
|
||||
TimingEventCallback m_callback;
|
||||
void* m_callback_param;
|
||||
|
||||
TickCount m_downcount;
|
||||
TickCount m_time_since_last_run;
|
||||
TickCount m_period;
|
||||
TickCount m_interval;
|
||||
|
||||
TimingEventCallback m_callback;
|
||||
std::string m_name;
|
||||
bool m_active;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
namespace TimingEvents {
|
||||
|
@ -79,7 +82,7 @@ void Shutdown();
|
|||
|
||||
/// Creates a new event.
|
||||
std::unique_ptr<TimingEvent> CreateTimingEvent(std::string name, TickCount period, TickCount interval,
|
||||
TimingEventCallback callback, bool activate);
|
||||
TimingEventCallback callback, void* callback_param, bool activate);
|
||||
|
||||
/// Serialization.
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
@ -90,6 +93,4 @@ void UpdateCPUDowncount();
|
|||
|
||||
TimingEvent** GetHeadEventPtr();
|
||||
|
||||
|
||||
|
||||
} // namespace TimingEventManager
|
||||
} // namespace TimingEvents
|
Loading…
Reference in a new issue