From bfbf987599ae431b5df8910d92d9f94093131f16 Mon Sep 17 00:00:00 2001 From: cola98765 Date: Sun, 26 Dec 2021 16:10:22 +0100 Subject: [PATCH] optimised setupColorAndTint, specifically part where it calculates if block is gray for no reason if it's not going to be tinted anyway. --- .../wrappers/block/BlockColorWrapper.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/seibel/lod/forge/wrappers/block/BlockColorWrapper.java b/src/main/java/com/seibel/lod/forge/wrappers/block/BlockColorWrapper.java index 0c7213922..7bb181819 100644 --- a/src/main/java/com/seibel/lod/forge/wrappers/block/BlockColorWrapper.java +++ b/src/main/java/com/seibel/lod/forge/wrappers/block/BlockColorWrapper.java @@ -173,6 +173,9 @@ public class BlockColorWrapper implements IBlockColorWrapper int numberOfGreyPixel = 0; int tempColor; int colorMultiplier; + boolean lookForTint = false; + if (grassInstance() || leavesInstance() || waterIstance()) + lookForTint = true; // generate the block's color for (int frameIndex = 0; frameIndex < texture.getFrameCount(); frameIndex++) @@ -188,12 +191,15 @@ public class BlockColorWrapper implements IBlockColorWrapper if (ColorUtil.getAlpha(texture.getPixelRGBA(frameIndex, u, v)) == 0) continue; - // determine if this pixel is gray - int colorMax = Math.max(Math.max(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor)); - int colorMin = 4 + Math.min(Math.min(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor)); - boolean isGray = colorMax < colorMin; - if (isGray) - numberOfGreyPixel++; + if (lookForTint) + { + // determine if this pixel is gray + int colorMax = Math.max(Math.max(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor)); + int colorMin = 4 + Math.min(Math.min(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor)); + boolean isGray = colorMax < colorMin; + if (isGray) + numberOfGreyPixel++; + } // for flowers, weight their non-green color higher @@ -228,7 +234,7 @@ public class BlockColorWrapper implements IBlockColorWrapper } // determine if this block should use the biome color tint - if ((grassInstance() || leavesInstance() || waterIstance()) && (float) numberOfGreyPixel / count > 0.75f) + if (lookForTint && (float) numberOfGreyPixel / count > 0.75f) this.toTint = true; // we check which kind of tint we need to apply