Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache AxisAlignedBB for tile entity render frustrum check #771

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gtnewhorizons.angelica.mixins.interfaces;

import net.minecraft.util.AxisAlignedBB;

public interface TileEntityExt {

AxisAlignedBB sodium$getCachedRenderBoundingBox();

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.jellysquid.mods.sodium.client.render;

import com.gtnewhorizons.angelica.compat.mojang.Camera;
import com.gtnewhorizons.angelica.compat.mojang.ChunkPos;
import com.gtnewhorizons.angelica.compat.toremove.MatrixStack;
import com.gtnewhorizons.angelica.compat.toremove.RenderLayer;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.mixins.interfaces.TileEntityExt;
import com.gtnewhorizons.angelica.rendering.RenderingState;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
Expand All @@ -29,7 +29,6 @@
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import me.jellysquid.mods.sodium.client.render.pipeline.context.ChunkRenderCacheShared;
import me.jellysquid.mods.sodium.client.util.math.FrustumExtended;
import me.jellysquid.mods.sodium.client.world.ChunkStatusListener;
import me.jellysquid.mods.sodium.common.util.ListUtil;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.layer.GbufferPrograms;
Expand Down Expand Up @@ -348,7 +347,7 @@ private static ChunkRenderBackend<?> createChunkRenderBackend(RenderDevice devic
}

private boolean checkBEVisibility(TileEntity entity) {
return frustum.isBoundingBoxInFrustum(entity.getRenderBoundingBox());
return frustum.isBoundingBoxInFrustum(((TileEntityExt) entity).sodium$getCachedRenderBoundingBox());
}

private void renderTE(TileEntity tileEntity, int pass, float partialTicks) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
package com.gtnewhorizons.angelica.mixins.early.sodium;

import com.gtnewhorizons.angelica.mixins.interfaces.TileEntityExt;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

@Mixin(TileEntity.class)
public class MixinTileEntity {
@Shadow private Block blockType;
@Shadow private int blockMetadata;
@Shadow World worldObj;
@Shadow int xCoord;
@Shadow int yCoord;
@Shadow int zCoord;
public abstract class MixinTileEntity implements TileEntityExt {

@Shadow
public Block blockType;
@Shadow
public int blockMetadata;
@Shadow
protected World worldObj;
@Shadow
public int xCoord;
@Shadow
public int yCoord;
@Shadow
public int zCoord;
@Unique
private int sodium$renderxCoord = -1;
@Unique
private int sodium$renderyCoord = -1;
@Unique
private int sodium$renderzCoord = -1;
@Unique
private AxisAlignedBB sodium$cachedRenderAABB;

@Shadow
public abstract AxisAlignedBB getRenderBoundingBox();

/**
* @author mitchej123
Expand All @@ -26,7 +47,6 @@ public Block getBlockType() {
if (block == null) {
this.blockType = block = this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord);
}

return block;
}

Expand All @@ -40,7 +60,20 @@ public int getBlockMetadata() {
if (metadata == -1) {
this.blockMetadata = metadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
}

return metadata;
}

// cache the render bounding box, otherwise the vanilla code
// creates a new AxisAlignedBB object everytime and that
// spams allocations
@Override
public AxisAlignedBB sodium$getCachedRenderBoundingBox() {
if (sodium$cachedRenderAABB == null || xCoord != sodium$renderxCoord || yCoord != sodium$renderyCoord || zCoord != sodium$renderzCoord) {
sodium$renderxCoord = xCoord;
sodium$renderyCoord = yCoord;
sodium$renderzCoord = zCoord;
sodium$cachedRenderAABB = this.getRenderBoundingBox();
}
return sodium$cachedRenderAABB;
}
}
Loading