1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Add ability to restore RandomNumberGenerator state

3.2 version of b5107715f1.

`get_seed()` still returns the previous state and not the initial seed,
because users may rely on this behavior for resetting the state in 3.2.
Documented this is going to be fixed in 4.0.

Co-authored-by: MidZik <matt.idzik1@gmail.com>
This commit is contained in:
Andrii Doroshenko (Xrayez)
2021-01-08 15:02:02 +02:00
parent e408a4a76d
commit 47899e67c5
4 changed files with 35 additions and 4 deletions

View File

@@ -36,6 +36,9 @@ void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &RandomNumberGenerator::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &RandomNumberGenerator::get_seed);
ClassDB::bind_method(D_METHOD("set_state", "state"), &RandomNumberGenerator::set_state);
ClassDB::bind_method(D_METHOD("get_state"), &RandomNumberGenerator::get_state);
ClassDB::bind_method(D_METHOD("randi"), &RandomNumberGenerator::randi);
ClassDB::bind_method(D_METHOD("randf"), &RandomNumberGenerator::randf);
ClassDB::bind_method(D_METHOD("randfn", "mean", "deviation"), &RandomNumberGenerator::randfn, DEFVAL(0.0), DEFVAL(1.0));
@@ -44,6 +47,8 @@ void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("randomize"), &RandomNumberGenerator::randomize);
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
// Default value is non-deterministic, override it for doc generation purposes.
ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state");
// Default values are non-deterministic, override for doc generation purposes.
ADD_PROPERTY_DEFAULT("seed", 0);
ADD_PROPERTY_DEFAULT("state", 0);
}