Skip to content

Commit

Permalink
block rendering improvements
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
EternalBlueFlame committed Jul 17, 2024
1 parent da91cbc commit 4570512
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 192 deletions.
6 changes: 1 addition & 5 deletions src/main/java/ebf/tim/render/CustomItemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand All @@ -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);
Expand Down
37 changes: 6 additions & 31 deletions src/main/java/fexcraft/tmt/slim/ModelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
53 changes: 0 additions & 53 deletions src/main/java/train/client/render/ItemRenderBridgePillar.java

This file was deleted.

37 changes: 0 additions & 37 deletions src/main/java/train/client/render/RenderBridgePillar.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/train/common/api/AbstractTrains.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
98 changes: 51 additions & 47 deletions src/main/java/train/common/api/blocks/TileRenderFacing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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));
Expand All @@ -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);
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/train/common/tile/TileBridgePillar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
13 changes: 9 additions & 4 deletions src/main/java/train/common/tile/TileEntityDistil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");

}

0 comments on commit 4570512

Please sign in to comment.