Example #1
0
        public bool IsPredictionCorrect(SnapshotWithLastInputId correctServerSnapshot, ushort playerEntityId)
        {
            PredictedSnapshot predictedSnapshot = predictedSnapshotsStorage
                                                  .GetByInputId(correctServerSnapshot.lastProcessedInputId);

            if (predictedSnapshot == null)
            {
                string mes = $"Не найдено предсказанное состояние. lastProcessedInputId = {correctServerSnapshot.lastProcessedInputId}";
                throw new Exception(mes);
            }

            bool timeIsSame = correctServerSnapshot.lastProcessedInputId == predictedSnapshot.lastInputId;

            if (!timeIsSame)
            {
                string message = "Время снимков не совпадает. " +
                                 $" inputId тика с сервера = {correctServerSnapshot.lastProcessedInputId} " +
                                 $" inputId предсказанного тика = {predictedSnapshot.lastInputId}";
                throw new ArgumentException(message);
            }

            bool isPredictionCorrect = playerEntityComparer
                                       .IsSame(predictedSnapshot, correctServerSnapshot, playerEntityId);

            return(isPredictionCorrect);
        }
        public void Initialize()
        {
            DateTime          now               = DateTime.UtcNow;
            uint              lastInputId       = 0;
            PredictedSnapshot predictedSnapshot = new PredictedSnapshot(now, lastInputId, 0);

            predictedSnapshotsStorage.PutPredicted(predictedSnapshot);
        }
        public void Cleanup()
        {
            Snapshot          snapshot          = snapshotFactory.Create();
            DateTime          now               = DateTime.UtcNow;
            uint              lastInputId       = lastInputIdStorage.GetLastInputId();
            float             deltaTimeSec      = Time.deltaTime;
            PredictedSnapshot predictedSnapshot = new PredictedSnapshot(now, lastInputId, deltaTimeSec);

            predictedSnapshot.Modify(snapshot);
            predictedSnapshotsStorage.PutPredicted(predictedSnapshot);
        }
Example #4
0
 public void PutPredicted(PredictedSnapshot predictedSnapshot)
 {
     if (!history.ContainsKey(predictedSnapshot.lastInputId))
     {
         history.Add(predictedSnapshot.lastInputId, predictedSnapshot);
     }
     else
     {
         log.Error($"Игровое состояние с таким lastInputId уже есть. time = {predictedSnapshot.lastInputId}");
     }
 }
Example #5
0
 public void PutCorrect(PredictedSnapshot predictedSnapshot)
 {
     log.Debug("Замена плохо предсказанного тика");
     if (history.ContainsKey(predictedSnapshot.lastInputId))
     {
         history.Remove(predictedSnapshot.lastInputId);
         history[predictedSnapshot.lastInputId] = predictedSnapshot;
     }
     else
     {
         throw new Exception("В истории нет снимка с таким lastInputId.");
     }
 }
Example #6
0
        private void ReplaceWrongSnapshot(SnapshotWithLastInputId correctServerSnapshot)
        {
            PredictedSnapshot wrongSnapshot = predictedSnapshotsStorage
                                              .GetByInputId(correctServerSnapshot.lastProcessedInputId);

            //изменение ошибочного снимка
            // ReSharper disable once PossibleNullReferenceException
            wrongSnapshot.Clear();
            wrongSnapshot.Modify(correctServerSnapshot);

            //todo это можно не делать
            predictedSnapshotsStorage.PutCorrect(wrongSnapshot);
        }