mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 03:49:22 +00:00
Maybe less deadlock-y (#1241)
This commit is contained in:
1 parent
42d7ed58aa
commit
34bfe513f1
4 files changed
+65
-7
No files matched your search
+3
@@ -3,6 +3,9 @@ package com.gtnewhorizons.angelica.mixins.interfaces;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
|
||||
import org.embeddedt.embeddium.impl.render.chunk.RenderSection;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
public interface RenderSectionManagerAccessor {
|
||||
Long2ReferenceMap<RenderSection> angelica$getSectionByPosition();
|
||||
ConcurrentLinkedDeque<Runnable> angelica$getAsyncSubmittedTasks();
|
||||
}
|
||||
+28
-7
@@ -38,12 +38,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput> {
|
||||
protected final RenderSection render;
|
||||
protected final int buildTime;
|
||||
protected final Vector3d camera;
|
||||
|
||||
private static final long DEFERRED_BLOCK_TIMEOUT_MS = 10_000; // 10 seconds
|
||||
private static final int MAX_RETRIES = 2;
|
||||
|
||||
protected record DeferredBlock(int x, int y, int z, Block block, int meta, int pass) {}
|
||||
|
||||
public AngelicaChunkBuilderMeshingTask(RenderSection render, int time, Vector3d camera) {
|
||||
@@ -255,13 +260,29 @@ public abstract class AngelicaChunkBuilderMeshingTask extends ChunkBuilderTask<C
|
||||
mainTessellator.setTranslation(0, 0, 0);
|
||||
}, AngelicaRenderQueue.executor());
|
||||
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Interrupted during deferred block rendering", e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Error during main thread deferred block rendering", e);
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int retries = 0;
|
||||
while (retries < MAX_RETRIES) {
|
||||
try {
|
||||
future.get(DEFERRED_BLOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
return;
|
||||
} catch (TimeoutException e) {
|
||||
retries++;
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
return;
|
||||
}
|
||||
if (retries >= MAX_RETRIES) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Error during main thread deferred block rendering", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
@@ -32,6 +32,8 @@ import com.gtnewhorizons.angelica.mixins.interfaces.RenderSectionManagerAccessor
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
public class AngelicaRenderSectionManager extends RenderSectionManager {
|
||||
private boolean initialCameraSectionReady = false;
|
||||
@@ -197,4 +199,25 @@ public class AngelicaRenderSectionManager extends RenderSectionManager {
|
||||
}
|
||||
super.renderLayer(matrices, pass, occlusionCamera, camera);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process both asyncSubmittedTasks and AngelicaRenderQueue.TASKS.
|
||||
*/
|
||||
@Override
|
||||
public void managedBlock(BooleanSupplier isDone) {
|
||||
final RenderSectionManagerAccessor accessor = (RenderSectionManagerAccessor) this;
|
||||
while (!isDone.getAsBoolean()) {
|
||||
Runnable task = accessor.angelica$getAsyncSubmittedTasks().poll();
|
||||
if (task != null) {
|
||||
task.run();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AngelicaRenderQueue.processTasks(1) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LockSupport.parkNanos("Wait", 100000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user