private void InitializeVisualData(GamePresentation presentation) { ClearData(); foreach (var chicken in presentation.Chickens) { var material = chicken.Team == GameTeam.Light ? LightTeamUnitMaterial : DarkTeamUnitMaterial; var currentPosition = chicken.GetCurrentPosition(); var matrix = GetChickenTransformMatrix(chicken); var transform = new MatrixTransform3D(matrix); var position = ConvertEnginePosition(currentPosition.Position); var chickenVisual = new ModelVisual3D { Content = new GeometryModel3D(_chickenGeometry, material) { Transform = transform } }; var billboardVisual = new BillboardTextVisual3D { Text = "(ID)", FontWeight = FontWeights.ExtraBold, FontSize = 9, Foreground = new SolidColorBrush( chicken.Team == GameTeam.Light ? LightTeamCaptionColor : DarkTeamCaptionColor), Background = new SolidColorBrush(Colors.Gray.WithAlpha(128)), BorderBrush = new SolidColorBrush(Colors.Red.WithAlpha(128)), BorderThickness = new Thickness(1) }; var data = new ChickenData( chicken.UniqueId, position, currentPosition.Angle.DegreeValue, chickenVisual, transform, billboardVisual); _chickenDatas.Add(data.Id, data); _chickenVisualToData.Add(chickenVisual, data); this.BoardVisual.Children.Add(chickenVisual); this.BoardVisual.Children.Add(billboardVisual); } }
private void PaintGameNoThreadCheck(GamePresentation presentation) { if (!_chickenDatas.Any()) { InitializeVisualData(presentation); } ////var lightMaxKillCount = //// presentation.Chickens.Where(obj => obj.Team == GameTeam.Light).Max(obj => obj.KillCount); ////var darkMaxKillCount = //// presentation.Chickens.Where(obj => obj.Team == GameTeam.Dark).Max(obj => obj.KillCount); var deadChickenIds = new HashSet <GameObjectId>(_chickenDatas.Keys); foreach (var chicken in presentation.Chickens) { var data = _chickenDatas[chicken.UniqueId]; var currentPosition = chicken.GetCurrentPosition(); data.Position = ConvertEnginePosition(currentPosition.Position); data.BeakAngle = currentPosition.Angle.DegreeValue; data.Transform.Matrix = GetChickenTransformMatrix(chicken); data.BillboardVisual.Position = ConvertEnginePosition( currentPosition.Position, GameConstants.ChickenUnit.BodyCircleRadius / _nominalSizeCoefficient * 1.5); data.BillboardVisual.Text = string.Format( CultureInfo.InvariantCulture, "#{0}: {1}", chicken.UniqueId.GetValueAsString(), chicken.KillCount); data.BillboardVisual.BorderThickness = new Thickness(1, chicken.KillCount + 1, 1, 1); deadChickenIds.Remove(data.Id); } foreach (var deadChickenId in deadChickenIds) { var data = _chickenDatas[deadChickenId]; this.BoardVisual.Children.Remove(data.Visual); this.BoardVisual.Children.Remove(data.BillboardVisual); _chickenDatas.Remove(deadChickenId); _chickenVisualToData.Remove(data.Visual); } var explodedShotIds = new HashSet <GameObjectId>(_shotDatas.Keys); foreach (var shot in presentation.Shots) { var currentPosition = shot.GetCurrentPosition(); var data = _shotDatas.GetValueOrDefault(shot.UniqueId); if (data == null) { var material = shot.OwnerTeam == GameTeam.Light ? LightTeamShotMaterial : DarkTeamShotMaterial; var matrix = GetShotTransformMatrix(shot); var transform = new MatrixTransform3D(matrix); var position = ConvertEnginePosition(currentPosition); var model = new GeometryModel3D(_shotGeometry, material) { Transform = transform }; data = new ShotData(shot.UniqueId, position, model, transform); _shotDatas.Add(data.Id, data); this.ShotsModelGroup.Children.Add(model); } else { var position = ConvertEnginePosition(currentPosition); data.Position = position; data.Transform.Matrix = GetShotTransformMatrix(shot); explodedShotIds.Remove(data.Id); } } foreach (var explodedShotId in explodedShotIds) { var data = _shotDatas[explodedShotId]; this.ShotsModelGroup.Children.Remove(data.Model); _shotDatas.Remove(explodedShotId); } FollowChicken(); }
private void UpdateLastGamePresentation() { var lastGamePresentation = new GamePresentation(this); _lastGamePresentation.Value = lastGamePresentation; }