diff --git a/build.gradle b/build.gradle index e5b5960..a67313d 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.1' } } diff --git a/src/main/java/makeo/gadomancy/client/effect/CheckpointingSet.java b/src/main/java/makeo/gadomancy/client/effect/CheckpointingSet.java new file mode 100644 index 0000000..f737316 --- /dev/null +++ b/src/main/java/makeo/gadomancy/client/effect/CheckpointingSet.java @@ -0,0 +1,68 @@ +package makeo.gadomancy.client.effect; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +class CheckpointingSet implements Iterable { + private final Set main = new HashSet<>(); + private final Set toAdd = Collections.synchronizedSet(new HashSet<>()); + private final Set toRemove = Collections.synchronizedSet(new HashSet<>()); + + public void add(E elem) { + toAdd.add(elem); + } + + public void remove(E elem) { + toRemove.add(elem); + } + + public void clear() { + synchronized (toAdd) { + synchronized (toRemove) { + toAdd.clear(); + toRemove.clear(); + main.clear(); + } + } + } + + public void update() { + synchronized (toAdd) { + main.addAll(toAdd); + toAdd.clear(); + } + synchronized (toRemove) { + main.removeAll(toRemove); + toRemove.clear(); + } + } + + @Override + public Iterator iterator() { + return new Iterator() { + private final Iterator backing = main.iterator(); + private boolean initialized = false; + private E cur = null; + + @Override + public boolean hasNext() { + return backing.hasNext(); + } + + @Override + public E next() { + initialized = true; + return cur = backing.next(); + } + + @Override + public void remove() { + if (!initialized) + throw new IllegalStateException(); + toRemove.add(cur); + } + }; + } +} diff --git a/src/main/java/makeo/gadomancy/client/effect/EffectHandler.java b/src/main/java/makeo/gadomancy/client/effect/EffectHandler.java index db913ef..34d4196 100644 --- a/src/main/java/makeo/gadomancy/client/effect/EffectHandler.java +++ b/src/main/java/makeo/gadomancy/client/effect/EffectHandler.java @@ -9,32 +9,21 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; -import java.util.AbstractList; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.locks.ReentrantLock; - /** * This class is part of the Gadomancy Mod * Gadomancy is Open Source and distributed under the * GNU LESSER GENERAL PUBLIC LICENSE * for more read the LICENSE file - * + *

* Created by HellFirePvP @ 17.11.2015 18:39 */ public class EffectHandler { public static final EffectHandler instance = new EffectHandler(); - public static List orbitals = new LinkedList(); - public static List fxFlows = new LinkedList(); - public static List fxVortexes = new LinkedList(); - - //Object that the EffectHandler locks on. - private static final Object lockEffects = new Object(); + private static final CheckpointingSet orbitals = new CheckpointingSet<>(); + private static final CheckpointingSet fxFlows = new CheckpointingSet<>(); + private static final CheckpointingSet fxVortexes = new CheckpointingSet<>(); public static EffectHandler getInstance() { return EffectHandler.instance; @@ -47,6 +36,10 @@ public class EffectHandler { FXFlow.FXFlowBase.sheduleRender(tessellator); Orbital.sheduleRenders(EffectHandler.orbitals, event.partialTicks); FXVortex.sheduleRender(EffectHandler.fxVortexes, tessellator, event.partialTicks); + + orbitals.update(); + fxFlows.update(); + fxVortexes.update(); } public FXFlow effectFlow(World world, Vector3 origin, FXFlow.EntityFlowProperties properties) { @@ -95,23 +88,4 @@ public class EffectHandler { EffectHandler.fxFlows.clear(); EffectHandler.fxVortexes.clear(); } - - public static class NonReentrantReentrantLock extends ReentrantLock { - - @Override - public boolean isHeldByCurrentThread() { - return false; - } - - @Override - public void lock() { - super.lock(); - } - - @Override - public void unlock() { - super.unlock(); - } - - } } diff --git a/src/main/java/makeo/gadomancy/client/effect/fx/FXFlow.java b/src/main/java/makeo/gadomancy/client/effect/fx/FXFlow.java index 1c34da4..6f448d3 100644 --- a/src/main/java/makeo/gadomancy/client/effect/fx/FXFlow.java +++ b/src/main/java/makeo/gadomancy/client/effect/fx/FXFlow.java @@ -14,7 +14,6 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.ArrayDeque; -import java.util.List; import java.util.Queue; import java.util.Random; @@ -135,8 +134,8 @@ public class FXFlow { } private void calculateVelocity() { - if(this.target == null) return; - if(this.livingTicks <= 0) return; //Never happens.. + if (this.target == null) return; + if (this.livingTicks <= 0) return; //Never happens.. Vector3 pos = this.getPositionVector(); double motDirX = this.target.getX() - pos.getX(); @@ -159,11 +158,11 @@ public class FXFlow { } private void doParticles() { - if(Minecraft.getMinecraft().theWorld == null) { + if (Minecraft.getMinecraft().theWorld == null) { EffectHandler.getInstance().unregisterFlow(this); return; } - if(Minecraft.getMinecraft().theWorld.provider.dimensionId != this.origin.provider.dimensionId) { + if (Minecraft.getMinecraft().theWorld.provider.dimensionId != this.origin.provider.dimensionId) { EffectHandler.getInstance().unregisterFlow(this); return; } @@ -176,7 +175,7 @@ public class FXFlow { FXFlowBase flow2 = new FXFlowBase(this.origin, lastPosX, lastPosY, lastPosZ, this.color, (float) (this.mainParticleSize * 0.8), 8, 240); Minecraft.getMinecraft().effectRenderer.addEffect(flow2); //Consistency to last position - if(this.policy != null) + if (this.policy != null) this.policy.doSubParticles(this, this.policyCounter, this.posX, this.posY, this.posZ, lastPosX, lastPosY, lastPosZ); } @@ -211,13 +210,14 @@ public class FXFlow { public Vector3 getTarget() { return this.target; } - + public World getOriginWorld() { return this.origin; } public Vector3 getMovementVector() { - if(this.isMovementVectorNullLength()) return new Vector3(this.unmodMotionBufX, this.unmodMotionBufY, this.unmodMotionBufZ); + if (this.isMovementVectorNullLength()) + return new Vector3(this.unmodMotionBufX, this.unmodMotionBufY, this.unmodMotionBufZ); return new Vector3(this.motionBufferX, this.motionBufferY, this.motionBufferZ); } @@ -226,43 +226,43 @@ public class FXFlow { } public FXFlow applyProperties(EntityFlowProperties properties) { - if(properties != null) { - if(properties.hasTarget) { + if (properties != null) { + if (properties.hasTarget) { this.applyTarget(properties.target); } - if(properties.color != null) { - if(properties.fading != null) { + if (properties.color != null) { + if (properties.fading != null) { this.setColor(properties.fading); this.setColor(properties.color); } else { this.setColor(properties.color); } } else { - if(properties.fading != null) { + if (properties.fading != null) { this.setColor(properties.fading); } } - if(properties.livingTicks != -1) + if (properties.livingTicks != -1) this.setLivingTicks(properties.livingTicks); - if(properties.mainParticleSize != -1) + if (properties.mainParticleSize != -1) this.setMainParticleSize(properties.mainParticleSize); - if(properties.surroundingDistance != -1) + if (properties.surroundingDistance != -1) this.setSurroundingDistance(properties.surroundingDistance); - if(properties.surroundingParticleSize != -1) + if (properties.surroundingParticleSize != -1) this.setSurroundingParticleSize(properties.surroundingParticleSize); - if(properties.motionMultiplier != Float.MAX_VALUE) { + if (properties.motionMultiplier != Float.MAX_VALUE) { this.setMotionMultiplier(properties.motionMultiplier); } - if(properties.policy != null) { + if (properties.policy != null) { this.setPolicy(properties.policy); } } return this; } - public static void tickFlows(List fxFlows) { - for(FXFlow flow : fxFlows) { - if((System.currentTimeMillis() - flow.lastUpdateCall) > 1000L) { + public static void tickFlows(Iterable fxFlows) { + for (FXFlow flow : fxFlows) { + if ((System.currentTimeMillis() - flow.lastUpdateCall) > 1000L) { EffectHandler.getInstance().unregisterFlow(flow); } flow.tick(); @@ -279,7 +279,8 @@ public class FXFlow { protected int livingTicks = -1; protected float motionMultiplier = Float.MAX_VALUE; - public EntityFlowProperties() {} + public EntityFlowProperties() { + } public EntityFlowProperties setTarget(Vector3 target) { this.hasTarget = target != null; @@ -350,7 +351,7 @@ public class FXFlow { public FXFlowBase(World world, double x, double y, double z, Color color, float size, int multiplier, int brightness) { super(world, x, y, z); - if(color != null) { + if (color != null) { this.partBlue = color.getBlue() / 255F; this.partGreen = color.getGreen() / 255F; this.partRed = color.getRed() / 255F; @@ -380,12 +381,12 @@ public class FXFlow { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); - if(isLightingEnabled) + if (isLightingEnabled) GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.75F); - for(FXFlowBase fx : FXFlowBase.fxQueue) { + for (FXFlowBase fx : FXFlowBase.fxQueue) { tessellator.startDrawingQuads(); fx.renderEssenceBase(tessellator); tessellator.draw(); @@ -393,7 +394,7 @@ public class FXFlow { GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.75F); - if(isLightingEnabled) + if (isLightingEnabled) GL11.glEnable(GL11.GL_LIGHTING); GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); GL11.glDisable(GL11.GL_BLEND); @@ -406,14 +407,14 @@ public class FXFlow { tessellator.setBrightness(this.rendBrightness); GL11.glColor4f(this.partRed, this.partGreen, this.partBlue, this.partAlpha); Minecraft.getMinecraft().renderEngine.bindTexture(this.texture); - if(this.particleAge >= this.particleMaxAge) return; + if (this.particleAge >= this.particleMaxAge) return; float agescale = (float) this.particleAge / this.buffHalfLife; - if(agescale >= 1.0F) agescale = 2 - agescale; + if (agescale >= 1.0F) agescale = 2 - agescale; this.particleScale = this.buffParticleScale * agescale; float f10 = 0.5F * this.particleScale; - float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * this.partialTicks - EntityFX.interpPosX); - float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * this.partialTicks - EntityFX.interpPosY); - float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * this.partialTicks - EntityFX.interpPosZ); + float f11 = (float) (this.prevPosX + (this.posX - this.prevPosX) * this.partialTicks - EntityFX.interpPosX); + float f12 = (float) (this.prevPosY + (this.posY - this.prevPosY) * this.partialTicks - EntityFX.interpPosY); + float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * this.partialTicks - EntityFX.interpPosZ); tessellator.addVertexWithUV(f11 - this.rendArg1 * f10 - this.rendArg4 * f10, f12 - this.rendArg2 * f10, f13 - this.rendArg3 * f10 - this.rendArg5 * f10, 0, 1); tessellator.addVertexWithUV(f11 - this.rendArg1 * f10 + this.rendArg4 * f10, f12 + this.rendArg2 * f10, f13 - this.rendArg3 * f10 + this.rendArg5 * f10, 1, 1); @@ -423,7 +424,8 @@ public class FXFlow { @Override public void renderParticle(Tessellator tessellator, float partialTicks, float par3, float par4, float par5, float par6, float par7) { - if(MiscUtils.getPositionVector(Minecraft.getMinecraft().renderViewEntity).distance(new Vector3(this.posX, this.posY, this.posZ)) > ModConfig.renderParticleDistance) return; + if (MiscUtils.getPositionVector(Minecraft.getMinecraft().renderViewEntity).distance(new Vector3(this.posX, this.posY, this.posZ)) > ModConfig.renderParticleDistance) + return; this.partialTicks = partialTicks; this.rendArg1 = par3; diff --git a/src/main/java/makeo/gadomancy/client/effect/fx/FXVortex.java b/src/main/java/makeo/gadomancy/client/effect/fx/FXVortex.java index ac78619..2031dd0 100644 --- a/src/main/java/makeo/gadomancy/client/effect/fx/FXVortex.java +++ b/src/main/java/makeo/gadomancy/client/effect/fx/FXVortex.java @@ -14,7 +14,6 @@ import org.lwjgl.opengl.GL11; import thaumcraft.client.lib.QuadHelper; import thaumcraft.client.lib.UtilsFX; -import java.util.List; import java.util.Random; /** @@ -62,9 +61,9 @@ public class FXVortex { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); float agescale = (float) (ClientHandler.ticks % 800) / 400F; - if(agescale >= 1.0F) agescale = 2 - agescale; + if (agescale >= 1.0F) agescale = 2 - agescale; float size = 0.2F + 0.1F * agescale; - if(this.parent != null) { + if (this.parent != null) { size += size * (((float) this.parent.getSizeStage()) * 0.04F); } @@ -72,7 +71,7 @@ public class FXVortex { float angle = FXVortex.RAD - FXVortex.RAD * anglePerc; Vector3 iV = MiscUtils.interpolateEntityPosition(Minecraft.getMinecraft().renderViewEntity, pTicks); - if(this.parent != null && this.parent.getSizeStage() > 4) { + if (this.parent != null && this.parent.getSizeStage() > 4) { float mult = 0.001F * (this.parent.getSizeStage() - 4F); Vector3 shake = new Vector3( FXVortex.RAND.nextFloat() * mult * (FXVortex.RAND.nextBoolean() ? 1 : -1), @@ -114,7 +113,7 @@ public class FXVortex { GL11.glPopMatrix(); } - public static void sheduleRender(List vortexes, Tessellator tessellator, float partialTicks) { + public static void sheduleRender(Iterable vortexes, Tessellator tessellator, float partialTicks) { for (FXVortex vortex : vortexes) { GL11.glPushMatrix(); vortex.render(tessellator, partialTicks); @@ -122,9 +121,9 @@ public class FXVortex { } } - public static void tickVortexes(List vortexes) { - for(FXVortex vortex : vortexes) { - if((System.currentTimeMillis() - vortex.lastUpdateCall) > 100L) { + public static void tickVortexes(Iterable vortexes) { + for (FXVortex vortex : vortexes) { + if ((System.currentTimeMillis() - vortex.lastUpdateCall) > 100L) { //System.out.println("tickTimeout"); EffectHandler.getInstance().unregisterVortex(vortex); } diff --git a/src/main/java/makeo/gadomancy/client/effect/fx/Orbital.java b/src/main/java/makeo/gadomancy/client/effect/fx/Orbital.java index 1394485..85ea6ac 100644 --- a/src/main/java/makeo/gadomancy/client/effect/fx/Orbital.java +++ b/src/main/java/makeo/gadomancy/client/effect/fx/Orbital.java @@ -41,7 +41,7 @@ public final class Orbital { } public void addOrbitalPoint(OrbitalRenderProperties properties) { - if(!this.orbitals.contains(properties)) { + if (!this.orbitals.contains(properties)) { this.orbitals.add(properties); } } @@ -55,10 +55,11 @@ public final class Orbital { } public void doRender(float partialTicks) { - if(MiscUtils.getPositionVector(Minecraft.getMinecraft().renderViewEntity).distance(this.center) > ModConfig.renderParticleDistance) return; - if(Minecraft.getMinecraft().isGamePaused()) return; + if (MiscUtils.getPositionVector(Minecraft.getMinecraft().renderViewEntity).distance(this.center) > ModConfig.renderParticleDistance) + return; + if (Minecraft.getMinecraft().isGamePaused()) return; - for(OrbitalRenderProperties orbitalNode : this.orbitals) { + for (OrbitalRenderProperties orbitalNode : this.orbitals) { Axis axis = orbitalNode.getAxis(); int counterOffset = orbitalNode.getOffsetTicks() % orbitalNode.getTicksForFullCircle(); @@ -68,16 +69,16 @@ public final class Orbital { Vector3 point = axis.getAxis().clone().perpendicular().normalize().multiply(orbitalNode.getOffset()).rotate(currentRad, axis.getAxis()).add(this.center); - if(orbitalNode.getRunnable() != null) { + if (orbitalNode.getRunnable() != null) { orbitalNode.getRunnable().onRender(this.world, point, orbitalNode, this.orbitalCounter, partialTicks); } - if(orbitalNode.getParticleSize() <= 0) continue; + if (orbitalNode.getParticleSize() <= 0) continue; FXFlow.FXFlowBase flow = new FXFlow.FXFlowBase(this.world, point.getX(), point.getY(), point.getZ(), orbitalNode.getColor(), orbitalNode.getParticleSize(), orbitalNode.getMultiplier(), orbitalNode.getBrightness()); - if(orbitalNode.getSubParticleColor() != null && this.world.rand.nextInt(3) == 0) { + if (orbitalNode.getSubParticleColor() != null && this.world.rand.nextInt(3) == 0) { Vector3 subOffset = this.genSubOffset(this.world.rand, 0.8F); Color c = (this.world.rand.nextBoolean()) ? orbitalNode.getSubParticleColor() : orbitalNode.getColor(); FXFlow.FXFlowBase flow2 = new FXFlow.FXFlowBase(this.world, @@ -99,7 +100,7 @@ public final class Orbital { } public void reduceAllOffsets(float percent) { - for(OrbitalRenderProperties node : this.orbitals) { + for (OrbitalRenderProperties node : this.orbitals) { node.reduceOffset(percent); } } @@ -108,7 +109,7 @@ public final class Orbital { Vector3[] arr = new Vector3[properties.length]; for (int i = 0; i < properties.length; i++) { OrbitalRenderProperties property = properties[i]; - if(property == null) { + if (property == null) { arr[i] = null; continue; } @@ -125,15 +126,15 @@ public final class Orbital { return arr; } - public static void sheduleRenders(List orbitals, float partialTicks) { - for(Orbital orbital : orbitals) { + public static void sheduleRenders(Iterable orbitals, float partialTicks) { + for (Orbital orbital : orbitals) { orbital.doRender(partialTicks); } } - public static void tickOrbitals(List orbitals) { - for(Orbital orbital : orbitals) { - if((System.currentTimeMillis() - orbital.lastRenderCall) > 1000L) { + public static void tickOrbitals(Iterable orbitals) { + for (Orbital orbital : orbitals) { + if ((System.currentTimeMillis() - orbital.lastRenderCall) > 1000L) { orbital.clearOrbitals(); EffectHandler.getInstance().unregisterOrbital(orbital); } else { @@ -176,7 +177,7 @@ public final class Orbital { } public OrbitalRenderProperties setSubSizeRunnable(OrbitalSubSizeRunnable subSizeRunnable) { - if(subSizeRunnable == null) return this; + if (subSizeRunnable == null) return this; this.subSizeRunnable = subSizeRunnable; return this; }