Example #1
0
 // Update this instance based on another instance
 // this avoid allocation such as using Copy constructor
 internal void UpdateFrom(TrackCircuitPosition source)
 {
     TrackCircuitSectionIndex = source.TrackCircuitSectionIndex;
     Direction         = source.Direction;
     Offset            = source.Offset;
     RouteListIndex    = source.RouteListIndex;
     TrackNode         = source.TrackNode;
     DistanceTravelled = source.DistanceTravelled;
 }
Example #2
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        public TrackCircuitPosition(TrackCircuitPosition source, bool reverse = false)
        {
            if (null == source)
            {
                throw new ArgumentNullException(nameof(source));
            }

            TrackCircuitSectionIndex = source.TrackCircuitSectionIndex;
            Direction         = reverse ? source.Direction.Reverse() : source.Direction;
            Offset            = source.Offset;
            RouteListIndex    = source.RouteListIndex;
            TrackNode         = source.TrackNode;
            DistanceTravelled = source.DistanceTravelled;
        }
Example #3
0
        // Restore
        public void RestorePresentPosition(BinaryReader inf, Train train)
        {
            if (null == train)
            {
                throw new ArgumentNullException(nameof(train));
            }
            if (null == inf)
            {
                throw new ArgumentNullException(nameof(inf));
            }

            TrackNode      tn        = train.FrontTDBTraveller.TN;
            float          offset    = train.FrontTDBTraveller.TrackNodeOffset;
            TrackDirection direction = (TrackDirection)train.FrontTDBTraveller.Direction;

            TrackCircuitPosition tempPosition = new TrackCircuitPosition();

            tempPosition.SetPosition(tn.TrackCircuitCrossReferences, offset, direction);

            TrackCircuitSectionIndex = inf.ReadInt32();
            Direction         = (TrackDirection)inf.ReadInt32();
            Offset            = inf.ReadSingle();
            RouteListIndex    = inf.ReadInt32();
            TrackNode         = inf.ReadInt32();
            DistanceTravelled = inf.ReadSingle();

            float offsetDif = Math.Abs(Offset - tempPosition.Offset);

            if (TrackCircuitSectionIndex != tempPosition.TrackCircuitSectionIndex ||
                (TrackCircuitSectionIndex == tempPosition.TrackCircuitSectionIndex && offsetDif > 5.0f))
            {
                Trace.TraceWarning("Train {0} restored at different present position : was {1} - {3}, is {2} - {4}",
                                   train.Number, TrackCircuitSectionIndex, tempPosition.TrackCircuitSectionIndex,
                                   Offset, tempPosition.Offset);
            }
        }