Cached Tesla objects; improving performance
This commit is contained in:
parent
052f14c540
commit
489154b92d
2 changed files with 41 additions and 4 deletions
|
@ -1,5 +1,13 @@
|
|||
package resonantinduction.fx;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_BLEND;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
|
||||
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
|
||||
import static org.lwjgl.opengl.GL11.glBlendFunc;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glShadeModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -271,6 +279,10 @@ public class FXElectricBolt extends EntityFX
|
|||
GL11.glDepthMask(false);
|
||||
GL11.glEnable(3042);
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
FMLClientHandler.instance().getClient().renderEngine.func_110577_a(TEXTURE);
|
||||
/**
|
||||
* Render the actual bolts.
|
||||
|
@ -278,7 +290,6 @@ public class FXElectricBolt extends EntityFX
|
|||
tessellator.startDrawingQuads();
|
||||
tessellator.setBrightness(15728880);
|
||||
Vector3 playerVector = new Vector3(sinYaw * -cosPitch, -cosSinPitch / cosYaw, cosYaw * cosPitch);
|
||||
float voltage = this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F;
|
||||
|
||||
int renderlength = (int) ((this.particleAge + partialframe + (int) (this.boltLength * 3.0F)) / (int) (this.boltLength * 3.0F) * this.segmentCount);
|
||||
|
||||
|
@ -302,7 +313,7 @@ public class FXElectricBolt extends EntityFX
|
|||
float ry2 = (float) (endVec.y - interpPosY);
|
||||
float rz2 = (float) (endVec.z - interpPosZ);
|
||||
|
||||
tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (1.0F - voltage * 0.5f) * segment.alpha);
|
||||
tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, (1.0F - (this.particleAge >= 0 ? ((float) this.particleAge / (float) this.particleMaxAge) : 0.0F) * 0.6f) * segment.alpha);
|
||||
tessellator.addVertexWithUV(rx2 - diffNext.x, ry2 - diffNext.y, rz2 - diffNext.z, 0.5D, 0.0D);
|
||||
tessellator.addVertexWithUV(rx1 - diffPrev.x, ry1 - diffPrev.y, rz1 - diffPrev.z, 0.5D, 0.0D);
|
||||
tessellator.addVertexWithUV(rx1 + diffPrev.x, ry1 + diffPrev.y, rz1 + diffPrev.z, 0.5D, 1.0D);
|
||||
|
|
|
@ -42,6 +42,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
public final Set<TileEntityTesla> temporarilyBlacklist = new HashSet<TileEntityTesla>();
|
||||
private final Set<TileEntityTesla> connectedTeslas = new HashSet<TileEntityTesla>();
|
||||
|
||||
/**
|
||||
* Caching
|
||||
*/
|
||||
private TileEntityTesla topCache = null;
|
||||
private TileEntityTesla controlCache = null;
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
|
@ -139,7 +145,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
tesla.transfer(transferEnergy * (1 - (this.worldObj.rand.nextFloat() * 0.1f)));
|
||||
this.transfer(-transferEnergy);
|
||||
|
||||
if (count++ > 2)
|
||||
if (count++ > 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -221,6 +227,8 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
{
|
||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
this.clearCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -262,6 +270,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) == 0;
|
||||
}
|
||||
|
||||
private void clearCache()
|
||||
{
|
||||
this.topCache = null;
|
||||
this.controlCache = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transfer(float transferEnergy)
|
||||
{
|
||||
|
@ -284,7 +298,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
|
||||
public int getRange()
|
||||
{
|
||||
return Math.min(4 * (this.getHeight() - 1), 50);
|
||||
return Math.min(5 * (this.getHeight() - 1), 50);
|
||||
}
|
||||
|
||||
public void updatePositionStatus()
|
||||
|
@ -313,6 +327,11 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
*/
|
||||
public TileEntityTesla getTopTelsa()
|
||||
{
|
||||
if (this.topCache != null)
|
||||
{
|
||||
return this.topCache;
|
||||
}
|
||||
|
||||
this.connectedTeslas.clear();
|
||||
Vector3 checkPosition = new Vector3(this);
|
||||
TileEntityTesla returnTile = this;
|
||||
|
@ -334,6 +353,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
checkPosition.y++;
|
||||
}
|
||||
|
||||
this.topCache = returnTile;
|
||||
return returnTile;
|
||||
}
|
||||
|
||||
|
@ -344,6 +364,11 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
*/
|
||||
public TileEntityTesla getControllingTelsa()
|
||||
{
|
||||
if (this.controlCache != null)
|
||||
{
|
||||
return this.controlCache;
|
||||
}
|
||||
|
||||
Vector3 checkPosition = new Vector3(this);
|
||||
TileEntityTesla returnTile = this;
|
||||
|
||||
|
@ -363,6 +388,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
checkPosition.y--;
|
||||
}
|
||||
|
||||
this.controlCache = returnTile;
|
||||
return returnTile;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue