Draw reload threshold is now based on size of map, fixes #472.

This commit is contained in:
UnknownShadow200 2017-07-20 20:38:44 +10:00
parent e5e565cbf1
commit cf578efa4f
7 changed files with 49 additions and 23 deletions

View File

@ -25,16 +25,20 @@ namespace MCGalaxy.Commands.Maintenance {
public override void Use(Player p, string message) {
string[] args = message.SplitSpaces();
if (message == "") { Help(p); return; }
bool hasLimit = args.Length > 1;
if (args[0].CaselessEq("rt") || args[0].CaselessEq("reloadthreshold")) {
float threshold = 0;
if (hasLimit && !CommandParser.GetReal(p, args[1], "Limit", ref threshold, 0, 100)) return;
SetLimitPercent(p, ref ServerConfig.DrawReloadThreshold, threshold, hasLimit);
return;
}
int limit = 0;
bool hasLimit = args.Length > 1;
if (hasLimit && !CommandParser.GetInt(p, args[1], "Limit", ref limit, 1)) return;
switch (args[0].ToLower()) {
case "rt":
case "reloadthreshold":
SetLimit(p, "Threshold before drawing reloads map", ref ServerConfig.DrawReloadLimit, limit, hasLimit);
return;
case "rp":
case "restartphysics":
SetLimit(p, "Custom /rp limit", ref ServerConfig.PhysicsRestartLimit, limit, hasLimit);
@ -72,12 +76,25 @@ namespace MCGalaxy.Commands.Maintenance {
Group.SaveList(Group.GroupList);
}
static void SetLimit(Player p, string format, ref int target, int value, bool hasValue) {
static void SetLimitPercent(Player p, ref float target, float value, bool hasValue) {
const string type = "Threshold before drawing reloads map";
if (hasValue) target = value / 100.0f;
string percent = (target * 100).ToString("F2") + "%";
if (!hasValue) {
Player.Message(p, format + ": &b" + target);
Player.Message(p, type + ": &b" + percent);
} else {
Chat.MessageGlobal(type + " set to &b" + percent);
SrvProperties.Save();
}
}
static void SetLimit(Player p, string type, ref int target, int value, bool hasValue) {
if (!hasValue) {
Player.Message(p, type + ": &b" + target);
} else {
target = value;
Chat.MessageGlobal(format + " set to &b" + target);
Chat.MessageGlobal(type + " set to &b" + target);
SrvProperties.Save();
}
}

View File

@ -65,7 +65,7 @@ namespace MCGalaxy.Commands.Building {
int count = op.Positions.Count;
bool confirmed = IsConfirmed(dArgs.Message), success = true;
if (count < p.group.MaxBlocks && count > ServerConfig.DrawReloadLimit && !confirmed) {
if (count < p.group.MaxBlocks && count > p.level.ReloadThreshold && !confirmed) {
Player.Message(p, "This fill would affect {0} blocks.", count);
Player.Message(p, "If you still want to fill, type %T/fill {0} confirm", dArgs.Message);
} else {

View File

@ -79,7 +79,7 @@ namespace MCGalaxy.Core {
if (line == "&all") p.ignoreAll = true;
else if (line == "&irc") p.ignoreIRC = true;
else if (line == "&8ball") p.ignore8ball = true;
else if (line == "&drawouput") p.ignoreDrawOutput = true;
else if (line == "&drawoutput") p.ignoreDrawOutput = true;
else if (line == "&titles") p.ignoreTitles = true;
else if (line == "&nicks") p.ignoreNicks = true;
else p.listignored.Add(line);

View File

@ -122,20 +122,19 @@ namespace MCGalaxy.Drawing.Ops {
entry.Start = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond);
if (item.Brush != null) item.Brush.Configure(item.Op, p);
DoDrawOp(item, 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 (item.Op.TotalModified > ServerConfig.DrawReloadLimit)
DoReload(p, item.Op.Level);
if (needReload) DoReload(p, item.Op.Level);
item.Op.TotalModified = 0; // reset total modified (as drawop instances are reused in static mode)
}
}
static void DoDrawOp(PendingDrawOp item, Player p) {
static bool DoDrawOp(PendingDrawOp item, Player p) {
Level lvl = item.Op.Level;
DrawOpOutputter outputter = new DrawOpOutputter(item.Op);
@ -144,6 +143,7 @@ namespace MCGalaxy.Drawing.Ops {
} else {
item.Op.Perform(item.Marks, item.Brush, outputter.Output);
}
return item.Op.TotalModified >= outputter.reloadThreshold;
}
static void DoReload(Player p, Level lvl) {
@ -158,8 +158,12 @@ namespace MCGalaxy.Drawing.Ops {
class DrawOpOutputter {
readonly DrawOp op;
internal readonly int reloadThreshold;
public DrawOpOutputter(DrawOp op) { this.op = op; }
public DrawOpOutputter(DrawOp op) {
this.op = op;
reloadThreshold = op.Level.ReloadThreshold;
}
public void Output(DrawOpBlock b) {
if (b.Block.BlockID == Block.Invalid) return;
@ -191,14 +195,15 @@ namespace MCGalaxy.Drawing.Ops {
p.SessionModified++; p.TotalModified++; p.TotalDrawn++; // increment block stats inline
}
// Potentially buffer the block change
if (op.TotalModified == ServerConfig.DrawReloadLimit) {
// Potentially buffer the block change
if (op.TotalModified == reloadThreshold) {
if (p == null || !p.ignoreDrawOutput) {
Player.Message(p, "Changed over {0} blocks, preparing to reload map..", ServerConfig.DrawReloadLimit);
Player.Message(p, "Changed over {0} blocks, preparing to reload map..", reloadThreshold);
}
lock (lvl.queueLock)
lvl.blockqueue.Clear();
} else if (op.TotalModified < ServerConfig.DrawReloadLimit) {
} else if (op.TotalModified < reloadThreshold) {
if (!old.VisuallyEquals(b.Block)) BlockQueue.Addblock(p, index, b.Block);
if (lvl.physics > 0) {

View File

@ -24,7 +24,7 @@ namespace MCGalaxy {
public static class BlockQueue {
public static int time = 100;
public static int blockupdates = 250;
public static int blockupdates = 1000;
static BufferedBlockSender bulkSender = new BufferedBlockSender();
public static void Loop(SchedulerTask task) {

View File

@ -60,7 +60,11 @@ namespace MCGalaxy {
public bool IsMuseum {
get { return name.StartsWith("&cMuseum " + ServerConfig.DefaultColor, StringComparison.Ordinal); }
}
}
public int ReloadThreshold {
get { return Math.Max(10000, (int)(ServerConfig.DrawReloadThreshold * Width * Height * Length)); }
}
public static bool cancelload;
public bool cancelsave;

View File

@ -133,8 +133,8 @@ namespace MCGalaxy {
public static bool ListEmptyRanks = false;
[ConfigInt("review-cooldown", "Review", 600, 0, 600)]
public static int ReviewCooldown = 600;
[ConfigInt("draw-reload-limit", "Other", 10000)]
public static int DrawReloadLimit = 10000;
[ConfigReal("draw-reload-threshold", "Other", 0.001f, 0, 1)]
public static float DrawReloadThreshold = 0.001f;
[ConfigBool("allow-tp-to-higher-ranks", "Other", true)]
public static bool HigherRankTP = true;
[ConfigPerm("os-perbuild-default", "Other", LevelPermission.Nobody)]