diff --git a/src/Train/Train.cs b/src/Train/Train.cs
index 3bcd09c..4b67e22 100644
--- a/src/Train/Train.cs
+++ b/src/Train/Train.cs
@@ -54,8 +54,11 @@ namespace OpenbveFcmbTrainPlugin
/// The current acceleration of the train.
internal double Acceleration { get; private set; }
- /// The time when acceleration was calculated.
- private Time AccelerationTime = new Time(0);
+ /// The time elapsed since acceleration was last calculated.
+ private double AccelerationTimer;
+
+ /// The maximum time elapsed between acceleration calculations.
+ private const double AccelerationMaximumTimer = 100;
/// The speed when acceleration was calculated.
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)