Just do it

- In OnMainThreadPlan#execute, don't queue anything if we're already on
  the render thread
This commit is contained in:
Jozufozu 2023-05-08 22:41:17 -07:00
parent e53f011544
commit 2520d4eb8c

View file

@ -2,6 +2,7 @@ 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) {
@ -10,7 +11,12 @@ public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan {
@Override
public void execute(TaskExecutor taskExecutor, Runnable onCompletion) {
// TODO: detect if we're already on the render thread and just run the task directly
if (RenderSystem.isOnRenderThread()) {
task.run();
onCompletion.run();
return;
}
taskExecutor.scheduleForMainThread(() -> {
task.run();
onCompletion.run();