/// <summary> /// Log a block of code entry, exit, and timing /// </summary> /// <param name="blockName">The name of the code block being logged</param> /// <param name="options">The log options</param> /// <returns>A disposable object or none if logging is disabled</returns> public static IDisposable EntryExitLog(string blockName, EntryExitLoggerOptions options = EntryExitLoggerOptions.AlwaysLog) { IDisposable logger = null; if (Log.LoggingLevel == LogSeverity.Trace || ((options & EntryExitLoggerOptions.AlwaysLog) == EntryExitLoggerOptions.AlwaysLog)) { // Check if ExecutionTime logging is requested, and if so log if Verbose logging (or greater) is chosen bool shouldCreate = ((options & EntryExitLoggerOptions.ExecutionTime) == EntryExitLoggerOptions.ExecutionTime); // If not logging ExecutionTime log only if Entry or Exit tracing is requested if (!shouldCreate) { shouldCreate = (((options & EntryExitLoggerOptions.Entry) == EntryExitLoggerOptions.Entry) || ((options & EntryExitLoggerOptions.Exit) == EntryExitLoggerOptions.Exit)); } // Check if we actually need to log anything if (shouldCreate) { logger = new EntryExitLogger(blockName, options); } } // Will return null if no method logger was needed - which will effectively be ignored in a using statement. return(logger); }
private void GUIAssignKey(string buttonDesc, TimeControlKeyBinding kb) { const string logBlockName = nameof(KeyBindingsEditorIMGUI) + "." + nameof(KeyBindingsEditorIMGUI.GUIAssignKey); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { // Left Mouse Button, Assign Key if (Event.current.button == 0 && !currentlyAssigningKey) { currentlyAssigningKey = true; KeyboardInputManager.Instance.GetPressedKeyCombination((lkc) => { const string logBlockName2 = nameof(KeyBindingsEditorIMGUI) + "." + nameof(KeyBindingsEditorIMGUI.GUIAssignKey) + " - " + nameof(KeyboardInputManager.Instance.GetPressedKeyCombination) + " Callback"; using (EntryExitLogger.EntryExitLog(logBlockName2, EntryExitLoggerOptions.All)) { currentlyAssigningKey = false; kb.KeyCombination = new List <KeyCode>(lkc); refreshKBCache = true; Log.Info("Key Combination " + kb.KeyCombinationDescription + " assigned to button " + buttonDesc, logBlockName2); TimeControlEvents.OnTimeControlKeyBindingsChanged?.Fire(kb); } }); } // Right Mouse Button, Clear Assigned Key else if (Event.current.button == 1 && !currentlyAssigningKey) { kb.KeyCombination = new List <KeyCode>(); TimeControlEvents.OnTimeControlKeyBindingsChanged?.Fire(kb); } } }
internal IEnumerator CRGetPressedKeyCombination(List <KeyCode> lkc, Action <List <KeyCode> > callback) { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(CRGetPressedKeyCombination); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { // Wait unti a key is pressed while (keysPressed.Count == 0) { yield return(null); } // Add keys as they are pressed and held down while (keysPressed.Count != 0) { foreach (KeyCode kc in keysPressed) { if (!lkc.Contains(kc)) { lkc.Add(kc); } } yield return(null); } // Finally execute the callback function to send back the key combination callback.Invoke(lkc); isAssigningKey = false; yield break; } }
private void OnTimeControlCustomWarpRatesChanged(bool d) { const string logBlockName = nameof(RailsEditorIMGUI) + "." + nameof(OnTimeControlCustomWarpRatesChanged); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (!RailsWarpController.IsReady || !TimeController.IsReady) { return; } warpRates = RailsWarpController.Instance.GetCustomWarpRates(); if (selectedGUISOI == null) { selectedGUISOI = TimeController.Instance.CurrentGameSOI; priorGUISOI = selectedGUISOI; } if (!altitudeLimits.ContainsKey(selectedGUISOI)) { altitudeLimits.Add(selectedGUISOI, null); } foreach (CelestialBody cb in altitudeLimits.Keys.ToList()) { altitudeLimits[cb] = RailsWarpController.Instance?.GetCustomAltitudeLimitsForBody(cb); } } }
public override void SetDifficultyPreset(GameParameters.Preset preset) { const string logBlockName = nameof(TimeControlParameterNode) + "." + nameof(SetDifficultyPreset); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { } }
public override void OnSave(ConfigNode node) { const string logBlockName = nameof(TimeControlParameterNode) + "." + nameof(OnSave); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { } }
private void Start() { const string logBlockName = nameof(FPSKeeperController) + "." + nameof(Start); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { StartCoroutine(Configure()); } }
private void Start() { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(Start); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { StartCoroutine(Configure()); } }
public List <TimeControlKeyBinding> GetActiveKeyBinds() { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(GetActiveKeyBinds); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { return(activeKeyBinds.ToList()); } }
private void Awake() { const string logBlockName = nameof(PerformanceManager) + "." + nameof(Awake); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { DontDestroyOnLoad(this); instance = this; } }
public void ResetKeyBindingsToDefault() { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(ResetKeyBindingsToDefault); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { GlobalSettings.Instance.ResetKeybindsToDefaultSettings(); activeKeyBinds = GlobalSettings.Instance.GetActiveKeyBinds().ToList(); } }
private void Awake() { const string logBlockName = nameof(FPSKeeperController) + "." + nameof(Awake); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { DontDestroyOnLoad(this); Instance = this; } }
/// <summary> /// Asynchronously gets a pressed key combination. /// Waits for keypresses in a coroutine, and then once no keys are pressed, returns the list of pressed keycodes to the callback function /// </summary> internal void GetPressedKeyCombination(Action <List <KeyCode> > callback) { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(GetPressedKeyCombination); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { List <KeyCode> lkc = new List <KeyCode>(); isAssigningKey = true; StartCoroutine(CRGetPressedKeyCombination(lkc, callback)); } }
private void Awake() { const string logBlockName = nameof(KeyboardInputManager) + "." + nameof(Awake); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { DontDestroyOnLoad(this); //Don't go away on scene changes KeyboardInputManager.Instance = this; List <KeyCode> ignoreKeys = new List <KeyCode>() { KeyCode.Mouse0, KeyCode.Mouse1, KeyCode.Mouse2, KeyCode.Mouse3, KeyCode.Mouse4, KeyCode.Mouse5, KeyCode.Mouse6, KeyCode.Escape, KeyCode.CapsLock, KeyCode.ScrollLock, KeyCode.Numlock, KeyCode.Break, KeyCode.LeftWindows, KeyCode.RightWindows, KeyCode.LeftApple, KeyCode.RightApple }; List <KeyCode> checkKeysl = System.Enum.GetValues(typeof(KeyCode)).Cast <KeyCode>().ToList(); checkKeysl.RemoveAll(k => ignoreKeys.Contains(k)); foreach (KeyCode kc in checkKeysl) { KeyCode setKC = kc; // Modifier Keys switch (kc) { case KeyCode.LeftShift: case KeyCode.RightShift: setKC = KeyCode.LeftShift; break; case KeyCode.LeftControl: case KeyCode.RightControl: setKC = KeyCode.LeftControl; break; case KeyCode.LeftAlt: case KeyCode.RightAlt: case KeyCode.AltGr: setKC = KeyCode.LeftAlt; break; case KeyCode.LeftCommand: case KeyCode.RightCommand: setKC = KeyCode.LeftCommand; break; } this.checkKeys.Add(kc, setKC); } } }
private void Awake() { const string logBlockName = nameof(Awake); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { DontDestroyOnLoad(this); // Common OnTimeControlDefaultFixedDeltaTimeChanged = new EventData <float>(nameof(OnTimeControlDefaultFixedDeltaTimeChanged)); OnTimeControlFixedDeltaTimeChanged = new EventData <float>(nameof(OnTimeControlFixedDeltaTimeChanged)); OnTimeControlTimeScaleChanged = new EventData <float>(nameof(OnTimeControlTimeScaleChanged)); OnTimeControlTimePaused = new EventData <bool>(nameof(OnTimeControlTimePaused)); OnTimeControlTimeUnpaused = new EventData <bool>(nameof(OnTimeControlTimeUnpaused)); // Hyper Warp OnTimeControlHyperWarpMaximumDeltaTimeChanged = new EventData <float>(nameof(OnTimeControlHyperWarpMaximumDeltaTimeChanged)); OnTimeControlHyperWarpMaxAttemptedRateChanged = new EventData <float>(nameof(OnTimeControlHyperWarpMaxAttemptedRateChanged)); OnTimeControlHyperWarpPhysicsAccuracyChanged = new EventData <float>(nameof(OnTimeControlHyperWarpPhysicsAccuracyChanged)); OnTimeControlCustomHyperWarpRatesChanged = new EventData <bool>(nameof(OnTimeControlCustomHyperWarpRatesChanged)); OnTimeControlCustomSlowMotionRatesChanged = new EventData <bool>(nameof(OnTimeControlCustomSlowMotionRatesChanged)); OnTimeControlHyperWarpStarting = new EventData <float>(nameof(OnTimeControlHyperWarpStarting)); OnTimeControlHyperWarpStarted = new EventData <float>(nameof(OnTimeControlHyperWarpStarted)); OnTimeControlHyperWarpStopping = new EventData <float>(nameof(OnTimeControlHyperWarpStopping)); OnTimeControlHyperWarpStopped = new EventData <float>(nameof(OnTimeControlHyperWarpStopped)); // Slow Motion OnTimeControlSlowMoRateChanged = new EventData <float>(nameof(OnTimeControlSlowMoRateChanged)); OnTimeControlSlowMoDeltaLockedChanged = new EventData <bool>(nameof(OnTimeControlSlowMoDeltaLockedChanged)); OnTimeControlSlowMoStarting = new EventData <float>(nameof(OnTimeControlSlowMoStarting)); OnTimeControlSlowMoStarted = new EventData <float>(nameof(OnTimeControlSlowMoStarted)); OnTimeControlSlowMoStopping = new EventData <float>(nameof(OnTimeControlSlowMoStopping)); OnTimeControlSlowMoStopped = new EventData <float>(nameof(OnTimeControlSlowMoStopped)); // Rails Limits Changed OnTimeControlCustomWarpRatesChanged = new EventData <bool>(nameof(OnTimeControlCustomWarpRatesChanged)); // Global Settings OnTimeControlGlobalSettingsSaved = new EventData <bool>(nameof(OnTimeControlGlobalSettingsSaved)); OnTimeControlGlobalSettingsChanged = new EventData <bool>(nameof(OnTimeControlGlobalSettingsChanged)); // Key Bindings OnTimeControlKeyBindingsChanged = new EventData <TimeControlKeyBinding>(nameof(OnTimeControlKeyBindingsChanged)); } }
private void OnTimeControlCustomHyperWarpRatesChanged(bool d) { const string logBlockName = nameof(HyperEditorIMGUI) + "." + nameof(OnTimeControlCustomHyperWarpRatesChanged); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (!RailsWarpController.IsReady || !TimeController.IsReady) { return; } hyperWarpRates = HyperWarpController.Instance.GetCustomHyperWarpRates(); hyperWarpPhysicsAccuracyRates = HyperWarpController.Instance.GetCustomHyperWarpPhysicsAccuracyRates(); } }
private void SetDefaults() { const string logBlockName = nameof(FPSKeeperController) + "." + nameof(SetDefaults); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { /* * defaultDeltaTime = Time.fixedDeltaTime; * currentScreenMessage = null; * currentScreenMessageStyle = ScreenMessageStyle.UPPER_CENTER; * currentScreenMessageDuration = Mathf.Infinity; * currentScreenMessagePrefix = "SLOW-MOTION"; * UpdateDefaultScreenMessage(); */ } }
private void SubscribeToGameEvents() { const string logBlockName = nameof(FPSKeeperController) + "." + nameof(SubscribeToGameEvents); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { /* * GameEvents.onGamePause.Add( this.onGamePause ); * GameEvents.onGameUnpause.Add( this.onGameUnpause ); * GameEvents.onGameSceneLoadRequested.Add( this.onGameSceneLoadRequested ); * * OnTimeControlSlowMoRateChangedEvent = GameEvents.FindEvent<EventData<float>>( nameof( TimeControlEvents.OnTimeControlSlowMoRateChanged ) ); * OnTimeControlSlowMoRateChangedEvent?.Add( SlowMoRateChanged ); */ } }
public override void OnLoad(ConfigNode node) { const string logBlockName = nameof(TimeControlParameterNode) + "." + nameof(OnLoad); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (GlobalSettings.IsReady) { LoggingLevel = GlobalSettings.Instance.LoggingLevel; CameraZoomFix = GlobalSettings.Instance.CameraZoomFix; KeyRepeatStart = GlobalSettings.Instance.KeyRepeatStart; KeyRepeatInterval = GlobalSettings.Instance.KeyRepeatInterval; } UseKerbinTime = GameSettings.KERBIN_TIME; } }
private IEnumerator Configure() { const string logBlockName = nameof(FPSKeeperController) + "." + nameof(Configure); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { this.SetDefaults(); this.SubscribeToGameEvents(); while (TimeWarp.fetch == null || FlightGlobals.Bodies == null || FlightGlobals.Bodies.Count <= 0) { yield return(new WaitForSeconds(1f)); } //Log.Info( nameof( FPSKeeperController ) + " is Ready!", logBlockName ); //FPSKeeperController.IsReady = true; yield break; } }
private void OnGameSettingsApplied() { const string logBlockName = nameof(GlobalSettings) + "." + nameof(OnGameSettingsApplied); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { TimeControlParameterNode TCPN = null; try { TCPN = HighLogic.CurrentGame.Parameters.CustomParams <TimeControlParameterNode>(); } catch (NullReferenceException) { } if (TCPN != null) { KeyRepeatStart = TCPN.KeyRepeatStart; KeyRepeatInterval = TCPN.KeyRepeatInterval; } } }
private IEnumerator Configure() { const string logBlockName = nameof(PerformanceManager) + "." + nameof(Configure); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { ptrRollingQ = new Queue <double>(); gsRollingQ = new Queue <double>(); FramesPerSecond = 0f; PhysicsUpdatesPerSecond = 0f; PhysicsTimeRatio = 0d; PerformanceCountersOn = true; while (!GlobalSettings.IsReady || !IsValidScene()) { yield return(new WaitForSeconds(1)); } Log.Info(nameof(PerformanceManager) + " is Ready!", logBlockName); IsReady = true; yield break; } }
private IEnumerator Configure() { const string logBlockName = nameof(HyperWarpController) + "." + nameof(Configure); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { keysPressed = new List <KeyCode>(); keysPressedDown = new List <KeyCode>(); keysReleased = new List <KeyCode>(); activeKeyBinds = GlobalSettings.Instance.GetActiveKeyBinds().ToList(); while (!GlobalSettings.IsReady || !HighLogic.LoadedSceneIsGame || TimeWarp.fetch == null || FlightGlobals.Bodies == null || FlightGlobals.Bodies.Count <= 0) { yield return(new WaitForSeconds(1f)); } GameEvents.OnGameSettingsApplied.Add(OnGameSettingsApplied); Log.Info(nameof(KeyboardInputManager) + " is Ready!", logBlockName); IsReady = true; yield break; } }