From 3bf19b4566e95e8d0f62b1e32ed9da6a7701dd7c Mon Sep 17 00:00:00 2001 From: William Thompson Date: Mon, 25 Sep 2017 19:43:28 -0400 Subject: [PATCH] Use display lists for heart rendering. Closes #12 This worked *perfect* first try. I'm scared. --- .../glasshearts/client/ClientProxy.java | 3 ++ .../glasshearts/client/RenderGlassHeart.java | 30 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/elytradev/glasshearts/client/ClientProxy.java b/src/main/java/com/elytradev/glasshearts/client/ClientProxy.java index e18fcba..d1deb79 100644 --- a/src/main/java/com/elytradev/glasshearts/client/ClientProxy.java +++ b/src/main/java/com/elytradev/glasshearts/client/ClientProxy.java @@ -44,6 +44,8 @@ public class ClientProxy extends CommonProxy { private List glassHearts = Lists.newArrayList(); public List guiParticles = Lists.newArrayList(); + public static int ticks; + @Override public void onPreInit() { super.onPreInit(); @@ -169,6 +171,7 @@ public void onTooltip(ItemTooltipEvent e) { public void onTick(ClientTickEvent e) { if (e.phase == Phase.START) { if (!Minecraft.getMinecraft().isGamePaused()) { + ticks++; Minecraft.getMinecraft().mcProfiler.startSection("glasshearts:guiparticlesupdate"); { Iterator iter = guiParticles.iterator(); while (iter.hasNext()) { diff --git a/src/main/java/com/elytradev/glasshearts/client/RenderGlassHeart.java b/src/main/java/com/elytradev/glasshearts/client/RenderGlassHeart.java index 150a6b5..8655be7 100644 --- a/src/main/java/com/elytradev/glasshearts/client/RenderGlassHeart.java +++ b/src/main/java/com/elytradev/glasshearts/client/RenderGlassHeart.java @@ -30,8 +30,11 @@ public class RenderGlassHeart extends TileEntitySpecialRenderer { + private int[] displayLists = new int[EnumGlassColor.values().length]; + private int[] lastHash = new int[EnumGlassColor.values().length]; + public static float getAnimTime(TileEntityGlassHeart te, float partialTicks) { - return (((te.getWorld().getTotalWorldTime()+te.hashCode())%24000)+partialTicks); + return (((ClientProxy.ticks+te.hashCode())%24000)+partialTicks); } @Override @@ -45,6 +48,25 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float IBlockState outerState = GlassHearts.inst.GLASS_HEART.getDefaultState().withProperty(BlockGlassHeart.INNER, false).withProperty(BlockGlassHeart.STAINED, stained); IBakedModel outer = brd.getModelForState(outerState); + + int listIdx = te.getColor().ordinal(); + int hash = outer.hashCode(); + + if (lastHash[listIdx] != hash || displayLists[listIdx] == 0) { + if (displayLists[listIdx] != 0) { + GlStateManager.glDeleteLists(displayLists[listIdx], 1); + } + displayLists[listIdx] = GlStateManager.glGenLists(1); + lastHash[listIdx] = hash; + GlStateManager.glNewList(displayLists[listIdx], GL11.GL_COMPILE); + if (stained) { + float[] color = EntitySheep.getDyeRgb(te.getColor().dye); + bmr.renderModelBrightnessColor(outerState, outer, 1f, color[0], color[1], color[2]); + } else { + bmr.renderModelBrightnessColor(outerState, outer, 1f, 1f, 1f, 1f); + } + GlStateManager.glEndList(); + } bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); GlStateManager.pushMatrix(); @@ -108,7 +130,6 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float GlStateManager.popMatrix(); } - if (stained) { GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, @@ -118,10 +139,9 @@ public void render(TileEntityGlassHeart te, double x, double y, double z, float GlStateManager.disableBlend(); } if (stained && MinecraftForgeClient.getRenderPass() == 1) { - float[] color = EntitySheep.getDyeRgb(te.getColor().dye); - bmr.renderModelBrightnessColor(outerState, outer, 1f, color[0], color[1], color[2]); + GlStateManager.callList(displayLists[listIdx]); } else if (MinecraftForgeClient.getRenderPass() == 0) { - bmr.renderModelBrightnessColor(outerState, outer, 1f, 1f, 1f, 1f); + GlStateManager.callList(displayLists[listIdx]); } GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend();