TimingEvents: Don't defer frame done callback

This commit is contained in:
Stenzek 2024-08-19 19:41:14 +10:00
parent 55bcf7261f
commit fefcfc906d
No known key found for this signature in database
6 changed files with 26 additions and 25 deletions

View file

@ -2019,10 +2019,8 @@ bool CPU::UpdateDebugDispatcherFlag()
void CPU::ExitExecution() void CPU::ExitExecution()
{ {
// can't exit while running events without messing things up // can't exit while running events without messing things up
if (TimingEvents::IsRunningEvents()) DebugAssert(!TimingEvents::IsRunningEvents());
TimingEvents::SetFrameDone(); fastjmp_jmp(&s_jmp_buf, 1);
else
fastjmp_jmp(&s_jmp_buf, 1);
} }
bool CPU::HasAnyBreakpoints() bool CPU::HasAnyBreakpoints()

View file

@ -977,6 +977,7 @@ void GPU::CRTCTickEvent(TickCount ticks)
Timers::AddTicks(HBLANK_TIMER_INDEX, static_cast<TickCount>(hblank_timer_ticks)); Timers::AddTicks(HBLANK_TIMER_INDEX, static_cast<TickCount>(hblank_timer_ticks));
} }
bool frame_done = false;
while (lines_to_draw > 0) while (lines_to_draw > 0)
{ {
const u32 lines_to_draw_this_loop = const u32 lines_to_draw_this_loop =
@ -1007,7 +1008,7 @@ void GPU::CRTCTickEvent(TickCount ticks)
// TODO: move present in here I guess // TODO: move present in here I guess
FlushRender(); FlushRender();
UpdateDisplay(); UpdateDisplay();
TimingEvents::SetFrameDone(); frame_done = true;
// switch fields early. this is needed so we draw to the correct one. // switch fields early. this is needed so we draw to the correct one.
if (m_GPUSTAT.InInterleaved480iMode()) if (m_GPUSTAT.InInterleaved480iMode())
@ -1068,6 +1069,9 @@ void GPU::CRTCTickEvent(TickCount ticks)
} }
UpdateCRTCTickEvent(); UpdateCRTCTickEvent();
if (frame_done)
System::FrameDone();
} }
void GPU::CommandTickEvent(TickCount ticks) void GPU::CommandTickEvent(TickCount ticks)

View file

@ -203,6 +203,9 @@ static u32 CompressAndWriteStateData(std::FILE* fp, std::span<const u8> src, Sav
u32* header_type, Error* error); u32* header_type, Error* error);
static bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display, bool is_memory_state); static bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display, bool is_memory_state);
static bool IsExecutionInterrupted();
static void ExitExecution();
static void SetRewinding(bool enabled); static void SetRewinding(bool enabled);
static bool SaveRewindState(); static bool SaveRewindState();
static void DoRewind(); static void DoRewind();
@ -559,6 +562,12 @@ bool System::IsExecutionInterrupted()
return s_state != State::Running || s_system_interrupted; return s_state != State::Running || s_system_interrupted;
} }
void System::ExitExecution()
{
TimingEvents::CancelRunningEvent();
CPU::ExitExecution();
}
bool System::IsPaused() bool System::IsPaused()
{ {
return s_state == State::Paused; return s_state == State::Paused;
@ -2043,7 +2052,7 @@ void System::FrameDone()
if (IsExecutionInterrupted()) if (IsExecutionInterrupted())
{ {
s_system_interrupted = false; s_system_interrupted = false;
CPU::ExitExecution(); ExitExecution();
return; return;
} }
} }
@ -2154,7 +2163,7 @@ void System::FrameDone()
if (IsExecutionInterrupted()) if (IsExecutionInterrupted())
{ {
s_system_interrupted = false; s_system_interrupted = false;
CPU::ExitExecution(); ExitExecution();
return; return;
} }
} }

View file

@ -147,7 +147,6 @@ std::string GetInputProfilePath(std::string_view name);
State GetState(); State GetState();
void SetState(State new_state); void SetState(State new_state);
bool IsRunning(); bool IsRunning();
bool IsExecutionInterrupted();
bool IsPaused(); bool IsPaused();
bool IsShutdown(); bool IsShutdown();
bool IsValid(); bool IsValid();

View file

@ -32,7 +32,6 @@ struct TimingEventsState
TimingEvent* active_events_tail = nullptr; TimingEvent* active_events_tail = nullptr;
TimingEvent* current_event = nullptr; TimingEvent* current_event = nullptr;
u32 active_event_count = 0; u32 active_event_count = 0;
bool frame_done = false;
GlobalTicks current_event_next_run_time = 0; GlobalTicks current_event_next_run_time = 0;
GlobalTicks global_tick_counter = 0; GlobalTicks global_tick_counter = 0;
GlobalTicks event_run_tick_counter = 0; GlobalTicks event_run_tick_counter = 0;
@ -305,20 +304,19 @@ bool TimingEvents::IsRunningEvents()
return (s_state.current_event != nullptr); return (s_state.current_event != nullptr);
} }
void TimingEvents::SetFrameDone()
{
s_state.frame_done = true;
CPU::g_state.downcount = 0;
}
void TimingEvents::CancelRunningEvent() void TimingEvents::CancelRunningEvent()
{ {
if (!s_state.current_event) TimingEvent* const event = s_state.current_event;
if (!event)
return; return;
// Might need to sort it, since we're bailing out. // Might need to sort it, since we're bailing out.
if (s_state.current_event->IsActive()) if (event->IsActive())
SortEvent(s_state.current_event); {
event->m_next_run_time = s_state.current_event_next_run_time;
SortEvent(event);
}
s_state.current_event = nullptr; s_state.current_event = nullptr;
} }
@ -375,12 +373,6 @@ void TimingEvents::RunEvents()
CommitGlobalTicks(new_global_ticks); CommitGlobalTicks(new_global_ticks);
} }
if (s_state.frame_done)
{
s_state.frame_done = false;
System::FrameDone();
}
if (CPU::HasPendingInterrupt()) if (CPU::HasPendingInterrupt())
CPU::DispatchInterrupt(); CPU::DispatchInterrupt();

View file

@ -86,7 +86,6 @@ void Shutdown();
bool DoState(StateWrapper& sw); bool DoState(StateWrapper& sw);
bool IsRunningEvents(); bool IsRunningEvents();
void SetFrameDone();
void CancelRunningEvent(); void CancelRunningEvent();
void RunEvents(); void RunEvents();
void CommitLeftoverTicks(); void CommitLeftoverTicks();