Ejemplo n.º 1
0
        public void UpdatePlayer(Data.PlayerInfo player, DemoData demo)
        {
            var isSpectator = player.State.Team <= DemoInfo.Team.Spectate;

            if (isSpectator)
            {
                return;
            }

            var renderInfo = GetOrCreateRenderInfo(player.EntityID);
            var playerPos  = demo.WorldSpaceToMinimapSpace(new System.Windows.Vector(player.Position.PositionX, player.Position.PositionY));

            var selected    = SelectedPlayers.Contains(player.EntityID);
            var team        = player.State.Team;
            var fillColor   = GetFillColor(selected, team);
            var strokeColor = GetStrokeColor(selected, team);

            if (player.State.IsAlive)
            {
                renderInfo.PlayerPos.Visibility   = Visibility.Visible;
                renderInfo.PlayerSight.Visibility = Visibility.Visible;
                renderInfo.DeathPos.Visibility    = Visibility.Hidden;

                renderInfo.PlayerPos.Fill   = fillColor;
                renderInfo.PlayerPos.Stroke = strokeColor;

                Canvas.SetLeft(renderInfo.PlayerPos, playerPos.X - 15 / 2);
                Canvas.SetTop(renderInfo.PlayerPos, playerPos.Y - 15 / 2);

                var left   = playerPos + CreateVectorFromRotation(128, player.Position.ViewDirectionX - 45f);
                var right  = playerPos + CreateVectorFromRotation(128, player.Position.ViewDirectionX + 45f);
                var center = (left + right) / 2;

                renderInfo.playerSightBrush.StartPoint = new Point(playerPos.X, playerPos.Y);
                renderInfo.playerSightBrush.EndPoint   = new Point(center.X, center.Y);

                renderInfo.PlayerSight.Points[0] = new Point(playerPos.X, playerPos.Y);
                renderInfo.PlayerSight.Points[1] = new Point(left.X, left.Y);
                renderInfo.PlayerSight.Points[2] = new Point(right.X, right.Y);
            }
            else
            {
                renderInfo.PlayerPos.Visibility   = Visibility.Hidden;
                renderInfo.PlayerSight.Visibility = Visibility.Hidden;
                renderInfo.DeathPos.Visibility    = Visibility.Visible;

                renderInfo.DeathPos.Fill   = fillColor;
                renderInfo.DeathPos.Stroke = strokeColor;

                Canvas.SetLeft(renderInfo.DeathPos, playerPos.X);
                Canvas.SetTop(renderInfo.DeathPos, playerPos.Y);
            }
        }
Ejemplo n.º 2
0
        public HeatmapWindow(CancellationTokenSource cts, DemoData demo, HashSet <int> selectedPlayers, int selectionStart, int selectionEnd, int radius)
        {
            InitializeComponent();

            this.demo            = demo;
            this.selectedPlayers = selectedPlayers;
            this.selectionStart  = selectionStart;
            this.selectionEnd    = selectionEnd;

            minimapImage.Source = Assets.GetMinimap(demo.MapName);

            _cts  = cts;
            _ct   = cts.Token;
            _task = Task.Run(() =>
            {
                var counter = 0;

                using (var heatmap = new Heatmap(1024, 1024))
                    using (var stroke = new HeatmapStamp(radius))
                    {
                        for (int i = selectionStart; i <= selectionEnd; i++)
                        {
                            _ct.ThrowIfCancellationRequested();

                            foreach (var player in demo.ReadPlayerInfos(i))
                            {
                                if (!selectedPlayers.Contains(player.EntityID))
                                {
                                    continue;
                                }

                                if (player.State.Team == DemoInfo.Team.Spectate)
                                {
                                    continue;
                                }

                                if (!player.State.IsAlive)
                                {
                                    continue;
                                }

                                var realPos = demo.WorldSpaceToMinimapSpace(new Vector(player.Position.PositionX, player.Position.PositionY));

                                heatmap.AddPoint((int)realPos.X, (int)realPos.Y, stroke);
                            }

                            if ((++counter & 0xF) == 0)
                            {
                                var percentage = (double)(i - selectionStart) / (selectionEnd - selectionStart);

                                Dispatcher.Invoke(() =>
                                {
                                    progressBar.Value = percentage;
                                });
                            }
                        }

                        Dispatcher.Invoke(() =>
                        {
                            heatmapImage.Source = heatmap.CreateHeatmap();
                        });
                    }
            }, _ct);
        }