Skip to content

Commit e1a5dc3

Browse files
committed
Make the spectator behaviour mimic a latch. the latch opens when filled and only closes(pauses) when the buffer is empty, then fills up again.
1 parent ad4b516 commit e1a5dc3

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

GekkoLib/src/spectator_session.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ void Gekko::SpectatorSession::Init(GekkoConfig* config)
2828

2929
// setup game event system
3030
_game_events.Init(_config.input_size * _config.num_players);
31+
32+
// start paused so the buffer fills before playback begins
33+
_delay_spectator = (_config.spectator_delay > 0);
3134
}
3235

3336
void Gekko::SpectatorSession::SetLocalDelay(i32 player, u8 delay)
@@ -167,7 +170,9 @@ bool Gekko::SpectatorSession::AllActorsValid()
167170

168171
// if none returned that the session is ready!
169172
_msg.session_events.AddSessionStartedEvent();
170-
173+
if (_config.spectator_delay > 0) {
174+
_msg.session_events.AddSpectatorPausedEvent();
175+
}
171176
_started = true;
172177

173178
return true;
@@ -226,14 +231,11 @@ bool Gekko::SpectatorSession::ShouldDelaySpectator()
226231
return true;
227232
}
228233

229-
// check every 600 frames (10 seconds at 60 fps) whether it should add delay.
230-
if (current % 600 == 0) {
231-
_delay_spectator = diff < delay;
232-
233-
if (_delay_spectator) {
234-
_msg.session_events.AddSpectatorPausedEvent();
235-
return true;
236-
}
234+
// Re-pause only when the buffer is completely exhausted
235+
if (diff == 0) {
236+
_delay_spectator = true;
237+
_msg.session_events.AddSpectatorPausedEvent();
238+
return true;
237239
}
238240

239241
return false;

0 commit comments

Comments
 (0)