OpenBve.PluginManager.Plugin.UpdatePlugin C# (CSharp) Method

UpdatePlugin() private method

Called every frame to update the plugin.
private UpdatePlugin ( ) : void
return void
			internal void UpdatePlugin() {
				/*
				 * Prepare the vehicle state.
				 * */
				double location = this.Train.Cars[0].FrontAxle.Follower.TrackPosition - this.Train.Cars[0].FrontAxlePosition + 0.5 * this.Train.Cars[0].Length;
			    //Curve Radius, Cant and Pitch Added
                double CurrentRadius = this.Train.Cars[0].FrontAxle.Follower.CurveRadius;
                double CurrentCant = this.Train.Cars[0].FrontAxle.Follower.CurveCant;
			    double CurrentPitch = this.Train.Cars[0].FrontAxle.Follower.Pitch;
                //If the list of stations has not been loaded, do so
			    if (!StationsLoaded)
			    {
                    currentRouteStations = new List<Station>();
			        foreach (Game.Station selectedStation in Game.Stations)
			        {
				        Station i = new Station
				        {
					        Name = selectedStation.Name,
					        ArrivalTime = selectedStation.ArrivalTime,
					        DepartureTime = selectedStation.DepartureTime,
					        StopTime = selectedStation.StopTime,
					        OpenLeftDoors = selectedStation.OpenLeftDoors,
					        OpenRightDoors = selectedStation.OpenRightDoors,
					        ForceStopSignal = selectedStation.ForceStopSignal,
					        DefaultTrackPosition = selectedStation.DefaultTrackPosition
				        };
				        currentRouteStations.Add(i);
			        }
			        StationsLoaded = true;
			    }
			    //End of additions
				double speed = this.Train.Cars[this.Train.DriverCar].Specs.CurrentPerceivedSpeed;
				double bcPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakeCylinderCurrentPressure;
				double mrPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.MainReservoirCurrentPressure;
				double erPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.EqualizingReservoirCurrentPressure;
				double bpPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.BrakePipeCurrentPressure;
				double sapPressure = this.Train.Cars[this.Train.DriverCar].Specs.AirBrake.StraightAirPipeCurrentPressure;
				VehicleState vehicle = new VehicleState(location, new Speed(speed), bcPressure, mrPressure, erPressure, bpPressure, sapPressure, CurrentRadius, CurrentCant, CurrentPitch);
				/*
				 * Prepare the preceding vehicle state.
				 * */
				double bestLocation = double.MaxValue;
				double bestSpeed = 0.0;
				for (int i = 0; i < TrainManager.Trains.Length; i++) {
					if (TrainManager.Trains[i] != this.Train & TrainManager.Trains[i].State == TrainManager.TrainState.Available) {
						int c = TrainManager.Trains[i].Cars.Length - 1;
						double z = TrainManager.Trains[i].Cars[c].RearAxle.Follower.TrackPosition - TrainManager.Trains[i].Cars[c].RearAxlePosition - 0.5 * TrainManager.Trains[i].Cars[c].Length;
						if (z >= location & z < bestLocation) {
							bestLocation = z;
							bestSpeed = TrainManager.Trains[i].Specs.CurrentAverageSpeed;
						}
					}
				}
				var precedingVehicle = bestLocation != double.MaxValue ? new PrecedingVehicleState(bestLocation, bestLocation - location, new Speed(bestSpeed)) : null;
				/*
				 * Get the driver handles.
				 * */
				Handles handles = GetHandles();
				/*
				 * Update the plugin.
				 * */
				double totalTime = Game.SecondsSinceMidnight;
				double elapsedTime = Game.SecondsSinceMidnight - LastTime;
                /* 
                 * Set the current camera view mode
                 * Could probably do away with the CurrentCameraViewMode and use a direct cast??
                 * 
                 */
			    CurrentCameraViewMode = (OpenBveApi.Runtime.CameraViewMode)World.CameraMode;
				ElapseData data = new ElapseData(vehicle, precedingVehicle, handles, new Time(totalTime), new Time(elapsedTime), currentRouteStations, CurrentCameraViewMode, Interface.CurrentLanguageCode);
				LastTime = Game.SecondsSinceMidnight;
				Elapse(data);
				this.PluginMessage = data.DebugMessage;
			    DisableTimeAcceleration = data.DisableTimeAcceleration;
				/*
				 * Set the virtual handles.
				 * */
				this.PluginValid = true;
				SetHandles(data.Handles, true);
			}
			/// <summary>Gets the driver handles.</summary>

Usage Example

コード例 #1
0
 /// <summary>Updates the safety system plugin for this train</summary>
 internal void UpdateSafetySystem()
 {
     if (Plugin != null)
     {
         SignalData[] data  = new SignalData[16];
         int          count = 0;
         int          start = CurrentSectionIndex >= 0 ? CurrentSectionIndex : 0;
         for (int i = start; i < Program.CurrentRoute.Sections.Length; i++)
         {
             SignalData signal = Program.CurrentRoute.Sections[i].GetPluginSignal(this);
             if (data.Length == count)
             {
                 Array.Resize <SignalData>(ref data, data.Length << 1);
             }
             data[count] = signal;
             count++;
             if (signal.Aspect == 0 | count == 16)
             {
                 break;
             }
         }
         Array.Resize <SignalData>(ref data, count);
         Plugin.UpdateSignals(data);
         Plugin.LastSection = CurrentSectionIndex;
         Plugin.UpdatePlugin();
     }
 }