From 239baaf644ada1caf8d25febfbf23c12b0b163dd Mon Sep 17 00:00:00 2001 From: Dan Knutson <19314778+Giesch@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:26:40 -0600 Subject: [PATCH] hold more inputs based on config --- examples/rollback/Rollback.roc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/examples/rollback/Rollback.roc b/examples/rollback/Rollback.roc index d18cb20..48eb841 100644 --- a/examples/rollback/Rollback.roc +++ b/examples/rollback/Rollback.roc @@ -78,9 +78,6 @@ RecordedWorld : { rollbackLog : List RollbackEvent, } -## a player input and the simulation frame it was polled on -InputTick : { tick : U64, input : Input } - ## the record of what happened on a previous simulation frame Snapshot : { ## the simulation frame this occurred on @@ -231,10 +228,13 @@ updateRemoteInputs = \world, inbox -> newMessages = List.map inbox \peerMessage -> peerMessage.message minSyncTick = Num.min world.syncTick world.remoteSyncTick + threshold = + configInputAge = Num.max world.config.maxRollbackTicks world.config.tickAdvantageLimit + Num.min minSyncTick (world.tick - Num.toU64 configInputAge) world.remoteMessages |> NonEmptyList.appendAll newMessages - |> NonEmptyList.dropNonLastIf \msg -> msg.lastTick < Num.toI64 minSyncTick + |> NonEmptyList.dropNonLastIf \msg -> msg.lastTick < Num.toI64 threshold { world & remoteMessages } @@ -293,11 +293,9 @@ messageIncludesTick = \msg, tick -> findMisprediction : RecordedWorld, (U64, U64) -> Result U64 [NotFound] findMisprediction = \{ snapshots, remoteMessages }, (begin, end) -> - findMatch : Snapshot -> Result InputTick [NotFound] + findMatch : Snapshot -> Result FrameMessage [NotFound] findMatch = \snap -> - remoteMessages - |> NonEmptyList.findLast \msg -> messageIncludesTick msg snap.tick - |> Result.map \msg -> { tick: snap.tick, input: msg.input } + NonEmptyList.findLast remoteMessages \msg -> messageIncludesTick msg snap.tick misprediction : Result Snapshot [NotFound] misprediction =