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>
|
/// <summary>The current acceleration of the train.</summary>
|
||||||
internal double Acceleration { get; private set; }
|
internal double Acceleration { get; private set; }
|
||||||
|
|
||||||
/// <summary>The time when acceleration was calculated.</summary>
|
/// <summary>The time elapsed since acceleration was last calculated.</summary>
|
||||||
private Time AccelerationTime = new Time(0);
|
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>
|
/// <summary>The speed when acceleration was calculated.</summary>
|
||||||
private Speed AccelerationSpeed = new Speed(0);
|
private Speed AccelerationSpeed = new Speed(0);
|
||||||
|
@ -133,16 +136,14 @@ namespace OpenbveFcmbTrainPlugin
|
||||||
data.Handles.BrakeNotch = data.Handles.BrakeNotch;
|
data.Handles.BrakeNotch = data.Handles.BrakeNotch;
|
||||||
|
|
||||||
// Calculate acceleration
|
// Calculate acceleration
|
||||||
if (OpenbveFcmbTrainPlugin.Initializing)
|
AccelerationTimer += data.ElapsedTime.Milliseconds;
|
||||||
|
if (AccelerationTimer >= AccelerationMaximumTimer)
|
||||||
{
|
{
|
||||||
AccelerationTime = data.TotalTime;
|
Acceleration = Math.Round((data.Vehicle.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / AccelerationTimer * 1000, 4);
|
||||||
}
|
AccelerationTimer = 0;
|
||||||
if (data.TotalTime.Milliseconds - AccelerationTime.Milliseconds > 200)
|
AccelerationSpeed = data.Vehicle.Speed;
|
||||||
{
|
|
||||||
Acceleration = Math.Round((State.Speed.MetersPerSecond - AccelerationSpeed.MetersPerSecond) / (data.TotalTime.Seconds - AccelerationTime.Seconds), 4);
|
|
||||||
AccelerationTime = data.TotalTime;
|
|
||||||
AccelerationSpeed = State.Speed;
|
|
||||||
}
|
}
|
||||||
|
data.DebugMessage = Acceleration.ToString();
|
||||||
|
|
||||||
// Retrieve data from all devices
|
// Retrieve data from all devices
|
||||||
foreach (Device dev in Devices)
|
foreach (Device dev in Devices)
|
||||||
|
|
Loading…
Add table
Reference in a new issue