-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Moonrise executor for section occlusion tasks
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/ca/spottedleaf/moonrise/mixin/render/SectionOcclusionGraphMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ca.spottedleaf.moonrise.mixin.render; | ||
|
||
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.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) { | ||
return CompletableFuture.runAsync( | ||
runnable, | ||
(final Runnable task) -> { | ||
SECTION_OCCLUSION_EXECUTOR.queueTask(task, Priority.NORMAL); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters