TimingEvents: Remove ticks_late parameter

Since we run events incrementally, it will never be "late" from the
handler's perspective. This has been the case for some time now.
pull/3732/head
Stenzek 5 months ago
parent 53c4176a17
commit 5d92da522b
No known key found for this signature in database

@ -294,7 +294,7 @@ static_assert(sizeof(XA_ADPCMBlockHeader) == 1, "XA-ADPCM block header is one by
} // namespace } // namespace
static TickCount SoftReset(TickCount ticks_late); static TickCount SoftReset();
static const CDImage::SubChannelQ& GetSectorSubQ(u32 lba, const CDImage::SubChannelQ& real_subq); static const CDImage::SubChannelQ& GetSectorSubQ(u32 lba, const CDImage::SubChannelQ& real_subq);
static bool CanReadMedia(); static bool CanReadMedia();
@ -315,7 +315,7 @@ static s16 SaturateVolume(s32 volume);
static void SetInterrupt(Interrupt interrupt); static void SetInterrupt(Interrupt interrupt);
static void SetAsyncInterrupt(Interrupt interrupt); static void SetAsyncInterrupt(Interrupt interrupt);
static void ClearAsyncInterrupt(); static void ClearAsyncInterrupt();
static void DeliverAsyncInterrupt(void*, TickCount ticks, TickCount ticks_late); static void DeliverAsyncInterrupt(void*, TickCount ticks);
static void QueueDeliverAsyncInterrupt(); static void QueueDeliverAsyncInterrupt();
static void SendACKAndStat(); static void SendACKAndStat();
static void SendErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = ERROR_REASON_NOT_READY); static void SendErrorResponse(u8 stat_bits = STAT_ERROR, u8 reason = ERROR_REASON_NOT_READY);
@ -340,18 +340,18 @@ static bool CompleteSeek();
static void BeginCommand(Command command); // also update status register static void BeginCommand(Command command); // also update status register
static void EndCommand(); // also updates status register static void EndCommand(); // also updates status register
static void ExecuteCommand(void*, TickCount ticks, TickCount ticks_late); static void ExecuteCommand(void*, TickCount ticks);
static void ExecuteTestCommand(u8 subcommand); static void ExecuteTestCommand(u8 subcommand);
static void ExecuteCommandSecondResponse(void*, TickCount ticks, TickCount ticks_late); static void ExecuteCommandSecondResponse(void*, TickCount ticks);
static void QueueCommandSecondResponse(Command command, TickCount ticks); static void QueueCommandSecondResponse(Command command, TickCount ticks);
static void ClearCommandSecondResponse(); static void ClearCommandSecondResponse();
static void UpdateCommandEvent(); static void UpdateCommandEvent();
static void ExecuteDrive(void*, TickCount ticks, TickCount ticks_late); static void ExecuteDrive(void*, TickCount ticks);
static void ClearDriveState(); static void ClearDriveState();
static void BeginReading(TickCount ticks_late = 0, bool after_seek = false); static void BeginReading(bool after_seek);
static void BeginPlaying(u8 track, TickCount ticks_late = 0, bool after_seek = false); static void BeginPlaying(u8 track, bool after_seek);
static void DoShellOpenComplete(TickCount ticks_late); static void DoShellOpenComplete();
static void DoSeekComplete(TickCount ticks_late); static void DoSeekComplete();
static void DoStatSecondResponse(); static void DoStatSecondResponse();
static void DoChangeSessionComplete(); static void DoChangeSessionComplete();
static void DoSpinUpComplete(); static void DoSpinUpComplete();
@ -631,7 +631,7 @@ void CDROM::Reset()
SetHoldPosition(0, 0); SetHoldPosition(0, 0);
} }
TickCount CDROM::SoftReset(TickCount ticks_late) TickCount CDROM::SoftReset()
{ {
const bool was_double_speed = s_state.mode.double_speed; const bool was_double_speed = s_state.mode.double_speed;
@ -672,7 +672,7 @@ TickCount CDROM::SoftReset(TickCount ticks_late)
const TickCount speed_change_ticks = was_double_speed ? GetTicksForSpeedChange() : 0; const TickCount speed_change_ticks = was_double_speed ? GetTicksForSpeedChange() : 0;
const TickCount seek_ticks = (s_state.current_lba != 0) ? GetTicksForSeek(0) : 0; const TickCount seek_ticks = (s_state.current_lba != 0) ? GetTicksForSeek(0) : 0;
total_ticks = std::max<TickCount>(speed_change_ticks + seek_ticks, INIT_TICKS) - ticks_late; total_ticks = std::max<TickCount>(speed_change_ticks + seek_ticks, INIT_TICKS);
DEV_LOG("CDROM init total disc ticks = {} (speed change = {}, seek = {})", total_ticks, speed_change_ticks, DEV_LOG("CDROM init total disc ticks = {} (speed change = {}, seek = {})", total_ticks, speed_change_ticks,
seek_ticks); seek_ticks);
@ -693,7 +693,7 @@ TickCount CDROM::SoftReset(TickCount ticks_late)
} }
else else
{ {
total_ticks = INIT_TICKS - ticks_late; total_ticks = INIT_TICKS;
} }
return total_ticks; return total_ticks;
@ -1416,7 +1416,7 @@ void CDROM::QueueDeliverAsyncInterrupt()
const u32 diff = static_cast<u32>(System::GetGlobalTickCounter() - s_state.last_interrupt_time); const u32 diff = static_cast<u32>(System::GetGlobalTickCounter() - s_state.last_interrupt_time);
if (diff >= MINIMUM_INTERRUPT_DELAY) if (diff >= MINIMUM_INTERRUPT_DELAY)
{ {
DeliverAsyncInterrupt(nullptr, 0, 0); DeliverAsyncInterrupt(nullptr, 0);
} }
else else
{ {
@ -1426,7 +1426,7 @@ void CDROM::QueueDeliverAsyncInterrupt()
} }
} }
void CDROM::DeliverAsyncInterrupt(void*, TickCount ticks, TickCount ticks_late) void CDROM::DeliverAsyncInterrupt(void*, TickCount ticks)
{ {
if (HasPendingInterrupt()) if (HasPendingInterrupt())
{ {
@ -1832,7 +1832,7 @@ void CDROM::EndCommand()
UpdateStatusRegister(); UpdateStatusRegister();
} }
void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late) void CDROM::ExecuteCommand(void*, TickCount ticks)
{ {
const CommandInfo& ci = s_command_info[static_cast<u8>(s_state.command)]; const CommandInfo& ci = s_command_info[static_cast<u8>(s_state.command)];
if (s_state.param_fifo.GetSize() < ci.min_parameters || s_state.param_fifo.GetSize() > ci.max_parameters) [[unlikely]] if (s_state.param_fifo.GetSize() < ci.min_parameters || s_state.param_fifo.GetSize() > ci.max_parameters) [[unlikely]]
@ -2084,7 +2084,7 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
} }
else else
{ {
BeginReading(); BeginReading(false);
} }
} }
@ -2114,7 +2114,7 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
} }
else else
{ {
BeginPlaying(track); BeginPlaying(track, false);
} }
} }
@ -2252,7 +2252,7 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)
DEV_COLOR_LOG(StrongOrange, "Init"); DEV_COLOR_LOG(StrongOrange, "Init");
SendACKAndStat(); SendACKAndStat();
const TickCount reset_ticks = SoftReset(ticks_late); const TickCount reset_ticks = SoftReset();
QueueCommandSecondResponse(Command::Init, reset_ticks); QueueCommandSecondResponse(Command::Init, reset_ticks);
EndCommand(); EndCommand();
return; return;
@ -2602,7 +2602,7 @@ void CDROM::ExecuteTestCommand(u8 subcommand)
} }
} }
void CDROM::ExecuteCommandSecondResponse(void*, TickCount ticks, TickCount ticks_late) void CDROM::ExecuteCommandSecondResponse(void*, TickCount ticks)
{ {
switch (s_state.command_second_response) switch (s_state.command_second_response)
{ {
@ -2681,17 +2681,17 @@ void CDROM::UpdateCommandEvent()
} }
} }
void CDROM::ExecuteDrive(void*, TickCount ticks, TickCount ticks_late) void CDROM::ExecuteDrive(void*, TickCount ticks)
{ {
switch (s_state.drive_state) switch (s_state.drive_state)
{ {
case DriveState::ShellOpening: case DriveState::ShellOpening:
DoShellOpenComplete(ticks_late); DoShellOpenComplete();
break; break;
case DriveState::SeekingPhysical: case DriveState::SeekingPhysical:
case DriveState::SeekingLogical: case DriveState::SeekingLogical:
DoSeekComplete(ticks_late); DoSeekComplete();
break; break;
case DriveState::SeekingImplicit: case DriveState::SeekingImplicit:
@ -2759,7 +2759,7 @@ void CDROM::ClearDriveState()
s_state.drive_event.Deactivate(); s_state.drive_event.Deactivate();
} }
void CDROM::BeginReading(TickCount ticks_late /* = 0 */, bool after_seek /* = false */) void CDROM::BeginReading(bool after_seek)
{ {
if (!after_seek && s_state.setloc_pending) if (!after_seek && s_state.setloc_pending)
{ {
@ -2786,7 +2786,7 @@ void CDROM::BeginReading(TickCount ticks_late /* = 0 */, bool after_seek /* = fa
DEBUG_LOG("Starting reading @ LBA {}", s_state.current_lba); DEBUG_LOG("Starting reading @ LBA {}", s_state.current_lba);
const TickCount ticks = GetTicksForRead(); const TickCount ticks = GetTicksForRead();
const TickCount first_sector_ticks = ticks + (after_seek ? 0 : GetTicksForSeek(s_state.current_lba)) - ticks_late; const TickCount first_sector_ticks = ticks + (after_seek ? 0 : GetTicksForSeek(s_state.current_lba));
ClearCommandSecondResponse(); ClearCommandSecondResponse();
ClearAsyncInterrupt(); ClearAsyncInterrupt();
@ -2808,7 +2808,7 @@ void CDROM::BeginReading(TickCount ticks_late /* = 0 */, bool after_seek /* = fa
s_reader.QueueReadSector(s_state.requested_lba); s_reader.QueueReadSector(s_state.requested_lba);
} }
void CDROM::BeginPlaying(u8 track, TickCount ticks_late /* = 0 */, bool after_seek /* = false */) void CDROM::BeginPlaying(u8 track, bool after_seek)
{ {
DEBUG_LOG("Starting playing CDDA track {}", track); DEBUG_LOG("Starting playing CDDA track {}", track);
s_state.play_track_number_bcd = track; s_state.play_track_number_bcd = track;
@ -2835,8 +2835,7 @@ void CDROM::BeginPlaying(u8 track, TickCount ticks_late /* = 0 */, bool after_se
} }
const TickCount ticks = GetTicksForRead(); const TickCount ticks = GetTicksForRead();
const TickCount first_sector_ticks = const TickCount first_sector_ticks = ticks + (after_seek ? 0 : GetTicksForSeek(s_state.current_lba, true));
ticks + (after_seek ? 0 : GetTicksForSeek(s_state.current_lba, true)) - ticks_late;
ClearCommandSecondResponse(); ClearCommandSecondResponse();
ClearAsyncInterrupt(); ClearAsyncInterrupt();
@ -3040,7 +3039,7 @@ void CDROM::EnsureLastSubQValid()
s_state.last_subq = subq; s_state.last_subq = subq;
} }
void CDROM::DoShellOpenComplete(TickCount ticks_late) void CDROM::DoShellOpenComplete()
{ {
// media is now readable (if any) // media is now readable (if any)
ClearDriveState(); ClearDriveState();
@ -3125,7 +3124,7 @@ bool CDROM::CompleteSeek()
return seek_okay; return seek_okay;
} }
void CDROM::DoSeekComplete(TickCount ticks_late) void CDROM::DoSeekComplete()
{ {
const bool logical = (s_state.drive_state == DriveState::SeekingLogical); const bool logical = (s_state.drive_state == DriveState::SeekingLogical);
const bool seek_okay = CompleteSeek(); const bool seek_okay = CompleteSeek();
@ -3139,11 +3138,11 @@ void CDROM::DoSeekComplete(TickCount ticks_late)
// INT2 is not sent on play/read // INT2 is not sent on play/read
if (s_state.read_after_seek) if (s_state.read_after_seek)
{ {
BeginReading(ticks_late, true); BeginReading(true);
} }
else if (s_state.play_after_seek) else if (s_state.play_after_seek)
{ {
BeginPlaying(0, ticks_late, true); BeginPlaying(0, true);
} }
else else
{ {

@ -179,7 +179,7 @@ static bool IsTransferHalted();
static void UpdateIRQ(); static void UpdateIRQ();
static void HaltTransfer(TickCount duration); static void HaltTransfer(TickCount duration);
static void UnhaltTransfer(void*, TickCount ticks, TickCount ticks_late); static void UnhaltTransfer(void*, TickCount ticks);
template<Channel channel> template<Channel channel>
static bool TransferChannel(); static bool TransferChannel();
@ -760,9 +760,9 @@ void DMA::HaltTransfer(TickCount duration)
s_state.unhalt_event.SetIntervalAndSchedule(s_state.halt_ticks_remaining); s_state.unhalt_event.SetIntervalAndSchedule(s_state.halt_ticks_remaining);
} }
void DMA::UnhaltTransfer(void*, TickCount ticks, TickCount ticks_late) void DMA::UnhaltTransfer(void*, TickCount ticks)
{ {
DEBUG_LOG("Resuming DMA after {} ticks, {} ticks late", ticks, -(s_state.halt_ticks_remaining - ticks)); DEBUG_LOG("Resuming DMA after {} ticks", ticks, -(s_state.halt_ticks_remaining - ticks));
s_state.halt_ticks_remaining -= ticks; s_state.halt_ticks_remaining -= ticks;
s_state.unhalt_event.Deactivate(); s_state.unhalt_event.Deactivate();

@ -62,14 +62,12 @@ u16 g_gpu_clut[GPU_CLUT_SIZE];
const GPU::GP0CommandHandlerTable GPU::s_GP0_command_handler_table = GPU::GenerateGP0CommandHandlerTable(); const GPU::GP0CommandHandlerTable GPU::s_GP0_command_handler_table = GPU::GenerateGP0CommandHandlerTable();
static TimingEvent s_crtc_tick_event( static TimingEvent
"GPU CRTC Tick", 1, 1, [](void* param, TickCount ticks, TickCount ticks_late) { g_gpu.CRTCTickEvent(ticks); }, s_crtc_tick_event("GPU CRTC Tick", 1, 1, [](void* param, TickCount ticks) { g_gpu.CRTCTickEvent(ticks); }, nullptr);
nullptr);
static TimingEvent s_command_tick_event( static TimingEvent s_command_tick_event(
"GPU Command Tick", 1, 1, [](void* param, TickCount ticks, TickCount ticks_late) { g_gpu.CommandTickEvent(ticks); }, "GPU Command Tick", 1, 1, [](void* param, TickCount ticks) { g_gpu.CommandTickEvent(ticks); }, nullptr);
nullptr); static TimingEvent
static TimingEvent s_frame_done_event( s_frame_done_event("Frame Done", 1, 1, [](void* param, TickCount ticks) { g_gpu.FrameDoneEvent(ticks); }, nullptr);
"Frame Done", 1, 1, [](void* param, TickCount ticks, TickCount ticks_late) { g_gpu.FrameDoneEvent(ticks); }, nullptr);
GPU::GPU() = default; GPU::GPU() = default;

@ -34,9 +34,9 @@ static constexpr std::array<const char*, NUM_CONTROLLER_AND_CARD_PORTS> s_event_
"Justifier IRQ P5", "Justifier IRQ P6", "Justifier IRQ P7"}}; "Justifier IRQ P5", "Justifier IRQ P6", "Justifier IRQ P7"}};
Justifier::Justifier(u32 index) Justifier::Justifier(u32 index)
: Controller(index), m_irq_event( : Controller(index),
s_event_names[index], 1, 1, m_irq_event(
[](void* param, TickCount, TickCount) { static_cast<Justifier*>(param)->IRQEvent(); }, this) s_event_names[index], 1, 1, [](void* param, TickCount) { static_cast<Justifier*>(param)->IRQEvent(); }, this)
{ {
} }

@ -113,7 +113,7 @@ static void SetScaleMatrix(const u16* values);
static bool DecodeMonoMacroblock(); static bool DecodeMonoMacroblock();
static bool DecodeColoredMacroblock(); static bool DecodeColoredMacroblock();
static void ScheduleBlockCopyOut(TickCount ticks); static void ScheduleBlockCopyOut(TickCount ticks);
static void CopyOutBlock(void* param, TickCount ticks, TickCount ticks_late); static void CopyOutBlock(void* param, TickCount ticks);
static bool DecodeRLE_Old(s16* blk, const u8* qt); static bool DecodeRLE_Old(s16* blk, const u8* qt);
static void IDCT_Old(s16* blk); static void IDCT_Old(s16* blk);
@ -650,7 +650,7 @@ void MDEC::ScheduleBlockCopyOut(TickCount ticks)
s_state.block_copy_out_event.SetIntervalAndSchedule(ticks); s_state.block_copy_out_event.SetIntervalAndSchedule(ticks);
} }
void MDEC::CopyOutBlock(void* param, TickCount ticks, TickCount ticks_late) void MDEC::CopyOutBlock(void* param, TickCount ticks)
{ {
Assert(s_state.state == State::WritingMacroblock); Assert(s_state.state == State::WritingMacroblock);
s_state.block_copy_out_event.Deactivate(); s_state.block_copy_out_event.Deactivate();

@ -35,8 +35,7 @@ static constexpr std::array<std::string_view, NUM_CONTROLLER_AND_CARD_PORTS> s_e
MemoryCard::MemoryCard(u32 index) MemoryCard::MemoryCard(u32 index)
: m_save_event( : m_save_event(
s_event_names[index], GetSaveDelayInTicks(), GetSaveDelayInTicks(), s_event_names[index], GetSaveDelayInTicks(), GetSaveDelayInTicks(),
[](void* param, TickCount ticks, TickCount ticks_late) { static_cast<MemoryCard*>(param)->SaveIfChanged(true); }, [](void* param, TickCount ticks) { static_cast<MemoryCard*>(param)->SaveIfChanged(true); }, this),
this),
m_index(index) m_index(index)
{ {
m_FLAG.no_write_yet = true; m_FLAG.no_write_yet = true;

@ -101,9 +101,9 @@ static constexpr TickCount GetACKTicks(bool memory_card)
static void SoftReset(); static void SoftReset();
static void UpdateJoyStat(); static void UpdateJoyStat();
static void TransferEvent(void*, TickCount ticks, TickCount ticks_late); static void TransferEvent(void*, TickCount ticks);
static void BeginTransfer(); static void BeginTransfer();
static void DoTransfer(TickCount ticks_late); static void DoTransfer();
static void DoACK(); static void DoACK();
static void EndTransfer(); static void EndTransfer();
static void ResetDeviceTransferState(); static void ResetDeviceTransferState();
@ -707,10 +707,10 @@ void Pad::UpdateJoyStat()
s_state.JOY_STAT.TXRDY = !s_state.transmit_buffer_full; s_state.JOY_STAT.TXRDY = !s_state.transmit_buffer_full;
} }
void Pad::TransferEvent(void*, TickCount ticks, TickCount ticks_late) void Pad::TransferEvent(void*, TickCount ticks)
{ {
if (s_state.state == State::Transmitting) if (s_state.state == State::Transmitting)
DoTransfer(ticks_late); DoTransfer();
else else
DoACK(); DoACK();
} }
@ -743,7 +743,7 @@ void Pad::BeginTransfer()
s_state.transfer_event.SetPeriodAndSchedule(GetTransferTicks()); s_state.transfer_event.SetPeriodAndSchedule(GetTransferTicks());
} }
void Pad::DoTransfer(TickCount ticks_late) void Pad::DoTransfer()
{ {
DEBUG_LOG("Transferring slot {}", s_state.JOY_CTRL.SLOT.GetValue()); DEBUG_LOG("Transferring slot {}", s_state.JOY_CTRL.SLOT.GetValue());

@ -356,12 +356,12 @@ static void ReverbWrite(u32 address, s16 data);
static void ProcessReverb(s32 left_in, s32 right_in, s32* left_out, s32* right_out); static void ProcessReverb(s32 left_in, s32 right_in, s32* left_out, s32* right_out);
static void InternalGeneratePendingSamples(); static void InternalGeneratePendingSamples();
static void Execute(void* param, TickCount ticks, TickCount ticks_late); static void Execute(void* param, TickCount ticks);
static void UpdateEventInterval(); static void UpdateEventInterval();
static void ExecuteFIFOWriteToRAM(TickCount& ticks); static void ExecuteFIFOWriteToRAM(TickCount& ticks);
static void ExecuteFIFOReadFromRAM(TickCount& ticks); static void ExecuteFIFOReadFromRAM(TickCount& ticks);
static void ExecuteTransfer(void* param, TickCount ticks, TickCount ticks_late); static void ExecuteTransfer(void* param, TickCount ticks);
static void ManualTransferWrite(u16 value); static void ManualTransferWrite(u16 value);
static void UpdateTransferEvent(); static void UpdateTransferEvent();
static void UpdateDMARequest(); static void UpdateDMARequest();
@ -1403,7 +1403,7 @@ ALWAYS_INLINE_RELEASE void SPU::ExecuteFIFOWriteToRAM(TickCount& ticks)
} }
} }
void SPU::ExecuteTransfer(void* param, TickCount ticks, TickCount ticks_late) void SPU::ExecuteTransfer(void* param, TickCount ticks)
{ {
const RAMTransferMode mode = s_state.SPUCNT.ram_transfer_mode; const RAMTransferMode mode = s_state.SPUCNT.ram_transfer_mode;
DebugAssert(mode != RAMTransferMode::Stopped); DebugAssert(mode != RAMTransferMode::Stopped);
@ -1464,7 +1464,7 @@ void SPU::ManualTransferWrite(u16 value)
{ {
WARNING_LOG("FIFO not empty on manual SPU write, draining to hopefully avoid corruption. Game is silly."); WARNING_LOG("FIFO not empty on manual SPU write, draining to hopefully avoid corruption. Game is silly.");
if (s_state.SPUCNT.ram_transfer_mode != RAMTransferMode::Stopped) if (s_state.SPUCNT.ram_transfer_mode != RAMTransferMode::Stopped)
ExecuteTransfer(nullptr, std::numeric_limits<s32>::max(), 0); ExecuteTransfer(nullptr, std::numeric_limits<s32>::max());
} }
std::memcpy(&s_ram[s_state.transfer_address], &value, sizeof(u16)); std::memcpy(&s_ram[s_state.transfer_address], &value, sizeof(u16));
@ -2377,7 +2377,7 @@ void SPU::ProcessReverb(s32 left_in, s32 right_in, s32* left_out, s32* right_out
#endif #endif
} }
void SPU::Execute(void* param, TickCount ticks, TickCount ticks_late) void SPU::Execute(void* param, TickCount ticks)
{ {
u32 remaining_frames; u32 remaining_frames;
if (g_settings.cpu_overclock_active) if (g_settings.cpu_overclock_active)

@ -67,7 +67,7 @@ struct CounterState
static void UpdateCountingEnabled(CounterState& cs); static void UpdateCountingEnabled(CounterState& cs);
static void CheckForIRQ(u32 index, u32 old_counter); static void CheckForIRQ(u32 index, u32 old_counter);
static void AddSysClkTicks(void*, TickCount sysclk_ticks, TickCount ticks_late); static void AddSysClkTicks(void*, TickCount sysclk_ticks);
static TickCount GetTicksUntilNextInterrupt(); static TickCount GetTicksUntilNextInterrupt();
static void UpdateSysClkEvent(); static void UpdateSysClkEvent();
@ -274,7 +274,7 @@ void Timers::CheckForIRQ(u32 timer, u32 old_counter)
} }
} }
void Timers::AddSysClkTicks(void*, TickCount sysclk_ticks, TickCount ticks_late) void Timers::AddSysClkTicks(void*, TickCount sysclk_ticks)
{ {
sysclk_ticks = System::UnscaleTicksToOverclock(sysclk_ticks, &s_state.sysclk_ticks_carry); sysclk_ticks = System::UnscaleTicksToOverclock(sysclk_ticks, &s_state.sysclk_ticks_carry);

@ -342,9 +342,11 @@ ALWAYS_INLINE_RELEASE void TimingEvents::CommitGlobalTicks(const GlobalTicks new
s_state.current_event = event; s_state.current_event = event;
// Factor late time into the time for the next invocation. // Factor late time into the time for the next invocation.
const TickCount ticks_late = static_cast<TickCount>(s_state.global_tick_counter - event->m_next_run_time);
const TickCount ticks_to_execute = static_cast<TickCount>(s_state.global_tick_counter - event->m_last_run_time); const TickCount ticks_to_execute = static_cast<TickCount>(s_state.global_tick_counter - event->m_last_run_time);
// Shouldn't ever be late due to the min() above.
DebugAssert(static_cast<TickCount>(s_state.global_tick_counter - event->m_next_run_time) == 0);
// Why don't we modify event->m_downcount directly? Because otherwise the event list won't be sorted. // Why don't we modify event->m_downcount directly? Because otherwise the event list won't be sorted.
// Adding the interval may cause this event to have a greater downcount than the next, and a new event // Adding the interval may cause this event to have a greater downcount than the next, and a new event
// may be inserted at the front, despite having a higher downcount than the next. // may be inserted at the front, despite having a higher downcount than the next.
@ -352,7 +354,7 @@ ALWAYS_INLINE_RELEASE void TimingEvents::CommitGlobalTicks(const GlobalTicks new
event->m_last_run_time = s_state.global_tick_counter; event->m_last_run_time = s_state.global_tick_counter;
// The cycles_late is only an indicator, it doesn't modify the cycles to execute. // The cycles_late is only an indicator, it doesn't modify the cycles to execute.
event->m_callback(event->m_callback_param, ticks_to_execute, ticks_late); event->m_callback(event->m_callback_param, ticks_to_execute);
if (event->m_active) if (event->m_active)
{ {
event->m_next_run_time = s_state.current_event_next_run_time; event->m_next_run_time = s_state.current_event_next_run_time;
@ -650,7 +652,7 @@ void TimingEvent::InvokeEarly(bool force /* = false */)
if (s_state.active_events_head == this) if (s_state.active_events_head == this)
UpdateCPUDowncount(); UpdateCPUDowncount();
m_callback(m_callback_param, ticks_to_execute, 0); m_callback(m_callback_param, ticks_to_execute);
} }
void TimingEvent::Activate() void TimingEvent::Activate()

@ -10,7 +10,7 @@
class StateWrapper; class StateWrapper;
// Event callback type. Second parameter is the number of cycles the event was executed "late". // Event callback type. Second parameter is the number of cycles the event was executed "late".
using TimingEventCallback = void (*)(void* param, TickCount ticks, TickCount ticks_late); using TimingEventCallback = void (*)(void* param, TickCount ticks);
class TimingEvent class TimingEvent
{ {

Loading…
Cancel
Save