Actually do it somewhere else

- Move main thread checking to TaskExecutor
This commit is contained in:
Jozufozu 2023-05-13 12:01:12 -07:00
parent 1f484da50b
commit d3ca86e118
2 changed files with 6 additions and 8 deletions

View File

@ -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);
}
}
/**

View File

@ -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 <C> Plan<C> 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();