Add task bar progress

(cherry picked from commit f1123480f9da8436ba62193556d7f676f2051bd7)
This commit is contained in:
mcrcortex committed 2024-11-16 16:20:45 +10:00
1 parent ad6cc38ed4
commit c9c7d9ab1b
6 files changed
+107 -1

No files matched your search

@@ -51,7 +51,7 @@ import static org.lwjgl.system.MemoryUtil.NULL;
public class CustomImGuiImplGlfw {
private static final String OS = System.getProperty("os.name", "generic").toLowerCase();
protected static final boolean IS_WINDOWS = OS.contains("win");
public static final boolean IS_WINDOWS = OS.contains("win");
protected static final boolean IS_APPLE = OS.contains("mac") || OS.contains("darwin");
// ImGui Structs
@@ -11,6 +11,8 @@ import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.Utils;
import com.moulberry.flashback.combo_options.VideoContainer;
import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.exporting.taskbar.ITaskbar;
import com.moulberry.flashback.exporting.taskbar.TaskbarHost;
import com.moulberry.flashback.keyframe.KeyframeType;
import com.moulberry.flashback.keyframe.handler.KeyframeHandler;
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
@@ -82,6 +84,8 @@ public class ExportJob {
private double audioSamples = 0.0;
private ITaskbar taskbar;
private final AtomicBoolean finishedServerTick = new AtomicBoolean(false);
public static final int SRC_PIXEL_FORMAT = avutil.AV_PIX_FMT_RGBA;
@@ -232,6 +236,8 @@ public class ExportJob {
double lastTickDouble = 0;
this.taskbar = TaskbarHost.createTaskbar();
for (int tickIndex = 0; tickIndex < ticks.size(); tickIndex++) {
this.currentTickDouble = ticks.getDouble(tickIndex);
float deltaTicksFloat = (float)(currentTickDouble - lastTickDouble);
@@ -349,6 +355,9 @@ public class ExportJob {
submitDownloadedFrames(videoWriter, downloader, true);
videoWriter.finish();
this.taskbar.close();
this.taskbar = null;
}
private void updateRandoms(Random random, Random mathRandom) {
@@ -489,6 +498,8 @@ public class ExportJob {
long currentTime = System.currentTimeMillis();
if (currentTime - this.lastRenderMillis > 1000/60 || currentFrame == totalFrames) {
this.taskbar.setProgress(currentFrame, totalFrames);
Window window = Minecraft.getInstance().getWindow();
this.lastRenderMillis = currentTime;
@@ -0,0 +1,7 @@
package com.moulberry.flashback.exporting.taskbar;
public interface ITaskbar {
void close();
void setProgress(long count, long outOf);
}
@@ -0,0 +1,13 @@
package com.moulberry.flashback.exporting.taskbar;
public class NoopTaskbar implements ITaskbar {
@Override
public void close() {
}
@Override
public void setProgress(long count, long outOf) {
}
}
@@ -0,0 +1,35 @@
package com.moulberry.flashback.exporting.taskbar;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.*;
import com.sun.jna.ptr.PointerByReference;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFWNativeWin32;
import static com.moulberry.flashback.editor.ui.CustomImGuiImplGlfw.IS_WINDOWS;
public class TaskbarHost {
public static ITaskbar createTaskbar() {
if (IS_WINDOWS) {
return createWindowsInterface();
} else {
return new NoopTaskbar();
}
}
private static WindowsTaskbar createWindowsInterface() {
var itaskbar3res = new PointerByReference();
if (W32Errors.FAILED(Ole32.INSTANCE.CoCreateInstance(new Guid.GUID("56FDF344-FD6D-11d0-958A-006097C9A090"),
null,
WTypes.CLSCTX_SERVER,
new Guid.GUID("EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF"),
itaskbar3res))) {
throw new IllegalStateException("Failed to create ITaskbar3");
}
var hwnd = new WinDef.HWND(new Pointer(GLFWNativeWin32.glfwGetWin32Window(Minecraft.getInstance().getWindow().getWindow())));
return new WindowsTaskbar(itaskbar3res.getValue(), hwnd);
}
}
@@ -0,0 +1,40 @@
package com.moulberry.flashback.exporting.taskbar;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.COM.COMInvoker;
import com.sun.jna.platform.win32.W32Errors;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
public class WindowsTaskbar extends COMInvoker implements ITaskbar {
private final WinDef.HWND hwnd;
WindowsTaskbar(Pointer ptr, WinDef.HWND hwnd) {
this.setPointer(ptr);
this.hwnd = hwnd;
try {
this.invokeNative(3);//HrInit
} finally {
this.invokeNative(2);//Release
}
}
private void invokeNative(int ventry, Object... objects) {
Object[] args = new Object[objects.length+1];
args[0] = this.getPointer();
System.arraycopy(objects, 0, args, 1, objects.length);
if (W32Errors.FAILED((WinNT.HRESULT) this._invokeNativeObject(ventry, args, WinNT.HRESULT.class))) {
throw new IllegalStateException("Failed to invoke vtable: " + ventry);
}
}
@Override
public void setProgress(long count, long outOf) {
this.invokeNative(9, this.hwnd, count, outOf);//SetProgressValue
}
@Override
public void close() {
this.invokeNative(10, this.hwnd, 0);//SetProgressState TBPF_NOPROGRESS
this.invokeNative(2);//Release
}
}