Skip to content

Commit

Permalink
Angelica Thread Safety
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Feb 19, 2024
1 parent e571a7b commit 7d69692
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 38 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
compileOnly("curse.maven:ee3-65509:2305023") { // https://www.curseforge.com/minecraft/mc-mods/ee3/files/2305023
transitive = false
}

compileOnly("com.github.GTNewHorizons:Angelica:1.0.0-alpha28:api") {
transitive = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ protected IIcon getIcon(ICarvingVariation variation, Object cachedObject, IBlock
@Override
@SideOnly(Side.CLIENT)
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
RenderBlocksColumn ret = theRenderBlocksColumn;
TextureType.initStatics();
RenderBlocksColumn ret = theRenderBlocksColumn.get();
Pair<TextureSubmap, IIcon> data = (Pair<TextureSubmap, IIcon>) cachedObject;

ret.blockAccess = world;
Expand Down Expand Up @@ -205,7 +206,7 @@ protected IIcon getIcon(ICarvingVariation variation, Object cachedObject, int si
@Override
@SideOnly(Side.CLIENT)
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
RenderBlocksCTM ret = theRenderBlocksCTM;
RenderBlocksCTM ret = theRenderBlocksCTM.get();
Triple<?, TextureSubmap, TextureSubmap> data = (Triple<?, TextureSubmap, TextureSubmap>) cachedObject;
ret.blockAccess = world;

Expand Down Expand Up @@ -325,9 +326,9 @@ private static long getCoordinateRandom(int x, int y, int z) {
private static final CTM ctm = CTM.getInstance();
private static final Random rand = new Random();
@SideOnly(Side.CLIENT)
private static RenderBlocksCTM theRenderBlocksCTM;
private static ThreadLocal<RenderBlocksCTM> theRenderBlocksCTM;
@SideOnly(Side.CLIENT)
private static RenderBlocksColumn theRenderBlocksColumn;
private static ThreadLocal<RenderBlocksColumn> theRenderBlocksColumn;

private String[] suffixes;
static {
Expand All @@ -338,16 +339,17 @@ private TextureType(String... suffixes) {
this.suffixes = suffixes.length == 0 ? new String[] { "" } : suffixes;
}

private static void initStatics() {
if (theRenderBlocksCTM == null) {
theRenderBlocksCTM = new RenderBlocksCTM();
theRenderBlocksColumn = new RenderBlocksColumn();
}
}
private static void initStatics() {
if (theRenderBlocksCTM == null) {
theRenderBlocksCTM = ThreadLocal.withInitial(RenderBlocksCTM::new);
theRenderBlocksColumn = ThreadLocal.withInitial(RenderBlocksColumn::new);
}
}

@SideOnly(Side.CLIENT)
public static void clearStatics() {
theRenderBlocksCTM = null;
theRenderBlocksColumn = null;
theRenderBlocksCTM.remove();
theRenderBlocksColumn.remove();
}

public ISubmapManager createManagerFor(ICarvingVariation variation, String texturePath) {
Expand Down Expand Up @@ -428,7 +430,6 @@ public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {

@Override
public RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world) {
initStatics();
RenderBlocks rb = type.createRenderContext(rendererOld, world, cachedObject);
rb.setRenderBoundsFromBlock(block);
return rb;
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/team/chisel/client/render/RendererCTMPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererCTMPane implements ISimpleBlockRenderingHandler {

public static int id;
Expand All @@ -32,8 +35,6 @@ public void renderInventoryBlock(Block block, int meta, int modelID, RenderBlock

class PaneRenderer {

Tessellator tessellator;

double i0u0;
double i0uh;
double i0u1;
Expand Down Expand Up @@ -69,8 +70,6 @@ class PaneRenderer {
double y1;

void set(double x, double y, double z, IIcon icon, IIcon icon1, IIcon icon2) {
tessellator = Tessellator.instance;

i0u0 = icon.getMinU();
i0uh = icon.getInterpolatedU(8.0D);
i0u1 = icon.getMaxU();
Expand Down Expand Up @@ -107,6 +106,8 @@ void set(double x, double y, double z, IIcon icon, IIcon icon1, IIcon icon2) {
}

public void renderNorthPane() {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(xh, y1, z0, i0uh, i0v0);
tessellator.addVertexWithUV(xh, y0, z0, i0uh, i0v1);
tessellator.addVertexWithUV(xh, y0, zh, i0u0, i0v1);
Expand All @@ -118,6 +119,8 @@ public void renderNorthPane() {
}

public void renderSouthPane() {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(xh, y1, zh, i0u1, i0v0);
tessellator.addVertexWithUV(xh, y0, zh, i0u1, i0v1);
tessellator.addVertexWithUV(xh, y0, z1, i0uh, i0v1);
Expand All @@ -129,6 +132,8 @@ public void renderSouthPane() {
}

public void renderWestPane() {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(x0, y1, zh, i0uh, i0v0);
tessellator.addVertexWithUV(x0, y0, zh, i0uh, i0v1);
tessellator.addVertexWithUV(xh, y0, zh, i0u0, i0v1);
Expand All @@ -140,6 +145,8 @@ public void renderWestPane() {
}

public void renderEastPane() {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(xh, y1, zh, i0u1, i0v0);
tessellator.addVertexWithUV(xh, y0, zh, i0u1, i0v1);
tessellator.addVertexWithUV(x1, y0, zh, i0uh, i0v1);
Expand All @@ -151,6 +158,8 @@ public void renderEastPane() {
}

public void renderVerticalNS(double y, double zoff0, double zoff1, double v0, double v1) {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(xp0, y0 + y, z0 + zoff0, i1u0, i1v0 + i1v * v0);
tessellator.addVertexWithUV(xp0, y0 + y, z0 + zoff1, i1u0, i1v0 + i1v * v1);
tessellator.addVertexWithUV(xp1, y0 + y, z0 + zoff1, i1u1, i1v0 + i1v * v1);
Expand All @@ -162,6 +171,8 @@ public void renderVerticalNS(double y, double zoff0, double zoff1, double v0, do
}

public void renderVerticalWE(double y, double xoff0, double xoff1, double v0, double v1) {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(x0 + xoff0, y0 + y, zp1, i1u1, i1v0 + i1v * v0);
tessellator.addVertexWithUV(x0 + xoff1, y0 + y, zp1, i1u1, i1v0 + i1v * v1);
tessellator.addVertexWithUV(x0 + xoff1, y0 + y, zp0, i1u0, i1v0 + i1v * v1);
Expand All @@ -173,6 +184,8 @@ public void renderVerticalWE(double y, double xoff0, double xoff1, double v0, do
}

public void renderHorizontalNS(double zoff, double v0, double v1) {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(xp0, y1, z0 + zoff, i2u0, i2v0 + i2v * v1);
tessellator.addVertexWithUV(xp0, y0, z0 + zoff, i2u0, i2v0 + i2v * v0);
tessellator.addVertexWithUV(xp1, y0, z0 + zoff, i2u1, i2v0 + i2v * v0);
Expand All @@ -185,6 +198,8 @@ public void renderHorizontalNS(double zoff, double v0, double v1) {
}

public void renderHorizontalWE(double xoff, double v0, double v1) {
Tessellator tessellator = Tessellator.instance;

tessellator.addVertexWithUV(x0 + xoff, y1, zp0, i2u0, i2v0 + i2v * v1);
tessellator.addVertexWithUV(x0 + xoff, y0, zp0, i2u0, i2v0 + i2v * v0);
tessellator.addVertexWithUV(x0 + xoff, y0, zp1, i2u1, i2v0 + i2v * v0);
Expand All @@ -196,13 +211,14 @@ public void renderHorizontalWE(double xoff, double v0, double v1) {
}
}

PaneRenderer paneRenderer = new PaneRenderer();
final ThreadLocal<PaneRenderer> paneRendererThreadLocal = ThreadLocal.withInitial(PaneRenderer::new);

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b, int modelId,
RenderBlocks renderer) {
BlockPane block = (BlockPane) b;
Tessellator tessellator = Tessellator.instance;
final Tessellator tessellator = Tessellator.instance;
final PaneRenderer paneRenderer = paneRendererThreadLocal.get();

tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.Chisel;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererEldritch implements ISimpleBlockRenderingHandler {

public RendererEldritch() {
Expand All @@ -24,12 +27,14 @@ public void renderInventoryBlock(Block block, int metadata, int modelID, RenderB
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}

RenderBlocksEldritch renderer = new RenderBlocksEldritch();
ThreadLocal<RenderBlocksEldritch> rendererThreadLocal = ThreadLocal.withInitial(RenderBlocksEldritch::new);

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
RenderBlocks rendererOld) {

final RenderBlocksEldritch renderer = rendererThreadLocal.get();

// tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x,
// y, z));
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.Chisel;
Expand All @@ -15,6 +17,7 @@
import team.chisel.ctmlib.Drawing;
import team.chisel.utils.GeneralClient;

@ThreadSafeISBRH(perThread = false)
public class RendererLayeredGlow implements ISimpleBlockRenderingHandler {

public RendererLayeredGlow() {
Expand All @@ -36,8 +39,9 @@ public void renderInventoryBlock(Block block, int metadata, int modelId, RenderB
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
RenderBlocks renderer) {
Tessellator.instance.setColorOpaque_I(Configurations.configColors[world.getBlockMetadata(x, y, z)]);
Tessellator.instance.setBrightness(0xF000F0);
final Tessellator tessellator = Tessellator.instance;
tessellator.setColorOpaque_I(Configurations.configColors[world.getBlockMetadata(x, y, z)]);
tessellator.setBrightness(0xF000F0);
Drawing.renderAllFaces(renderer, block, x, y, z, ((BlockCarvableGlow) block).getGlowTexture());
renderer.renderStandardBlock(block, x, y, z);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.MinecraftForgeClient;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.block.BlockMultiLayerBase;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererMultiLayer implements ISimpleBlockRenderingHandler {

float bot = -0.001f, top = 1.0f - bot;
final static float bot = -0.001f;
final static float top = 1.0f - bot;
public static int id;

public RendererMultiLayer() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/team/chisel/client/render/RendererRoadLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.Chisel;
import team.chisel.block.BlockRoadLine;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererRoadLine implements ISimpleBlockRenderingHandler {

public RendererRoadLine() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.Chisel;
import team.chisel.block.BlockCarvableLayered;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererSimpleLayered implements ISimpleBlockRenderingHandler {

public RendererSimpleLayered() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.block.BlockSnakestone;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererSnakeStone implements ISimpleBlockRenderingHandler {

public static int id;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/team/chisel/client/render/RendererStairs.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import org.lwjgl.opengl.GL11;

import com.gtnewhorizons.angelica.api.ThreadSafeISBRH;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import team.chisel.block.BlockCarvableStairs;
import team.chisel.ctmlib.Drawing;

@ThreadSafeISBRH(perThread = false)
public class RendererStairs implements ISimpleBlockRenderingHandler {

public static int id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/chisel/ctmlib/CTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class CTM {

public Optional<Boolean> disableObscuredFaceCheck = Optional.absent();

protected TIntObjectMap<Dir[]> submapMap = new TIntObjectHashMap<Dir[]>();
protected TIntObjectMap<Dir[]> submapMap = new TIntObjectHashMap<>();
protected EnumMap<Dir, Boolean> connectionMap = Maps.newEnumMap(Dir.class);

protected CTM() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/team/chisel/ctmlib/CTMLib.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package team.chisel.ctmlib;

import cpw.mods.fml.common.ModAPIManager;
import team.chisel.Tags;

public class CTMLib {

public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String VERSION = Tags.VERSION;

private static boolean chiselPresent, chiselInitialized;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/chisel/ctmlib/CTMRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class CTMRenderer implements ISimpleBlockRenderingHandler {

private int renderId;
private final int renderId;

public CTMRenderer(int renderId) {
this.renderId = renderId;
Expand Down
Loading

0 comments on commit 7d69692

Please sign in to comment.