Minor performace improvement when building chunks and rendering blocks (#5286)
This commit is contained in:
parent
45902676fd
commit
1aae18d4bc
2 changed files with 19 additions and 3 deletions
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
package net.minecraftforge.client.model.pipeline;
|
package net.minecraftforge.client.model.pipeline;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.model.BakedQuad;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -120,8 +120,14 @@ public class LightUtil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final VertexFormat DEFAULT_FROM = VertexLighterFlat.withNormal(DefaultVertexFormats.BLOCK);
|
||||||
|
private static final VertexFormat DEFAULT_TO = DefaultVertexFormats.ITEM;
|
||||||
|
private static final int[] DEFAULT_MAPPING = generateMapping(DEFAULT_FROM, DEFAULT_TO);
|
||||||
public static int[] mapFormats(VertexFormat from, VertexFormat to)
|
public static int[] mapFormats(VertexFormat from, VertexFormat to)
|
||||||
{
|
{
|
||||||
|
//Speedup: in 99.99% this is the mapping, no need to go make a pair, and go through the slower hash map
|
||||||
|
if (from.equals(DEFAULT_FROM) && to.equals(DEFAULT_TO))
|
||||||
|
return DEFAULT_MAPPING;
|
||||||
return formatMaps.computeIfAbsent(Pair.of(from, to), pair -> generateMapping(pair.getLeft(), pair.getRight()));
|
return formatMaps.computeIfAbsent(Pair.of(from, to), pair -> generateMapping(pair.getLeft(), pair.getRight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.renderer.GameRenderer;
|
||||||
import net.minecraft.client.renderer.color.BlockColors;
|
import net.minecraft.client.renderer.color.BlockColors;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
@ -107,7 +108,16 @@ public class VertexLighterFlat extends QuadGatheringTransformer
|
||||||
updateIndices();
|
updateIndices();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static VertexFormat withNormal(VertexFormat format)
|
private static final VertexFormat BLOCK_WITH_NORMAL = withNormalUncached(DefaultVertexFormats.BLOCK);
|
||||||
|
static VertexFormat withNormal(VertexFormat format)
|
||||||
|
{
|
||||||
|
//This is the case in 99.99%. Cache the value, so we don't have to redo it every time, and the speed up the equals check in LightUtil
|
||||||
|
if (format == DefaultVertexFormats.BLOCK)
|
||||||
|
return BLOCK_WITH_NORMAL;
|
||||||
|
return withNormalUncached(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VertexFormat withNormalUncached(VertexFormat format)
|
||||||
{
|
{
|
||||||
if (format == null || format.hasNormal()) return format;
|
if (format == null || format.hasNormal()) return format;
|
||||||
return new VertexFormat(format).addElement(NORMAL_4F);
|
return new VertexFormat(format).addElement(NORMAL_4F);
|
||||||
|
|
Loading…
Reference in a new issue