diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bede827ec..12c70f1ea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ * exposed currentSeed as an external representation of internalSeed * removed intRanged() and floatRanged(), int() and float() now provide optional ranges * removed weightedGetObject(), getObject() now has an optional weights parameter + * removed colorExt(), try using FlxColor to get finer control over randomly-generated colors * updated random number generation equation to avoid inconsistent results across platforms; may break recordings made in 3.x! * FlxArrayUtil: removed randomness-related functions, please use FlxRandom instead * FlxText: diff --git a/flixel/math/FlxRandom.hx b/flixel/math/FlxRandom.hx index 8d038bfe71..42721ebb51 100644 --- a/flixel/math/FlxRandom.hx +++ b/flixel/math/FlxRandom.hx @@ -17,12 +17,6 @@ class FlxRandom */ public static var globalSeed(default, set):Int = 1; - /** - * Current seed used to generate new random numbers. You can retrieve this value if, - * for example, you want to store the seed that was used to randomly generate a level. - */ - public static var currentSeed(get, set):Int; - /** * Function to easily set the global seed to a new random number. * Used primarily by FlxG whenever the game is reset. @@ -33,9 +27,15 @@ class FlxRandom */ public static inline function resetGlobalSeed():Int { - return globalSeed = Std.int(Math.random() * MODULUS); + return globalSeed = rangeBound(Std.int(Math.random() * FlxMath.MAX_VALUE_INT)); } + /** + * Current seed used to generate new random numbers. You can retrieve this value if, + * for example, you want to store the seed that was used to randomly generate a level. + */ + public static var currentSeed(get, set):Int; + /** * Returns a pseudorandom integer between Min and Max, inclusive. * Will not return a number in the Excludes array, if provided. @@ -206,7 +206,7 @@ class FlxRandom * @return A pseudorandomly chosen object from Objects. */ @:generic - public static function getObject(Objects:Array, ?WeightsArray:Array, StartIndex:Int = 0, EndIndex:Int = 0):T + public static function getObject(Objects:Array, ?WeightsArray:Array, StartIndex:Int = 0, ?EndIndex:Null):T { var selected:Null = null; @@ -217,10 +217,16 @@ class FlxRandom WeightsArray = [for (i in 0...Objects.length) 1]; } + if (EndIndex == null) + { + EndIndex = Objects.length - 1; + } + StartIndex = Std.int(FlxMath.bound(StartIndex, 0, Objects.length - 1)); EndIndex = Std.int(FlxMath.bound(EndIndex, 0, Objects.length - 1)); // Swap values if reversed + if (EndIndex < StartIndex) { StartIndex = StartIndex + EndIndex; @@ -228,7 +234,6 @@ class FlxRandom StartIndex = StartIndex - EndIndex; } - if (EndIndex > WeightsArray.length - 1) { EndIndex = WeightsArray.length - 1; @@ -291,29 +296,6 @@ class FlxRandom return FlxColor.fromRGB(red, green, blue, Alpha); } - /** - * Much like color(), but with finer control over the output color. - * - * @param RedMinimum The minimum amount of red in the output color, from 0 to 255. - * @param RedMaximum The maximum amount of red in the output color, from 0 to 255. - * @param GreedMinimum The minimum amount of green in the output color, from 0 to 255. - * @param GreenMaximum The maximum amount of green in the output color, from 0 to 255. - * @param BlueMinimum The minimum amount of blue in the output color, from 0 to 255. - * @param BlueMaximum The maximum amount of blue in the output color, from 0 to 255. - * @param AlphaMinimum The minimum alpha value for the output color, from 0 (fully transparent) to 255 (fully opaque). - * @param AlphaMaximum The maximum alpha value for the output color, from 0 (fully transparent) to 255 (fully opaque). - * @return A pseudorandomly generated color within the ranges specified. - */ - public static function colorExt(RedMinimum:Int = 0, RedMaximum:Int = 255, GreenMinimum:Int = 0, GreenMaximum:Int = 255, BlueMinimum:Int = 0, BlueMaximum:Int = 255, AlphaMinimum:Int = 255, AlphaMaximum:Int = 255):FlxColor - { - var red = int(Std.int(FlxMath.bound(RedMinimum, 0, 255)), Std.int(FlxMath.bound(RedMaximum, 0, 255))); - var green = int(Std.int(FlxMath.bound(GreenMinimum, 0, 255)), Std.int(FlxMath.bound(GreenMaximum, 0, 255))); - var blue = int(Std.int(FlxMath.bound(BlueMinimum, 0, 255)), Std.int(FlxMath.bound(BlueMaximum, 0, 255))); - var alpha = int(Std.int(FlxMath.bound(AlphaMinimum, 0, 255)), Std.int(FlxMath.bound(AlphaMaximum, 0, 255))); - - return FlxColor.fromRGB(red, green, blue, alpha); - } - /** * The actual internal seed. Stored as a Float value to prevent inaccuracies due to * integer overflow in the generate() equation.