Merge pull request #14517 from jordan-woyak/event-functor

CoreTiming: Change TimedCallback to a Common::MoveOnlyFunction.
This commit is contained in:
JMC47 2026-03-28 16:19:28 -04:00 committed by GitHub
commit 67f1afeb74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 19 deletions

View File

@ -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;

View File

@ -23,6 +23,7 @@
#include <vector>
#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<void(Core::System& system, u64 userdata, s64 cyclesLate)>;
struct EventType
{

View File

@ -228,29 +228,21 @@ void SerialInterfaceManager::DoState(PointerWrap& p)
p.Do(m_si_buffer);
}
template <int device_number>
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<CoreTiming::TimedCallback, MAX_SI_CHANNELS> 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);
});
}
}

View File

@ -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 <int device_number>
static void DeviceEventCallback(Core::System& system, u64 userdata, s64 cyclesLate);
// SI Channel Output
union USIChannelOut