diff --git a/MCGalaxy/Commands/Fun/CmdMissile.cs b/MCGalaxy/Commands/Fun/CmdMissile.cs index e0925677f..51573893a 100644 --- a/MCGalaxy/Commands/Fun/CmdMissile.cs +++ b/MCGalaxy/Commands/Fun/CmdMissile.cs @@ -15,11 +15,11 @@ or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. */ -using System; -using System.Collections.Generic; -using System.Threading; -using MCGalaxy.Drawing.Ops; -using MCGalaxy.Maths; +using System; +using System.Collections.Generic; +using MCGalaxy.Drawing.Ops; +using MCGalaxy.Maths; +using MCGalaxy.Tasks; namespace MCGalaxy.Commands.Fun { public sealed class CmdMissile : WeaponCmd { @@ -42,9 +42,9 @@ namespace MCGalaxy.Commands.Fun { args.ending = bp.ending; args.pos = MakePos(p); - Thread gunThread = new Thread(() => DoShoot(args)); - gunThread.Name = "MCG_Missile"; - gunThread.Start(); + SchedulerTask task = new SchedulerTask(MissileCallback, args, + TimeSpan.FromMilliseconds(100), true); + p.CriticalTasks.Add(task); } class MissileArgs { @@ -52,6 +52,7 @@ namespace MCGalaxy.Commands.Fun { public ExtBlock block; public EndType ending; public Vec3U16 pos; + public bool Moving = true; public List previous = new List(); public List allBlocks = new List(); @@ -59,30 +60,39 @@ namespace MCGalaxy.Commands.Fun { public int iterations; } - void DoShoot(MissileArgs args) { + static void MissileCallback(SchedulerTask task) { + MissileArgs args = (MissileArgs)task.State; Player p = args.player; + if (args.Moving) { PerformMove(args); return; } + if (args.ending == EndType.Teleport) { + args.ending = EndType.Normal; + int index = args.previous.Count - 3; + if (index >= 0 && index < args.previous.Count) + DoTeleport(p, args.previous[index]); + } + + if (args.previous.Count > 0) { + Vec3U16 pos = args.previous[0]; + args.previous.RemoveAt(0); + p.level.Blockchange(pos.X, pos.Y, pos.Z, ExtBlock.Air, true); + } + task.Repeating = args.previous.Count > 0; + } + + static void PerformMove(MissileArgs args) { while (true) { args.iterations++; Vec3U16 target = MissileTarget(args); FindNext(target, ref args.pos, args.buffer); if (args.iterations <= 3) continue; - if (!MoveMissile(args, args.pos, target)) break; - Thread.Sleep(100); - } - - if (args.ending == EndType.Teleport) { - int index = args.previous.Count - 3; - if (index >= 0 && index < args.previous.Count) - DoTeleport(p, args.previous[index]); - } - foreach (Vec3U16 pos1 in args.previous) { - p.level.Blockchange(pos1.X, pos1.Y, pos1.Z, ExtBlock.Air, true); - Thread.Sleep(100); + args.Moving = MoveMissile(args, args.pos, target); + return; } } + static Vec3U16 MissileTarget(MissileArgs args) { Player p = args.player; Vec3U16 start = MakePos(p); @@ -147,7 +157,7 @@ namespace MCGalaxy.Commands.Fun { return (Vec3U16)p.Pos.BlockCoords; } - void FindNext(Vec3U16 lookedAt, ref Vec3U16 pos, List buffer) { + static void FindNext(Vec3U16 lookedAt, ref Vec3U16 pos, List buffer) { LineDrawOp.DrawLine(pos.X, pos.Y, pos.Z, 2, lookedAt.X, lookedAt.Y, lookedAt.Z, buffer); Vec3U16 end = (Vec3U16)buffer[buffer.Count - 1]; pos.X = end.X; pos.Y = end.Y; pos.Z = end.Z; diff --git a/MCGalaxy/Player/List/PlayerList.cs b/MCGalaxy/Player/List/PlayerList.cs index 7b53a3ede..33f973658 100644 --- a/MCGalaxy/Player/List/PlayerList.cs +++ b/MCGalaxy/Player/List/PlayerList.cs @@ -125,8 +125,5 @@ namespace MCGalaxy { } return list; } - - [Obsolete("Group parameter is completely ignored.")] - public static PlayerList Load(string path, Group grp) { return Load(path); } } } \ No newline at end of file diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index 1533933ad..7e07cf962 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -248,11 +248,6 @@ namespace MCGalaxy { } } - [Obsolete("Use LevelInfo.Loaded.Add()")] - public static void addLevel(Level level) { - LevelInfo.Loaded.Add(level); - } - public void PlayerListUpdate() { if (Server.s.OnPlayerListChange != null) Server.s.OnPlayerListChange(Player.players); } @@ -335,10 +330,6 @@ namespace MCGalaxy { internal void SettingsUpdate() { if (OnSettingsUpdate != null) OnSettingsUpdate(); } - - public static string FindColor(string name) { - return Group.findPlayerGroup(name).color; - } /// Sets the main level of the server that new players spawn in. /// true if main level was changed, false if not @@ -367,7 +358,9 @@ namespace MCGalaxy { long end = GC.GetTotalMemory(false); double deltaKB = (start - end) / 1024.0; if (deltaKB >= 100.0) { - Server.s.Log("GC performed (freed " + deltaKB.ToString("F2") + " KB)", true); + string track = (end / 1024.0).ToString("F2"); + string delta = deltaKB.ToString("F2"); + Server.s.Log("GC performed (tracking " + track + " KB, freed " + delta + " KB)", true); } } } diff --git a/MCGalaxy/Server/Tasks/ServerTasks.cs b/MCGalaxy/Server/Tasks/ServerTasks.cs index 76f7b259e..f5688812c 100644 --- a/MCGalaxy/Server/Tasks/ServerTasks.cs +++ b/MCGalaxy/Server/Tasks/ServerTasks.cs @@ -73,9 +73,13 @@ namespace MCGalaxy.Tasks { } SchedulerTask[] tasks = p.CriticalTasks.Items; + DateTime now = DateTime.UtcNow; for (int i = 0; i < tasks.Length; i++) { SchedulerTask task = tasks[i]; + if (now < task.NextRun) continue; + task.Callback(task); + task.NextRun = now.Add(task.Delay); if (task.Repeating) continue; p.CriticalTasks.Remove(task);