From 4570512d2fdc14874f0cc62ef33c778923044884 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 17 Jul 2024 16:20:37 -0500 Subject: [PATCH] block rendering improvements - Some reworks to the internals for render caching on blocks, gives roughly around 20% FPS improvement, hardware depending. - Removed some unnecessary classes for the bridge pillar render. - Fixed a rotation bug with the bridge pillar --- .../java/ebf/tim/render/CustomItemModel.java | 6 +- .../java/fexcraft/tmt/slim/ModelBase.java | 37 ++----- .../client/render/ItemRenderBridgePillar.java | 53 ---------- .../client/render/RenderBridgePillar.java | 37 ------- .../java/train/common/api/AbstractTrains.java | 2 +- .../common/api/blocks/TileRenderFacing.java | 98 ++++++++++--------- .../train/common/tile/TileBridgePillar.java | 25 +++-- .../train/common/tile/TileEntityDistil.java | 13 ++- 8 files changed, 79 insertions(+), 192 deletions(-) delete mode 100644 src/main/java/train/client/render/ItemRenderBridgePillar.java delete mode 100644 src/main/java/train/client/render/RenderBridgePillar.java diff --git a/src/main/java/ebf/tim/render/CustomItemModel.java b/src/main/java/ebf/tim/render/CustomItemModel.java index 17824c416..a10874049 100644 --- a/src/main/java/ebf/tim/render/CustomItemModel.java +++ b/src/main/java/ebf/tim/render/CustomItemModel.java @@ -166,9 +166,7 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) { return; } switch (type){ - case EQUIPPED_FIRST_PERSON:{ - break; - } + case EQUIPPED_FIRST_PERSON:{break;} case INVENTORY:{break;} case EQUIPPED:{break;} case FIRST_PERSON_MAP:{break;} @@ -181,8 +179,6 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) { break; } } - GL11.glScalef(0.95f,0.95f,0.95f); - GL11.glTranslatef(0,-0.1f,0); if (blockTextures.get(item.getItem()).host!=null && blockTextures.get(item.getItem()).host.tesr instanceof TileEntitySpecialRenderer) { ((TileEntitySpecialRenderer) blockTextures.get(item.getItem()).host.tesr) .renderTileEntityAt(blockTextures.get(item.getItem()), 0, 0, 0, 0); diff --git a/src/main/java/fexcraft/tmt/slim/ModelBase.java b/src/main/java/fexcraft/tmt/slim/ModelBase.java index cc5ee1ca6..0cf0c8ac7 100644 --- a/src/main/java/fexcraft/tmt/slim/ModelBase.java +++ b/src/main/java/fexcraft/tmt/slim/ModelBase.java @@ -5,8 +5,6 @@ import net.minecraft.client.renderer.GLAllocation; import net.minecraft.entity.Entity; import org.lwjgl.opengl.GL11; -import train.common.core.handlers.ConfigHandler; -import train.common.core.util.TraincraftUtil; import java.util.ArrayList; import java.util.HashMap; @@ -113,40 +111,17 @@ public void render(){ } public void renderBlock(){ - if(!init) { + if(init){ initAllParts(); } - render(boxList); - ModelRendererTurbo part; - for(int i = 0; i< namedList.size(); i++){ - //for animations to work we have to limit the displaylist cache to ONLY the geometry, and then - // the position and offsets must be done manually every frame. - if(displayList.size()>i){ - part= namedList.get(i); - if(!part.showModel){ - continue; - } - GL11.glPushMatrix(); - if (part.ignoresLighting){ - Minecraft.getMinecraft().entityRenderer.disableLightmap(1D); - } - GL11.glTranslatef(part.rotationPointX * 0.0625F, part.rotationPointY * 0.0625F, part.rotationPointZ * 0.0625F); - GL11.glRotatef(part.rotateAngleY, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(part.rotateAngleZ, 0.0F, 0.0F, 1.0F); - GL11.glRotatef(part.rotateAngleX, 1.0F, 0.0F, 0.0F); - for (TexturedPolygon poly : namedList.get(i).faces) { - Tessellator.getInstance().drawTexturedVertsWithNormal(poly, 0.0625F); - } + render(boxList); - GL11.glTranslatef(-part.rotationPointX * 0.0625F, -part.rotationPointY * 0.0625F, -part.rotationPointZ * 0.0625F); - if (part.ignoresLighting){ - Minecraft.getMinecraft().entityRenderer.enableLightmap(1D); - } - GL11.glPopMatrix(); - } else if(namedList.get(i)!=null) { - for (TexturedPolygon poly : namedList.get(i).faces) { + if(namedList ==null){return;} + for (ModelRendererTurbo named : namedList) { + if (named != null) { + for (TexturedPolygon poly : named.faces) { Tessellator.getInstance().drawTexturedVertsWithNormal(poly, 0.0625F); } } diff --git a/src/main/java/train/client/render/ItemRenderBridgePillar.java b/src/main/java/train/client/render/ItemRenderBridgePillar.java deleted file mode 100644 index 7da84ebe7..000000000 --- a/src/main/java/train/client/render/ItemRenderBridgePillar.java +++ /dev/null @@ -1,53 +0,0 @@ -package train.client.render; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.IItemRenderer; -import org.lwjgl.opengl.GL11; -import fexcraft.tmt.slim.Tessellator; -import train.common.library.Info; - -import static train.client.render.RenderBridgePillar.modelBridgePillar; - -public class ItemRenderBridgePillar implements IItemRenderer { - - public ItemRenderBridgePillar() { - } - - @Override - public boolean handleRenderType(ItemStack item, ItemRenderType type) { - return true; - } - - @Override - public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { - return true; - } - - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) { - switch (type) { - case ENTITY: - case INVENTORY: { - renderBridgePillar(0f, 0f, 0f); - return; - } - case EQUIPPED: - case EQUIPPED_FIRST_PERSON: { - renderBridgePillar(0.2f, 1f, 1f); - return; - } - default: - break; - } - } - - private void renderBridgePillar(float x, float y, float z) { - Tessellator.bindTexture(new ResourceLocation(Info.resourceLocation, Info.modelTexPrefix + "bridgePillar.png")); - GL11.glPushMatrix(); - GL11.glTranslatef(x, y - 0.5f, z); - GL11.glRotatef(180f, 0f, 0f, 1f); - modelBridgePillar.render(); - GL11.glPopMatrix(); - } -} diff --git a/src/main/java/train/client/render/RenderBridgePillar.java b/src/main/java/train/client/render/RenderBridgePillar.java deleted file mode 100644 index 10f8cadaf..000000000 --- a/src/main/java/train/client/render/RenderBridgePillar.java +++ /dev/null @@ -1,37 +0,0 @@ -package train.client.render; - -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; -import fexcraft.tmt.slim.Tessellator; -import train.client.render.models.blocks.ModelBridgePillar; -import train.common.library.Info; - -public class RenderBridgePillar extends TileEntitySpecialRenderer { - static final ModelBridgePillar modelBridgePillar = new ModelBridgePillar(); - static final ResourceLocation texture = new ResourceLocation(Info.modID, Info.modelTexPrefix + "bridgePillar.png"); - static Integer GLID = null; - - @Override - public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) { - Tessellator.bindTexture(texture); - GL11.glPushMatrix(); - GL11.glTranslated(x + 0.5, y, z + 0.5); - GL11.glRotatef(180f, 180f, 1f, 0f); - /* - if(GLID==null || !GL11.glIsList(GLID)) { - GLID = GLAllocation.generateDisplayLists(1); - GL11.glNewList(GLID, GL11.GL_COMPILE); - modelBridgePillar.render(); - GL11.glEndList(); - } else { - GL11.glCallList(GLID); - } - - */ - - modelBridgePillar.render(); - GL11.glPopMatrix(); - } -} diff --git a/src/main/java/train/common/api/AbstractTrains.java b/src/main/java/train/common/api/AbstractTrains.java index 96c3eab5c..6616cb184 100644 --- a/src/main/java/train/common/api/AbstractTrains.java +++ b/src/main/java/train/common/api/AbstractTrains.java @@ -708,7 +708,7 @@ public String transportFuelType(){ *example: * return new int[]{11000, 1000}; * may return null*/ - public int[] getTankCapacity(){return new int[]{getSpec().getTankCapacity()};} + public int[] getTankCapacity(){return getSpec()==null?new int[]{0}:new int[]{getSpec().getTankCapacity()};} /**defines the rider position offsets, with 0 being the center of the entity. * Each set of coords represents a new rider seat, with the first one being the "driver" diff --git a/src/main/java/train/common/api/blocks/TileRenderFacing.java b/src/main/java/train/common/api/blocks/TileRenderFacing.java index 929b5ad97..2db928486 100644 --- a/src/main/java/train/common/api/blocks/TileRenderFacing.java +++ b/src/main/java/train/common/api/blocks/TileRenderFacing.java @@ -21,6 +21,7 @@ public class TileRenderFacing extends TileEntity { public int facing =-1; private Integer blockGLID =null; + private int uiTexture=0; public BlockDynamic host; public TileRenderFacing(BlockDynamic block){ @@ -80,7 +81,7 @@ public AxisAlignedBB getRenderBoundingBox(){ @Override public void func_145828_a(CrashReportCategory r){ if(r==null){ - int boundTexture = org.lwjgl.opengl.GL11.glGetInteger( org.lwjgl.opengl.GL11.GL_TEXTURE_2D); + uiTexture = org.lwjgl.opengl.GL11.glGetInteger( org.lwjgl.opengl.GL11.GL_TEXTURE_2D); if(getTexture(xCoord,yCoord,zCoord)!=null) { org.lwjgl.opengl.GL11.glEnable( org.lwjgl.opengl.GL11.GL_TEXTURE_2D); TextureManager.bindTexture(getTexture(xCoord,yCoord,zCoord)); @@ -89,31 +90,55 @@ public void func_145828_a(CrashReportCategory r){ } - if(worldObj==null) { - Minecraft.getMinecraft().entityRenderer.disableLightmap(1); - } else { - Minecraft.getMinecraft().entityRenderer.enableLightmap(1); - } - org.lwjgl.opengl.GL11.glTranslatef(0.5f,0.5f,0.5f); - switch (facing){ - //north - case 0:{ org.lwjgl.opengl.GL11.glRotatef(90,0,1,0);break;} - //east - case 1:{org.lwjgl.opengl.GL11.glRotatef(180,0,1,0);break;} - //south - case 2:{ org.lwjgl.opengl.GL11.glRotatef(270,0,1,0);break;} - //west - case 3:{break;} + if(blockGLID ==null) { + blockGLID = net.minecraft.client.renderer.GLAllocation.generateDisplayLists(1); + org.lwjgl.opengl.GL11.glNewList(blockGLID, org.lwjgl.opengl.GL11.GL_COMPILE); + if (worldObj == null) { + Minecraft.getMinecraft().entityRenderer.disableLightmap(1); + } else { + Minecraft.getMinecraft().entityRenderer.enableLightmap(1); + } + org.lwjgl.opengl.GL11.glTranslatef(0.5f, 0.5f, 0.5f); + switch (facing) { + //north + case 0: { + org.lwjgl.opengl.GL11.glRotatef(90, 0, 1, 0); + break; + } + //east + case 1: { + org.lwjgl.opengl.GL11.glRotatef(180, 0, 1, 0); + break; + } + //south + case 2: { + org.lwjgl.opengl.GL11.glRotatef(270, 0, 1, 0); + break; + } + //west + case 3: { + break; + } + } + org.lwjgl.opengl.GL11.glRotatef(180, 1, 0, 0); + + renderModel(); + if (worldObj == null) { + Minecraft.getMinecraft().entityRenderer.disableLightmap(1); + } + org.lwjgl.opengl.GL11.glEndList(); } - org.lwjgl.opengl.GL11.glRotatef(180,1,0,0); - renderModel(); + if(blockGLID!=null){ + org.lwjgl.opengl.GL11.glCallList(blockGLID); + if(false){//todo:config option to disable render caching + org.lwjgl.opengl.GL11.glDeleteLists(blockGLID,1); + blockGLID =null; + } + } //be sure to re-enable the texture biding, because the UI wont org.lwjgl.opengl.GL11.glEnable( org.lwjgl.opengl.GL11.GL_TEXTURE_2D); - org.lwjgl.opengl.GL11.glBindTexture( org.lwjgl.opengl.GL11.GL_TEXTURE_2D,boundTexture); - if(worldObj==null) { - Minecraft.getMinecraft().entityRenderer.disableLightmap(1); - } + org.lwjgl.opengl.GL11.glBindTexture( org.lwjgl.opengl.GL11.GL_TEXTURE_2D,uiTexture); } else{ super.func_145828_a(r); } @@ -124,29 +149,8 @@ public void renderModel(){ if(host!=null && host.model!=null) { host.model.render(); } else { - if(blockGLID ==null) { - for (TexturedPolygon poly : cube.faces) { - Tessellator.getInstance().drawTexturedVertsWithNormal(poly, 0.0625f); - } - if(!false) {//todo:config option to disable render caching - blockGLID = org.lwjgl.opengl.GL11.glGenLists(1); - org.lwjgl.opengl.GL11.glNewList(blockGLID, org.lwjgl.opengl.GL11.GL_COMPILE); - for (TexturedPolygon poly : cube.faces) { - Tessellator.getInstance().drawTexturedVertsWithNormal(poly, 0.0625f); - } - org.lwjgl.opengl.GL11.glEndList(); - } - } else { - - if(!org.lwjgl.opengl.GL11.glIsList(blockGLID)){ - blockGLID=null; - return; - } - org.lwjgl.opengl.GL11.glCallList(blockGLID); - if(false){//todo:config option to disable render caching - org.lwjgl.opengl.GL11.glDeleteLists(blockGLID,1); - blockGLID =null; - } + for (TexturedPolygon poly : cube.faces) { + Tessellator.getInstance().drawTexturedVertsWithNormal(poly, 0.0625f); } } } @@ -175,8 +179,8 @@ public void markDirty() { worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); this.worldObj.func_147453_f(this.xCoord, this.yCoord, this.zCoord, host); if (worldObj.isRemote && blockGLID != null) { - org.lwjgl.opengl.GL11.glDeleteLists(blockGLID, 1); - blockGLID = null; + // org.lwjgl.opengl.GL11.glDeleteLists(blockGLID, 1); + // blockGLID = null; } } } diff --git a/src/main/java/train/common/tile/TileBridgePillar.java b/src/main/java/train/common/tile/TileBridgePillar.java index b07296ff8..f4cdb15f7 100644 --- a/src/main/java/train/common/tile/TileBridgePillar.java +++ b/src/main/java/train/common/tile/TileBridgePillar.java @@ -3,9 +3,6 @@ import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import train.common.api.blocks.TileRenderFacing; import train.common.library.Info; @@ -38,17 +35,17 @@ public boolean canUpdate() static final train.client.render.models.blocks.ModelBridgePillar modelBridgePillar = new train.client.render.models.blocks.ModelBridgePillar(); @SideOnly(Side.CLIENT) static final ResourceLocation texture = new ResourceLocation(Info.modID, Info.modelTexPrefix + "bridgePillar.png"); - @Override - public void func_145828_a(CrashReportCategory r){ - if(r==null) { - fexcraft.tmt.slim.Tessellator.bindTexture(texture); - org.lwjgl.opengl.GL11.glTranslated(0.5, 0, 0.5); - org.lwjgl.opengl.GL11.glRotatef(180f, 180f, 1f, 0f); - - modelBridgePillar.render(); - } else { - super.func_145828_a(r); - } + @Override + @SideOnly(Side.CLIENT) + public void renderModel(){ + org.lwjgl.opengl.GL11.glTranslated(0, 0.5, 0); + org.lwjgl.opengl.GL11.glRotatef(180f, 0f, 1f, 0f); + modelBridgePillar.renderBlock(); + } + @Override + @SideOnly(Side.CLIENT) + public ResourceLocation getTexture(int x, int y, int z){ + return texture; } } \ No newline at end of file diff --git a/src/main/java/train/common/tile/TileEntityDistil.java b/src/main/java/train/common/tile/TileEntityDistil.java index f01f7f7d8..999dc8f40 100644 --- a/src/main/java/train/common/tile/TileEntityDistil.java +++ b/src/main/java/train/common/tile/TileEntityDistil.java @@ -257,7 +257,6 @@ else if (slots[i].stackSize < itemstack1.getMaxStackSize()) { } private boolean canSmelt() { - DebugUtil.println(slots[0] == null); if (slots[0] == null || (slots[3] != null && slots[3].stackSize==64) || (slots[4] != null && slots[4].stackSize==64)) { return false; } @@ -395,8 +394,14 @@ public boolean canExtractItem(int slot, ItemStack stack, int side){ @Override @SideOnly(Side.CLIENT) public ResourceLocation getTexture(int x, int y, int z){ - return new ResourceLocation(Info.modID, - (worldObj==null|| CommonUtil.getBlockAt(Minecraft.getMinecraft().theWorld,x,y,z)== TCBlocks.distilActive)? - "textures/blocks/distil_on.png":"textures/blocks/distil_off.png"); + return (worldObj==null|| CommonUtil.getBlockAt(Minecraft.getMinecraft().theWorld,x,y,z)== TCBlocks.distilActive)? + textureOn:textureOff; } + + @SideOnly(Side.CLIENT) + static final ResourceLocation textureOn = new ResourceLocation(Info.modID, "textures/blocks/distil_on.png"); + + @SideOnly(Side.CLIENT) + static final ResourceLocation textureOff = new ResourceLocation(Info.modID, "textures/blocks/distil_off.png"); + }