mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-25 22:46:26 +01:00
Just do it
- In OnMainThreadPlan#execute, don't queue anything if we're already on the render thread
This commit is contained in:
parent
e53f011544
commit
2520d4eb8c
1 changed files with 7 additions and 1 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue