Skip to content

Commit

Permalink
Remove duplicate fastinvsqrt, use regular invsqrt too
Browse files Browse the repository at this point in the history
Oops, didn't realize there was a duplicate lol
Also turns out fastinvsqrt is actually NOT faster, so I removed it. It's only faster on ancient computers, meaning anything newer than 1999 :kek:

This should ACTUALLY optimize invsqrt funcs... which is basically just used by geodes lol
  • Loading branch information
Roadhog360 committed Nov 16, 2024
1 parent 8b89222 commit 0e29c2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
33 changes: 7 additions & 26 deletions src/main/java/ganymedes01/etfuturum/core/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static double atan2(double p_181159_0_, double p_181159_2_) {
p_181159_0_ = d1;
}

double d9 = fastInvSqrt(d0);
double d9 = invSqrt(d0);
p_181159_2_ = p_181159_2_ * d9;
p_181159_0_ = p_181159_0_ * d9;
double d2 = FRAC_BIAS + p_181159_0_;
Expand All @@ -270,13 +270,12 @@ public static double atan2(double p_181159_0_, double p_181159_2_) {
return d8;
}

public static double fastInvSqrt(double p_181161_0_) {
double d0 = 0.5D * p_181161_0_;
long i = Double.doubleToRawLongBits(p_181161_0_);
i = 6910469410427058090L - (i >> 1);
p_181161_0_ = Double.longBitsToDouble(i);
p_181161_0_ *= 1.5D - d0 * p_181161_0_ * p_181161_0_;
return p_181161_0_;
public static float invSqrt(float num) {
return 1 / (float) Math.sqrt(num);
}

public static double invSqrt(double num) {
return 1 / Math.sqrt(num);
}

public static double perlinFade(double value) {
Expand Down Expand Up @@ -348,24 +347,6 @@ public static long lfloor(double value) {
return value < (double) l ? l - 1L : l;
}

public static float fastInverseSqrt(float x) {
float f = 0.5F * x;
int i = Float.floatToIntBits(x);
i = 1597463007 - (i >> 1);
x = Float.intBitsToFloat(i);
x *= 1.5F - f * x * x;
return x;
}

public static double fastInverseSqrt(double x) {
double d = 0.5D * x;
long l = Double.doubleToRawLongBits(x);
l = 6910469410427058090L - (l >> 1);
x = Double.longBitsToDouble(l);
x *= 1.5D - d * x * x;
return x;
}

public static <T> T getRandom(List<T> list, Random rand) {
return list.get(rand.nextInt(list.size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ public boolean generate(World world, Random random, int x, int y, int z) {

Iterator<Pair<BlockPos, Integer>> var40;
Pair<BlockPos, Integer> pair;
for (var40 = list.iterator(); var40.hasNext(); currentLayerSqrt += Utils.fastInverseSqrt(blockPos3.getSquaredDistance(pair.getLeft()) + (double) pair.getRight()) + t) {
for (var40 = list.iterator(); var40.hasNext(); currentLayerSqrt += Utils.invSqrt(blockPos3.getSquaredDistance(pair.getLeft()) + (double) pair.getRight()) + t) {
pair = var40.next();
} //Almost deleted this code for being unused, but the variable in the for loop is vital to later parts of the code.

BlockPos blockPos4;
Iterator<BlockPos> var41;
for (var41 = list2.iterator(); var41.hasNext(); v += Utils.fastInverseSqrt(blockPos3.getSquaredDistance(blockPos4) + (double) crackPointOffset) + t) {
for (var41 = list2.iterator(); var41.hasNext(); v += Utils.invSqrt(blockPos3.getSquaredDistance(blockPos4) + (double) crackPointOffset) + t) {
blockPos4 = var41.next();
} //Almost deleted this code for being unused, but the variable in the for loop is vital to later parts of the code.
} while (currentLayerSqrt < outerLayerSqrt);
Expand Down

0 comments on commit 0e29c2a

Please sign in to comment.