Skip to content

Commit

Permalink
VectorTable should be static. Building a new (data huge) object every…
Browse files Browse the repository at this point in the history
… time we want to gradient isn't a good idea in Java. According to my runs through VisualVM, this small change speeds up the drawing time x1000. I'd be interested if others that have more complex requirements see a similar difference.
  • Loading branch information
Michael Nugent committed Feb 24, 2012
1 parent c9fe1b0 commit 4063059
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 313 deletions.
11 changes: 7 additions & 4 deletions src/libnoiseforjava/NoiseGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static double GradientNoise3D (double fx, double fy, double fz, int ix,
int iy, int iz, int seed)
{

VectorTable vectorTable = new VectorTable();
//VectorTable vectorTable = new VectorTable();
// Randomly generate a gradient vector given the integer coordinates of the
// input value. This implementation generates a random number and uses it
// as an index into a normalized-vector lookup table.
Expand All @@ -135,9 +135,12 @@ public static double GradientNoise3D (double fx, double fy, double fz, int ix,
vectorIndex ^= (vectorIndex >> SHIFT_NOISE_GEN);
vectorIndex &= 0xff;

double xvGradient = vectorTable.getRandomVectors(vectorIndex, 0);
double yvGradient = vectorTable.getRandomVectors(vectorIndex, 1);
double zvGradient = vectorTable.getRandomVectors(vectorIndex, 2);
//double xvGradient = vectorTable.getRandomVectors(vectorIndex, 0);
//double yvGradient = vectorTable.getRandomVectors(vectorIndex, 1);
//double zvGradient = vectorTable.getRandomVectors(vectorIndex, 2);
double xvGradient = VectorTable.getRandomVectors(vectorIndex, 0);
double yvGradient = VectorTable.getRandomVectors(vectorIndex, 1);
double zvGradient = VectorTable.getRandomVectors(vectorIndex, 2);
// array size too large when using this original, changed to above for all 3
// double zvGradient = vectorTable.getRandomVectors(vectorIndex << 2, 2);

Expand Down
Loading

1 comment on commit 4063059

@cogchoir
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta try this when I get home. If this works, you are literally Jesus.

Please sign in to comment.