Skip to content

Commit bce8ddd

Browse files
authored
Runahead fixes (#50)
* skip runahead rewind load when limited saving reloads too RewindRunahead only skipped the rewind load when a rollback was coming. with limited saving HandleSavingConfirmedFrame also does a load+resim of the current frame, so the rewind load got overwritten there too. extract RollbackPending and ConfirmedSaveDue so the handlers and RewindRunahead share one firing condition, then skip the rewind load when either is due.
1 parent f45c428 commit bce8ddd

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

GekkoLib/include/session.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ namespace Gekko {
8282

8383
void RewindRunahead();
8484

85+
bool RollbackPending();
86+
87+
bool ConfirmedSaveDue();
88+
8589
void SendSessionHealthCheck();
8690

8791
void SendNetworkHealthCheck();

GekkoLib/src/game_session.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,12 @@ void Gekko::GameSession::NetworkPoll()
221221

222222
void Gekko::GameSession::HandleSavingConfirmedFrame()
223223
{
224-
if (IsLockstepActive() || !_config.limited_saving ||
225-
IsPlayingLocally()) {
224+
if (!ConfirmedSaveDue()) {
226225
return;
227226
}
228227

229228
const Frame confirmed_frame = _sync.GetMinReceivedFrame();
230229
const Frame current = _sync.GetCurrentFrame();
231-
const Frame diff = current - (_last_saved_frame + 1);
232-
233-
if (diff <= _config.input_prediction_window) {
234-
return;
235-
}
236230

237231
assert(_last_saved_frame < confirmed_frame);
238232

@@ -361,18 +355,13 @@ void Gekko::GameSession::HandleRollback()
361355
_sync.IncrementFrame();
362356
}
363357

364-
if (IsLockstepActive() || IsPlayingLocally()) {
358+
if (!RollbackPending()) {
365359
return;
366360
}
367361

368362
current = _sync.GetCurrentFrame();
369363
const Frame min = _sync.GetMinIncorrectFrame();
370364

371-
// dont allow rollbacks starting before the null frame
372-
if (min == GameInput::NULL_FRAME) {
373-
return;
374-
}
375-
376365
const Frame sync_frame = _config.limited_saving ? _last_saved_frame : min - 1;
377366
const Frame frame_to_save = std::min(current - 1, min);
378367

@@ -521,21 +510,39 @@ bool Gekko::GameSession::IsLockstepActive() const
521510
return _config.input_prediction_window == 0;
522511
}
523512

513+
bool Gekko::GameSession::RollbackPending()
514+
{
515+
if (IsLockstepActive() || IsPlayingLocally()) {
516+
return false;
517+
}
518+
519+
return _sync.GetMinIncorrectFrame() != GameInput::NULL_FRAME;
520+
}
521+
522+
bool Gekko::GameSession::ConfirmedSaveDue()
523+
{
524+
if (IsLockstepActive() || !_config.limited_saving || IsPlayingLocally()) {
525+
return false;
526+
}
527+
528+
const Frame diff = _sync.GetCurrentFrame() - (_last_saved_frame + 1);
529+
return diff > _config.input_prediction_window;
530+
}
531+
524532
void Gekko::GameSession::RewindRunahead()
525533
{
526534
if (_runahead_start_frame == GameInput::NULL_FRAME) {
527535
return;
528536
}
529537

530-
// rollback is coming so dont load the state twice.
531-
// its get overwritten anyways
532-
if (_sync.GetMinIncorrectFrame() != GameInput::NULL_FRAME) {
533-
_runahead_start_frame = GameInput::NULL_FRAME;
538+
_runahead_start_frame = GameInput::NULL_FRAME;
539+
540+
// a rollback or confirmed save will load+resim this frame, so dont load twice.
541+
if (RollbackPending() || ConfirmedSaveDue()) {
534542
return;
535543
}
536544

537545
_game_events.AddRunaheadLoadEvent(_storage);
538-
_runahead_start_frame = GameInput::NULL_FRAME;
539546
}
540547

541548
void Gekko::GameSession::HandleRunahead()

0 commit comments

Comments
 (0)