Compare commits
3 Commits
v0.3.0-bet
...
section-oc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
500c0777f8 | ||
|
|
b5b6e38cb7 | ||
|
|
e69eeba47c |
@@ -32,6 +32,7 @@ public final class MoonriseCommon {
|
||||
public static final long WORKER_QUEUE_HOLD_TIME = (long)(20.0e6); // 20ms
|
||||
public static final int CLIENT_DIVISION = 0;
|
||||
public static final PrioritisedThreadPool.ExecutorGroup RENDER_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0);
|
||||
public static final PrioritisedThreadPool.ExecutorGroup SECTION_OCCLUSION_EXECUTOR_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(CLIENT_DIVISION, 0);
|
||||
public static final int SERVER_DIVISION = 1;
|
||||
public static final PrioritisedThreadPool.ExecutorGroup PARALLEL_GEN_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0);
|
||||
public static final PrioritisedThreadPool.ExecutorGroup RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(SERVER_DIVISION, 0);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package ca.spottedleaf.moonrise.mixin.render;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor;
|
||||
import ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool;
|
||||
import ca.spottedleaf.concurrentutil.util.Priority;
|
||||
import ca.spottedleaf.moonrise.common.util.MoonriseCommon;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import net.minecraft.client.renderer.SectionOcclusionGraph;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(SectionOcclusionGraph.class)
|
||||
abstract class SectionOcclusionGraphMixin {
|
||||
|
||||
@Unique
|
||||
private static final PrioritisedThreadPool.ExecutorGroup.ThreadPoolExecutor SECTION_OCCLUSION_EXECUTOR = MoonriseCommon.SECTION_OCCLUSION_EXECUTOR_GROUP.createExecutor(
|
||||
-1, MoonriseCommon.WORKER_QUEUE_HOLD_TIME, 0
|
||||
);
|
||||
|
||||
/**
|
||||
* @reason Change executor to use our thread pool
|
||||
* Note: even at normal priority, our worker pool will try to share resources equally rather than having it
|
||||
* be a free-for-all
|
||||
* @author jpenilla
|
||||
*/
|
||||
@Redirect(
|
||||
method = "scheduleFullUpdate",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Ljava/util/concurrent/CompletableFuture;runAsync(Ljava/lang/Runnable;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"
|
||||
)
|
||||
)
|
||||
private CompletableFuture<Void> changeExecutor(final Runnable runnable, final Executor executor) {
|
||||
final PrioritisedExecutor.PrioritisedTask[] prioritisedTask = new PrioritisedExecutor.PrioritisedTask[1];
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>() {
|
||||
@Override
|
||||
public Void get() throws InterruptedException, ExecutionException {
|
||||
prioritisedTask[0].execute();
|
||||
return super.get();
|
||||
}
|
||||
};
|
||||
prioritisedTask[0] = SECTION_OCCLUSION_EXECUTOR.queueTask(() -> {
|
||||
try {
|
||||
runnable.run();
|
||||
future.complete(null);
|
||||
} catch (final Throwable throwable) {
|
||||
future.completeExceptionally(throwable);
|
||||
}
|
||||
}, Priority.HIGH); // Higher than SectionRenderDispatcherMixin#changeExecutor
|
||||
return future;
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,7 @@
|
||||
"config.MinecraftMixin",
|
||||
"loading_screen.LevelLoadStatusManagerMixin",
|
||||
"profiler.MinecraftMixin",
|
||||
"render.SectionOcclusionGraphMixin",
|
||||
"render.SectionRenderDispatcherMixin",
|
||||
"serverlist.ClientConnectionMixin",
|
||||
"serverlist.ServerAddressResolverMixin",
|
||||
|
||||
Reference in New Issue
Block a user