Skip to content

Commit

Permalink
Make the BlockStateModelFactory a thread-local and reuse it during re…
Browse files Browse the repository at this point in the history
…ndering
  • Loading branch information
TBlueF committed Sep 2, 2024
1 parent bca6647 commit 38a8423
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 38a8423

Please sign in to comment.