static void PerformRedo(Player p) { UndoDrawOpEntry[] entries = p.DrawOps.Items; if (entries.Length == 0) { p.Message("You have no &T/Undo %Sor &T/Undo [seconds] %Sto redo."); return; } for (int i = entries.Length - 1; i >= 0; i--) { UndoDrawOpEntry entry = entries[i]; if (entry.DrawOpName != "UndoSelf") { continue; } p.DrawOps.Remove(entry); RedoSelfDrawOp op = new RedoSelfDrawOp(); op.Start = entry.Start; op.End = entry.End; DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal }); p.Message("Redo performed."); return; } p.Message("No &T/Undo %Sor &T/Undo [timespan] %Scalls were " + "found in the last 200 draw operations."); }
internal static void Execute(Player p, DrawOp op, Brush brush, Vec3S32[] marks) { UndoDrawOpEntry entry = new UndoDrawOpEntry(); entry.Init(op.Name, op.Level.name); if (brush != null) { brush.Configure(op, p); } Level lvl = op.Level; DrawOpOutputter outputter = new DrawOpOutputter(op); if (op.AffectedByTransform) { p.Transform.Perform(marks, p, lvl, op, brush, outputter.Output); } else { op.Perform(marks, brush, outputter.Output); } bool needsReload = op.TotalModified >= outputter.reloadThreshold; if (op.Undoable) { entry.Finish(p); } if (needsReload) { DoReload(p, op.Level); } op.TotalModified = 0; // reset total modified (as drawop instances are reused in static mode) }
static void PerformRedo(Player p) { UndoDrawOpEntry[] entries = p.DrawOps.Items; if (entries.Length == 0) { Player.SendMessage(p, "You have no %T/undo%S or %T/undo <seconds>%S to redo."); return; } for (int i = entries.Length - 1; i >= 0; i--) { UndoDrawOpEntry entry = entries[i]; if (entry.DrawOpName != "UndoSelf") { continue; } p.DrawOps.Remove(entry); RedoSelfDrawOp op = new RedoSelfDrawOp(); op.Start = entry.Start; op.End = entry.End; DrawOp.DoDrawOp(op, null, p, new [] { Vec3U16.MaxVal, Vec3U16.MaxVal }); Player.SendMessage(p, "Redo performed."); return; } Player.SendMessage(p, "No %T/undo%S or %T/undo <seconds>%S calls were " + "found in the last 200 draw operations."); }
void UndoSelf(Player p) { UndoDrawOpEntry[] entries = p.DrawOps.Items; if (entries.Length == 0) { Player.Message(p, "You have no draw operations to undo."); Player.Message(p, "Try using %T/undo [seconds] %Sinstead."); return; } for (int i = entries.Length - 1; i >= 0; i--) { UndoDrawOpEntry entry = entries[i]; if (entry.DrawOpName == "UndoSelf") { continue; } p.DrawOps.Remove(entry); UndoSelfDrawOp op = new UndoSelfDrawOp(); op.who = p; op.Start = entry.Start; op.End = entry.End; DrawOp.DoDrawOp(op, null, p, new Vec3S32[] { Vec3U16.MaxVal, Vec3U16.MaxVal }); Player.Message(p, "Undo performed."); return; } Player.Message(p, "Unable to undo any draw operations, as all of the " + "past 50 draw operations are %T/undo %Sor %T/undo [seconds]."); Player.Message(p, "Try using %T/undo [seconds] %Sinstead."); }
void UndoLastDrawOp(Player p) { UndoDrawOpEntry[] entries = p.DrawOps.Items; if (entries.Length == 0) { p.Message("You have no draw operations to undo."); p.Message("Try using %T/Undo [timespan] %Sinstead."); return; } for (int i = entries.Length - 1; i >= 0; i--) { UndoDrawOpEntry entry = entries[i]; if (entry.DrawOpName == "UndoSelf") { continue; } p.DrawOps.Remove(entry); UndoSelfDrawOp op = new UndoSelfDrawOp(); op.who = p.name; op.ids = NameConverter.FindIds(p.name); op.Start = entry.Start; op.End = entry.End; DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal }); p.Message("Undo performed."); return; } p.Message("Unable to undo any draw operations, as all of the " + "past 50 draw operations are %T/Undo %Sor %T/Undo [timespan]"); p.Message("Try using %T/Undo [timespan] %Sinstead"); }
static void ProcessDrawOps(Player p) { while (true) { PendingDrawOp item; lock (p.pendingDrawOpsLock) { if (p.PendingDrawOps.Count == 0) { return; } item = p.PendingDrawOps[0]; p.PendingDrawOps.RemoveAt(0); // Flush any remaining draw ops if the player has left the server. // (so as to not keep alive references) if (p.disconnected) { p.PendingDrawOps.Clear(); return; } } UndoDrawOpEntry entry = new UndoDrawOpEntry(); entry.DrawOpName = item.Op.Name; entry.LevelName = item.Op.Level.name; entry.Start = DateTime.UtcNow; // Use same time method as DoBlockchange writing to undo buffer int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; entry.Start = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond); if (item.Brush != null) { item.Brush.Configure(item.Op, p); } bool needReload = DoDrawOp(item, p); timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds + 1; entry.End = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond); if (item.Op.Undoable) { p.DrawOps.Add(entry); } if (p.DrawOps.Count > 200) { p.DrawOps.RemoveFirst(); } if (needReload) { DoReload(p, item.Op.Level); } item.Op.TotalModified = 0; // reset total modified (as drawop instances are reused in static mode) } }
static void ProcessDrawOps(Player p) { while (true) { PendingDrawOp item; lock (p.pendingDrawOpsLock) { if (p.PendingDrawOps.Count == 0) { return; } item = p.PendingDrawOps[0]; p.PendingDrawOps.RemoveAt(0); // Flush any remaining draw ops if the player has left the server. // (so as to not keep alive references) if (p.disconnected) { p.PendingDrawOps.Clear(); return; } } UndoDrawOpEntry entry = new UndoDrawOpEntry(); entry.DrawOpName = item.Op.Name; entry.LevelName = item.Level.name; entry.Start = DateTime.UtcNow; // Use same time method as DoBlockchange writing to undo buffer int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; entry.Start = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond); bool needReveal = item.Op.DetermineDrawOpMethod(item.Level, item.Affected); item.Op.Perform(item.Marks, p, item.Level, item.Brush); timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; entry.End = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond); p.DrawOps.Add(entry); if (p.DrawOps.Count > 200) { p.DrawOps.RemoveFirst(); } DoReload(p, item.Level, needReveal); } }