diff options
author | Yuri Roubinsky <chaosus89@gmail.com> | 2021-06-21 12:58:31 +0300 |
---|---|---|
committer | Yuri Roubinsky <chaosus89@gmail.com> | 2021-11-17 14:29:19 +0300 |
commit | a74acca858b5d2f8ee07d6e0cb521dbcdce1e5f0 (patch) | |
tree | d7840a27ff057a9345cca8830f884ab3ee5435b1 /modules/mono/glue | |
parent | 3c04522ece1cedccdd1d5fff919a5d4e223bed50 (diff) |
Expose `randfn` to global scope
Diffstat (limited to 'modules/mono/glue')
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs | 19 | ||||
-rw-r--r-- | modules/mono/glue/gd_glue.cpp | 23 |
2 files changed, 30 insertions, 12 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs index ef42374041..a3afc83222 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs @@ -323,6 +323,16 @@ namespace Godot } /// <summary> + /// Returns a normally-distributed pseudo-random number, using Box-Muller transform with the specified <c>mean</c> and a standard <c>deviation</c>. + /// This is also called Gaussian distribution. + /// </summary> + /// <returns>A random normally-distributed <see langword="float"/> number.</returns> + public static double Randfn(double mean, double deviation) + { + return godot_icall_GD_randfn(mean, deviation); + } + + /// <summary> /// Returns a random unsigned 32-bit integer. /// Use remainder to obtain a random value in the interval <c>[0, N - 1]</c> (where N is smaller than 2^32). /// </summary> @@ -564,19 +574,22 @@ namespace Godot internal static extern void godot_icall_GD_printt(object[] what); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern float godot_icall_GD_randf(); + internal static extern void godot_icall_GD_randomize(); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern uint godot_icall_GD_randi(); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern void godot_icall_GD_randomize(); + internal static extern float godot_icall_GD_randf(); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern int godot_icall_GD_randi_range(int from, int to); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern double godot_icall_GD_randf_range(double from, double to); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern int godot_icall_GD_randi_range(int from, int to); + internal static extern double godot_icall_GD_randfn(double mean, double deviation); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern uint godot_icall_GD_rand_seed(ulong seed, out ulong newSeed); diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index a2ff868f65..07ddf5d945 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -182,26 +182,30 @@ void godot_icall_GD_printt(MonoArray *p_what) { print_line(str); } -float godot_icall_GD_randf() { - return Math::randf(); +void godot_icall_GD_randomize() { + Math::randomize(); } uint32_t godot_icall_GD_randi() { return Math::rand(); } -void godot_icall_GD_randomize() { - Math::randomize(); +float godot_icall_GD_randf() { + return Math::randf(); } -double godot_icall_GD_randf_range(double from, double to) { +int32_t godot_icall_GD_randi_range(int32_t from, int32_t to) { return Math::random(from, to); } -int32_t godot_icall_GD_randi_range(int32_t from, int32_t to) { +double godot_icall_GD_randf_range(double from, double to) { return Math::random(from, to); } +double godot_icall_GD_randfn(double mean, double deviation) { + return Math::randfn(mean, deviation); +} + uint32_t godot_icall_GD_rand_seed(uint64_t seed, uint64_t *newSeed) { uint32_t ret = Math::rand_from_seed(&seed); *newSeed = seed; @@ -300,11 +304,12 @@ void godot_register_gd_icalls() { GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_printraw", godot_icall_GD_printraw); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_prints", godot_icall_GD_prints); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_printt", godot_icall_GD_printt); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf", godot_icall_GD_randf); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi", godot_icall_GD_randi); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randomize", godot_icall_GD_randomize); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf_range", godot_icall_GD_randf_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi", godot_icall_GD_randi); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf", godot_icall_GD_randf); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi_range", godot_icall_GD_randi_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf_range", godot_icall_GD_randf_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randfn", godot_icall_GD_randfn); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_rand_seed", godot_icall_GD_rand_seed); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_seed", godot_icall_GD_seed); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_str", godot_icall_GD_str); |