mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
LocationChecks and PositionUpdate now share a scheduler thread.
This commit is contained in:
parent
16e3545551
commit
09e10eb75b
@ -161,7 +161,7 @@ namespace MCGalaxy {
|
||||
|
||||
void UpdatePosition() {
|
||||
if (movement) {
|
||||
double scale = Math.Ceiling(Server.updateTimer.Interval / 25.0);
|
||||
double scale = Math.Ceiling(Server.PositionInterval / 25.0);
|
||||
int steps = movementSpeed * (int)scale;
|
||||
for (int i = 0; i < steps; i++)
|
||||
DoMove();
|
||||
|
@ -33,11 +33,11 @@ namespace MCGalaxy {
|
||||
if (text[0] == '@') text = text.Remove(0, 1).Trim();
|
||||
|
||||
if (p == null || p.whisperTo == "") {
|
||||
int pos = text.IndexOf(' ');
|
||||
if ( pos != -1 ) {
|
||||
string to = text.Substring(0, pos);
|
||||
string msg = text.Substring(pos + 1);
|
||||
HandleWhisper(p, to, msg);
|
||||
int sepIndex = text.IndexOf(' ');
|
||||
if (sepIndex != -1) {
|
||||
string target = text.Substring(0, sepIndex);
|
||||
text = text.Substring(sepIndex + 1);
|
||||
HandleWhisper(p, target, text);
|
||||
} else {
|
||||
Player.Message(p, "No message entered");
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
up.Shorten(true), Server.SoftwareName, Server.VersionString);
|
||||
|
||||
Player.Message(p, "Player positions are updated every &b"
|
||||
+ Server.updateTimer.Interval + " %Smilliseconds.");
|
||||
+ Server.PositionInterval + " %Smilliseconds.");
|
||||
string owner = Server.server_owner;
|
||||
if (!owner.CaselessEq("Notch"))
|
||||
Player.Message(p, "Owner is &3{0}. %SConsole state: &3{1}", owner, Server.ZallState);
|
||||
|
@ -23,7 +23,7 @@ namespace MCGalaxy.Commands.Maintenance {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "" && Server.updateTimer.Interval > 1000) {
|
||||
if (message == "" && Server.PositionInterval > 1000) {
|
||||
Server.PositionInterval = 100;
|
||||
Chat.MessageGlobal("&dLow lag %Sturned &cOFF %S- positions update every &b100 %Sms.");
|
||||
} else if (message == "") {
|
||||
@ -36,7 +36,6 @@ namespace MCGalaxy.Commands.Maintenance {
|
||||
Server.PositionInterval = interval;
|
||||
Chat.MessageGlobal("Positions now update every &b{0} %Smilliseconds.", interval);
|
||||
}
|
||||
Server.updateTimer.Interval = Server.PositionInterval;
|
||||
SrvProperties.Save();
|
||||
}
|
||||
|
||||
|
@ -47,12 +47,10 @@ namespace MCGalaxy {
|
||||
ZombieGameProps.SaveSettings();
|
||||
ZombieGameProps.LoadSettings();
|
||||
|
||||
Database.Backend = Server.useMySQL ?
|
||||
MySQLBackend.Instance : SQLiteBackend.Instance;
|
||||
Database.Backend = Server.useMySQL ? MySQLBackend.Instance : SQLiteBackend.Instance;
|
||||
|
||||
if (!Directory.Exists(Server.backupLocation))
|
||||
Server.backupLocation = Path.Combine(Utils.FolderPath, "levels/backups");
|
||||
Server.updateTimer.Interval = Server.PositionInterval;
|
||||
Save(givenPath);
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ namespace MCGalaxy {
|
||||
} catch {
|
||||
}
|
||||
|
||||
if (Server.updateTimer.Interval > 1000)
|
||||
if (Server.PositionInterval > 1000)
|
||||
SendMessage("Lowlag mode is currently &aON.");
|
||||
|
||||
if (String.IsNullOrEmpty(appName)) {
|
||||
|
@ -70,9 +70,7 @@ namespace MCGalaxy {
|
||||
|
||||
// URL hash for connecting to the server
|
||||
public static string Hash = String.Empty, URL = String.Empty;
|
||||
|
||||
public static Socket listen;
|
||||
public static System.Timers.Timer updateTimer = new System.Timers.Timer(100);
|
||||
|
||||
//Chatrooms
|
||||
public static List<string> Chatrooms = new List<string>();
|
||||
@ -123,6 +121,7 @@ namespace MCGalaxy {
|
||||
|
||||
public static Scheduler MainScheduler = new Scheduler("MCG_MainScheduler");
|
||||
public static Scheduler Background = new Scheduler("MCG_BackgroundScheduler");
|
||||
public static Scheduler Critical = new Scheduler("MCG_CriticalScheduler");
|
||||
public static Server s;
|
||||
|
||||
public const byte version = 7;
|
||||
|
@ -102,33 +102,29 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
void InitTimers() {
|
||||
updateTimer.Elapsed += delegate {
|
||||
Entities.GlobalUpdate();
|
||||
PlayerBot.GlobalUpdatePosition();
|
||||
};
|
||||
updateTimer.Start();
|
||||
|
||||
if (File.Exists(Paths.AnnouncementsFile)) {
|
||||
string[] lines = File.ReadAllLines(Paths.AnnouncementsFile);
|
||||
messages = new List<string>(lines);
|
||||
} else {
|
||||
using (File.Create(Paths.AnnouncementsFile)) {}
|
||||
}
|
||||
Server.MainScheduler.QueueRepeat(RandomMessage, null, TimeSpan.FromMinutes(5));
|
||||
|
||||
MainScheduler.QueueRepeat(RandomMessage, null,
|
||||
TimeSpan.FromMinutes(5));
|
||||
Critical.QueueRepeat(ServerTasks.UpdateEntityPositions, null,
|
||||
TimeSpan.FromMilliseconds(PositionInterval));
|
||||
}
|
||||
|
||||
void InitRest() {
|
||||
IRC = new IRCBot();
|
||||
if (Server.irc) IRC.Connect();
|
||||
|
||||
locationChecker = new Thread(ServerTasks.LocationChecks);
|
||||
locationChecker.Name = "MCG_LocationCheck";
|
||||
locationChecker.Start();
|
||||
|
||||
InitZombieSurvival();
|
||||
InitLavaSurvival();
|
||||
MainScheduler.QueueRepeat(BlockQueue.Loop, null,
|
||||
TimeSpan.FromMilliseconds(BlockQueue.time));
|
||||
Critical.QueueRepeat(ServerTasks.LocationChecks, null,
|
||||
TimeSpan.FromMilliseconds(20));
|
||||
|
||||
Log("Finished setting up server, finding classicube.net url..");
|
||||
ServerSetupFinished = true;
|
||||
|
@ -26,11 +26,11 @@ using MCGalaxy.Maths;
|
||||
namespace MCGalaxy.Tasks {
|
||||
internal static class ServerTasks {
|
||||
|
||||
internal static void LocationChecks() {
|
||||
while (true) {
|
||||
internal static void LocationChecks(SchedulerTask task) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
Thread.Sleep(players.Length == 0 ? 20 : 10);
|
||||
players = PlayerInfo.Online.Items;
|
||||
int delay = players.Length == 0 ? 100 : 20;
|
||||
task.Delay = TimeSpan.FromMilliseconds(delay);
|
||||
|
||||
for (int i = 0; i < players.Length; i++) {
|
||||
try {
|
||||
@ -64,6 +64,11 @@ namespace MCGalaxy.Tasks {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpdateEntityPositions(SchedulerTask task) {
|
||||
Entities.GlobalUpdate();
|
||||
PlayerBot.GlobalUpdatePosition();
|
||||
task.Delay = TimeSpan.FromMilliseconds(Server.PositionInterval);
|
||||
}
|
||||
|
||||
internal static void CheckState(SchedulerTask task) {
|
||||
|
@ -77,21 +77,26 @@ namespace MCGalaxy.Tasks {
|
||||
|
||||
|
||||
SchedulerTask GetNextTask() {
|
||||
DateTime now = DateTime.UtcNow;
|
||||
DateTime minTime = DateTime.UtcNow;
|
||||
SchedulerTask minTask = null;
|
||||
|
||||
lock (taskLock) {
|
||||
foreach (SchedulerTask task in tasks) {
|
||||
if (task.NextRun < now) return task;
|
||||
if (task.NextRun > minTime) continue;
|
||||
minTime = task.NextRun; minTask = task;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return minTask;
|
||||
}
|
||||
|
||||
SchedulerTask lastTask = null;
|
||||
void DoTask(SchedulerTask task) {
|
||||
try {
|
||||
task.Callback(task);
|
||||
} catch (Exception ex) {
|
||||
MCGalaxy.Server.ErrorLog(ex);
|
||||
}
|
||||
lastTask = task;
|
||||
|
||||
if (task.Repeating) {
|
||||
task.NextRun = DateTime.UtcNow.Add(task.Delay);
|
||||
|
Loading…
x
Reference in New Issue
Block a user