Skip to content

Commit

Permalink
improved rail model caching.
Browse files Browse the repository at this point in the history
still runs poorly, but it's more reliable and slightly less memory use.
  • Loading branch information
EternalBlueFlame committed Oct 11, 2023
1 parent 03332db commit a3d9a96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/main/java/ebf/tim/blocks/RailTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ebf.tim.render.models.Model1x1Rail;
import ebf.tim.utility.ClientProxy;
import ebf.tim.utility.CommonUtil;
import ebf.tim.utility.DebugUtil;
import fexcraft.tmt.slim.TextureManager;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand All @@ -36,7 +37,7 @@ public class RailTileEntity extends TileEntity {
//todo public int timer=0;
//todo public int overgrowth=0;
//public Integer railGLID=null;
public static Map<XmlBuilder,Integer> displayListMap = new HashMap<>();
public static Map<Integer,Integer> displayListMap = new HashMap<>();
private int meta=0;
private XmlBuilder data = new XmlBuilder();
private Integer glID=null;
Expand Down Expand Up @@ -80,15 +81,15 @@ public void func_145828_a(@Nullable CrashReportCategory report) {
}
else if(data !=null && data.floatArrayMap.size()>0){
RailShapeCore route =new RailShapeCore().fromXML(data);
if(displayListMap.containsKey(data)){
glID=displayListMap.get(data);
if(displayListMap.containsKey(data.toXMLString().hashCode())){
glID=displayListMap.get(data.toXMLString().hashCode());
org.lwjgl.opengl.GL11.glCallList(glID);
}
else if (route.activePath!=null) {
if(!ClientProxy.disableCache) {
displayListMap.put(data,
net.minecraft.client.renderer.GLAllocation.generateDisplayLists(1));
org.lwjgl.opengl.GL11.glNewList(displayListMap.get(data), org.lwjgl.opengl.GL11.GL_COMPILE);
glID=net.minecraft.client.renderer.GLAllocation.generateDisplayLists(1);
displayListMap.put(data.toXMLString().hashCode(), glID);
org.lwjgl.opengl.GL11.glNewList(glID, org.lwjgl.opengl.GL11.GL_COMPILE);

Model1x1Rail.Model3DRail(worldObj, xCoord, yCoord, zCoord, route);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ebf/tim/render/models/Model1x1Rail.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static void rotateVertexPoint(float x, float y, float z, float pitch, fl

public static void addVertexWithOffset(Vec6f p, float width, float height, float depth){
rotateVertexPoint(depth,height,width-Math.copySign(p.w,width),p.u,p.v);
Tessellator.getInstance().addVertexWithUV(vert[0]+p.xCoord,vert[1]+p.yCoord, vert[2]+p.zCoord,0,0);
Tessellator.getInstance().addVertex(vert[0]+p.xCoord,vert[1]+p.yCoord, vert[2]+p.zCoord);
}

public static void addVertexWithOffsetAndUV(Vec5f p, float width, float height, float depth, float U, float V){
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void Model3DRail(World world, int xPos, int yPos, int zPos, RailSh
if(colors==null){return;}
//DebugUtil.println(ClientProxy.railLoD);
//renders the rails, also defines min and max width
GL11.glEnable(GL11.GL_NORMALIZE);
//GL11.glEnable(GL11.GL_NORMALIZE);
GL11.glPushMatrix();
GL11.glColor4f(1,1,1,1);
GL11.glDisable(GL_TEXTURE_2D);
Expand Down

0 comments on commit a3d9a96

Please sign in to comment.