Skip to content

Commit

Permalink
Simplify iris and sodium integration by taking advantage of sodium's …
Browse files Browse the repository at this point in the history
…version of the maintained removable section tree
  • Loading branch information
douira committed Jan 19, 2025
1 parent d918ca6 commit 1be776a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo;
import net.caffeinemc.mods.sodium.client.render.chunk.lists.SortedRenderLists;
import net.caffeinemc.mods.sodium.client.render.chunk.lists.VisibleChunkCollectorAsync;
import net.caffeinemc.mods.sodium.client.render.chunk.region.RenderRegionManager;
import net.caffeinemc.mods.sodium.client.render.chunk.tree.RemovableMultiForest;
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;
import net.irisshaders.iris.compat.sodium.mixinterface.ShadowRenderRegion;
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.irisshaders.iris.shadows.ShadowSectionTree;
import net.minecraft.client.Camera;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -45,9 +44,6 @@ public abstract class MixinRenderSectionManagerShadow {
@Unique
private boolean shadowNeedsRenderListUpdate = true;

@Unique
private ShadowSectionTree shadowSectionTree;

@Unique
private boolean renderListStateIsShadow = false;

Expand All @@ -66,19 +62,21 @@ private void updateRenderLists(Camera camera, Viewport viewport, boolean spectat
this.shadowNeedsRenderListUpdate |= this.needsRenderListUpdate;
}

@Shadow(remap = false)
protected abstract float getRenderDistance();

@Shadow(remap = false)
public abstract int getVisibleChunkCount();

@Shadow(remap = false)
public abstract int getTotalSections();

@Shadow
@Final
private RemovableMultiForest renderableSectionTree;

@Shadow
protected abstract float getSearchDistance();

@Inject(method = "updateRenderLists", at = @At("HEAD"), cancellable = true)
private void updateShadowRenderLists(Camera camera, Viewport viewport, boolean spectator, boolean updateImmediately, CallbackInfo ci) {
this.ensureShadowSectionTree();

if (!ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
if (this.renderListStateIsShadow) {
for (var region : this.regions.getLoadedRegions()) {
Expand All @@ -98,43 +96,22 @@ private void updateShadowRenderLists(Camera camera, Viewport viewport, boolean s
}

var visibleCollector = new VisibleChunkCollectorAsync(this.regions, -this.frame);
this.shadowSectionTree.prepareTreesForTraversal();
this.shadowSectionTree.traverseVisible(visibleCollector, viewport);
this.shadowRenderLists = visibleCollector.createRenderLists();
this.renderableSectionTree.prepareForTraversal();
this.renderableSectionTree.traverse(visibleCollector, viewport, this.getSearchDistance());
this.shadowRenderLists = visibleCollector.createRenderLists(viewport);
}

this.shadowNeedsRenderListUpdate = false;
ci.cancel();
}

@Unique
private void ensureShadowSectionTree() {
if (this.shadowSectionTree == null) {
this.shadowSectionTree = new ShadowSectionTree(this.getRenderDistance());
}
}

@Inject(method = "updateSectionInfo", at = @At("HEAD"))
private void updateSectionInfo(RenderSection render, BuiltSectionInfo info, CallbackInfo ci) {
this.ensureShadowSectionTree();

var x = render.getChunkX();
var y = render.getChunkY();
var z = render.getChunkZ();

if (info == null || (info.flags & RenderSectionFlags.MASK_NEEDS_RENDER) == 0) {
this.shadowSectionTree.removeSection(x, y, z);
} else {
this.shadowSectionTree.addSection(x, y, z);
}
private void updateSectionInfo(RenderSection render, BuiltSectionInfo info, CallbackInfoReturnable<Boolean> cir) {
this.shadowNeedsRenderListUpdate = true;
}

@Inject(method = "onSectionRemoved", at = @At("HEAD"))
private void onSectionRemoved(int x, int y, int z, CallbackInfo ci) {
this.ensureShadowSectionTree();

this.shadowSectionTree.removeSection(x, y, z);
this.shadowNeedsRenderListUpdate = true;
}

Expand Down

This file was deleted.

0 comments on commit 1be776a

Please sign in to comment.