TimingEvents: Move interrupt dispatch to end of loop

Saves another iteration.
This commit is contained in:
Stenzek 2024-07-20 13:41:50 +10:00
parent 4f7ddfaae6
commit 9b77a9aff7
No known key found for this signature in database

View file

@ -16,7 +16,7 @@ static void SortEvent(TimingEvent* event);
static void AddActiveEvent(TimingEvent* event); static void AddActiveEvent(TimingEvent* event);
static void RemoveActiveEvent(TimingEvent* event); static void RemoveActiveEvent(TimingEvent* event);
static void SortEvents(); static void SortEvents();
static TimingEvent* FindActiveEvent(const char* name); static TimingEvent* FindActiveEvent(const std::string_view name);
namespace { namespace {
struct TimingEventsState struct TimingEventsState
@ -268,11 +268,11 @@ void TimingEvents::SortEvents()
AddActiveEvent(event); AddActiveEvent(event);
} }
static TimingEvent* TimingEvents::FindActiveEvent(const char* name) static TimingEvent* TimingEvents::FindActiveEvent(const std::string_view name)
{ {
for (TimingEvent* event = s_state.active_events_head; event; event = event->next) for (TimingEvent* event = s_state.active_events_head; event; event = event->next)
{ {
if (event->GetName().compare(name) == 0) if (event->GetName() == name)
return event; return event;
} }
@ -296,9 +296,6 @@ void TimingEvents::RunEvents()
do do
{ {
if (CPU::HasPendingInterrupt())
CPU::DispatchInterrupt();
TickCount pending_ticks = CPU::GetPendingTicks(); TickCount pending_ticks = CPU::GetPendingTicks();
if (pending_ticks >= s_state.active_events_head->GetDowncount()) if (pending_ticks >= s_state.active_events_head->GetDowncount())
{ {
@ -348,6 +345,9 @@ void TimingEvents::RunEvents()
System::FrameDone(); System::FrameDone();
} }
if (CPU::HasPendingInterrupt())
CPU::DispatchInterrupt();
UpdateCPUDowncount(); UpdateCPUDowncount();
} while (CPU::GetPendingTicks() >= CPU::g_state.downcount); } while (CPU::GetPendingTicks() >= CPU::g_state.downcount);
} }
@ -375,7 +375,7 @@ bool TimingEvents::DoState(StateWrapper& sw)
if (sw.HasError()) if (sw.HasError())
return false; return false;
TimingEvent* event = FindActiveEvent(event_name.c_str()); TimingEvent* event = FindActiveEvent(event_name);
if (!event) if (!event)
{ {
WARNING_LOG("Save state has event '{}', but couldn't find this event when loading.", event_name); WARNING_LOG("Save state has event '{}', but couldn't find this event when loading.", event_name);