Skip to content

Commit

Permalink
* **FIX**: Fixed major bug that was causing time handling to be trunc…
Browse files Browse the repository at this point in the history
…ated, causing part updates to happen less and less frequently the longer your save went on
  • Loading branch information
jwvanderbeck committed Mar 26, 2016
1 parent 90c0055 commit 40cbd88
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
Binary file modified GameData/TestFlight/Plugins/TestFlight.dll
Binary file not shown.
Binary file modified GameData/TestFlight/Plugins/TestFlightAPI.dll
Binary file not shown.
Binary file modified GameData/TestFlight/Plugins/TestFlightContracts.dll
Binary file not shown.
Binary file modified GameData/TestFlight/Plugins/TestFlightCore.dll
Binary file not shown.
13 changes: 6 additions & 7 deletions TestFlightCore/TestFlightCore/TestFlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal struct PartStatus
internal bool acknowledged;
internal String mtbfString;
internal float timeToRepair;
internal float lastSeen;
internal double lastSeen;
internal float flightData;
}

Expand Down Expand Up @@ -194,10 +194,10 @@ public class TestFlightManager : MonoBehaviourExtended

private Dictionary<Guid, MasterStatusItem> masterStatus = null;

float currentUTC = 0.0f;
float lastDataPoll = 0.0f;
float lastFailurePoll = 0.0f;
float lastMasterStatusUpdate = 0.0f;
double currentUTC = 0.0f;
double lastDataPoll = 0.0f;
double lastFailurePoll = 0.0f;
double lastMasterStatusUpdate = 0.0f;


internal void Log(string message)
Expand Down Expand Up @@ -394,7 +394,7 @@ internal override void Update()
if (masterStatus == null)
masterStatus = new Dictionary<Guid, MasterStatusItem>();

currentUTC = (float)Planetarium.GetUniversalTime();
currentUTC = Planetarium.GetUniversalTime();
// ensure out vessel list is up to date
CacheVessels();
if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
Expand All @@ -416,7 +416,6 @@ internal override void Update()
// Poll for flight data and part status
if (currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency)
{

// Old data structure deprecated v1.3
PartStatus partStatus = new PartStatus();
partStatus.lastSeen = currentUTC;
Expand Down
41 changes: 22 additions & 19 deletions TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ namespace TestFlightCore
/// </summary>
public class TestFlightCore : PartModuleExtended, ITestFlightCore
{
// New API

// New v1.3
[KSPField(isPersistant=true)]
public float currentFlightData;
[KSPField(isPersistant=true)]
public float initialFlightData;
[KSPField]
public float startFlightData;

Expand All @@ -34,12 +27,6 @@ public class TestFlightCore : PartModuleExtended, ITestFlightCore
public float techTransferMax = 1000;
[KSPField]
public float techTransferGenerationPenalty = 0.05f;
[KSPField(isPersistant=true)]
public float operatingTime;
[KSPField(isPersistant=true)]
public float lastMET;
[KSPField(isPersistant=true)]
public bool initialized = false;
[KSPField]
public float maxData = 0f;
[KSPField]
Expand All @@ -54,14 +41,30 @@ public class TestFlightCore : PartModuleExtended, ITestFlightCore
[KSPField]
public float rndCost = 1f;

#region Persistant KSP Fields

[KSPField(isPersistant=true)]
public float operatingTime;
[KSPField(isPersistant=true)]
public double lastMET;
[KSPField(isPersistant=true)]
public bool initialized = false;
[KSPField(isPersistant=true)]
public float currentFlightData;
[KSPField(isPersistant=true)]
public float initialFlightData;
[KSPField(isPersistant=true)]
private double missionStartTime;

#endregion

private double baseFailureRate;
// We store the base, or initial, flight data for calculation of Base Failure Rate
// Momentary Failure Rates are calculated based on modifiers. Those modifiers
// are stored per SCOPE and per TRIGGER
private List<MomentaryFailureRate> momentaryFailureRates;
private List<MomentaryFailureModifier> momentaryFailureModifiers;
private List<String> disabledFailures;
private float missionStartTime;
private bool firstStaged;

// These were created for KCT integration but might have other uses
Expand Down Expand Up @@ -748,7 +751,7 @@ public void OnStageActivate(int stage)
{
GameEvents.onStageActivate.Remove(OnStageActivate);
firstStaged = true;
missionStartTime = (float)Planetarium.GetUniversalTime();
missionStartTime = Planetarium.GetUniversalTime();
Log("First stage activated");
}
/// <summary>
Expand Down Expand Up @@ -796,13 +799,13 @@ public override void Update()
}


float currentMET = (float)Planetarium.GetUniversalTime() - (float)missionStartTime;
double currentMET = Planetarium.GetUniversalTime() - missionStartTime;
Log("Operating Time: " + operatingTime);
Log("Current MET: " + currentMET + ", Last MET: " + lastMET);
if (operatingTime != -1 && IsPartOperating())
{
Log("Adding " + (currentMET - lastMET) + " seconds to operatingTime");
operatingTime += currentMET - lastMET;
operatingTime += (float)(currentMET - lastMET);
}

lastMET = currentMET;
Expand All @@ -826,7 +829,7 @@ public override void Start()
else
{
firstStaged = true;
missionStartTime = (float)Planetarium.GetUniversalTime();
missionStartTime = Planetarium.GetUniversalTime();
}
}
}
Expand Down Expand Up @@ -877,7 +880,7 @@ public void InitializeFlightData(float flightData)
currentFlightData = flightData;
initialFlightData = flightData;

missionStartTime = (float)Planetarium.GetUniversalTime();
missionStartTime = Planetarium.GetUniversalTime();

if (HighLogic.LoadedSceneIsFlight)
initialized = true;
Expand Down
3 changes: 2 additions & 1 deletion TestFlightReliability_EngineCycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ protected void UpdateCycle()
else
{
// If so then we add burn time based on time passed, optionally modified by the thrust
Log(String.Format("TestFlightReliability_EngineCycle: Engine Thrust {0:F4}", engine.finalThrust));
float actualThrustModifier = thrustModifier.Evaluate(engine.finalThrust);
engineOperatingTime = engineOperatingTime + (deltaTime * actualThrustModifier);

// Check for failure
float penalty = cycle.Evaluate((float)engineOperatingTime);
Log(String.Format("TestFlightFailure_EngineCycle: Applying modifier {0:F4} at cycle time {1:F4}", penalty, engineOperatingTime));
Log(String.Format("TestFlightReliability_EngineCycle: Applying modifier {0:F4} at cycle time {1:F4}", penalty, engineOperatingTime));
core.SetTriggerMomentaryFailureModifier("EngineCycle", penalty, this);
}
}
Expand Down

0 comments on commit 40cbd88

Please sign in to comment.