Пример #1
0
        public void ReportTime(long startClock)
        {
            var currentClock = LunaProfiler.LmpReferenceTime.ElapsedTicks;

            TickTime      = currentClock - startClock;
            DeltaTime     = startClock - LastDeltaTime;
            LastDeltaTime = currentClock;

            if (TickTime < TickMinTime)
            {
                TickMinTime = TickTime;
            }
            if (TickTime > TickMaxTime)
            {
                TickMaxTime = TickTime;
            }

            //Ignore the first delta as it will be incorrect on reset.
            if (DeltaHistory.Count != 0)
            {
                if (DeltaTime < DeltaMinTime)
                {
                    DeltaMinTime = DeltaTime;
                }
                if (DeltaTime > DeltaMaxTime)
                {
                    DeltaMaxTime = DeltaTime;
                }
            }

            TickHistory.Add(TickTime);
            if (TickHistory.Count > 300)
            {
                TickHistory.RemoveAt(0);
            }
            TickAverage  = TickHistory.Sum();
            TickAverage /= TickHistory.Count;

            DeltaHistory.Add(DeltaTime);
            if (DeltaHistory.Count > 300)
            {
                DeltaHistory.RemoveAt(0);
            }
            DeltaAverage  = DeltaHistory.Sum();
            DeltaAverage /= DeltaHistory.Count;
        }
Пример #2
0
        public static void AddState(this GameHistory history, GameState gameState, IDictionary <string, PlayerAction> actions)
        {
            var state = gameState.Convert();

            var stringActions = new Dictionary <string, string?>();
            var latencies     = new Dictionary <string, double?>();

            foreach (var playerId in state.Players.Keys)
            {
                if (actions.TryGetValue(playerId, out var action))
                {
                    stringActions[playerId] = action.Action.ToString().ToLowerInvariant();
                    latencies[playerId]     = action.Latency.TotalSeconds;
                }
                else
                {
                    stringActions[playerId] = null;
                    latencies[playerId]     = null;
                }
            }

            var tickHistory = new TickHistory(state, stringActions, latencies);

            history.Ticks.Add(tickHistory);

            foreach (var(playerId, player) in state.Players)
            {
                if (!history.Summary.Players.TryGetValue(playerId, out var playerSummary))
                {
                    playerSummary      = history.Summary.Players[playerId] = new GamePlayerSummary();
                    playerSummary.Id   = player.Id;
                    playerSummary.Name = player.Name;
                }

                playerSummary.Score = player.Score;
            }
        }