Train: improve acceleration formula
This commit is contained in:
parent
be091a5784
commit
aa863a7464
1 changed files with 11 additions and 10 deletions
|
@ -54,8 +54,11 @@ namespace OpenbveFcmbTrainPlugin
|
|||
/// <summary>The current acceleration of the train.</summary>
|
||||
internal double Acceleration { get; private set; }
|
||||
|
||||
/// <summary>The time when acceleration was calculated.</summary>
|
||||
private Time AccelerationTime = new Time(0);
|
||||
/// <summary>The time elapsed since acceleration was last calculated.</summary>
|
||||
private double AccelerationTimer;
|
||||
|
||||
/// <summary>The maximum time elapsed between acceleration calculations.</summary>
|
||||
private const double AccelerationMaximumTimer = 100;
|
||||
|
||||
/// <summary>The speed when acceleration was calculated.</summary>
|
||||
private Speed AccelerationSpeed = new Speed(0);
|
||||
|
@ -133,16 +136,14 @@ namespace OpenbveFcmbTrainPlugin
|
|||
data.Handles.BrakeNotch = data.Handles.BrakeNotch;
|
||||
|
||||
// Calculate acceleration
|
||||
if (OpenbveFcmbTrainPlugin.Initializing)
|
||||
AccelerationTimer += data.ElapsedTime.Milliseconds;
|
||||
if (AccelerationTimer >= AccelerationMaximumTimer)
|
||||
{
|
||||
AccelerationTime = data.TotalTime;
|
||||
}
|
||||
if (data.TotalTime.Milliseconds - AccelerationTime.Milliseconds > 200)
|
||||
{
|
||||
Acceleration = Math.Round((State.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / (data.TotalTime.Seconds - AccelerationTime.Seconds), 4);
|
||||
AccelerationTime = data.TotalTime;
|
||||
AccelerationSpeed = State.Speed;
|
||||
Acceleration = Math.Round((data.Vehicle.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / AccelerationTimer * 1000, 4);
|
||||
AccelerationTimer = 0;
|
||||
AccelerationSpeed = data.Vehicle.Speed;
|
||||
}
|
||||
data.DebugMessage = Acceleration.ToString();
|
||||
|
||||
// Retrieve data from all devices
|
||||
foreach (Device dev in Devices)
|
||||
|
|
Loading…
Add table
Reference in a new issue