Fix dumb stuff costing performance on world gen

This commit is contained in:
TomTheFurry
2022-04-03 16:01:54 +08:00
parent a43b2b69a6
commit b367e5c3aa
2 changed files with 2 additions and 23 deletions
@@ -27,15 +27,9 @@ import java.util.stream.Stream;
public class TintGetterOverrideFast implements BlockAndTintGetter {
LevelReader parent;
private final Object2ObjectArrayMap<ColorResolver, ConcurrentHashMap<Biome, Integer>> tintCaches;
public TintGetterOverrideFast(LevelReader parent) {
this.parent = parent;
this.tintCaches = Util.make(new Object2ObjectArrayMap(3), object2ObjectArrayMap -> {
object2ObjectArrayMap.put(BiomeColors.GRASS_COLOR_RESOLVER, new ConcurrentHashMap<Biome, Integer>());
object2ObjectArrayMap.put(BiomeColors.FOLIAGE_COLOR_RESOLVER, new ConcurrentHashMap<Biome, Integer>());
object2ObjectArrayMap.put(BiomeColors.WATER_COLOR_RESOLVER, new ConcurrentHashMap<Biome, Integer>());
});
}
private Biome _getBiome(BlockPos pos) {
@@ -49,11 +43,7 @@ public class TintGetterOverrideFast implements BlockAndTintGetter {
@Override
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
Biome b = _getBiome(blockPos);
ConcurrentHashMap<Biome, Integer> concurrentHashMap = this.tintCaches.get(colorResolver);
if (concurrentHashMap == null) { // This is a compat fix for Colormatic's mixin
this.tintCaches.put(colorResolver, concurrentHashMap = new ConcurrentHashMap<>());
}
return concurrentHashMap.computeIfAbsent(b, (key) -> colorResolver.getColor(b, blockPos.getX(), blockPos.getZ()));
return colorResolver.getColor(b, blockPos.getX(), blockPos.getZ());
}
@Override
@@ -26,17 +26,11 @@ import java.util.stream.Stream;
public class TintGetterOverrideSmooth implements BlockAndTintGetter {
LevelReader parent;
private final Object2ObjectArrayMap<ColorResolver, BlockTintCache> tintCaches;
public int smoothingRange;
public TintGetterOverrideSmooth(LevelReader parent, int smoothingRange) {
this.parent = parent;
this.smoothingRange = smoothingRange;
this.tintCaches = Util.make(new Object2ObjectArrayMap(3), object2ObjectArrayMap -> {
object2ObjectArrayMap.put(BiomeColors.GRASS_COLOR_RESOLVER, new BlockTintCache((pos) -> calculateBlockTint(pos, BiomeColors.GRASS_COLOR_RESOLVER)));
object2ObjectArrayMap.put(BiomeColors.FOLIAGE_COLOR_RESOLVER, new BlockTintCache((pos) -> calculateBlockTint(pos, BiomeColors.FOLIAGE_COLOR_RESOLVER)));
object2ObjectArrayMap.put(BiomeColors.WATER_COLOR_RESOLVER, new BlockTintCache((pos) -> calculateBlockTint(pos, BiomeColors.WATER_COLOR_RESOLVER)));
});
}
private Biome _getBiome(BlockPos pos) {
@@ -71,12 +65,7 @@ public class TintGetterOverrideSmooth implements BlockAndTintGetter {
@Override
public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) {
BlockTintCache blockTintCache = this.tintCaches.get(colorResolver);
if (blockTintCache == null) { // This is a compat fix for Colormatic's mixin
this.tintCaches.put(colorResolver,
blockTintCache = new BlockTintCache((pos) -> calculateBlockTint(pos, colorResolver)));
}
return blockTintCache.getColor(blockPos);
return calculateBlockTint(blockPos, colorResolver);
}
@Override