Feat: in text UIs, show render progress in one line (#257)
The text UI gets quite messy during the render process, as it takes at least one extra line of the screen per second. This PR fixes that issue and also shows an ASCII bar to show the render progress.
This commit is contained in:
@@ -28,6 +28,8 @@ public interface Gui {
|
||||
|
||||
public void status(String msg_, boolean overwriteSuspendedMsg);
|
||||
|
||||
public void status(String msg_, int progress);
|
||||
|
||||
public void status(String msg_, int progress, long size);
|
||||
|
||||
public void updateTrayIcon(Integer percentage_);
|
||||
|
||||
@@ -293,10 +293,11 @@ import lombok.Getter;
|
||||
try {
|
||||
int progress = -1;
|
||||
|
||||
Pattern tilePattern = Pattern.compile(" ([0-9]+)\\s?\\/\\s?([0-9]+) ");
|
||||
Pattern tilePattern = Pattern.compile(" (Rendered|Path Tracing Tile|Rendering) (\\d+)\\s?\\/\\s?(\\d+)( Tiles| samples|,)");
|
||||
|
||||
// Initialise the progress bar in the icon (0% completed at this time)
|
||||
// Initialise the progress bar in the icon and the UI (0% completed at this time)
|
||||
gui.updateTrayIcon(0);
|
||||
gui.status("Preparing scene", 0);
|
||||
|
||||
while ((line = input.readLine()) != null) {
|
||||
log.debug(line);
|
||||
@@ -458,15 +459,16 @@ import lombok.Getter;
|
||||
int newProgress = currentProgress;
|
||||
|
||||
if (standardTileInfo.find()) {
|
||||
int tileJustProcessed = Integer.parseInt(standardTileInfo.group(1));
|
||||
int totalTilesInJob = Integer.parseInt(standardTileInfo.group(2));
|
||||
int tileJustProcessed = Integer.parseInt(standardTileInfo.group(2));
|
||||
int totalTilesInJob = Integer.parseInt(standardTileInfo.group(3));
|
||||
|
||||
newProgress = Math.abs((tileJustProcessed * 100) / totalTilesInJob);
|
||||
}
|
||||
|
||||
// Only update the tray icon if percentage has changed
|
||||
// Only update the tray icon and the screen if percentage has changed
|
||||
if (newProgress != currentProgress) {
|
||||
gui.updateTrayIcon(newProgress);
|
||||
gui.status("Rendering", newProgress);
|
||||
}
|
||||
|
||||
return newProgress;
|
||||
|
||||
@@ -191,12 +191,16 @@ public class GuiSwing extends JFrame implements Gui {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress, long size) {
|
||||
@Override public void status(String msg, int progress) {
|
||||
if (activityWorking != null) {
|
||||
this.activityWorking.setStatus(String.format("%s %d%%", msg, progress));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress, long size) {
|
||||
this.status(msg, progress);
|
||||
}
|
||||
|
||||
@Override public void setRenderingProjectName(String name_) {
|
||||
if (activityWorking != null) {
|
||||
this.activityWorking.setRenderingProjectName(name_);
|
||||
|
||||
@@ -42,6 +42,7 @@ public class GuiText implements Gui {
|
||||
private int sigIntCount = 0;
|
||||
private Log log;
|
||||
private DateFormat df;
|
||||
private String eta;
|
||||
|
||||
private Client client;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class GuiText implements Gui {
|
||||
this.framesRendered = 0;
|
||||
this.log = Log.getInstance(null);
|
||||
this.df = new SimpleDateFormat("MMM dd HH:mm:ss");
|
||||
this.eta = "";
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@@ -111,6 +113,10 @@ public class GuiText implements Gui {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress) {
|
||||
this.status(msg, progress, 0);
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress, long size) {
|
||||
System.out.print("\r");
|
||||
System.out.print(String.format("%s %s", this.df.format(new Date()), showProgress(msg, progress, size)));
|
||||
@@ -144,7 +150,7 @@ public class GuiText implements Gui {
|
||||
}
|
||||
|
||||
@Override public void setRemainingTime(String time_) {
|
||||
System.out.println(String.format("%s Rendering (remaining %s)", this.df.format(new Date()), time_));
|
||||
this.eta = time_;
|
||||
}
|
||||
|
||||
@Override public void setRenderingTime(String time_) {
|
||||
@@ -169,6 +175,8 @@ public class GuiText implements Gui {
|
||||
|
||||
private String showProgress(String message, int progress, long size) {
|
||||
StringBuilder progressBar = new StringBuilder(140);
|
||||
|
||||
if (progress < 100) {
|
||||
progressBar
|
||||
.append(message)
|
||||
.append(" ")
|
||||
@@ -183,9 +191,19 @@ public class GuiText implements Gui {
|
||||
progressBar.append(String.format(" %dMB", (size / 1024 / 1024)));
|
||||
}
|
||||
|
||||
// Once the process has completed, show the output in a new line
|
||||
if (progress == 100) {
|
||||
progressBar.append("\n");
|
||||
if (!this.eta.equals("")) {
|
||||
progressBar.append(String.format(" ETA %s", this.eta));
|
||||
}
|
||||
|
||||
progressBar.append(String.join("", Collections.nCopies(60 - progressBar.length(), " ")));
|
||||
}
|
||||
// If progress has reached 100%
|
||||
else {
|
||||
progressBar
|
||||
.append(message)
|
||||
.append(" done")
|
||||
.append(String.join("", Collections.nCopies(60 - progressBar.length(), " ")))
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
return progressBar.toString();
|
||||
|
||||
@@ -46,6 +46,7 @@ public class GuiTextOneLine implements Gui {
|
||||
private String computeMethod;
|
||||
private String status;
|
||||
private String line;
|
||||
private String eta;
|
||||
|
||||
private int uploadQueueSize;
|
||||
private long uploadQueueVolume;
|
||||
@@ -65,6 +66,7 @@ public class GuiTextOneLine implements Gui {
|
||||
uploadQueueSize = 0;
|
||||
uploadQueueVolume = 0;
|
||||
df = new SimpleDateFormat("MMM dd HH:mm:ss");
|
||||
eta = "";
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@@ -123,6 +125,10 @@ public class GuiTextOneLine implements Gui {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress) {
|
||||
this.status(msg, progress, 0);
|
||||
}
|
||||
|
||||
@Override public void status(String msg, int progress, long size) {
|
||||
status = showProgress(msg, progress, size);
|
||||
updateLine();
|
||||
@@ -160,7 +166,7 @@ public class GuiTextOneLine implements Gui {
|
||||
}
|
||||
|
||||
@Override public void setRemainingTime(String time_) {
|
||||
status = "Rendering (remaining " + time_ + ")";
|
||||
this.eta = time_;
|
||||
updateLine();
|
||||
}
|
||||
|
||||
@@ -226,6 +232,10 @@ public class GuiTextOneLine implements Gui {
|
||||
progressBar.append(String.format(" %dMB", (size / 1024 / 1024)));
|
||||
}
|
||||
|
||||
if (!this.eta.equals("")) {
|
||||
progressBar.append(String.format(" ETA %s", this.eta));
|
||||
}
|
||||
|
||||
return progressBar.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user