Skip to content

Commit

Permalink
Update to libGDX 1.9.8, improve NumberTools
Browse files Browse the repository at this point in the history
The change to libGDX 1.9.8 is generally minor and no issues have
surfaced so far, but because libGDX's ScrollPane.setWidget() is now
deprecated and it may be removed in an upcoming release, the
differently-named and just-added ScrollPane.setActor() is used instead.
This setActor() method wasn't available in libGDX 1.9.6, so as of this
revision the display module needs libGDX 1.9.7 or newer to build.
Because 1.9.8 seems pretty painless to upgrade to, I think this won't be
an issue. It's hard to measure, but it looks like the framerate is
smoother in this libGDX version; there may have been optimizations that
reduce GC load.

The NumberTools changes affect the randomFloat, randomDouble,
randomSignedFloat, and randomFloatCurved methods. These simply use a
more efficient random number generation algorithm, but operate on long
values instead of the ints they previously used so the issues with
larger-than-normal ints on GWT won't change results. They also may
generate the full range of numbers from 0.0 to 1.0 instead of only a
fraction of it, which they were limited to before.
  • Loading branch information
tommyettinger committed Dec 10, 2017
1 parent 6b6e604 commit 06595ec
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 99 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -256,7 +256,7 @@ Current Features:
- You should use [the stable version of SquidSetup](https://github.com/tommyettinger/SquidSetup/releases/tag/v3.0.0-b9) if you want to use
the latest stable SquidLib, since it has squidlib 3.0.0-b9 (as well as squidlib-util and regexodus) all configured as default.
There's a SquidLib demo as an example that defaults to being selected. You should probably select libGDX version 1.9.6 if you use the
stable version, and currently also the snapshot (1.9.7 was briefly tried, but immediate bugs ended the attempt).
stable version, or 1.9.8 if you use the snapshot (1.9.8 includes important fixes to bugs from 1.9.7).
- Some ways of setting up a project won't include assets, so if you use the DefaultResources class in the display
module (recommended for several things, like distance field fonts), you need to get the assets you want separately.
They're in the assets/ folder of this GitHub repo, or you can get all the assets in a .zip file from SquidLib's
Expand Down Expand Up @@ -329,7 +329,7 @@ Optional Serialization Support
compile 'com.squidpony:squidlib-extra:3.0.0-b9'
```

If you want the latest version of SquidLib, which uses libGDX 1.9.6 and GWT 2.8.0 (if you use GWT), you can use JitPack
If you want the latest version of SquidLib, which uses libGDX 1.9.8 and GWT 2.8.0 (if you use GWT), you can use JitPack
to build the latest commit on-demand. It needs an additional repository, which is this for Maven:

```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -50,7 +50,7 @@ sourceSets {
// define 'gdxVersion' if not defined yet. This allows
// a project depending on SquidLib (like: your game) to define
// 'gdxVersion' itself, and yet be able to build SquidLib standalone too.
def gdxVersion = System.getenv("gdxVersion") ?: "1.9.6" // As in pom.xml
def gdxVersion = System.getenv("gdxVersion") ?: "1.9.8" // As in pom.xml
project.sourceCompatibility = 1.7
// project.sourceCompatibility = '1.6' // For android. Commented because not honored (diamonds) :-(

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -65,7 +65,7 @@
<cobertura.version>2.7</cobertura.version>
<jdk.version>1.7</jdk.version>
<!-- As in build.gradle-->
<gdx.version>1.9.6</gdx.version>
<gdx.version>1.9.8</gdx.version>
<junit.version>4.11</junit.version>
<regexodus.version>0.1.9</regexodus.version>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions squidlib-extra/README.md
Expand Up @@ -256,7 +256,7 @@ Current Features:
- You should use [the stable version of SquidSetup](https://github.com/tommyettinger/SquidSetup/releases/tag/v3.0.0-b9) if you want to use
the latest stable SquidLib, since it has squidlib 3.0.0-b9 (as well as squidlib-util and regexodus) all configured as default.
There's a SquidLib demo as an example that defaults to being selected. You should probably select libGDX version 1.9.6 if you use the
stable version, and currently also the snapshot (1.9.7 was briefly tried, but immediate bugs ended the attempt).
stable version, or 1.9.8 if you use the snapshot (1.9.8 includes important fixes to bugs from 1.9.7).
- Some ways of setting up a project won't include assets, so if you use the DefaultResources class in the display
module (recommended for several things, like distance field fonts), you need to get the assets you want separately.
They're in the assets/ folder of this GitHub repo, or you can get all the assets in a .zip file from SquidLib's
Expand Down Expand Up @@ -329,7 +329,7 @@ Optional Serialization Support
compile 'com.squidpony:squidlib-extra:3.0.0-b9'
```

If you want the latest version of SquidLib, which uses libGDX 1.9.6 and GWT 2.8.0 (if you use GWT), you can use JitPack
If you want the latest version of SquidLib, which uses libGDX 1.9.8 and GWT 2.8.0 (if you use GWT), you can use JitPack
to build the latest commit on-demand. It needs an additional repository, which is this for Maven:

```
Expand Down
4 changes: 2 additions & 2 deletions squidlib-performance/README.md
Expand Up @@ -256,7 +256,7 @@ Current Features:
- You should use [the stable version of SquidSetup](https://github.com/tommyettinger/SquidSetup/releases/tag/v3.0.0-b9) if you want to use
the latest stable SquidLib, since it has squidlib 3.0.0-b9 (as well as squidlib-util and regexodus) all configured as default.
There's a SquidLib demo as an example that defaults to being selected. You should probably select libGDX version 1.9.6 if you use the
stable version, and currently also the snapshot (1.9.7 was briefly tried, but immediate bugs ended the attempt).
stable version, or 1.9.8 if you use the snapshot (1.9.8 includes important fixes to bugs from 1.9.7).
- Some ways of setting up a project won't include assets, so if you use the DefaultResources class in the display
module (recommended for several things, like distance field fonts), you need to get the assets you want separately.
They're in the assets/ folder of this GitHub repo, or you can get all the assets in a .zip file from SquidLib's
Expand Down Expand Up @@ -329,7 +329,7 @@ Optional Serialization Support
compile 'com.squidpony:squidlib-extra:3.0.0-b9'
```

If you want the latest version of SquidLib, which uses libGDX 1.9.6 and GWT 2.8.0 (if you use GWT), you can use JitPack
If you want the latest version of SquidLib, which uses libGDX 1.9.8 and GWT 2.8.0 (if you use GWT), you can use JitPack
to build the latest commit on-demand. It needs an additional repository, which is this for Maven:

```
Expand Down
4 changes: 2 additions & 2 deletions squidlib-util/README.md
Expand Up @@ -256,7 +256,7 @@ Current Features:
- You should use [the stable version of SquidSetup](https://github.com/tommyettinger/SquidSetup/releases/tag/v3.0.0-b9) if you want to use
the latest stable SquidLib, since it has squidlib 3.0.0-b9 (as well as squidlib-util and regexodus) all configured as default.
There's a SquidLib demo as an example that defaults to being selected. You should probably select libGDX version 1.9.6 if you use the
stable version, and currently also the snapshot (1.9.7 was briefly tried, but immediate bugs ended the attempt).
stable version, or 1.9.8 if you use the snapshot (1.9.8 includes important fixes to bugs from 1.9.7).
- Some ways of setting up a project won't include assets, so if you use the DefaultResources class in the display
module (recommended for several things, like distance field fonts), you need to get the assets you want separately.
They're in the assets/ folder of this GitHub repo, or you can get all the assets in a .zip file from SquidLib's
Expand Down Expand Up @@ -329,7 +329,7 @@ Optional Serialization Support
compile 'com.squidpony:squidlib-extra:3.0.0-b9'
```

If you want the latest version of SquidLib, which uses libGDX 1.9.6 and GWT 2.8.0 (if you use GWT), you can use JitPack
If you want the latest version of SquidLib, which uses libGDX 1.9.8 and GWT 2.8.0 (if you use GWT), you can use JitPack
to build the latest commit on-demand. It needs an additional repository, which is this for Maven:

```
Expand Down
Expand Up @@ -193,43 +193,26 @@ public static long splitMix64(long state) {
return state ^ (state >>> 31);
}

public static double randomDouble(int seed)
public static double randomDouble(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
state ^= (state >>> 31);
wia.set(0, (int)(state & 0xFFFFFFFF));
wia.set(1, (int)(state >>> 44) | 0x3ff00000);
return wda.get(0) - 1.0;
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) & 0x1FFFFFFFFFFFFFL) * 0x1p-53;
}
public static float randomFloat(int seed)

public static float randomFloat(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
wia.set(0, (int)(state >>> 41) | 0x3f800000);
return (wfa.get(0) - 1f);
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) & 0xFFFFFF) * 0x1p-24f;
}

public static float randomSignedFloat(int seed)
public static float randomSignedFloat(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
wia.set(0, (int)(state >>> 40) | 0x3f800000);
return (wfa.get(0) - 1f) * (state >> 63 | 1L);
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) >> 39) * 0x1p-24f;
}
public static float randomFloatCurved(int seed)

public static float randomFloatCurved(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
state ^= (state >>> 31);
wia.set(0, (int)(state & 0x7FFFFF) | 0x3f800000);
wia.set(1, (int)(state >>> 40) | 0x3f800000);
return (wfa.get(0) - 1f) * (wfa.get(1) - 1f) * (state >> 63 | 1L);
return formCurvedFloat(((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)));
}

public static float formFloat(final int seed)
{
wia.set(0, (seed & 0x7FFFFF) | 0x3f800000);
Expand Down
92 changes: 34 additions & 58 deletions squidlib-util/src/main/java/squidpony/squidmath/NumberTools.java
Expand Up @@ -387,89 +387,65 @@ public static long splitMix64(long state) {
}

/**
* Generates a pseudo-random double between 0.0 (inclusive) and 1.0 (exclusive) using the given int seed, passing it
* once through the (very high-quality and rather fast) {@link LightRNG} algorithm, also called SplitMix64. This
* produces a pair of random ints, which this produces a double from using the equivalent of
* {@link #longBitsToDouble(long)} or something functionally equivalent on GWT.
* Generates a pseudo-random double between 0.0 (inclusive) and 1.0 (exclusive) using the given long seed, passing
* it once through the (high-quality and very fast) {@link ThrustAltRNG} algorithm.
* <br>
* Consider calling this with {@code NumberTools.randomDouble(++seed)} for an optimal period of 2 to the 32 when
* repeatedly called, but {@code NumberTools.randomDouble(seed += ODD_INT)} will also work just fine if ODD_INT is
* any odd-number integer, positive or negative.
* @param seed any int to be used as a seed
* Consider calling this with {@code NumberTools.randomDouble(++seed)} for an optimal period of 2 to the 64 when
* repeatedly called, but {@code NumberTools.randomDouble(seed += ODD_LONG)} will also work just fine if ODD_LONG is
* any odd-number long, positive or negative.
* @param seed any long to be used as a seed
* @return a pseudo-random double from 0.0 (inclusive) to 1.0 (exclusive)
*/
public static double randomDouble(int seed)
public static double randomDouble(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
return Double.longBitsToDouble(((state ^ (state >>> 31)) >>> 12) | 0x3ff0000000000000L) - 1.0;
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) & 0x1FFFFFFFFFFFFFL) * 0x1p-53;
}
/**
* Generates a pseudo-random float between 0.0f (inclusive) and 1.0f (exclusive) using the given int seed, passing
* it once through the (very high-quality and rather fast) {@link LightRNG} algorithm, also called SplitMix64. This
* produces a random int, which this produces a float from using {@link #intBitsToFloat(int)} (long)} or something
* functionally equivalent on GWT.
* Generates a pseudo-random float between 0f (inclusive) and 1f (exclusive) using the given long seed, passing it
* once through the (high-quality and very fast) {@link ThrustAltRNG} algorithm.
* <br>
* Consider calling this with {@code NumberTools.randomFloat(++seed)} for an optimal period of 2 to the 32 when
* repeatedly called, but {@code NumberTools.randomFloat(seed += ODD_INT)} will also work just fine if ODD_INT is
* any odd-number integer, positive or negative.
* @param seed any int to be used as a seed
* Consider calling this with {@code NumberTools.randomFloat(++seed)} for an optimal period of 2 to the 64 when
* repeatedly called, but {@code NumberTools.randomFloat(seed += ODD_LONG)} will also work just fine if ODD_LONG is
* any odd-number long, positive or negative.
* @param seed any long to be used as a seed
* @return a pseudo-random float from -1.0f (exclusive) to 1.0f (exclusive)
*/
public static float randomFloat(int seed)
public static float randomFloat(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
return Float.intBitsToFloat((int)(state >>> 41) | 0x3f800000) - 1f;
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) & 0xFFFFFF) * 0x1p-24f;
}
/**
* Generates a pseudo-random float between -1.0f (exclusive) and 1.0f (exclusive) using the given int seed, passing
* it once through the (very high-quality and rather fast) {@link LightRNG} algorithm, also called SplitMix64. This
* produces a random int, which this produces a float from using {@link #intBitsToFloat(int)} (long)} or something
* functionally equivalent on GWT. The sign bit of the result is determined by data that is not used by the float
* otherwise, and keeps the results almost linear in distribution between -1.0 and 1.0, exclusive for both (0 shows
* up twice as often as any single other result, but this shouldn't affect the odds very strongly; it's about a 1 in
* 8 million chance of exactly 0 occurring vs. a 1 in 16 million of any other specific float this can produce).
* Generates a pseudo-random float between -1f (inclusive) and 1f (exclusive) using the given long seed, passing
* it once through the (high-quality and very fast) {@link ThrustAltRNG} algorithm. This can be useful as a
* multiplier that has approximately equal likelihood of changing or leaving the sign of its multiplicand, and won't
* make the result larger (more significant) but will usually make it closer to 0.
* <br>
* Consider calling this with {@code NumberTools.randomSignedFloat(++seed)} for an optimal period of 2 to the 32
* when repeatedly called, but {@code NumberTools.randomSignedFloat(seed += ODD_INT)} will also work just fine if
* ODD_INT is any odd-number integer, positive or negative.
* @param seed any int to be used as a seed
* Consider calling this with {@code NumberTools.randomDouble(++seed)} for an optimal period of 2 to the 64 when
* repeatedly called, but {@code NumberTools.randomDouble(seed += ODD_LONG)} will also work just fine if ODD_LONG is
* any odd-number long, positive or negative.
* @param seed any long to be used as a seed
* @return a pseudo-random float from -1.0f (exclusive) to 1.0f (exclusive)
*/
public static float randomSignedFloat(int seed)
public static float randomSignedFloat(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
return (Float.intBitsToFloat((int)(state >>> 40) | 0x3f800000) - 1f) * (state >> 63 | 1L);
return (((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)) >> 39) * 0x1p-24f;
}

/**
* Generates a pseudo-random double between -1.0 (exclusive) and 1.0 (exclusive) with a distribution that has a
* strong central bias (around 0.0). Uses the given int seed, passing it once through the (very high-quality and
* rather fast) {@link LightRNG} algorithm, also called SplitMix64. This produces a pair of random ints, which this
* uses to generate a pair of floats between 0.0 (inclusive)and 1.0 (exclusive) using the equivalent of
* {@link #intBitsToFloat(int)} or something functionally equivalent on GWT, multiplies the floats, and sets the
* sign pseudo-randomly based on an unused bit from earlier.
* strong central bias (around 0.0). Uses the given long seed, passing it once through the (high-quality and very
* fast) {@link ThrustAltRNG} algorithm. This produces a pseudo-random long, which this simply passes to
* {@link #formCurvedFloat(long)}, since it is already well-suited to generating a curved distribution.
* <br>
* Consider calling this with {@code NumberTools.randomFloatCurved(++seed)} for an optimal period of 2 to the 32
* when repeatedly called, but {@code NumberTools.randomFloatCurved(seed += ODD_INT)} will also work just fine if
* ODD_INT is any odd-number integer, positive or negative.
* Consider calling this with {@code NumberTools.randomFloatCurved(++seed)} for an optimal period of 2 to the 64
* when repeatedly called, but {@code NumberTools.randomFloatCurved(seed += ODD_LONG)} will also work just fine if
* ODD_LONG is any odd-number long, positive or negative.
* @param seed any int to be used as a seed
* @return a pseudo-random double from -1.0 (exclusive) to 1.0 (exclusive), distributed on a curve centered on 0.0
*/
public static float randomFloatCurved(int seed)
public static float randomFloatCurved(long seed)
{
long state = seed * 0x9E3779B97F4A7C15L;
state = ((state >>> 30) ^ state) * 0xBF58476D1CE4E5B9L;
state = (state ^ (state >>> 27)) * 0x94D049BB133111EBL;
state ^= (state >>> 31);
return (Float.intBitsToFloat((int)(state & 0x7FFFFF) | 0x3f800000) - 1f)
* (Float.intBitsToFloat((int)(state >>> 40) | 0x3f800000) - 1f)
* (state >> 63 | 1L);
return formCurvedFloat(((seed = ((seed *= 0x6C8E9CF570932BD5L) ^ (seed >>> 25)) * (seed | 0xA529L)) ^ (seed >>> 22)));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions squidlib/README.md
Expand Up @@ -256,7 +256,7 @@ Current Features:
- You should use [the stable version of SquidSetup](https://github.com/tommyettinger/SquidSetup/releases/tag/v3.0.0-b9) if you want to use
the latest stable SquidLib, since it has squidlib 3.0.0-b9 (as well as squidlib-util and regexodus) all configured as default.
There's a SquidLib demo as an example that defaults to being selected. You should probably select libGDX version 1.9.6 if you use the
stable version, and currently also the snapshot (1.9.7 was briefly tried, but immediate bugs ended the attempt).
stable version, or 1.9.8 if you use the snapshot (1.9.8 includes important fixes to bugs from 1.9.7).
- Some ways of setting up a project won't include assets, so if you use the DefaultResources class in the display
module (recommended for several things, like distance field fonts), you need to get the assets you want separately.
They're in the assets/ folder of this GitHub repo, or you can get all the assets in a .zip file from SquidLib's
Expand Down Expand Up @@ -329,7 +329,7 @@ Optional Serialization Support
compile 'com.squidpony:squidlib-extra:3.0.0-b9'
```

If you want the latest version of SquidLib, which uses libGDX 1.9.6 and GWT 2.8.0 (if you use GWT), you can use JitPack
If you want the latest version of SquidLib, which uses libGDX 1.9.8 and GWT 2.8.0 (if you use GWT), you can use JitPack
to build the latest commit on-demand. It needs an additional repository, which is this for Maven:

```
Expand Down
Expand Up @@ -312,7 +312,7 @@ public void init(float width, float maxHeight, Collection<? extends IColoredStri
textActor.setHeight(/* Entire height */ totalTextHeight);
final boolean yscroll = maxHeight < totalTextHeight;
scrollPane.setHeight(/* Maybe not the entire height */ Math.min(totalTextHeight, maxHeight));
scrollPane.setWidget(new TextActor());
scrollPane.setActor(new TextActor());
yScrollingCallback(yscroll);
}

Expand Down

0 comments on commit 06595ec

Please sign in to comment.