diff options
Diffstat (limited to 'modules/mono/glue')
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs | 13 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs | 75 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs | 19 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs | 110 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs | 3 | ||||
-rw-r--r-- | modules/mono/glue/base_object_glue.cpp | 6 | ||||
-rw-r--r-- | modules/mono/glue/collections_glue.cpp | 7 | ||||
-rw-r--r-- | modules/mono/glue/gd_glue.cpp | 20 | ||||
-rw-r--r-- | modules/mono/glue/glue_header.h | 16 | ||||
-rw-r--r-- | modules/mono/glue/nodepath_glue.cpp | 4 | ||||
-rw-r--r-- | modules/mono/glue/rid_glue.cpp | 6 | ||||
-rw-r--r-- | modules/mono/glue/scene_tree_glue.cpp | 6 | ||||
-rw-r--r-- | modules/mono/glue/string_glue.cpp | 6 | ||||
-rw-r--r-- | modules/mono/glue/string_name_glue.cpp | 4 |
14 files changed, 196 insertions, 99 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index f77d3052f4..ce613f7ef9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -81,6 +81,11 @@ namespace Godot.Collections return godot_icall_Array_Resize(GetPtr(), newSize); } + public void Shuffle() + { + godot_icall_Array_Shuffle(GetPtr()); + } + public static Array operator +(Array left, Array right) { return new Array(godot_icall_Array_Concatenate(left.GetPtr(), right.GetPtr())); @@ -220,6 +225,9 @@ namespace Godot.Collections internal extern static Error godot_icall_Array_Resize(IntPtr ptr, int newSize); [MethodImpl(MethodImplOptions.InternalCall)] + internal extern static Error godot_icall_Array_Shuffle(IntPtr ptr); + + [MethodImpl(MethodImplOptions.InternalCall)] internal extern static void godot_icall_Array_Generic_GetElementTypeInfo(Type elemType, out int elemTypeEncoding, out IntPtr elemTypeClass); [MethodImpl(MethodImplOptions.InternalCall)] @@ -295,6 +303,11 @@ namespace Godot.Collections return objectArray.Resize(newSize); } + public void Shuffle() + { + objectArray.Shuffle(); + } + public static Array<T> operator +(Array<T> left, Array<T> right) { return new Array<T>(left.objectArray + right.objectArray); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 3700a6194f..90141928ca 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -257,20 +257,6 @@ namespace Godot } /// <summary> - /// Returns the most contrasting color. - /// </summary> - /// <returns>The most contrasting color</returns> - public Color Contrasted() - { - return new Color( - (r + 0.5f) % 1.0f, - (g + 0.5f) % 1.0f, - (b + 0.5f) % 1.0f, - a - ); - } - - /// <summary> /// Returns a new color resulting from making this color darker /// by the specified ratio (on the range of 0 to 1). /// </summary> @@ -351,8 +337,8 @@ namespace Godot } /// <summary> - /// Returns the color's 32-bit integer in ABGR format - /// (each byte represents a component of the ABGR profile). + /// Returns the color converted to an unsigned 32-bit integer in ABGR + /// format (each byte represents a color channel). /// ABGR is the reversed version of the default format. /// </summary> /// <returns>A uint representing this color in ABGR32 format.</returns> @@ -370,8 +356,8 @@ namespace Godot } /// <summary> - /// Returns the color's 64-bit integer in ABGR format - /// (each word represents a component of the ABGR profile). + /// Returns the color converted to an unsigned 64-bit integer in ABGR + /// format (each word represents a color channel). /// ABGR is the reversed version of the default format. /// </summary> /// <returns>A ulong representing this color in ABGR64 format.</returns> @@ -389,8 +375,8 @@ namespace Godot } /// <summary> - /// Returns the color's 32-bit integer in ARGB format - /// (each byte represents a component of the ARGB profile). + /// Returns the color converted to an unsigned 32-bit integer in ARGB + /// format (each byte represents a color channel). /// ARGB is more compatible with DirectX, but not used much in Godot. /// </summary> /// <returns>A uint representing this color in ARGB32 format.</returns> @@ -408,8 +394,8 @@ namespace Godot } /// <summary> - /// Returns the color's 64-bit integer in ARGB format - /// (each word represents a component of the ARGB profile). + /// Returns the color converted to an unsigned 64-bit integer in ARGB + /// format (each word represents a color channel). /// ARGB is more compatible with DirectX, but not used much in Godot. /// </summary> /// <returns>A ulong representing this color in ARGB64 format.</returns> @@ -427,8 +413,8 @@ namespace Godot } /// <summary> - /// Returns the color's 32-bit integer in RGBA format - /// (each byte represents a component of the RGBA profile). + /// Returns the color converted to an unsigned 32-bit integer in RGBA + /// format (each byte represents a color channel). /// RGBA is Godot's default and recommended format. /// </summary> /// <returns>A uint representing this color in RGBA32 format.</returns> @@ -446,8 +432,8 @@ namespace Godot } /// <summary> - /// Returns the color's 64-bit integer in RGBA format - /// (each word represents a component of the RGBA profile). + /// Returns the color converted to an unsigned 64-bit integer in RGBA + /// format (each word represents a color channel). /// RGBA is Godot's default and recommended format. /// </summary> /// <returns>A ulong representing this color in RGBA64 format.</returns> @@ -486,7 +472,7 @@ namespace Godot } /// <summary> - /// Constructs a color from RGBA values on the range of 0 to 1. + /// Constructs a color from RGBA values, typically on the range of 0 to 1. /// </summary> /// <param name="r">The color's red component, typically on the range of 0 to 1.</param> /// <param name="g">The color's green component, typically on the range of 0 to 1.</param> @@ -514,8 +500,8 @@ namespace Godot } /// <summary> - /// Constructs a color from a 32-bit integer - /// (each byte represents a component of the RGBA profile). + /// Constructs a color from an unsigned 32-bit integer in RGBA format + /// (each byte represents a color channel). /// </summary> /// <param name="rgba">The uint representing the color.</param> public Color(uint rgba) @@ -530,8 +516,8 @@ namespace Godot } /// <summary> - /// Constructs a color from a 64-bit integer - /// (each word represents a component of the RGBA profile). + /// Constructs a color from an unsigned 64-bit integer in RGBA format + /// (each word represents a color channel). /// </summary> /// <param name="rgba">The ulong representing the color.</param> public Color(ulong rgba) @@ -791,31 +777,10 @@ namespace Godot return ParseCol4(str, ofs) * 16 + ParseCol4(str, ofs + 1); } - private String ToHex32(float val) + private string ToHex32(float val) { - int v = Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255)); - - var ret = string.Empty; - - for (int i = 0; i < 2; i++) - { - char c; - int lv = v & 0xF; - - if (lv < 10) - { - c = (char)('0' + lv); - } - else - { - c = (char)('a' + lv - 10); - } - - v >>= 4; - ret = c + ret; - } - - return ret; + byte b = (byte)Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255)); + return b.HexEncode(); } internal static bool HtmlIsValid(string color) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs index e050d1fdd1..6699c5992c 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs @@ -39,14 +39,6 @@ namespace Godot return val * sgn; } - public static FuncRef FuncRef(Object instance, StringName funcName) - { - var ret = new FuncRef(); - ret.SetInstance(instance); - ret.SetFunction(funcName); - return ret; - } - public static int Hash(object var) { return godot_icall_GD_hash(var); @@ -129,7 +121,12 @@ namespace Godot public static double RandRange(double from, double to) { - return godot_icall_GD_rand_range(from, to); + return godot_icall_GD_randf_range(from, to); + } + + public static int RandRange(int from, int to) + { + return godot_icall_GD_randi_range(from, to); } public static uint RandSeed(ulong seed, out ulong newSeed) @@ -238,9 +235,11 @@ namespace Godot [MethodImpl(MethodImplOptions.InternalCall)] internal extern static void godot_icall_GD_randomize(); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern static double godot_icall_GD_randf_range(double from, double to); [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static double godot_icall_GD_rand_range(double from, double to); + internal extern static int godot_icall_GD_randi_range(int from, int to); [MethodImpl(MethodImplOptions.InternalCall)] internal extern static uint godot_icall_GD_rand_seed(ulong seed, out ulong newSeed); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index d63db0f905..0700f197ff 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -322,6 +322,15 @@ namespace Godot return instance.IndexOf(what, from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); } + /// <summary>Find the first occurrence of a char. Optionally, the search starting position can be passed.</summary> + /// <returns>The first instance of the char, or -1 if not found.</returns> + public static int Find(this string instance, char what, int from = 0, bool caseSensitive = true) + { + // TODO: Could be more efficient if we get a char version of `IndexOf`. + // See https://github.com/dotnet/runtime/issues/44116 + return instance.IndexOf(what.ToString(), from, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); + } + /// <summary>Find the last occurrence of a substring.</summary> /// <returns>The starting position of the substring, or -1 if not found.</returns> public static int FindLast(this string instance, string what, bool caseSensitive = true) @@ -437,6 +446,53 @@ namespace Godot return hashv; } + /// <summary> + /// Returns a hexadecimal representation of this byte as a string. + /// </summary> + /// <param name="bytes">The byte to encode.</param> + /// <returns>The hexadecimal representation of this byte.</returns> + internal static string HexEncode(this byte b) + { + var ret = string.Empty; + + for (int i = 0; i < 2; i++) + { + char c; + int lv = b & 0xF; + + if (lv < 10) + { + c = (char)('0' + lv); + } + else + { + c = (char)('a' + lv - 10); + } + + b >>= 4; + ret = c + ret; + } + + return ret; + } + + /// <summary> + /// Returns a hexadecimal representation of this byte array as a string. + /// </summary> + /// <param name="bytes">The byte array to encode.</param> + /// <returns>The hexadecimal representation of this byte array.</returns> + public static string HexEncode(this byte[] bytes) + { + var ret = string.Empty; + + foreach (byte b in bytes) + { + ret += b.HexEncode(); + } + + return ret; + } + // <summary> // Convert a string containing an hexadecimal number into an int. // </summary> @@ -659,6 +715,33 @@ namespace Godot } /// <summary> + /// Returns a copy of the string with characters removed from the left. + /// </summary> + /// <param name="instance">The string to remove characters from.</param> + /// <param name="chars">The characters to be removed.</param> + /// <returns>A copy of the string with characters removed from the left.</returns> + public static string LStrip(this string instance, string chars) + { + int len = instance.Length; + int beg; + + for (beg = 0; beg < len; beg++) + { + if (chars.Find(instance[beg]) == -1) + { + break; + } + } + + if (beg == 0) + { + return instance; + } + + return instance.Substr(beg, len - beg); + } + + /// <summary> /// Do a simple expression match, where '*' matches zero or more arbitrary characters and '?' matches any single character except '.'. /// </summary> private static bool ExprMatch(this string instance, string expr, bool caseSensitive) @@ -886,6 +969,33 @@ namespace Godot return instance.Substring(pos, instance.Length - pos); } + /// <summary> + /// Returns a copy of the string with characters removed from the right. + /// </summary> + /// <param name="instance">The string to remove characters from.</param> + /// <param name="chars">The characters to be removed.</param> + /// <returns>A copy of the string with characters removed from the right.</returns> + public static string RStrip(this string instance, string chars) + { + int len = instance.Length; + int end; + + for (end = len - 1; end >= 0; end--) + { + if (chars.Find(instance[end]) == -1) + { + break; + } + } + + if (end == len - 1) + { + return instance; + } + + return instance.Substr(0, end + 1); + } + public static byte[] SHA256Buffer(this string instance) { return godot_icall_String_sha256_buffer(instance); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 06bbe98497..bc0f81b2a7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -221,8 +221,7 @@ namespace Godot real_t dot = v1.Dot(v2); - // Clamp dot to [-1, 1] - dot = dot < -1.0f ? -1.0f : (dot > 1.0f ? 1.0f : dot); + dot = Mathf.Clamp(dot, -1.0f, 1.0f); Vector2 v; diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 439fb1ab0a..544f414cba 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -30,9 +30,9 @@ #ifdef MONO_GLUE_ENABLED -#include "core/class_db.h" -#include "core/reference.h" -#include "core/string_name.h" +#include "core/object/class_db.h" +#include "core/object/reference.h" +#include "core/string/string_name.h" #include "../csharp_script.h" #include "../mono_gd/gd_mono_cache.h" diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp index 3313e8cb77..bb3ea0f730 100644 --- a/modules/mono/glue/collections_glue.cpp +++ b/modules/mono/glue/collections_glue.cpp @@ -32,7 +32,7 @@ #include <mono/metadata/exception.h> -#include "core/array.h" +#include "core/variant/array.h" #include "../mono_gd/gd_mono_cache.h" #include "../mono_gd/gd_mono_class.h" @@ -162,6 +162,10 @@ Error godot_icall_Array_Resize(Array *ptr, int new_size) { return ptr->resize(new_size); } +void godot_icall_Array_Shuffle(Array *ptr) { + ptr->shuffle(); +} + void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class) { MonoType *elem_type = mono_reflection_type_get_type(refltype); @@ -322,6 +326,7 @@ void godot_register_collections_icalls() { mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", (void *)godot_icall_Array_Remove); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_RemoveAt", (void *)godot_icall_Array_RemoveAt); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Resize", (void *)godot_icall_Array_Resize); + mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Shuffle", (void *)godot_icall_Array_Shuffle); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Generic_GetElementTypeInfo", (void *)godot_icall_Array_Generic_GetElementTypeInfo); mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_ToString", (void *)godot_icall_Array_ToString); diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index 5e892b616b..58d8dceb25 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -30,12 +30,12 @@ #ifdef MONO_GLUE_ENABLED -#include "core/array.h" #include "core/io/marshalls.h" #include "core/os/os.h" -#include "core/ustring.h" -#include "core/variant.h" -#include "core/variant_parser.h" +#include "core/string/ustring.h" +#include "core/variant/array.h" +#include "core/variant/variant.h" +#include "core/variant/variant_parser.h" #include "../mono_gd/gd_mono_cache.h" #include "../mono_gd/gd_mono_marshal.h" @@ -55,7 +55,8 @@ MonoObject *godot_icall_GD_convert(MonoObject *p_what, int32_t p_type) { Variant what = GDMonoMarshal::mono_object_to_variant(p_what); const Variant *args[1] = { &what }; Callable::CallError ce; - Variant ret = Variant::construct(Variant::Type(p_type), args, 1, ce); + Variant ret; + Variant::construct(Variant::Type(p_type), ret, args, 1, ce); ERR_FAIL_COND_V(ce.error != Callable::CallError::CALL_OK, nullptr); return GDMonoMarshal::variant_to_mono_object(ret); } @@ -193,7 +194,11 @@ void godot_icall_GD_randomize() { Math::randomize(); } -double godot_icall_GD_rand_range(double from, double to) { +double godot_icall_GD_randf_range(double from, double to) { + return Math::random(from, to); +} + +int32_t godot_icall_GD_randi_range(int32_t from, int32_t to) { return Math::random(from, to); } @@ -298,7 +303,8 @@ void godot_register_gd_icalls() { mono_add_internal_call("Godot.GD::godot_icall_GD_randf", (void *)godot_icall_GD_randf); mono_add_internal_call("Godot.GD::godot_icall_GD_randi", (void *)godot_icall_GD_randi); mono_add_internal_call("Godot.GD::godot_icall_GD_randomize", (void *)godot_icall_GD_randomize); - mono_add_internal_call("Godot.GD::godot_icall_GD_rand_range", (void *)godot_icall_GD_rand_range); + mono_add_internal_call("Godot.GD::godot_icall_GD_randf_range", (void *)godot_icall_GD_randf_range); + mono_add_internal_call("Godot.GD::godot_icall_GD_randi_range", (void *)godot_icall_GD_randi_range); mono_add_internal_call("Godot.GD::godot_icall_GD_rand_seed", (void *)godot_icall_GD_rand_seed); mono_add_internal_call("Godot.GD::godot_icall_GD_seed", (void *)godot_icall_GD_seed); mono_add_internal_call("Godot.GD::godot_icall_GD_str", (void *)godot_icall_GD_str); diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h index dc3bf47838..f4263e286e 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -58,15 +58,15 @@ void godot_register_glue_header_icalls() { // Used by the generated glue -#include "core/array.h" -#include "core/class_db.h" -#include "core/dictionary.h" -#include "core/engine.h" -#include "core/method_bind.h" -#include "core/node_path.h" -#include "core/reference.h" +#include "core/config/engine.h" +#include "core/object/class_db.h" +#include "core/object/method_bind.h" +#include "core/object/reference.h" +#include "core/string/node_path.h" +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" +#include "core/variant/array.h" +#include "core/variant/dictionary.h" #include "../mono_gd/gd_mono_class.h" #include "../mono_gd/gd_mono_internals.h" diff --git a/modules/mono/glue/nodepath_glue.cpp b/modules/mono/glue/nodepath_glue.cpp index 2aa75dd309..09c6d8f482 100644 --- a/modules/mono/glue/nodepath_glue.cpp +++ b/modules/mono/glue/nodepath_glue.cpp @@ -30,8 +30,8 @@ #ifdef MONO_GLUE_ENABLED -#include "core/node_path.h" -#include "core/ustring.h" +#include "core/string/node_path.h" +#include "core/string/ustring.h" #include "../mono_gd/gd_mono_marshal.h" diff --git a/modules/mono/glue/rid_glue.cpp b/modules/mono/glue/rid_glue.cpp index a7b18c36dd..cb4f26511f 100644 --- a/modules/mono/glue/rid_glue.cpp +++ b/modules/mono/glue/rid_glue.cpp @@ -30,9 +30,9 @@ #ifdef MONO_GLUE_ENABLED -#include "core/class_db.h" -#include "core/resource.h" -#include "core/rid.h" +#include "core/io/resource.h" +#include "core/object/class_db.h" +#include "core/templates/rid.h" #include "../mono_gd/gd_mono_marshal.h" diff --git a/modules/mono/glue/scene_tree_glue.cpp b/modules/mono/glue/scene_tree_glue.cpp index b43daccc1b..53d6c1436d 100644 --- a/modules/mono/glue/scene_tree_glue.cpp +++ b/modules/mono/glue/scene_tree_glue.cpp @@ -30,9 +30,9 @@ #ifdef MONO_GLUE_ENABLED -#include "core/array.h" -#include "core/class_db.h" -#include "core/string_name.h" +#include "core/object/class_db.h" +#include "core/string/string_name.h" +#include "core/variant/array.h" #include "scene/main/node.h" #include "scene/main/scene_tree.h" diff --git a/modules/mono/glue/string_glue.cpp b/modules/mono/glue/string_glue.cpp index 595b8d71f1..9271731573 100644 --- a/modules/mono/glue/string_glue.cpp +++ b/modules/mono/glue/string_glue.cpp @@ -30,9 +30,9 @@ #ifdef MONO_GLUE_ENABLED -#include "core/ustring.h" -#include "core/variant.h" -#include "core/vector.h" +#include "core/string/ustring.h" +#include "core/templates/vector.h" +#include "core/variant/variant.h" #include "../mono_gd/gd_mono_marshal.h" diff --git a/modules/mono/glue/string_name_glue.cpp b/modules/mono/glue/string_name_glue.cpp index 4b2e88569b..9323e3bbb3 100644 --- a/modules/mono/glue/string_name_glue.cpp +++ b/modules/mono/glue/string_name_glue.cpp @@ -30,8 +30,8 @@ #ifdef MONO_GLUE_ENABLED -#include "core/string_name.h" -#include "core/ustring.h" +#include "core/string/string_name.h" +#include "core/string/ustring.h" #include "../mono_gd/gd_mono_marshal.h" |