public Timer(int timerLength, bool continuous, VoidDel onTimerEndCallback) { this.timerLength = timerLength; this.continuous = continuous; isRunning = false; this.onTimerEndCallback = onTimerEndCallback; }
/// <summary> /// Record statistics for a code block categorically ... i.e., create a Stats object for the /// code label, that will be written to the file TimeThisCodeCategories.txt, when TimeThis.Flush() is called. /// </summary> /// <param name="sLabel"></param> /// <param name="fnCode"></param> /// <returns></returns> public static bool ByCategory(string sLabel, VoidDel fnCode) { string fn = MethodBase.GetCurrentMethod().Name; Type type = typeof(TimeThis); try { Stopwatch sw = new Stopwatch(); sw.Start(); DateTime TaskStart = DateTime.Now; fnCode(); sw.Stop(); if (!m_oTimingStats.ContainsKey(sLabel)) { m_oTimingStats.Add(sLabel, new Stats()); } Stats stats = m_oTimingStats[sLabel]; stats.AddObs(sw.ElapsedMilliseconds); //Record(TaskStart, Kinds.CodeBlock, sLabel, sSubCat, sDependencies, dArg1, dArg2, sw.Elapsed.TotalMilliseconds, 0.0F, 0.0F, ttime); return(true); } catch (Exception exc) { Util.HandleExc(type, fn, exc); return(false); } }
public void AssignMenuClickFuncs(VoidDel function) { foreach (Button B in MyDropEntities) { VoidDel NewClickFunction = new VoidDel(delegate() { SetTopText(B.Name.Remove(0, B.Name.IndexOf("_DROPOPTION_") + 12)); function(); }); B.ButtonPressFunction += NewClickFunction; } }
public void UpdateProg() { if (trackProg.InvokeRequired) { VoidDel d = new VoidDel(UpdateProg); this.Invoke(d, new object[] { }); } else { float pos = (float)sync.Music.Position / (float)sync.Music.Length; trackProg.Value = (int)((float)trackProg.Maximum * pos); } }
protected void MainUpdate(GameTime gameTime, KeyboardState KCurrent) { if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) { if (ScriptProcessor.ActiveGame()) { if (!ButtonScripts.Paused) { ButtonScripts.Pause(); } else { ButtonScripts.Unpause(); } } else { ButtonScripts.Quit(); } } if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.OemTilde) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.OemTilde)) { if (!ConsoleOpen) { ButtonScripts.OpenAndConstructConsole(); ConsoleOpen = true; } else { ButtonScripts.CloseConsole(); ConsoleOpen = false; } } if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.H) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.H) && ScriptProcessor.ActiveGame()) { ButtonScripts.RefreshUIHideState(); } if (AutoCamera != null && LooseCamera) { if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.R) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.R)) { AutoCamera.CenterDefault(); AutoCamera.ResetZoom(); } AutoCamera.MouseDragEnabled = KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F); if (!UpdateQueue.Contains(AutoCamera)) { UpdateQueue.Add(AutoCamera); } } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed || ExitOut) { Exit(); } if (((KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter) && !ConsoleOpen) || DoNextShifter) && AllowEnter) { DoNextShifter = false; Boolean Found = false; foreach (WorldEntity E in UpdateQueue) { if (E is TextEntity && E.Name == "TEXT_MAIN") { if (((TextEntity)E).WrittenAll()) { GlobalWorldState = "CONTINUE"; } ((TextEntity)E).SkipWrite(); Found = true; break; } } if (!Found) { GlobalWorldState = "CONTINUE"; } } if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F11) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F11)) { ToggleFullscreen(); } if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up)) { UpKeyPress?.Invoke(); } if (KCurrent.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down) && !LastKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down)) { DownKeyPress?.Invoke(); } LastKeyState = KCurrent; foreach (WorldEntity E in UpdateQueue) { E.Update(); } foreach (WorldEntity E in DeleteQueue) { if (UpdateQueue.Contains(E)) { UpdateQueue.Remove(E); } if (RenderQueue.Contains(E)) { RenderQueue.Remove(E); } if (NonSerializables.Contains(E)) { NonSerializables.Remove(E); } E.ManualDispose(); } DeleteQueue = new ArrayList(); foreach (VoidDel V in RunQueue) { V(); } RunQueue = new ArrayList(); if (FadeoutAmount != -100) { if (MediaPlayer.Volume > 0) { MediaPlayer.Volume -= FadeoutAmount; } else { MediaPlayer.Volume = GlobalVolume; if (QueuedSong != null) { MediaPlayer.Play(QueuedSong); } else { MediaPlayer.Stop(); } QueuedSong = null; FadeoutAmount = -100; } } ArrayList RemSounds = new ArrayList(); if (!(CaptureVolume is null) && CaptureVolume.Enabled) { if (CaptureVolume.Output() != LastCapturedVol) { GlobalVolume = CaptureVolume.Output(); } LastCapturedVol = CaptureVolume.Output(); } foreach (SoundEffectInstance S in ActiveSounds) { if (S.State == SoundState.Stopped) { RemSounds.Add(S); } } foreach (SoundEffectInstance RS in RemSounds) { ActiveSounds.Remove(RS); } if (!(CaptureTextrate is null) && CaptureTextrate.Enabled) { if (CaptureTextrate.Output() != LastCapturedText) { TextEntity.TickWriteInterval = TextEntity.GetTicksFromSliderValue(CaptureTextrate.Output()); if (!(CaptureRateDisplay is null)) { CaptureRateDisplay.Text = TextEntity.TickWriteInterval + (TextEntity.TickWriteInterval != 1 ? " milliseconds" : " millisecond"); CaptureRateDisplay.ReWrite(); } } LastCapturedText = CaptureTextrate.Output(); } MouseState Current = Mouse.GetState(); if (Current.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && LastMouseState.LeftButton != Microsoft.Xna.Framework.Input.ButtonState.Pressed && MouseLeftClick != null) { MouseLeftClick(); } LastMouseState = Current; if (GlobalVoid != null) { GlobalVoid(); GlobalVoid = null; } }
public ControlManager(int player) { this.player = player; var gs = GamePad.GetState((PlayerIndex)player); if (gs.IsConnected) update = updateGamePad; else { update = updateKeyboard; keyset = getKeys(keyboardCounter++); } }
public void LoadOut() { Del += () => { Destroy(gameObject); }; }
public void LoadClose() { Del += () => { gameObject.SetActive(false); }; }
public static bool Code(string sLabel, string sSubCat, string sDependencies, double dArg1, double dArg2, double ttime, VoidDel fnCode) { string fn = MethodBase.GetCurrentMethod().Name; Type type = typeof(TimeThis); try { Stopwatch sw = new Stopwatch(); sw.Start(); DateTime TaskStart = DateTime.Now; fnCode(); sw.Stop(); Record(TaskStart, Kinds.CodeBlock, sLabel, sSubCat, sDependencies, dArg1, dArg2, sw.Elapsed.TotalMilliseconds, 0.0F, 0.0F, ttime); return(true); } catch (Exception exc) { Util.HandleExc(type, fn, exc); return(false); } }
/// <summary> /// Log the elapsed time to complete a block of code. /// </summary> /// <param name="sLabel"></param> /// <param name="sSubCat"></param> /// <param name="dArg1"></param> /// <param name="dArg2"></param> /// <param name="fnCode"></param> /// <returns></returns> public static bool Code(string sLabel, double ttime, VoidDel fnCode) { return(Code(sLabel, "", "", 0.0, 0.0, ttime, fnCode)); }
public static bool Lock(object oLockObj, string sLabel, string sDependencies, string sSubCat, double dArg1, double dArg2, VoidDel fnCode, double ttime) { string fn = MethodBase.GetCurrentMethod().Name; Type type = typeof(TimeThis); try { if (null == oLockObj) { Util.HandleAppErr(type, fn, "Unable to lock null object for label/category " + sLabel + "/" + sSubCat); Record(DateTime.Now, Kinds.Lock, sLabel, "**ERROR**", sDependencies, 0, 0, -1000.0, 0.0F, 0.0F, ttime); return(false); } Stopwatch sw = new Stopwatch(); sw.Start(); lock (oLockObj) { sw.Stop(); Record(DateTime.Now, Kinds.Lock, sLabel, sSubCat, sDependencies, dArg1, dArg2, sw.Elapsed.TotalMilliseconds, 0.0F, 0.0F, ttime); fnCode(); } return(true); } catch (Exception exc) { Util.HandleExc(type, fn, exc); return(false); } }
/// <summary> /// Perform a locking operation and record timing information for it. /// If the lock object is invalid, logs an error and does NOT perform the lock /// or execute the protected code. /// </summary> /// <param name="oLockObj"></param> /// <param name="sLabel"></param> /// <param name="sSubCat"></param> /// <param name="dArg1"></param> /// <param name="dArg2"></param> /// <param name="fnCode"></param> /// <returns></returns> public static bool Lock(object oLockObject, string sLabel, VoidDel fnCode, double ttime) { return(Lock(oLockObject, sLabel, "", "", 0.0, 0.0, fnCode, ttime)); }