Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 8891556d77bf6ad2d14e874d5b6d8d7f48ee056f Mon Sep 17 00:00:00 2001
- From: Kyle Repinski <repinski23@gmail.com>
- Date: Sat, 1 Jul 2017 05:32:54 -0500
- Subject: [PATCH] Particle: Add and use Vec3dM to save memory allocations.
- This saves roughly 2MB/sec of RAM just in a small field of torches.
- Note: The 'if (this.particleAngle != 0.0F)' path (doParticleRenderCalc)
- is only used by falling dust, but is verified to work properly.
- ---
- .../net/minecraft/client/particle/Particle.java | 68 +++-
- src/minecraft/net/minecraft/util/math/Vec3dM.java | 343 +++++++++++++++++++++
- 2 files changed, 395 insertions(+), 16 deletions(-)
- create mode 100644 src/minecraft/net/minecraft/util/math/Vec3dM.java
- diff --git a/src/minecraft/net/minecraft/client/particle/Particle.java b/src/minecraft/net/minecraft/client/particle/Particle.java
- index a5ddf8a..b7e1fa7 100644
- --- a/src/minecraft/net/minecraft/client/particle/Particle.java
- +++ b/src/minecraft/net/minecraft/client/particle/Particle.java
- @@ -9,6 +9,7 @@ import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.math.Vec3d;
- +import net.minecraft.util.math.Vec3dM;
- import net.minecraft.world.World;
- public class Particle
- @@ -192,11 +193,11 @@ public class Particle
- */
- public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
- {
- - float f = (float)this.particleTextureIndexX / 16.0F;
- - float f1 = f + 0.0624375F;
- - float f2 = (float)this.particleTextureIndexY / 16.0F;
- - float f3 = f2 + 0.0624375F;
- - float f4 = 0.1F * this.particleScale;
- + float f;
- + float f1;
- + float f2;
- + float f3;
- +
- if (this.particleTexture != null)
- {
- @@ -205,14 +206,34 @@ public class Particle
- f2 = this.particleTexture.getMinV();
- f3 = this.particleTexture.getMaxV();
- }
- + else
- + {
- + f = (float)this.particleTextureIndexX / 16.0F;
- + f1 = f + 0.0624375F;
- + f2 = (float)this.particleTextureIndexY / 16.0F;
- + f3 = f2 + 0.0624375F;
- + }
- + float f4 = 0.1F * this.particleScale;
- float f5 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTicks - interpPosX);
- float f6 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTicks - interpPosY);
- float f7 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTicks - interpPosZ);
- int i = this.getBrightnessForRender(partialTicks);
- int j = i >> 16 & 65535;
- int k = i & 65535;
- - Vec3d[] avec3d = new Vec3d[] {new Vec3d((double)(-rotationX * f4 - rotationXY * f4), (double)(-rotationZ * f4), (double)(-rotationYZ * f4 - rotationXZ * f4)), new Vec3d((double)(-rotationX * f4 + rotationXY * f4), (double)(rotationZ * f4), (double)(-rotationYZ * f4 + rotationXZ * f4)), new Vec3d((double)(rotationX * f4 + rotationXY * f4), (double)(rotationZ * f4), (double)(rotationYZ * f4 + rotationXZ * f4)), new Vec3d((double)(rotationX * f4 - rotationXY * f4), (double)(-rotationZ * f4), (double)(rotationYZ * f4 - rotationXZ * f4))};
- +
- + double x1 = (double)(-rotationX * f4 - rotationXY * f4);
- + double y1 = (double)(-rotationZ * f4);
- + double z1 = (double)(-rotationYZ * f4 - rotationXZ * f4);
- + double x2 = (double)(-rotationX * f4 + rotationXY * f4);
- + double y2 = (double)( rotationZ * f4);
- + double z2 = (double)(-rotationYZ * f4 + rotationXZ * f4);
- + double x3 = (double)( rotationX * f4 + rotationXY * f4);
- + double y3 = y2;
- + double z3 = (double)( rotationYZ * f4 + rotationXZ * f4);
- + double x4 = (double)( rotationX * f4 - rotationXY * f4);
- + double y4 = y1;
- + double z4 = (double)( rotationYZ * f4 - rotationXZ * f4);
- if (this.particleAngle != 0.0F)
- {
- @@ -221,18 +242,33 @@ public class Particle
- float f10 = MathHelper.sin(f8 * 0.5F) * (float)cameraViewDir.x;
- float f11 = MathHelper.sin(f8 * 0.5F) * (float)cameraViewDir.y;
- float f12 = MathHelper.sin(f8 * 0.5F) * (float)cameraViewDir.z;
- - Vec3d vec3d = new Vec3d((double)f10, (double)f11, (double)f12);
- -
- - for (int l = 0; l < 4; ++l)
- - {
- - avec3d[l] = vec3d.scale(2.0D * avec3d[l].dotProduct(vec3d)).add(avec3d[l].scale((double)(f9 * f9) - vec3d.dotProduct(vec3d))).add(vec3d.crossProduct(avec3d[l]).scale((double)(2.0F * f9)));
- - }
- + double d10 = (double)f10;
- + double d11 = (double)f11;
- + double d12 = (double)f12;
- + Vec3dM temp = new Vec3dM(d10, d11, d12);
- +
- + temp = temp.doParticleRenderCalc( x1, y1, z1, d10, d11, d12, f9 );
- + x1 = temp.xCoord;
- + y1 = temp.yCoord;
- + z1 = temp.zCoord;
- + temp = temp.doParticleRenderCalc( x2, y2, z2, d10, d11, d12, f9 );
- + x2 = temp.xCoord;
- + y2 = temp.yCoord;
- + z2 = temp.zCoord;
- + temp = temp.doParticleRenderCalc( x3, y3, z3, d10, d11, d12, f9 );
- + x3 = temp.xCoord;
- + y3 = temp.yCoord;
- + z3 = temp.zCoord;
- + temp = temp.doParticleRenderCalc( x4, y4, z4, d10, d11, d12, f9 );
- + x4 = temp.xCoord;
- + y4 = temp.yCoord;
- + z4 = temp.zCoord;
- }
- - buffer.pos((double)f5 + avec3d[0].x, (double)f6 + avec3d[0].y, (double)f7 + avec3d[0].z).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- - buffer.pos((double)f5 + avec3d[1].x, (double)f6 + avec3d[1].y, (double)f7 + avec3d[1].z).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- - buffer.pos((double)f5 + avec3d[2].x, (double)f6 + avec3d[2].y, (double)f7 + avec3d[2].z).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- - buffer.pos((double)f5 + avec3d[3].x, (double)f6 + avec3d[3].y, (double)f7 + avec3d[3].z).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- + buffer.pos((double)f5 + x1, (double)f6 + y1, (double)f7 + z1).tex((double)f1, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- + buffer.pos((double)f5 + x2, (double)f6 + y2, (double)f7 + z2).tex((double)f1, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- + buffer.pos((double)f5 + x3, (double)f6 + y3, (double)f7 + z3).tex((double)f, (double)f2).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- + buffer.pos((double)f5 + x4, (double)f6 + y4, (double)f7 + z4).tex((double)f, (double)f3).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k).endVertex();
- }
- /**
- diff --git a/src/minecraft/net/minecraft/util/math/Vec3dM.java b/src/minecraft/net/minecraft/util/math/Vec3dM.java
- new file mode 100644
- index 0000000..c11c0df
- --- /dev/null
- +++ b/src/minecraft/net/minecraft/util/math/Vec3dM.java
- @@ -0,0 +1,343 @@
- +package net.minecraft.util.math;
- +
- +import javax.annotation.Nullable;
- +
- +public class Vec3dM
- +{
- + public static final Vec3dM ZERO = new Vec3dM(0.0D, 0.0D, 0.0D);
- +
- + /** X coordinate of Vec3D */
- + public double xCoord;
- +
- + /** Y coordinate of Vec3D */
- + public double yCoord;
- +
- + /** Z coordinate of Vec3D */
- + public double zCoord;
- +
- + public Vec3dM(double x, double y, double z)
- + {
- + if (x == -0.0D)
- + {
- + x = 0.0D;
- + }
- +
- + if (y == -0.0D)
- + {
- + y = 0.0D;
- + }
- +
- + if (z == -0.0D)
- + {
- + z = 0.0D;
- + }
- +
- + this.xCoord = x;
- + this.yCoord = y;
- + this.zCoord = z;
- + }
- +
- + public Vec3dM(Vec3i vector)
- + {
- + this((double)vector.getX(), (double)vector.getY(), (double)vector.getZ());
- + }
- +
- + /**
- + * Returns a new vector with the result of the specified vector minus this.
- + */
- + public Vec3dM subtractReverse(Vec3dM vec)
- + {
- + this.xCoord = vec.xCoord - this.xCoord;
- + this.yCoord = vec.yCoord - this.yCoord;
- + this.zCoord = vec.zCoord - this.zCoord;
- + return this;
- + }
- +
- + /**
- + * Normalizes the vector to a length of 1 (except if it is the zero vector)
- + */
- + public Vec3dM normalize()
- + {
- + double d0 = (double)MathHelper.sqrt(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
- + return d0 < 1.0E-4D ? ZERO : new Vec3dM(this.xCoord / d0, this.yCoord / d0, this.zCoord / d0);
- + }
- +
- + public double dotProduct(Vec3dM vec)
- + {
- + return this.xCoord * vec.xCoord + this.yCoord * vec.yCoord + this.zCoord * vec.zCoord;
- + }
- +
- + public double dotProduct(double x, double y, double z)
- + {
- + return this.xCoord * x + this.yCoord * y + this.zCoord * z;
- + }
- +
- + /**
- + * Returns a new vector with the result of this vector x the specified vector.
- + */
- + public Vec3dM crossProduct(Vec3dM vec)
- + {
- + double newX = this.yCoord * vec.zCoord - this.zCoord * vec.yCoord;
- + double newY = this.zCoord * vec.xCoord - this.xCoord * vec.zCoord;
- + double newZ = this.xCoord * vec.yCoord - this.yCoord * vec.xCoord;
- + this.xCoord = newX;
- + this.yCoord = newY;
- + this.zCoord = newZ;
- + return this;
- + }
- +
- + public Vec3dM subtract(Vec3dM vec)
- + {
- + return this.subtract(vec.xCoord, vec.yCoord, vec.zCoord);
- + }
- +
- + public Vec3dM subtract(double x, double y, double z)
- + {
- + return this.addVector(-x, -y, -z);
- + }
- +
- + public Vec3dM add(Vec3dM vec)
- + {
- + return this.addVector(vec.xCoord, vec.yCoord, vec.zCoord);
- + }
- +
- + /**
- + * Adds the specified x,y,z vector components to this vector and returns the resulting vector. Does not change this
- + * vector.
- + */
- + public Vec3dM addVector(double x, double y, double z)
- + {
- + this.xCoord += x;
- + this.yCoord += y;
- + this.zCoord += z;
- + return this;
- + }
- +
- + /**
- + * Euclidean distance between this and the specified vector, returned as double.
- + */
- + public double distanceTo(Vec3dM vec)
- + {
- + double d0 = vec.xCoord - this.xCoord;
- + double d1 = vec.yCoord - this.yCoord;
- + double d2 = vec.zCoord - this.zCoord;
- + return (double)MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
- + }
- +
- + /**
- + * The square of the Euclidean distance between this and the specified vector.
- + */
- + public double squareDistanceTo(Vec3dM vec)
- + {
- + double d0 = vec.xCoord - this.xCoord;
- + double d1 = vec.yCoord - this.yCoord;
- + double d2 = vec.zCoord - this.zCoord;
- + return d0 * d0 + d1 * d1 + d2 * d2;
- + }
- +
- + public double squareDistanceTo(double xIn, double yIn, double zIn)
- + {
- + double d0 = xIn - this.xCoord;
- + double d1 = yIn - this.yCoord;
- + double d2 = zIn - this.zCoord;
- + return d0 * d0 + d1 * d1 + d2 * d2;
- + }
- +
- + public Vec3dM scale(double p_186678_1_)
- + {
- + this.xCoord *= p_186678_1_;
- + this.yCoord *= p_186678_1_;
- + this.zCoord *= p_186678_1_;
- + return this;
- + }
- +
- + /**
- + * Returns the length of the vector.
- + */
- + public double lengthVector()
- + {
- + return (double)MathHelper.sqrt(this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord);
- + }
- +
- + public double lengthSquared()
- + {
- + return this.xCoord * this.xCoord + this.yCoord * this.yCoord + this.zCoord * this.zCoord;
- + }
- +
- + @Nullable
- +
- + /**
- + * Returns a new vector with x value equal to the second parameter, along the line between this vector and the
- + * passed in vector, or null if not possible.
- + */
- + public Vec3dM getIntermediateWithXValue(Vec3dM vec, double x)
- + {
- + double d0 = vec.xCoord - this.xCoord;
- + double d1 = vec.yCoord - this.yCoord;
- + double d2 = vec.zCoord - this.zCoord;
- +
- + if (d0 * d0 < 1.0000000116860974E-7D)
- + {
- + return null;
- + }
- + else
- + {
- + double d3 = (x - this.xCoord) / d0;
- + return d3 >= 0.0D && d3 <= 1.0D ? new Vec3dM(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
- + }
- + }
- +
- + @Nullable
- +
- + /**
- + * Returns a new vector with y value equal to the second parameter, along the line between this vector and the
- + * passed in vector, or null if not possible.
- + */
- + public Vec3dM getIntermediateWithYValue(Vec3dM vec, double y)
- + {
- + double d0 = vec.xCoord - this.xCoord;
- + double d1 = vec.yCoord - this.yCoord;
- + double d2 = vec.zCoord - this.zCoord;
- +
- + if (d1 * d1 < 1.0000000116860974E-7D)
- + {
- + return null;
- + }
- + else
- + {
- + double d3 = (y - this.yCoord) / d1;
- + return d3 >= 0.0D && d3 <= 1.0D ? new Vec3dM(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
- + }
- + }
- +
- + @Nullable
- +
- + /**
- + * Returns a new vector with z value equal to the second parameter, along the line between this vector and the
- + * passed in vector, or null if not possible.
- + */
- + public Vec3dM getIntermediateWithZValue(Vec3dM vec, double z)
- + {
- + double d0 = vec.xCoord - this.xCoord;
- + double d1 = vec.yCoord - this.yCoord;
- + double d2 = vec.zCoord - this.zCoord;
- +
- + if (d2 * d2 < 1.0000000116860974E-7D)
- + {
- + return null;
- + }
- + else
- + {
- + double d3 = (z - this.zCoord) / d2;
- + return d3 >= 0.0D && d3 <= 1.0D ? new Vec3dM(this.xCoord + d0 * d3, this.yCoord + d1 * d3, this.zCoord + d2 * d3) : null;
- + }
- + }
- +
- + public boolean equals(Object p_equals_1_)
- + {
- + if (this == p_equals_1_)
- + {
- + return true;
- + }
- + else if (!(p_equals_1_ instanceof Vec3dM))
- + {
- + return false;
- + }
- + else
- + {
- + Vec3dM vec3d = (Vec3dM)p_equals_1_;
- + return Double.compare(vec3d.xCoord, this.xCoord) != 0 ? false : (Double.compare(vec3d.yCoord, this.yCoord) != 0 ? false : Double.compare(vec3d.zCoord, this.zCoord) == 0);
- + }
- + }
- +
- + public int hashCode()
- + {
- + long j = Double.doubleToLongBits(this.xCoord);
- + int i = (int)(j ^ j >>> 32);
- + j = Double.doubleToLongBits(this.yCoord);
- + i = 31 * i + (int)(j ^ j >>> 32);
- + j = Double.doubleToLongBits(this.zCoord);
- + i = 31 * i + (int)(j ^ j >>> 32);
- + return i;
- + }
- +
- + public String toString()
- + {
- + return "(" + this.xCoord + ", " + this.yCoord + ", " + this.zCoord + ")";
- + }
- +
- + public Vec3dM rotatePitch(float pitch)
- + {
- + float f = MathHelper.cos(pitch);
- + float f1 = MathHelper.sin(pitch);
- + double newY = this.yCoord * (double)f + this.zCoord * (double)f1;
- + double newZ = this.zCoord * (double)f - this.yCoord * (double)f1;
- + this.yCoord = newY;
- + this.zCoord = newZ;
- + return this;
- + }
- +
- + public Vec3dM rotateYaw(float yaw)
- + {
- + float f = MathHelper.cos(yaw);
- + float f1 = MathHelper.sin(yaw);
- + double newX = this.xCoord * (double)f + this.zCoord * (double)f1;
- + double newZ = this.zCoord * (double)f - this.xCoord * (double)f1;
- + this.xCoord = newX;
- + this.zCoord = newZ;
- + return this;
- + }
- +
- + /**
- + * returns a Vec3d from given pitch and yaw degrees as Vec2f
- + */
- + public static Vec3dM fromPitchYawVector(Vec2f p_189984_0_)
- + {
- + return fromPitchYaw(p_189984_0_.x, p_189984_0_.y);
- + }
- +
- + /**
- + * returns a Vec3d from given pitch and yaw degrees
- + */
- + public static Vec3dM fromPitchYaw(float p_189986_0_, float p_189986_1_)
- + {
- + float f = MathHelper.cos(-p_189986_1_ * 0.017453292F - (float)Math.PI);
- + float f1 = MathHelper.sin(-p_189986_1_ * 0.017453292F - (float)Math.PI);
- + float f2 = -MathHelper.cos(-p_189986_0_ * 0.017453292F);
- + float f3 = MathHelper.sin(-p_189986_0_ * 0.017453292F);
- + return new Vec3dM((double)(f1 * f2), (double)f3, (double)(f * f2));
- + }
- +
- + public Vec3dM doParticleRenderCalc(double avec3dX, double avec3dY, double avec3dZ, double vec3dX, double vec3dY, double vec3dZ, float f9)
- + {
- + this.xCoord = vec3dX;
- + this.yCoord = vec3dY;
- + this.zCoord = vec3dZ;
- +
- + // vec3d.scale(2.0D * avec3d[l].dotProduct(vec3d))
- + double avec3d_l_dotProduct_vec3d = avec3dX * vec3dX + avec3dY * vec3dY + avec3dZ * vec3dZ;
- + double scale0scale = 2.0D * avec3d_l_dotProduct_vec3d;
- + this.xCoord *= scale0scale;
- + this.yCoord *= scale0scale;
- + this.zCoord *= scale0scale;
- +
- + // .add(avec3d[l].scale((double)(f9 * f9) - vec3d.dotProduct(vec3d)))
- + double vec3d_dotProduct_vec3d = vec3dX * vec3dX + vec3dY * vec3dY + vec3dZ * vec3dZ;
- + double add1scale = (double)(f9 * f9) - vec3d_dotProduct_vec3d;
- + this.xCoord += (avec3dX * add1scale);
- + this.yCoord += (avec3dY * add1scale);
- + this.zCoord += (avec3dZ * add1scale);
- +
- + // .add(vec3d.crossProduct(avec3d[l]).scale((double)(2.0F * f9)));
- + double vec3d_crossProduct_avec3d_l_X = vec3dY * avec3dZ - vec3dZ * avec3dY;
- + double vec3d_crossProduct_avec3d_l_Y = vec3dZ * avec3dX - vec3dX * avec3dZ;
- + double vec3d_crossProduct_avec3d_l_Z = vec3dX * avec3dY - vec3dY * avec3dX;
- + double add2scale = (double)(2.0F * f9);
- +
- + this.xCoord += (vec3d_crossProduct_avec3d_l_X * add2scale);
- + this.yCoord += (vec3d_crossProduct_avec3d_l_Y * add2scale);
- + this.zCoord += (vec3d_crossProduct_avec3d_l_Z * add2scale);
- +
- + return this;
- + }
- +}
- --
- 2.10.1.windows.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement