v2.5.3: fixed RNG in falling loading affecting levelgen
This commit is contained in:
@@ -75,7 +75,12 @@ public class Random {
|
|||||||
|
|
||||||
//returns a uniformly distributed float in the range [0, 1)
|
//returns a uniformly distributed float in the range [0, 1)
|
||||||
public static synchronized float Float() {
|
public static synchronized float Float() {
|
||||||
return generators.peek().nextFloat();
|
return Float(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized float Float( boolean useGeneratorStack ) {
|
||||||
|
if (useGeneratorStack) return generators.peekFirst().nextFloat();
|
||||||
|
else return generators.peekLast().nextFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns a uniformly distributed float in the range [0, max)
|
//returns a uniformly distributed float in the range [0, max)
|
||||||
@@ -95,12 +100,27 @@ public class Random {
|
|||||||
|
|
||||||
//returns a uniformly distributed int in the range [-2^31, 2^31)
|
//returns a uniformly distributed int in the range [-2^31, 2^31)
|
||||||
public static synchronized int Int() {
|
public static synchronized int Int() {
|
||||||
return generators.peek().nextInt();
|
return Int(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns a uniformly distributed int in the range [-2^31, 2^31)
|
||||||
|
//can either use the current generator in the stack, or force the first generator (pure random)
|
||||||
|
public static synchronized int Int( boolean useGeneratorStack ) {
|
||||||
|
if (useGeneratorStack) return generators.peekFirst().nextInt();
|
||||||
|
else return generators.peekLast().nextInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns a uniformly distributed int in the range [0, max)
|
//returns a uniformly distributed int in the range [0, max)
|
||||||
public static synchronized int Int( int max ) {
|
public static synchronized int Int( int max ) {
|
||||||
return max > 0 ? generators.peek().nextInt(max) : 0;
|
return Int(max, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns a uniformly distributed int in the range [0, max)
|
||||||
|
//can either use the current generator in the stack, or force the first generator (pure random)
|
||||||
|
public static synchronized int Int( int max, boolean useGeneratorStack ) {
|
||||||
|
if (max <= 0) return 0;
|
||||||
|
else if (useGeneratorStack) return generators.peekFirst().nextInt(max);
|
||||||
|
else return generators.peekLast().nextInt(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns a uniformly distributed int in the range [min, max)
|
//returns a uniformly distributed int in the range [min, max)
|
||||||
@@ -132,7 +152,14 @@ public class Random {
|
|||||||
|
|
||||||
//returns a uniformly distributed long in the range [-2^63, 2^63)
|
//returns a uniformly distributed long in the range [-2^63, 2^63)
|
||||||
public static synchronized long Long() {
|
public static synchronized long Long() {
|
||||||
return generators.peek().nextLong();
|
return Long(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns a uniformly distributed long in the range [-2^63, 2^63)
|
||||||
|
//can either use the current generator in the stack, or force the first generator (pure random)
|
||||||
|
public static synchronized long Long( boolean useGeneratorStack ) {
|
||||||
|
if (useGeneratorStack) return generators.peekFirst().nextLong();
|
||||||
|
else return generators.peekLast().nextLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
//returns a mostly uniformly distributed long in the range [0, max)
|
//returns a mostly uniformly distributed long in the range [0, max)
|
||||||
|
|||||||
@@ -577,8 +577,11 @@ public class InterlevelScene extends PixelScene {
|
|||||||
|
|
||||||
if (mode == Mode.FALL) {
|
if (mode == Mode.FALL) {
|
||||||
loadingText.setPos(
|
loadingText.setPos(
|
||||||
(Camera.main.width - loadingText.width() - 4) + Random.NormalFloat(-2, 2),
|
//the randomization is effectively -2 to +2
|
||||||
(Camera.main.height - loadingText.height() - 6) + Random.NormalFloat(-2, 2)
|
// we don't use the generator stack as levelgen may be occurring
|
||||||
|
// and we don't want to accidentally use a seeded generator
|
||||||
|
(Camera.main.width - loadingText.width() - 4) + 4*(Random.Float(false)-0.5f),
|
||||||
|
(Camera.main.height - loadingText.height() - 6) + 4*(Random.Float(false)-0.5f)
|
||||||
);
|
);
|
||||||
align(loadingText);
|
align(loadingText);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user