diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index 9e45a7c387..18e86f11e0 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -70,7 +70,7 @@ EventType* CoreTimingManager::RegisterEvent(const std::string& name, TimedCallba "during Init to avoid breaking save states.", name); - auto info = m_event_types.emplace(name, EventType{callback, nullptr}); + auto info = m_event_types.emplace(name, EventType{std::move(callback), nullptr}); EventType* event_type = &info.first->second; event_type->name = &info.first->first; return event_type; diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h index 68d1fd4fd2..29d636e433 100644 --- a/Source/Core/Core/CoreTiming.h +++ b/Source/Core/Core/CoreTiming.h @@ -23,6 +23,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/Functional.h" #include "Common/HookableEvent.h" #include "Common/SPSCQueue.h" #include "Common/Timer.h" @@ -47,7 +48,8 @@ struct Globals float last_OC_factor_inverted = 0.0f; }; -typedef void (*TimedCallback)(Core::System& system, u64 userdata, s64 cyclesLate); +using TimedCallback = + Common::MoveOnlyFunction; struct EventType { diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index f451be328d..11e0c6f2e7 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -228,29 +228,21 @@ void SerialInterfaceManager::DoState(PointerWrap& p) p.Do(m_si_buffer); } -template -void SerialInterfaceManager::DeviceEventCallback(Core::System& system, u64 userdata, s64 cyclesLate) -{ - const auto& si = system.GetSerialInterface(); - si.m_channel[device_number].device->OnEvent(userdata, cyclesLate); -} - void SerialInterfaceManager::RegisterEvents() { auto& core_timing = m_system.GetCoreTiming(); + m_event_type_change_device = core_timing.RegisterEvent("ChangeSIDevice", ChangeDeviceCallback); m_event_type_tranfer_pending = core_timing.RegisterEvent("SITransferPending", GlobalRunSIBuffer); - constexpr std::array event_callbacks = { - DeviceEventCallback<0>, - DeviceEventCallback<1>, - DeviceEventCallback<2>, - DeviceEventCallback<3>, - }; - for (int i = 0; i < MAX_SI_CHANNELS; ++i) + for (u32 i = 0; i != MAX_SI_CHANNELS; ++i) { + auto& channel = m_channel[i]; m_event_types_device[i] = - core_timing.RegisterEvent(fmt::format("SIEventChannel{}", i), event_callbacks[i]); + core_timing.RegisterEvent(fmt::format("SIEventChannel{}", i), + [&channel](Core::System&, u64 user_data, s64 cycles_late) { + channel.device->OnEvent(user_data, cycles_late); + }); } } diff --git a/Source/Core/Core/HW/SI/SI.h b/Source/Core/Core/HW/SI/SI.h index 8e2e3afe3b..5229bd045f 100644 --- a/Source/Core/Core/HW/SI/SI.h +++ b/Source/Core/Core/HW/SI/SI.h @@ -88,8 +88,6 @@ private: void RunSIBuffer(u64 user_data, s64 cycles_late); static void GlobalRunSIBuffer(Core::System& system, u64 user_data, s64 cycles_late); static void ChangeDeviceCallback(Core::System& system, u64 user_data, s64 cycles_late); - template - static void DeviceEventCallback(Core::System& system, u64 userdata, s64 cyclesLate); // SI Channel Output union USIChannelOut