public void LinkTrainMultiple(Train orig, TimeEntry offset, TimeEntry diff, int count, ITrainNameGen tnc) { if (orig.ParentTimetable !.Type == TimetableType.Network && orig.ParentTimetable !.Version.CompareTo(TimetableVersion.Extended_FPL2) < 0) { throw new TimetableTypeNotSupportedException("train links"); } if (count < 0) { throw new ArgumentException("Value must be greater than or equal to zero", nameof(count)); } var link = new TrainLink(orig, count) { TimeDifference = diff, TimeOffset = offset, TrainNamingScheme = tnc, }; orig.AddLink(link); for (int i = 0; i < count; i++) { var linkedTrain = new LinkedTrain(link, i); orig.ParentTimetable !.AddTrain(linkedTrain); } }
/// <summary> /// Create a new dialog to edit (= discard + create new) the given train link. /// </summary> /// <param name="link">Link object that is used as blueprint. Note: The referenced object will not be mutated!</param> /// <param name="tt">Current timetable instance.</param> public TrainLinkEditDialog(TrainLink link, Timetable tt) { if (tt.Type == TimetableType.Network && tt.Version.CompareTo(TimetableVersion.Extended_FPL2) < 0) { throw new TimetableTypeNotSupportedException("train links"); } Eto.Serialization.Xaml.XamlReader.Load(this); differenceValidator = new TimeValidator(differenceTextBox, false, errorMessage: T._("Bitte die Verschiebung als Zeitangabe angeben!")); offsetValidator = new TimeValidator(startOffsetTextBox, false, errorMessage: T._("Bitte die Startverschiebung als Zeitangabe angeben!")); countValidator = new NumberValidator(countTextBox, false, true, allowNegative: false, errorMessage: T._("Bitte eine gültige Anzahl >0 neuer Züge eingeben!")); changeValidator = new NumberValidator(changeTextBox, false, true, errorMessage: T._("Bitte eine gültige Veränderung der Zugnummer eingeben!")); origLink = link; train = link.ParentTrain; this.tt = tt; startOffsetTextBox.Text = link.TimeOffset.ToTimeString(); differenceTextBox.Text = link.TimeDifference.ToTimeString(); countTextBox.Text = link.TrainCount.ToString(); switch (link.TrainNamingScheme) { case AutoTrainNameGen atnc: autoTrainNameTableLayout.Visible = true; changeTextBox.Text = atnc.Increment.ToString(); nameTextBox.Text = atnc.BaseTrainName.FullName; break; case SpecialTrainNameGen stnc: specialTrainNameTableLayout.Visible = true; specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.RowNumber.ToString(), ""); specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.Name, T._("Zugname"), true); var ds = new SpecialNameEntry[stnc.Names.Length]; for (int i = 0; i < stnc.Names.Length; i++) { ds[i] = new SpecialNameEntry(i + 1, stnc.Names[i]); } specialNameGridView.DataStore = ds; break; default: throw new NotSupportedException("Not Implemented: Name calculator not supported!"); } }
public void ExtendTrack() { //Calculate destination Vector3 dir = (LinkBeyond.transform.position - NextLink.transform.position).normalized; dir = Tools.RandomDirection(dir, 10.0f, 80.0f); //float angle = Mathf.Deg2Rad * (Random.Range(10.0f, 80.0f) * (Random.Range(0, 2) == 0 ? 1 : -1)); //dir = new Vector3(Mathf.Cos(angle) * dir.x - Mathf.Sin(angle) * dir.y, //Mathf.Sin(angle) * dir.x + Mathf.Cos(angle) * dir.y); int distance = Random.Range(5, 15); //dir *= distance; //place link TrainLink link = Instantiate(LinkPrefab, LinkBeyond.transform.position + dir * distance, Quaternion.identity); NextLink.LinkBeyond = link; LinkBeyond.NextLink = link; //place tracks TrackPair trackPair; Quaternion trackAngle = Quaternion.FromToRotation(Vector3.right, dir); for (int i = 1; i < distance; i++) { trackPair = Instantiate(Rail, LinkBeyond.transform.position + dir * i, trackAngle); trackPair.Initialize(Random.Range(0, 4) == 0); } //Try again later //NextLink.FaceNext.rotation = trackAngle; //LinkBeyond.FacePrevious.rotation = Quaternion.FromToRotation(Vector3.right, -dir); //prevent multiple activation Active = false; }
public void LinkedTrainsPerformanceTest() { var tt = new Timetable(TimetableType.Linear); var stations = new Station[100]; for (int i = 0; i < 100; i++) { var sta = new Station(tt); sta.SName = "Station " + i; sta.Positions.SetPosition(Timetable.LINEAR_ROUTE_ID, i); tt.AddStation(sta, Timetable.LINEAR_ROUTE_ID); stations[i] = sta; } var normalTrain = new Train(TrainDirection.ti, tt) { TName = "P 01" }; tt.AddTrain(normalTrain); normalTrain.AddLinearArrDeps(); for (int i = 0; i < 100; i++) { var ardp = normalTrain.GetArrDep(stations[i]); ardp.Arrival = new TimeEntry(0, i * 30); ardp.Departure = new TimeEntry(0, i * 30 + 10); } var link = new TrainLink(normalTrain, 10) { TimeDifference = new TimeEntry(0, 30), TimeOffset = new TimeEntry(0, 0), TrainNamingScheme = new AutoTrainNameGen(normalTrain.TName, 2) }; normalTrain.AddLink(link); LinkedTrain linkedTrain = null; for (int i = 0; i < link.TrainCount; i++) { linkedTrain = new LinkedTrain(link, i); tt.AddTrain(linkedTrain); } var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100; i++) { var ardps = linkedTrain.GetArrDepsUnsorted(); } sw.Stop(); Console.WriteLine("Linked read: " + ((float)sw.ElapsedMilliseconds) / 100); var sw2 = new Stopwatch(); sw2.Start(); for (int i = 0; i < 100; i++) { var ardps = normalTrain.GetArrDepsUnsorted(); } sw2.Stop(); Console.WriteLine("Normal read: " + ((float)sw2.ElapsedMilliseconds) / 100); var sw3 = new Stopwatch(); var sta3 = stations[0]; var ardp3 = normalTrain.GetArrDep(sta3); sw3.Start(); for (int i = 0; i < 100; i++) { ardp3.Arrival = new TimeEntry(0, i); } sw3.Stop(); Console.WriteLine("Write: " + ((float)sw3.ElapsedMilliseconds) / 100); }