Skip to content

Commit

Permalink
clear input earlier when correct to protect overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
RevenantX committed Jan 27, 2025
1 parent 080ec66 commit 3d0ff4e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions LiteEntitySystem/ServerEntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ public unsafe DeserializeResult Deserialize(NetPlayer player, ReadOnlySpan<byte>
bool correctInput = player.State == NetPlayerState.WaitingForFirstInput ||
Utils.SequenceDiff(inputInfo.Tick, player.LastReceivedTick) > 0;

if (inData.Length == 0)
//remove oldest input if overflow
int removedTick = player.AvailableInput.Count == MaxStoredInputs && correctInput
? player.AvailableInput.ExtractMin().Tick
: -1;

if (correctInput && inData.Length == 0)
{
//empty input when no controllers
player.AvailableInput.Add(inputInfo, inputInfo.Tick);
Expand Down Expand Up @@ -350,10 +355,7 @@ public unsafe DeserializeResult Deserialize(NetPlayer player, ReadOnlySpan<byte>
clientTick++;


//remove oldest input if overflow
int removedTick = player.AvailableInput.Count == MaxStoredInputs
? player.AvailableInput.ExtractMin().Tick
: -1;


//read input
foreach (var controller in GetEntities<HumanControllerLogic>())
Expand Down

0 comments on commit 3d0ff4e

Please sign in to comment.