From 7c8e63851f19057cd7bdb8fb37b0dd45bd5a23e4 Mon Sep 17 00:00:00 2001 From: Brad White Date: Mon, 5 Sep 2016 21:05:07 -0400 Subject: [PATCH 1/3] Try to fix RemoteTech steering again kOSVesselModule.cs * Update some logging to simplify references * Add counter to refresh RT sactioned pilot once every 25 ticks (1s real time in theory) --- src/kOS/Module/kOSVesselModule.cs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/kOS/Module/kOSVesselModule.cs b/src/kOS/Module/kOSVesselModule.cs index b5a860f43..0682728eb 100644 --- a/src/kOS/Module/kOSVesselModule.cs +++ b/src/kOS/Module/kOSVesselModule.cs @@ -19,6 +19,7 @@ public class kOSVesselModule : VesselModule private bool initialized = false; private Vessel parentVessel; private bool hasRemoteTech = false; + private int counterRemoteTechRefresh = 0; public Guid ID { @@ -46,16 +47,16 @@ public Guid ID /// public override void OnAwake() { - if (kOS.Safe.Utilities.SafeHouse.Logger != null) + if (SafeHouse.Logger != null) { - kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose("kOSVesselModule Awake()!"); + SafeHouse.Logger.SuperVerbose("kOSVesselModule Awake()!"); parentVessel = GetComponent(); if (parentVessel != null) { allInstances[ID] = this; AddDefaultParameters(); } - kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Awake() finished on {0} ({1})", parentVessel.name, ID)); + SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Awake() finished on {0} ({1})", parentVessel.vesselName, ID)); } } @@ -66,7 +67,7 @@ public override void OnAwake() /// public void Start() { - kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Start()! On {0} ({1})", parentVessel.name, ID)); + SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Start()! On {0} ({1})", parentVessel.vesselName, ID)); HarvestParts(); HookEvents(); initialized = true; @@ -78,9 +79,9 @@ public void Start() /// public void OnDestroy() { - if (kOS.Safe.Utilities.SafeHouse.Logger != null) + if (SafeHouse.Logger != null) { - kOS.Safe.Utilities.SafeHouse.Logger.SuperVerbose("kOSVesselModule OnDestroy()!"); + SafeHouse.Logger.SuperVerbose("kOSVesselModule OnDestroy()!"); UnHookEvents(); ClearParts(); if (parentVessel != null && allInstances.ContainsKey(ID)) @@ -260,6 +261,14 @@ private void CheckSwapEvents() HookRemoteTechPilot(); } } + if (hasRemoteTech) + { + if (++counterRemoteTechRefresh > 25) + { + counterRemoteTechRefresh = 0; + HookRemoteTechPilot(); + } + } } private void HookRemoteTechPilot() @@ -271,6 +280,7 @@ private void HookRemoteTechPilot() private void UnHookRemoteTechPilot() { RemoteTechHook.Instance.RemoveSanctionedPilot(parentVessel.id, HandleRemoteTechSanctionedPilot); + counterRemoteTechRefresh = 0; } private void HookStockPilot() @@ -345,7 +355,7 @@ public IFlightControlParameter GetFlightControlParameter(string name) { name = name.ToLower(); if (!flightControlParameters.ContainsKey(name)) - throw new Exception(string.Format("kOSVesselModule on {0} does not contain a parameter named {1}", parentVessel.name, name)); + throw new Exception(string.Format("kOSVesselModule on {0} does not contain a parameter named {1}", parentVessel.vesselName, name)); return flightControlParameters[name]; } From a5699d45d6be40994c7d89ec2195ea8e3258e602 Mon Sep 17 00:00:00 2001 From: Dunbaratu Date: Thu, 8 Sep 2016 16:25:58 -0500 Subject: [PATCH 2/3] Changed the starting value of the counter to 23 --- src/kOS/Module/kOSVesselModule.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kOS/Module/kOSVesselModule.cs b/src/kOS/Module/kOSVesselModule.cs index 0682728eb..dc5c3d4b2 100644 --- a/src/kOS/Module/kOSVesselModule.cs +++ b/src/kOS/Module/kOSVesselModule.cs @@ -19,7 +19,9 @@ public class kOSVesselModule : VesselModule private bool initialized = false; private Vessel parentVessel; private bool hasRemoteTech = false; - private int counterRemoteTechRefresh = 0; + /// How often to re-attempt the remote tech hook, expressed as a number of physics updates + private const int RemoteTechRehookPeriod = 25; + private int counterRemoteTechRefresh = RemoteTechRehookPeriod - 2; // make sure it starts out ready to trigger soon public Guid ID { @@ -263,7 +265,7 @@ private void CheckSwapEvents() } if (hasRemoteTech) { - if (++counterRemoteTechRefresh > 25) + if (++counterRemoteTechRefresh > RemoteTechRehookPeriod) { counterRemoteTechRefresh = 0; HookRemoteTechPilot(); From 3ccee6786e52be7a2276b24837fcb1a562e51be4 Mon Sep 17 00:00:00 2001 From: hvacengi Date: Fri, 9 Sep 2016 16:28:42 -0400 Subject: [PATCH 3/3] Reset counter on UnHook too kOSVesselModule.cs * Reset the counter to right before triggering when we unhook too, just to head off another race condition. --- src/kOS/Module/kOSVesselModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kOS/Module/kOSVesselModule.cs b/src/kOS/Module/kOSVesselModule.cs index dc5c3d4b2..dba060bfe 100644 --- a/src/kOS/Module/kOSVesselModule.cs +++ b/src/kOS/Module/kOSVesselModule.cs @@ -282,7 +282,7 @@ private void HookRemoteTechPilot() private void UnHookRemoteTechPilot() { RemoteTechHook.Instance.RemoveSanctionedPilot(parentVessel.id, HandleRemoteTechSanctionedPilot); - counterRemoteTechRefresh = 0; + counterRemoteTechRefresh = RemoteTechRehookPeriod - 2; // make sure it starts out ready to trigger soon } private void HookStockPilot()