/// <summary> /// The primary tick entry point from the OpenGL window. /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The frame event details, including delta timing</param> static void Window_UpdateFrame(object sender, FrameEventArgs e) { Delta = ((double)Ticker.ElapsedTicks) / ((double)Stopwatch.Frequency); Ticker.Reset(); Ticker.Start(); try { GlobalTickTime += Delta; MouseHandler.Tick(); KeyHandler.Tick(); UIConsole.Tick(); ClientCommands.Tick(); ClientNetworkBase.Tick(); TickWorld(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / updateframe: " + ex.ToString()); } }
/// <summary> /// Handles the full main tick. /// </summary> /// <param name="delt">The current delta timings (See Delta).</param> void Tick(double delt) { lock (TickLock) { Delta = delt * CVars.g_timescale.ValueD; GlobalTickTimeLocal += Delta; Engine.GlobalTickTime = GlobalTickTimeLocal; try { opsat += Delta; if (opsat >= 1) { opsat -= 1; OncePerSecondActions(); } Schedule.RunAllSyncTasks(Delta); Textures.Update(GlobalTickTimeLocal); Shaders.Update(GlobalTickTimeLocal); Models.Update(GlobalTickTimeLocal); KeyHandler.Tick(); if (RawGamePad != null) { for (int i = 0; i < 4; i++) { if (GamePad.GetCapabilities(i).IsConnected) { RawGamePad.SetVibration(i, GamePadVibration, GamePadVibration); } } } Gamepad.Tick(Delta); MouseHandler.Tick(); UIConsole.Tick(); Commands.Tick(); TickWorld(Delta); TickChatSystem(); TickInvMenu(); CWindow.ClientEngineTick(); CWindow.MouseX = MouseHandler.MouseX(); CWindow.MouseY = MouseHandler.MouseY(); CScreen.FullTick(Delta); Sounds.Update(MainWorldView.CameraPos, MainWorldView.CameraTarget - MainWorldView.CameraPos, MainWorldView.CameraUp(), Player.GetVelocity(), Window.Focused); Schedule.RunAllSyncTasks(0); Player.PostTick(); TheRegion.SolveJoints(); //ProcessChunks(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Ticking: " + ex.ToString()); } PlayerEyePosition = Player.ItemSource(); Location forw = Player.ItemDir(); bool h = TheRegion.SpecialCaseRayTrace(PlayerEyePosition, forw, 100, MaterialSolidity.ANY, IgnorePlayer, out RayCastResult rcr); Location loc = new Location(rcr.HitData.Location); Location nrm = new Location(rcr.HitData.Normal); h = h && !loc.IsInfinite() && !loc.IsNaN() && nrm.LengthSquared() > 0; if (h) { nrm = nrm.Normalize(); } CameraFinalTarget = h ? loc - nrm * 0.01: PlayerEyePosition + forw * 100; CameraImpactNormal = h ? new Location(rcr.HitData.Normal).Normalize() : Location.Zero; CameraDistance = h ? rcr.HitData.T: 100; if (CameraDistance <= 0.01) { CameraDistance = 0.01; } double cping = Math.Max(LastPingValue, GlobalTickTimeLocal - LastPingTime); AveragePings.Push(new KeyValuePair <double, double>(GlobalTickTimeLocal, cping)); while ((GlobalTickTimeLocal - AveragePings.Peek().Key) > 1) { AveragePings.Pop(); } APing = 0; for (int i = 0; i < AveragePings.Length; i++) { APing += AveragePings[i].Value; } APing /= (double)AveragePings.Length; if (FogEnhanceTime > 0.0) { FogEnhanceTime -= Delta; } else { FogEnhanceTime = 0.0; } } }