/// <summary> /// Ticks the server, include the network, /// and all worlds (and all chunks within those [and all entities within those]). /// </summary> /// <param name="delta">The time between the last tick and this one</param> public static void Tick(double delta) { Delta = delta; GlobalTickTime += delta; try { NetworkBase.Tick(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / networktick: " + ex.ToString()); } try { secondTracker += Delta; if (secondTracker >= 1.0) { secondTracker -= 1.0; OncePerSecondTick(); } } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / oncepersecondtick: " + ex.ToString()); } try { ServerCommands.Tick(); ConsoleHandler.CheckInput(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / command tick: " + ex.ToString()); } try { for (int i = 0; i < WaitingPlayers.Count; i++) { if (GlobalTickTime - WaitingPlayers[i].JoinTime > 10) { WaitingPlayers.RemoveAt(i); i--; } } for (int i = 0; i < Players.Count; i++) { // TODO: CVar if (GlobalTickTime - Players[i].LastPing > 60 || GlobalTickTime - Players[i].LastSecondaryPing > 60) { DespawnPlayer(Players[i]); i--; } } } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / general tick: " + ex.ToString()); } }
/// <summary> /// The server's primary tick function. /// </summary> public void Tick(double delta) { tpsc++; Delta = delta;// * CVars.g_timescale.ValueD; try { Stopwatch sw = new Stopwatch(); sw.Start(); opsat += Delta; if (opsat >= 1.0) { opsat -= 1.0; OncePerSecondActions(); } // TODO: Re-implement! /*if (CVars.g_timescale.ValueD != pts) // TODO: Make this CVar per-world * { * for (int i = 0; i < LoadedRegions.Count; i++) * { * LoadedRegions[i].SendToAll(new CVarSetPacketOut(CVars.g_timescale, this)); * } * }*/ //pts = CVars.g_timescale.ValueD; Networking.Tick(Delta); // TODO: Asynchronize network ticking ConsoleHandler.CheckInput(); // TODO: Asynchronize command ticking Commands.Tick(Delta); // TODO: Asynchronize command ticking //TickWorlds(Delta); Stopwatch schedw = new Stopwatch(); schedw.Start(); Schedule.RunAllSyncTasks(Delta); schedw.Stop(); ScheduleTimeC += schedw.Elapsed.TotalMilliseconds; ScheduleTimes++; sw.Stop(); TickTimeC += sw.Elapsed.TotalMilliseconds; TickTimes++; } catch (Exception ex) { Utilities.CheckException(ex); SysConsole.Output(OutputType.ERROR, "Tick: " + ex.ToString()); } }