Make the BlockStateModelFactory a thread-local and reuse it during rendering

This commit is contained in:
Lukas Rieger (Blue) 2024-09-02 16:33:39 +02:00
parent bca6647670
commit 38a8423428
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -31,19 +31,21 @@
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
import de.bluecolored.bluemap.core.util.math.Color;
import de.bluecolored.bluemap.core.world.Chunk;
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
import de.bluecolored.bluemap.core.world.World;
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
public class HiresModelRenderer {
private final ResourcePack resourcePack;
private final TextureGallery textureGallery;
private final RenderSettings renderSettings;
private final ThreadLocal<BlockStateModelFactory> threadLocalModelFactory;
public HiresModelRenderer(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
this.resourcePack = resourcePack;
this.textureGallery = textureGallery;
this.renderSettings = renderSettings;
this.threadLocalModelFactory = ThreadLocal.withInitial(() -> new BlockStateModelFactory(resourcePack, textureGallery, renderSettings));
}
public void render(World world, Vector3i modelMin, Vector3i modelMax, TileModel model) {
@ -55,8 +57,7 @@ public void render(World world, Vector3i modelMin, Vector3i modelMax, TileModel
Vector3i max = modelMax.min(renderSettings.getMaxPos());
Vector3i modelAnchor = new Vector3i(modelMin.getX(), 0, modelMin.getZ());
// create new for each tile-render since the factory is not threadsafe
BlockStateModelFactory modelFactory = new BlockStateModelFactory(resourcePack, textureGallery, renderSettings);
BlockStateModelFactory modelFactory = threadLocalModelFactory.get();
int maxHeight, minY, maxY;
double topBlockLight;