private const int SLEEP_TIME = 100; //100 miliseconds // This method will be called when the thread is started. public void DoWork(object appender) { var outputAppender = (IOutputAppender)appender; while (!_shouldStop) { char key = KeyBoardHelper.GetKeyPressed(); if (!key.Equals(char.MinValue)) { outputAppender.SaveToBuffer(key); } Thread.Sleep(SLEEP_TIME); } outputAppender.FinalPush(); }
public async void GameLoop(GameLoopObject glo) { if (glo.pauseanimation) { lastTimeStamp = glo.timestamp; Utils.dOut("Exited GameLoop", true); return; } loopCount++; var timeStamp = glo.timestamp; //Start Animation Logic delta += (int)(timeStamp - lastTimeStamp); lastTimeStamp = timeStamp; while (delta >= targetTicksPerFrame) { sw.Restart(); animationService.Animate(); Utils.dOut("animationService.Animate()", sw.ElapsedMilliseconds); delta -= targetTicksPerFrame; } if (Utils.FPS > 50 && Utils.FPS <= 55) { drawmod = 3; } else if (Utils.FPS > 45 && Utils.FPS <= 50) { drawmod = 4; } else if (Utils.FPS <= 45) { drawmod = 5; } else { drawmod = 2; } if (loopCount % drawmod == 0 || glo.captureship || glo.morphbug) { sw.Restart(); animationService.Draw(glo.editcurveschecked); if (sw.ElapsedMilliseconds >= 8) { totaldraw += sw.ElapsedMilliseconds; } if (sw.ElapsedMilliseconds > maxdraw && sw.ElapsedMilliseconds < 50) { maxdraw = sw.ElapsedMilliseconds; } Utils.dOut("animationService.Draw()", sw.ElapsedMilliseconds + " Avg: " + ((int)totaldraw / (loopCount / drawmod)) + " Max: " + maxdraw); sw.Restart(); if (gameService.animationService != null) { if (gameService.Ship == null) { gameService.Ship = ship; } gameService.Process(timeStamp, glo); if (gameService.Started && BackGroundClass == "background") { BackGroundClass = "background backgroundmoving"; StateHasChanged(); } else if (!gameService.Started && BackGroundClass == "background backgroundmoving") { BackGroundClass = "background"; StateHasChanged(); } Utils.dOut("gameService.Process()", sw.ElapsedMilliseconds); } } //End Animation Logic //Start Curve Editor Logic if (glo.editcurveschecked) { CurveEditorHelper.EditCurves(animationService, glo); } else { CurveEditorHelper.DisableLines(animationService); } if (glo.resetanimation) { CurveEditorHelper.ResetAnimation(animationService); } ////End Curve Editor Logic Utils.LogFPS(); KeyBoardHelper.ControlShip(ship, animationService); await JsRuntime.InvokeAsync <object>("logDiagnosticInfo", Utils.DiagnosticInfo); }