public void KOSUpdate(double deltaTime) { if (camPositionDelegate == null) { camPositionTrigger = null; } else if (camPositionTrigger == null) { camPositionTrigger = camPositionDelegate.TriggerOnFutureUpdate(Safe.Execution.InterruptPriority.Normal); } else if (camPositionTrigger.CallbackFinished) { var result = camPositionTrigger.ReturnValue as Vector; if (result != null) { SetCameraPosition(result); camPositionTrigger = camPositionDelegate.TriggerOnFutureUpdate(Safe.Execution.InterruptPriority.Normal); } else { camPositionTrigger = null; camPositionDelegate = null; throw new KOSInvalidDelegateType("FLIGHTCAMERA:POSITIONUPDATER", "Vector", camPositionTrigger.ReturnValue.KOSName); } } }
private void HandleDelegateUpdates() { // If a UserDelegate went away, throw away any previous trigger handles we may have been waiting to finish: // -------------------------------------------------------------------------------------------------------- if (StartDelegate == null) // Note: if the user assigns the NoDelegate, we re-map that to null (See how the SetSuffixes of this class are set up). { StartTrigger = null; } if (VectorDelegate == null) // Note: if the user assigns the NoDelegate, we re-map that to null (See how the SetSuffixes of this class are set up). { VectorTrigger = null; } if (ColorDelegate == null) // Note: if the user assigns the NoDelegate, we re-map that to null (See how the SetSuffixes of this class are set up). { ColorTrigger = null; } // For any trigger handles for delegate calls that were in progress already, if they're now done // then update the value to what they returned: // --------------------------------------------------------------------------------------------- bool needToRender = false; // track when to call RenderPointCoords if (StartTrigger != null && StartTrigger.CallbackFinished) { if (StartTrigger.ReturnValue is Vector) { Start = StartTrigger.ReturnValue as Vector; needToRender = true; } else { throw new KOSInvalidDelegateType("VECDRAW:STARTDELEGATE", "Vector", StartTrigger.ReturnValue.KOSName); } } if (VectorTrigger != null && VectorTrigger.CallbackFinished) { if (VectorTrigger.ReturnValue is Vector) { Vector = VectorTrigger.ReturnValue as Vector; needToRender = true; } else { throw new KOSInvalidDelegateType("VECDRAW:VECTORDELEGATE", "Vector", VectorTrigger.ReturnValue.KOSName); } } if (needToRender) { RenderPointCoords(); // save a little execution time by only rendering once if both start and vec are updated } if (ColorTrigger != null && ColorTrigger.CallbackFinished) { if (ColorTrigger.ReturnValue is RgbaColor) { Color = ColorTrigger.ReturnValue as RgbaColor; RenderColor(); } else { throw new KOSInvalidDelegateType("VECDRAW:COLORDELEGATE", "Vector", ColorTrigger.ReturnValue.KOSName); } } // For those UserDelegates that have been assigned, if there isn't a current UserDelegate call in progress, start a new one: // ------------------------------------------------------------------------------------------------------------------------- if (StartDelegate != null && (StartTrigger == null || StartTrigger.CallbackFinished)) { StartTrigger = StartDelegate.TriggerOnFutureUpdate(InterruptPriority.Recurring); if (StartTrigger == null) // Delegate must be from a stale ProgramContext. Stop trying to call it. { StartDelegate = null; } } if (VectorDelegate != null && (VectorTrigger == null || VectorTrigger.CallbackFinished)) { VectorTrigger = VectorDelegate.TriggerOnFutureUpdate(InterruptPriority.Recurring); if (VectorTrigger == null) // Delegate must be from a stale ProgramContext. Stop trying to call it. { VectorDelegate = null; } } if (ColorDelegate != null && (ColorTrigger == null || ColorTrigger.CallbackFinished)) { ColorTrigger = ColorDelegate.TriggerOnFutureUpdate(InterruptPriority.Recurring); if (ColorTrigger == null) // Delegate must be from a stale ProgramContext. Stop trying to call it. { ColorDelegate = null; } } }