From d1e54d65da8f655715cd1a6669db44fd898c92ca Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 13 May 2023 12:01:12 -0700 Subject: [PATCH] Actually do it somewhere else - Move main thread checking to TaskExecutor --- .../flywheel/backend/task/ParallelTaskExecutor.java | 7 ++++++- .../com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java | 7 ------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/task/ParallelTaskExecutor.java b/src/main/java/com/jozufozu/flywheel/backend/task/ParallelTaskExecutor.java index 7e7e16d68..0590d301a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/task/ParallelTaskExecutor.java +++ b/src/main/java/com/jozufozu/flywheel/backend/task/ParallelTaskExecutor.java @@ -15,6 +15,7 @@ import org.slf4j.Logger; import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.task.TaskExecutor; import com.jozufozu.flywheel.lib.task.WaitGroup; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.logging.LogUtils; import net.minecraft.util.Mth; @@ -124,7 +125,11 @@ public class ParallelTaskExecutor implements TaskExecutor { throw new IllegalStateException("Executor is stopped"); } - mainThreadQueue.add(runnable); + if (RenderSystem.isOnRenderThread()) { + runnable.run(); + } else { + mainThreadQueue.add(runnable); + } } /** diff --git a/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java b/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java index a21d86d74..60b8f9bcb 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java +++ b/src/main/java/com/jozufozu/flywheel/lib/task/OnMainThreadPlan.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.lib.task; import com.jozufozu.flywheel.api.task.Plan; import com.jozufozu.flywheel.api.task.TaskExecutor; -import com.mojang.blaze3d.systems.RenderSystem; public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan { public static Plan of(Runnable task) { @@ -11,12 +10,6 @@ public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan { @Override public void execute(TaskExecutor taskExecutor, Runnable onCompletion) { - if (RenderSystem.isOnRenderThread()) { - task.run(); - onCompletion.run(); - return; - } - taskExecutor.scheduleForMainThread(() -> { task.run(); onCompletion.run();