Skip to content

Commit 1c9b804

Browse files
committed
Command prediction halt fixes
1 parent cf3f591 commit 1c9b804

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

Runtime/Code/Player/Character/NetworkedMovement/AirshipMovementManager.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ public void AuthServerCaptureSnapshot(double time, bool replay)
378378
// get snapshot to send to clients
379379
var state = this.movementSystem.GetCurrentState(this.lastProcessedCommandNumber,
380380
time);
381-
// Todo: expose state history for lag compensation use
382381
this.stateHistory.Add(time, state);
383382
Debug.Log("Processing commands up to " + this.lastProcessedCommandNumber + " resulted in " + state);
384383

@@ -409,31 +408,21 @@ public void NonAuthClientTick(double time, bool replay)
409408
{
410409
// Get the command that we used at this tick previously
411410
var command = this.inputHistory.GetExact(time);
412-
// If we can't find a command, return since that means we just won't process an input.
413-
if (command == null) return;
414411
// Process the command again like before, but pass replay into the network system so that
415412
// it doesn't replay effects or animations, etc.
416-
this.movementSystem.Tick(command, replay);
413+
this.movementSystem.Tick(command, true);
417414
return;
418415
}
419416

420-
// Before we start our tick update, make sure our current predicted state is the most correct it can be.
421-
// if (this.clientLastConfirmedState != null)
422-
// {
423-
// this.ReconcileInputHistory(this.clientLastConfirmedState);
424-
// // We set this to null so that we don't re-reconcile on ticks where there's no new information
425-
// // to base our prediction off of.
426-
// this.clientLastConfirmedState = null;
427-
// }
428-
429417
// If the prediction is paused, we still tick the movement system, but we include no command
430418
// for the tick. We want to wait for our current set of commands to be confirmed before
431-
// we start predicting again, so it's important that we do not add anything else to
432-
// inputHistory.
419+
// we start predicting again, so it's important that we do not continue processing new commands
420+
// and incrementing our commandNumber.
433421
if (this.clientPausePrediction)
434422
{
435423
this.movementSystem.GetCommand(this.clientCommandNumber, time); // We tick GetCommand to clear any input, but we don't use it
436424
this.movementSystem.Tick(null, false);
425+
this.inputHistory.Add(time, null);
437426
return;
438427
}
439428

@@ -485,14 +474,6 @@ public void NonAuthClientCaptureSnapshot(double time, bool replay)
485474
}
486475
}
487476

488-
// If prediction is disabled, we are waiting for our current stateHistory to be confirmed
489-
// by the server, so we tick the networked command system, but we don't store the state.
490-
if (this.clientPausePrediction)
491-
{
492-
this.movementSystem.GetCurrentState(clientCommandNumber, time);
493-
return;
494-
}
495-
496477
// Store the current physics state for prediction
497478
var state = this.movementSystem.GetCurrentState(clientCommandNumber, time);
498479
this.stateHistory.Add(time, state);
@@ -714,7 +695,6 @@ private void ReconcileInputHistory(PerformResimulate resimulate, State state)
714695
}
715696
}
716697

717-
// TODO: we somehow hit this case early on. It checked lastProcesssed = 5 against lastProcessed = 2. Weird.
718698
if (clientPredictedState == null)
719699
{
720700
// This should never happen since our checks above confirm that our command should be in our history.
@@ -789,6 +769,7 @@ private void ClientReceiveSnapshot(State state)
789769
// Reconcile when this callback is executed. Use the last confirmed state received,
790770
// (since more could come in from the network while we are waiting for the callback)
791771
this.ReconcileInputHistory(resimulate, this.clientLastConfirmedState);
772+
this.clientLastConfirmedState = null;
792773
});
793774
}
794775
// We received a new state update before we were able to reconcile, just update the stored
@@ -827,6 +808,8 @@ private void ServerReceiveInputCommand(Input[] commands)
827808
Debug.Log("Server received command " + command.commandNumber);
828809
// This should only occur if the server is authoritative.
829810
if (!serverAuth) continue;
811+
812+
if (command == null) continue;
830813

831814
if (this.serverCommandBuffer.TryGetValue(command.commandNumber, out Input existingInput))
832815
{

0 commit comments

Comments
 (0)