mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 20:45:59 +01:00
Actually do it somewhere else
- Move main thread checking to TaskExecutor
This commit is contained in:
parent
1f484da50b
commit
d3ca86e118
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user