Chat progress tracker

This commit is contained in:
Jesse Boyd 2017-02-20 11:10:23 +11:00
parent a080735b83
commit e6dfdf0ecf
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
7 changed files with 106 additions and 25 deletions

View File

@ -28,7 +28,7 @@ ext {
date = git.head().date.format("yy.MM.dd") date = git.head().date.format("yy.MM.dd")
revision = "-${git.head().abbreviatedId}" revision = "-${git.head().abbreviatedId}"
parents = git.head().parentIds; parents = git.head().parentIds;
index = -73; // Offset to mach CI index = -74; // Offset to mach CI
int major, minor, patch; int major, minor, patch;
major = minor = patch = 0; major = minor = patch = 0;
for (;parents != null && !parents.isEmpty();index++) { for (;parents != null && !parents.isEmpty();index++) {

View File

@ -204,7 +204,7 @@ public enum BBC {
COMMAND_INVALID_SYNTAX("The command was not used properly (no more help available).", "WorldEdit.Command"), COMMAND_INVALID_SYNTAX("The command was not used properly (no more help available).", "WorldEdit.Command"),
PROGRESS_MESSAGE("[ Queue: %s0 | Dispatched: %s1 ]", "Progress"), PROGRESS_MESSAGE("%s1/%s0 (%s2%) @%s3cps %s4s left", "Progress"),
PROGRESS_FINISHED("[ Done! ]", "Progress"), PROGRESS_FINISHED("[ Done! ]", "Progress"),
COMMAND_SYNTAX("&cUsage: &7%s0", "Error"), COMMAND_SYNTAX("&cUsage: &7%s0", "Error"),

View File

@ -248,10 +248,16 @@ public class Settings extends Config {
public static int DISCARD_AFTER_MS = 60000; public static int DISCARD_AFTER_MS = 60000;
public static class PROGRESS { public static class PROGRESS {
@Comment("Display constant titles about the progress of a user's edit") @Comment({"Display constant titles about the progress of a user's edit",
public boolean DISPLAY = false; " - false = disabled",
" - title = Display progress titles",
" - chat = Display progress in chat"
})
public String DISPLAY = "false";
@Comment("How often edit progress is displayed") @Comment("How often edit progress is displayed")
public int INTERVAL = 1; public int INTERVAL = 1;
@Comment("Delay sending progress in milliseconds (so quick edits don't spam)")
public int DELAY = 5000;
} }
} }

View File

@ -222,6 +222,9 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> exte
} }
public void end(FaweChunk chunk) { public void end(FaweChunk chunk) {
if (getProgressTask() != null) {
getProgressTask().run(ProgressType.DISPATCH, size() + 1);
}
chunk.end(); chunk.end();
} }

View File

@ -0,0 +1,26 @@
package com.boydti.fawe.object.progress;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer;
public class ChatProgressTracker extends DefaultProgressTracker {
public ChatProgressTracker(FawePlayer player) {
super(player);
setInterval(getDelay() / 50);
}
@Override
public void sendTask() {
super.sendTask();
}
@Override
public void doneTask() {
super.doneTask();
}
@Override
public void sendTile(String title, String sub) {
getPlayer().sendMessage(BBC.getPrefix() + title + sub);
}
}

View File

@ -15,38 +15,71 @@ public class DefaultProgressTracker extends RunnableVal2<FaweQueue.ProgressType,
private final FawePlayer player; private final FawePlayer player;
private final long start; private final long start;
private int delay = Settings.IMP.QUEUE.PROGRESS.DELAY;
private int interval = Settings.IMP.QUEUE.PROGRESS.INTERVAL;
public DefaultProgressTracker(FawePlayer player) { public DefaultProgressTracker(FawePlayer player) {
this.start = System.currentTimeMillis(); this.start = System.currentTimeMillis();
this.player = player; this.player = player;
} }
public void setInterval(int interval) {
this.interval = interval;
}
public void setDelay(int delay) {
this.delay = delay;
}
public int getInterval() {
return interval;
}
public int getDelay() {
return delay;
}
public FawePlayer getPlayer() {
return player;
}
// Number of times a chunk was queued // Number of times a chunk was queued
private int totalQueue = 0; private int totalQueue = 0;
// Current size of the queue // Current size of the queue
private int amountQueue = 0; private int amountQueue = 0;
// Number of chunks dispatched // Number of chunks dispatched
private int amountDispatch = 0; private int amountDispatch = 0;
// Last size (to calculate speed)
private int lastSize = 0;
// If the task is finished
private boolean done = false;
@Override @Override
public void run(FaweQueue.ProgressType type, Integer amount) { public void run(FaweQueue.ProgressType type, Integer amount) {
switch (type) { switch (type) {
case DISPATCH: case DISPATCH:
amountDispatch = amount; amountDispatch++;
amountQueue = amount;
break; break;
case QUEUE: case QUEUE:
totalQueue++; totalQueue++;
amountQueue = amount; amountQueue = amount;
break; break;
case DONE: case DONE:
if (totalQueue > 64) { if (totalQueue > 64 && !done) {
done = true;
done(); done();
} }
return; return;
} }
// Only send a message after 64 chunks (i.e. ignore smaller edits) // Only send a message after 64 chunks (i.e. ignore smaller edits)
if (totalQueue > 64) { long now = System.currentTimeMillis();
send(); if (now - start > delay) {
long currentTick = now / 50;
if (currentTick > lastTick + interval) {
lastTick = currentTick;
send();
}
} }
} }
@ -62,26 +95,30 @@ public class DefaultProgressTracker extends RunnableVal2<FaweQueue.ProgressType,
private long lastTick = 0; private long lastTick = 0;
private final void send() { private final void send() {
// Avoid duplicates TaskManager.IMP.task(new Runnable() { // Run on main thread
long currentTick = System.currentTimeMillis() / 50; @Override
if (currentTick > lastTick + Settings.IMP.QUEUE.PROGRESS.INTERVAL) { public void run() {
lastTick = currentTick; sendTask();
TaskManager.IMP.task(new Runnable() { // Run on main thread }
@Override });
public void run() {
sendTask();
}
});
}
} }
public void doneTask() { public void doneTask() {
player.sendTitle("", BBC.PROGRESS_FINISHED.s()); sendTile("", BBC.PROGRESS_FINISHED.s());
} }
public void sendTask() { public void sendTask() {
String queue = StringMan.padRight("" + amountQueue, 3); String queue = StringMan.padRight("" + totalQueue, 3);
String dispatch = StringMan.padRight("" + amountDispatch, 3); String dispatch = StringMan.padLeft("" + amountDispatch, 3);
player.sendTitle("", BBC.PROGRESS_MESSAGE.format(queue, dispatch)); int total = amountDispatch != 0 ? amountDispatch : amountQueue;
int speed = total != 0 ? (int) (total / Math.max((System.currentTimeMillis() - start) / 1000d, 1)) : 0;
String speedStr = StringMan.padRight("" + speed, 3);
String percent = StringMan.padRight("" + (amountDispatch != 0 ? (amountDispatch * 100) / totalQueue : 0), 3);
int remaining = speed != 0 ? amountQueue / speed : -1;
sendTile("", BBC.PROGRESS_MESSAGE.format(queue, dispatch, percent, StringMan.padLeft("" + speed, 3), StringMan.padLeft("" + remaining, 3)));
}
public void sendTile(String title, String sub) {
player.sendTitle(title, sub);
} }
} }

View File

@ -54,6 +54,7 @@ import com.boydti.fawe.object.extent.SlowExtent;
import com.boydti.fawe.object.extent.SourceMaskExtent; import com.boydti.fawe.object.extent.SourceMaskExtent;
import com.boydti.fawe.object.function.block.LegacyBlockReplace; import com.boydti.fawe.object.function.block.LegacyBlockReplace;
import com.boydti.fawe.object.mask.ResettableMask; import com.boydti.fawe.object.mask.ResettableMask;
import com.boydti.fawe.object.progress.ChatProgressTracker;
import com.boydti.fawe.object.progress.DefaultProgressTracker; import com.boydti.fawe.object.progress.DefaultProgressTracker;
import com.boydti.fawe.object.visitor.FastChunkIterator; import com.boydti.fawe.object.visitor.FastChunkIterator;
import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.ExtentTraverser;
@ -269,8 +270,16 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
} }
this.queue = queue; this.queue = queue;
this.queue.addEditSession(this); this.queue.addEditSession(this);
if (Settings.IMP.QUEUE.PROGRESS.DISPLAY && player != null) { if (!Settings.IMP.QUEUE.PROGRESS.DISPLAY.equalsIgnoreCase("false") && player != null) {
this.queue.setProgressTask(new DefaultProgressTracker(player)); switch (Settings.IMP.QUEUE.PROGRESS.DISPLAY.toLowerCase()) {
case "chat":
this.queue.setProgressTask(new ChatProgressTracker(player));
break;
case "title":
case "true":
default:
this.queue.setProgressTask(new DefaultProgressTracker(player));
}
} }
this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE); this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE);
this.bypassHistory = (this.extent = wrapExtent(bypassAll, bus, event, Stage.BEFORE_REORDER)); this.bypassHistory = (this.extent = wrapExtent(bypassAll, bus, event, Stage.BEFORE_REORDER));