Skip to content

Commit

Permalink
Only track rendered sprites on specific RenderBlocks instances (#355)
Browse files Browse the repository at this point in the history
* Only track rendered sprites on specific RenderBlocks instances
  • Loading branch information
embeddedt authored Mar 3, 2024
1 parent f41f27e commit 51a6a72
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public class MixinChunkCache implements ITexturesCache {
public HashSet<IIcon> getRenderedTextures() {
return renderedIcons;
}

@Override
public void enableTextureTracking() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFire;
import net.minecraft.client.renderer.RenderBlocks;
Expand All @@ -27,7 +27,8 @@ public class MixinRenderBlocks implements ITexturesCache {
@Shadow
public IIcon overrideBlockTexture;

private Set<IIcon> renderedSprites = new ObjectOpenHashSet<>();
private Set<IIcon> renderedSprites = new ReferenceOpenHashSet<>();
private boolean enableSpriteTracking;

/**
* @author laetansky Here where things get very tricky. We can't just mark blocks textures for update because this
Expand All @@ -46,14 +47,17 @@ public class MixinRenderBlocks implements ITexturesCache {

AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);

this.renderedSprites.add(icon);
if(this.enableSpriteTracking)
this.renderedSprites.add(icon);
}

@Inject(method = "renderBlockFire", at = @At("HEAD"))
public void angelica$markFireBlockAnimationForUpdate(BlockFire instance, int x, int y, int z,
CallbackInfoReturnable<Boolean> cir) {
this.renderedSprites.add(instance.getFireIcon(0));
this.renderedSprites.add(instance.getFireIcon(1));
if(this.enableSpriteTracking) {
this.renderedSprites.add(instance.getFireIcon(0));
this.renderedSprites.add(instance.getFireIcon(1));
}
AnimationsRenderUtils.markBlockTextureForUpdate(instance.getFireIcon(0), blockAccess);
AnimationsRenderUtils.markBlockTextureForUpdate(instance.getFireIcon(1), blockAccess);
}
Expand All @@ -62,7 +66,8 @@ public class MixinRenderBlocks implements ITexturesCache {
public IIcon angelica$markFluidAnimationForUpdate(IIcon icon) {
AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);

this.renderedSprites.add(icon);
if(this.enableSpriteTracking)
this.renderedSprites.add(icon);

return icon;
}
Expand All @@ -72,11 +77,17 @@ public class MixinRenderBlocks implements ITexturesCache {
CallbackInfo ci) {
AnimationsRenderUtils.markBlockTextureForUpdate(icon, blockAccess);

this.renderedSprites.add(icon);
if(this.enableSpriteTracking)
this.renderedSprites.add(icon);
}

@Override
public Set<IIcon> getRenderedTextures() {
return renderedSprites;
}

@Override
public void enableTextureTracking() {
enableSpriteTracking = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class MixinWorldRenderer implements ITexturesCache {

@ModifyArg(method = "updateRenderer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBlocks;<init>(Lnet/minecraft/world/IBlockAccess;)V"))
private IBlockAccess angelica$onUpdateRenderer(IBlockAccess chunkCache) {
((ITexturesCache) chunkCache).enableTextureTracking();
renderedIcons = ((ITexturesCache) chunkCache).getRenderedTextures();
return chunkCache;
}
Expand All @@ -43,4 +44,9 @@ public class MixinWorldRenderer implements ITexturesCache {
public Set<IIcon> getRenderedTextures() {
return renderedIcons;
}

@Override
public void enableTextureTracking() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
public interface ITexturesCache {

Set<IIcon> getRenderedTextures();
void enableTextureTracking();
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB

final WorldSlice slice = cache.getWorldSlice();
final RenderBlocks renderBlocks = new RenderBlocks(slice);
if(renderBlocks instanceof ITexturesCache) ((ITexturesCache)renderBlocks).enableTextureTracking();

final int baseX = this.render.getOriginX();
final int baseY = this.render.getOriginY();
Expand Down Expand Up @@ -246,6 +247,7 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
final int baseZ = this.render.getOriginZ();
final BlockPosImpl renderOffset = this.offset;
final RenderBlocks rb = new RenderBlocks(slice.getWorld());
if(rb instanceof ITexturesCache) ((ITexturesCache)rb).enableTextureTracking();
while(!mainThreadBlocks.isEmpty()) {
final long longPos = mainThreadBlocks.dequeueLong();
if (cancellationSource.isCancelled()) {
Expand Down

0 comments on commit 51a6a72

Please sign in to comment.