private string ExtractBoatStatisticString(ReplayBoat b, IViewPort target, string name, DateTime time) { string speedString = name + ": "; speedString = speedString + string.Format("{0:0.##}", b.TotalStatistics.GetValue <float>(name, time, target.StatisticUnitType)); if (target.StatisticUnitType == StatisticUnitType.metric) { speedString = speedString + " " + b.TotalStatistics.GetStatisticMetricUnit(typeof(float), name); } else if (target.StatisticUnitType == StatisticUnitType.standard) { speedString = speedString + " " + b.TotalStatistics.GetStatisticStandardUnit(typeof(float), name); } return(speedString); }
private new void LoadBoats() { //LoadBouys(); _boats = new List <ReplayBoat>(); for (int i = 0; i < _race.Boats.Count; i++) { Boat r = _race.Boats[i]; ReplayBoat b = ReplayBoat.FromBoat(ref r /*, new Notify(this.UpdateStatistics)*/); _race.Boats[i] = r; //b.LoadResources(_device, _content,_race.UtcReplayStart); _boats.Add(b); } //foreach (AmphibianSoftware.VisualSail.Library.Bouy b in _bouys) //{ //b.LoadResources(_device, _content); //} //_skyTexture = LoadAndScaleTexture(ContentHelper.ContentPath + "average_day.jpg", _device); //_mouseTexture = _content.Load<Texture2D>(ContentHelper.ContentPath + "mouse"); //_mouseLeftTexture = _content.Load<Texture2D>(ContentHelper.ContentPath + "mouse-left"); //_mouseRightTexture = _content.Load<Texture2D>(ContentHelper.ContentPath + "mouse-right"); //_lakeTextureEffect = new BasicEffect(_device, null); //if (!File.Exists(ContentHelper.ContentPath + SatelliteImageryHelper.GetFileName(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West))) //{ // try // { // string lakeFile = SatelliteImageryHelper.GetSatelliteImage(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West, (int)_race.Lake.WidthInMeters / 10, (int)_race.Lake.HeightInMeters / 10); // FileInfo fi = new FileInfo(lakeFile); // fi.MoveTo(ContentHelper.ContentPath + SatelliteImageryHelper.GetFileName(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West)); // } // catch //(Exception e) // { // } //} //try //{ // _lakeTexture = LoadAndScaleTexture(ContentHelper.ContentPath + SatelliteImageryHelper.GetFileName(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West), _device); // //_lakeTexture = Texture2D.FromFile(device, ContentHelper.ContentPath + SatelliteImageryHelper.GetFileName(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West)); // //_lakeTexture = content.Load<Texture2D>(ContentHelper.ContentPath + SatelliteImageryHelper.GetFileName(_race.Lake.North, _race.Lake.South, _race.Lake.East, _race.Lake.West)); // _lakeTextureEffect.Texture = _lakeTexture; // _lakeTextureEffect.TextureEnabled = true; // _lakeTextureAvailible = true; // //lakeTextureEffect.FogEnabled = true; // //lakeTextureEffect.FogColor = Color.White.ToVector3(); // //lakeTextureEffect.FogStart = Camera.FarClipDistance - 300; // //lakeTextureEffect.FogEnd = Camera.FarClipDistance; // //MessageBox.Show("Loaded lake texture:"+_lakeTexture.Width+"x"+_lakeTexture.Height); //} //catch(Exception /*e*/) //{ // //MessageBox.Show("Failed to load area texture." + e.Message + ":" + e.StackTrace); // _lakeTextureAvailible = false; //} //_skyBoxEffect = new BasicEffect(_device, null); //_skyBoxEffect.Texture = _skyTexture; //_skyBoxEffect.TextureEnabled = true; //_skyBoxEffect.FogEnabled = true; //_skyBoxEffect.FogColor = Color.White.ToVector3(); //_skyBoxEffect.FogStart = Camera.FarClipDistance - 300; //_skyBoxEffect.FogEnd = Camera.FarClipDistance; //water = new BasicEffect(device, null); //water.TextureEnabled = true; //water.Alpha = 0.5f; //water.Texture = waterTexture; //effect = new BasicEffect(device, null); //effect.EnableDefaultLighting(); //_instruments = new BasicEffect(_device, null); //_instruments.VertexColorEnabled = true; //text = new BasicEffect(device, null); //_font = _content.Load<SpriteFont>(ContentHelper.ContentPath + "tahoma"); //_batch = new SpriteBatch(_device); //_line = new PrimitiveLine(_device); //_photos = Photo.FindInDateRange(_race.LocalCountdownStart, _race.LocalEnd); }
private void SetPositions() { DataTable sorter = new DataTable(); sorter.Columns.Add(new DataColumn("boat_id", typeof(int))); sorter.Columns.Add(new DataColumn("finished", typeof(bool))); sorter.Columns.Add(new DataColumn("finished_position", typeof(int))); sorter.Columns.Add(new DataColumn("mark_index", typeof(int))); sorter.Columns.Add(new DataColumn("distance_to_mark", typeof(float))); foreach (ReplayBoat b in _boats) { int pos = int.MaxValue; bool finished = false; if (b.CurrentRacingStatus == ReplayBoat.RacingStatus.Finished) { pos = b.GetCurrentPosition(_simTime); finished = true; } object[] row = { b.Id, finished, pos, b.GetCurrentLeg(_simTime), b.DistanceToMark }; sorter.Rows.Add(row); } DataView dv = new DataView(sorter, "", "finished desc,finished_position asc,mark_index desc, distance_to_mark asc", DataViewRowState.CurrentRows); DataTable sorted = dv.ToTable(); ReplayBoat leader = null; int leaderBoatId = (int)sorted.Rows[0]["boat_id"]; foreach (ReplayBoat b in _boats) { if (b.Id == leaderBoatId) { leader = b; } } if (leader == null) { throw new Exception("Failed to find race leader"); } for (int i = 0; i < sorted.Rows.Count; i++) { foreach (ReplayBoat b in _boats) { if ((int)sorted.Rows[i]["boat_id"] == b.Id) { TimeSpan leaderLag = new TimeSpan(); TimeSpan nextLag = new TimeSpan(); int leg = b.GetCurrentLeg(_simTime); if (leg > 0) { if (b.Id != leader.Id) { DateTime previousLeaderEnd = leader.GetLegEndTime(leg - 1, _simTime); DateTime previousCurrentEnd = b.GetLegEndTime(leg - 1, _simTime); leaderLag = new TimeSpan(previousLeaderEnd.Ticks - previousCurrentEnd.Ticks); } if (i > 0) { ReplayBoat nextBoat = null; int nextId = (int)sorted.Rows[i - 1]["boat_id"]; foreach (ReplayBoat b2 in _boats) { if (b2.Id == nextId) { nextBoat = b2; } } DateTime previousNextEnd = nextBoat.GetLegEndTime(leg - 1, _simTime); DateTime previousCurrentEnd = b.GetLegEndTime(leg - 1, _simTime); nextLag = new TimeSpan(previousNextEnd.Ticks - previousCurrentEnd.Ticks); } } b.SetPosition(i + 1, _simTime, leaderLag, nextLag); break; } } } }