internal void UpdatePlayerState(PlayerStateData playerState) { if (!isLocalPlayer) { interpolation.PushStateData(playerState); return; } if (history.Count == 0) { return; } // erstmal verwerfen wir alle inputs die bereits vom server authorisiert wurden while (history.Count > 0 && history.Peek().InputTick < playerState.InputTick) { history.Dequeue(); } if (history.Peek().InputTick != playerState.InputTick) { return; } var predictedState = history.Dequeue(); if ((predictedState.StateData.Position - playerState.Position).sqrMagnitude < reconciliationTolerance) { return; } //Debug.Log($"start reconciliation for frame {predictedState.InputTick}"); //Debug.Log($"predicted position: {predictedState.StateData.Position}\nserver position: {playerState.Position}"); // dann setzen wir den Spieler auf den letzten authorisierten Zustand interpolation.CurrentStateData = playerState; playerController.ResetTo(playerState); // dann wenden wir alle noch nicht authorisierten inputs wieder an if (history.Count != 0) { //Debug.Log($"applying {history.Count} inputs..."); var reconciliationInfos = history.ToArray(); foreach (var ri in reconciliationInfos) { //Debug.Log($"applying input {ri.InputTick}: {ri.InputData.MovementAxes}"); playerController.ResetTo(interpolation.CurrentStateData); var psd = playerController.GetNextFrameData(ri.InputData, interpolation.CurrentStateData); interpolation.PushStateData(psd); //Debug.Log($"moved from {interpolation.PreviousStateData.Position} to {interpolation.CurrentStateData.Position}"); } } }
internal void UpdateBulletState(BulletStateData stateData) { if (!isInitialized) { return; } if (!isLocal) { interpolation.PushStateData(stateData); return; } while (history.Count > 0 && history.Peek().InputTick < stateData.InputTick) { history.Dequeue(); } if (history.Count == 0) { return; } if (history.Peek().InputTick != stateData.InputTick) { return; } var predictedState = history.Dequeue(); if ((predictedState.StateData.Position - stateData.Position).sqrMagnitude < reconciliationTolerance) { return; } //Debug.Log($"start reconciliation for frame {predictedState.InputTick}"); //Debug.Log($"predicted position: {predictedState.StateData.Position}\nserver position: {stateData.Position}"); interpolation.CurrentStateData = stateData; var h = history.ToArray(); foreach (var ri in h) { //Debug.Log($"applying input {ri.InputTick}: {ri.InputData.MovementAxes}"); bulletController.ResetTo(interpolation.CurrentStateData); var sd = bulletController.GetNextFrameData(ri.InputData, interpolation.CurrentStateData); interpolation.PushStateData(sd); //Debug.Log($"moved from {interpolation.PreviousStateData.Position} to {interpolation.CurrentStateData.Position}"); } }