Esempio n. 1
0
 public void GetSnapshots(float matchTime,
                          out SnapshotWithTime s0, out SnapshotWithTime s1,
                          out SnapshotWithTime s2, out SnapshotWithTime s3)
 {
     lock (lockObj)
     {
         history.GetSnapshots(matchTime, out s0, out s1, out s2, out s3);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Возвращает снимки по такому принципу:
        /// s0.tickTime < s1.tickTime < matchTime <= s2.tickTime < s3.tickTime
        /// </summary>
        /// <exception cref="Exception"></exception>
        public static void GetSnapshots(this SortedDictionary <int, SnapshotWithLastInputId> history, float matchTime,
                                        out SnapshotWithTime s0, out SnapshotWithTime s1,
                                        out SnapshotWithTime s2, out SnapshotWithTime s3)
        {
            int?s2TickNumber = GetTickNumber(history, matchTime);

            //Нет тика с нужным временем
            if (s2TickNumber == null)
            {
                //Смещение времени
                var firstSavedGs = history[history.Keys.Min()];
                if (matchTime < firstSavedGs.tickTime)
                {
                    //ещё нет тиков с таким большим временем
                    //время придётся сдвинуть назад
                    throw new MatchTimeIsTooShort();
                }
                else
                {
                    //запрашиваемое время слишком маленькое.
                    //есть тики с временем современным временем
                    throw new MatchTimeIsTooLong();
                }
            }

            int?s3TickNumber = GetClosetTickNumber(history, s2TickNumber.Value, TimeShift.Later);

            if (s3TickNumber == null)
            {
                string message = $"Не хватает кадров для интерполяции. Нужно сместить время старта матча назад. " +
                                 $"p2TickNumber = {s2TickNumber.Value} " +
                                 $"p2TickTime = {history[s2TickNumber.Value].tickTime} " +
                                 $"matchTime = {matchTime}";
                throw new Exception(message);
            }

            int?s1TickNumber = history.GetClosetTickNumber(s2TickNumber.Value, TimeShift.Earlier);

            if (s1TickNumber == null)
            {
                throw new Exception("p1TickNumber == null");
            }

            int?s0TickNumber = history.GetClosetTickNumber(s1TickNumber.Value, TimeShift.Earlier);

            if (s0TickNumber == null)
            {
                throw new Exception("p0TickNumber == null");
            }

            s0 = history[s0TickNumber.Value];
            s1 = history[s1TickNumber.Value];
            s2 = history[s2TickNumber.Value];
            s3 = history[s3TickNumber.Value];
        }
        public void Execute()
        {
            if (matchStartTime == null)
            {
                matchStartTime = tickStartTimeStorage.GetTickStartTime();
                log.Info($"Установка времени старта матча {matchStartTime}");
            }

            float            matchTime        = (float)(tickStartTimeStorage.GetTickStartTime() - matchStartTime.Value).TotalSeconds;
            int              tickNumber       = serverSnapshotHistory.GetLastTickNumber() + 1;
            var              snapshot         = snapshotFactory.Create();
            SnapshotWithTime snapshotWithTime = new SnapshotWithTime(tickNumber, matchTime);

            snapshotWithTime.Modify(snapshot);
            serverSnapshotHistory.Add(snapshotWithTime);
        }
Esempio n. 4
0
 public void SetActualGameState(SnapshotWithTime gameState)
 {
     actualState = gameState;
 }