mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-07 12:56:31 +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
aa38ae4125
commit
d44c973bcc
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.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) {
|
||||||
|
@ -10,7 +11,12 @@ public record OnMainThreadPlan(Runnable task) implements ContextAgnosticPlan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(TaskExecutor taskExecutor, Runnable onCompletion) {
|
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(() -> {
|
taskExecutor.scheduleForMainThread(() -> {
|
||||||
task.run();
|
task.run();
|
||||||
onCompletion.run();
|
onCompletion.run();
|
||||||
|
|
Loading…
Reference in a new issue