mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-07 12:56:31 +01:00
Actually do it somewhere else
- Move main thread checking to TaskExecutor
This commit is contained in:
parent
639b2185ab
commit
d1e54d65da
2 changed files with 6 additions and 8 deletions
|
@ -15,6 +15,7 @@ import org.slf4j.Logger;
|
||||||
import com.jozufozu.flywheel.Flywheel;
|
import com.jozufozu.flywheel.Flywheel;
|
||||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||||
import com.jozufozu.flywheel.lib.task.WaitGroup;
|
import com.jozufozu.flywheel.lib.task.WaitGroup;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
|
@ -124,7 +125,11 @@ public class ParallelTaskExecutor implements TaskExecutor {
|
||||||
throw new IllegalStateException("Executor is stopped");
|
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.Plan;
|
||||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
|
|
||||||
public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan {
|
public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan {
|
||||||
public static <C> Plan<C> of(Runnable task) {
|
public static <C> Plan<C> of(Runnable task) {
|
||||||
|
@ -11,12 +10,6 @@ public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(TaskExecutor taskExecutor, Runnable onCompletion) {
|
public void execute(TaskExecutor taskExecutor, Runnable onCompletion) {
|
||||||
if (RenderSystem.isOnRenderThread()) {
|
|
||||||
task.run();
|
|
||||||
onCompletion.run();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
taskExecutor.scheduleForMainThread(() -> {
|
taskExecutor.scheduleForMainThread(() -> {
|
||||||
task.run();
|
task.run();
|
||||||
onCompletion.run();
|
onCompletion.run();
|
||||||
|
|
Loading…
Reference in a new issue