diff options
Diffstat (limited to 'modules/mono/glue')
12 files changed, 258 insertions, 68 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs index 130776499b..df306e5244 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs @@ -499,7 +499,7 @@ namespace Godot.Collections VariantUtils.CreateFromArray(godotArray); private static Array<T> FromVariantFunc(in godot_variant variant) => - VariantUtils.ConvertToArrayObject<T>(variant); + VariantUtils.ConvertToArray<T>(variant); static unsafe Array() { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs index e6a8054ae2..dafa83431b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs @@ -297,7 +297,7 @@ namespace Godot.Bridge foreach (var type in assembly.GetTypes()) { - if (type.IsNested) + if (type.IsNested || type.IsGenericType) continue; if (!typeOfGodotObject.IsAssignableFrom(type)) @@ -314,9 +314,12 @@ namespace Godot.Bridge if (scriptTypes != null) { - for (int i = 0; i < scriptTypes.Length; i++) + foreach (var type in scriptTypes) { - LookupScriptForClass(scriptTypes[i]); + if (type.IsGenericType) + continue; + + LookupScriptForClass(type); } } } @@ -729,6 +732,7 @@ namespace Godot.Bridge { ExceptionUtils.LogException(e); *outTool = godot_bool.False; + *outMethodsDest = NativeFuncs.godotsharp_array_new(); *outRpcFunctionsDest = NativeFuncs.godotsharp_dictionary_new(); *outEventSignalsDest = NativeFuncs.godotsharp_dictionary_new(); *outBaseScript = default; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index f49023555b..4075a878d2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using Godot.NativeInterop; namespace Godot { @@ -187,6 +188,19 @@ namespace Godot } /// <summary> + /// Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). + /// This is useful when determining light or dark color. Colors with a luminance smaller + /// than 0.5 can be generally considered dark. + /// Note: <see cref="Luminance"/> relies on the color being in the linear color space to + /// return an accurate relative luminance value. If the color is in the sRGB color space + /// use <see cref="SrgbToLinear"/> to convert it to the linear color space first. + /// </summary> + public readonly float Luminance + { + get { return 0.2126f * r + 0.7152f * g + 0.0722f * b; } + } + + /// <summary> /// Access color components using their index. /// </summary> /// <value> @@ -363,6 +377,35 @@ namespace Godot } /// <summary> + /// Returns the color converted to the sRGB color space. + /// This method assumes the original color is in the linear color space. + /// See also <see cref="SrgbToLinear"/> which performs the opposite operation. + /// </summary> + /// <returns>The sRGB color.</returns> + public readonly Color LinearToSrgb() + { + return new Color( + r < 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * (float)Mathf.Pow(r, 1.0f / 2.4f) - 0.055f, + g < 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * (float)Mathf.Pow(g, 1.0f / 2.4f) - 0.055f, + b < 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * (float)Mathf.Pow(b, 1.0f / 2.4f) - 0.055f, a); + } + + /// <summary> + /// Returns the color converted to linear color space. + /// This method assumes the original color already is in sRGB color space. + /// See also <see cref="LinearToSrgb"/> which performs the opposite operation. + /// </summary> + /// <returns>The color in linear color space.</returns> + public readonly Color SrgbToLinear() + { + return new Color( + r < 0.04045f ? r * (1.0f / 12.92f) : (float)Mathf.Pow((r + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), + g < 0.04045f ? g * (1.0f / 12.92f) : (float)Mathf.Pow((g + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), + b < 0.04045f ? b * (1.0f / 12.92f) : (float)Mathf.Pow((b + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), + a); + } + + /// <summary> /// 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. @@ -565,6 +608,10 @@ namespace Godot /// <see cref="Colors"/> constants. /// </summary> /// <param name="code">The HTML color code or color name to construct from.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// A color cannot be inferred from the given <paramref name="code"/>. + /// It was invalid HTML and a color with that name was not found. + /// </exception> public Color(string code) { if (HtmlIsValid(code)) @@ -597,7 +644,7 @@ namespace Godot /// <exception name="ArgumentOutOfRangeException"> /// <paramref name="rgba"/> color code is invalid. /// </exception> - private static Color FromHTML(ReadOnlySpan<char> rgba) + public static Color FromHTML(ReadOnlySpan<char> rgba) { Color c; if (rgba.Length == 0) @@ -705,28 +752,59 @@ namespace Godot /// the constants defined in <see cref="Colors"/>. /// </summary> /// <param name="name">The name of the color.</param> + /// <exception cref="ArgumentOutOfRangeException"> + /// A color with the given name is not found. + /// </exception> /// <returns>The constructed color.</returns> private static Color Named(string name) { + if (!FindNamedColor(name, out Color color)) + { + throw new ArgumentOutOfRangeException($"Invalid Color Name: {name}"); + } + + return color; + } + + /// <summary> + /// Returns a color according to the standardized name, with the + /// specified alpha value. Supported color names are the same as + /// the constants defined in <see cref="Colors"/>. + /// If a color with the given name is not found, it returns + /// <paramref name="default"/>. + /// </summary> + /// <param name="name">The name of the color.</param> + /// <param name="default"> + /// The default color to return when a color with the given name + /// is not found. + /// </param> + /// <returns>The constructed color.</returns> + private static Color Named(string name, Color @default) + { + if (!FindNamedColor(name, out Color color)) + { + return @default; + } + + return color; + } + + private static bool FindNamedColor(string name, out Color color) + { name = name.Replace(" ", string.Empty); name = name.Replace("-", string.Empty); name = name.Replace("_", string.Empty); name = name.Replace("'", string.Empty); name = name.Replace(".", string.Empty); - name = name.ToUpper(); - - if (!Colors.namedColors.ContainsKey(name)) - { - throw new ArgumentOutOfRangeException($"Invalid Color Name: {name}"); - } + name = name.ToUpperInvariant(); - return Colors.namedColors[name]; + return Colors.namedColors.TryGetValue(name, out color); } /// <summary> - /// Constructs a color from an HSV profile, with values on the - /// range of 0 to 1. This is equivalent to using each of - /// the <c>h</c>/<c>s</c>/<c>v</c> properties, but much more efficient. + /// Constructs a color from an HSV profile. The <paramref name="hue"/>, + /// <paramref name="saturation"/>, and <paramref name="value"/> are typically + /// between 0.0 and 1.0. /// </summary> /// <param name="hue">The HSV hue, typically on the range of 0 to 1.</param> /// <param name="saturation">The HSV saturation, typically on the range of 0 to 1.</param> @@ -841,13 +919,78 @@ namespace Godot return ParseCol4(str, index) * 16 + ParseCol4(str, index + 1); } + /// <summary> + /// Constructs a color from an OK HSL profile. The <paramref name="hue"/>, + /// <paramref name="saturation"/>, and <paramref name="lightness"/> are typically + /// between 0.0 and 1.0. + /// </summary> + /// <param name="hue">The OK HSL hue, typically on the range of 0 to 1.</param> + /// <param name="saturation">The OK HSL saturation, typically on the range of 0 to 1.</param> + /// <param name="lightness">The OK HSL lightness, typically on the range of 0 to 1.</param> + /// <param name="alpha">The alpha (transparency) value, typically on the range of 0 to 1.</param> + /// <returns>The constructed color.</returns> + public static Color FromOkHsl(float hue, float saturation, float lightness, float alpha = 1.0f) + { + return NativeFuncs.godotsharp_color_from_ok_hsl(hue, saturation, lightness, alpha); + } + + /// <summary> + /// Encodes a <see cref="Color"/> from a RGBE9995 format integer. + /// See <see cref="Image.Format.Rgbe9995"/>. + /// </summary> + /// <param name="rgbe">The RGBE9995 encoded color.</param> + /// <returns>The constructed color.</returns> + public static Color FromRgbe9995(uint rgbe) + { + float r = rgbe & 0x1ff; + float g = (rgbe >> 9) & 0x1ff; + float b = (rgbe >> 18) & 0x1ff; + float e = rgbe >> 27; + float m = (float)Mathf.Pow(2.0f, e - 15.0f - 9.0f); + + float rd = r * m; + float gd = g * m; + float bd = b * m; + + return new Color(rd, gd, bd, 1.0f); + } + + /// <summary> + /// Constructs a color from the given string, which can be either an HTML color + /// code or a named color. Returns <paramref name="default"/> if the color cannot + /// be inferred from the string. Supported color names are the same as the + /// <see cref="Colors"/> constants. + /// </summary> + /// <param name="str">The HTML color code or color name.</param> + /// <param name="default">The fallback color to return if the color cannot be inferred.</param> + /// <returns>The constructed color.</returns> + public static Color FromString(string str, Color @default) + { + if (HtmlIsValid(str)) + { + return FromHTML(str); + } + else + { + return Named(str, @default); + } + } + private static string ToHex32(float val) { byte b = (byte)Mathf.RoundToInt(Mathf.Clamp(val * 255, 0, 255)); return b.HexEncode(); } - internal static bool HtmlIsValid(ReadOnlySpan<char> color) + /// <summary> + /// Returns <see langword="true"/> if <paramref name="color"/> is a valid HTML hexadecimal + /// color string. The string must be a hexadecimal value (case-insensitive) of either 3, + /// 4, 6 or 8 digits, and may be prefixed by a hash sign (<c>#</c>). This method is + /// identical to <see cref="StringExtensions.IsValidHtmlColor(string)"/>. + /// </summary> + /// <param name="color">The HTML hexadecimal color string.</param> + /// <returns>Whether or not the string was a valid HTML hexadecimal color string.</returns> + public static bool HtmlIsValid(ReadOnlySpan<char> color) { if (color.IsEmpty) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs index cf25e1f0ae..b5a8742d3d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs @@ -366,7 +366,7 @@ namespace Godot.Collections VariantUtils.CreateFromDictionary(godotDictionary); private static Dictionary<TKey, TValue> FromVariantFunc(in godot_variant variant) => - VariantUtils.ConvertToDictionaryObject<TKey, TValue>(variant); + VariantUtils.ConvertToDictionary<TKey, TValue>(variant); static unsafe Dictionary() { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs index c7deb6423b..57488bd586 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs @@ -153,6 +153,8 @@ namespace Godot.NativeInterop internal static partial void godotsharp_callable_call_deferred(in godot_callable p_callable, godot_variant** p_args, int p_arg_count); + internal static partial Color godotsharp_color_from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha); + // GDNative functions // gdnative.h diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index 6a4717f2c3..9c9258dd9e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -170,39 +170,66 @@ namespace Godot.NativeInterop [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedByteArray(Span<byte> from) - => CreateFromPackedByteArray(Marshaling.ConvertSystemArrayToNativePackedByteArray(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedByteArray(from); + return CreateFromPackedByteArray(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedInt32Array(Span<int> from) - => CreateFromPackedInt32Array(Marshaling.ConvertSystemArrayToNativePackedInt32Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedInt32Array(from); + return CreateFromPackedInt32Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedInt64Array(Span<long> from) - => CreateFromPackedInt64Array(Marshaling.ConvertSystemArrayToNativePackedInt64Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedInt64Array(from); + return CreateFromPackedInt64Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedFloat32Array(Span<float> from) - => CreateFromPackedFloat32Array(Marshaling.ConvertSystemArrayToNativePackedFloat32Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedFloat32Array(from); + return CreateFromPackedFloat32Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedFloat64Array(Span<double> from) - => CreateFromPackedFloat64Array(Marshaling.ConvertSystemArrayToNativePackedFloat64Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedFloat64Array(from); + return CreateFromPackedFloat64Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedStringArray(Span<string> from) - => CreateFromPackedStringArray(Marshaling.ConvertSystemArrayToNativePackedStringArray(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedStringArray(from); + return CreateFromPackedStringArray(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedVector2Array(Span<Vector2> from) - => CreateFromPackedVector2Array(Marshaling.ConvertSystemArrayToNativePackedVector2Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedVector2Array(from); + return CreateFromPackedVector2Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedVector3Array(Span<Vector3> from) - => CreateFromPackedVector3Array(Marshaling.ConvertSystemArrayToNativePackedVector3Array(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedVector3Array(from); + return CreateFromPackedVector3Array(nativePackedArray); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedColorArray(Span<Color> from) - => CreateFromPackedColorArray(Marshaling.ConvertSystemArrayToNativePackedColorArray(from)); + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedColorArray(from); + return CreateFromPackedColorArray(nativePackedArray); + } public static godot_variant CreateFromSystemArrayOfStringName(Span<StringName> from) => CreateFromArray(new Collections.Array(from)); @@ -436,7 +463,7 @@ namespace Godot.NativeInterop public static Godot.Object ConvertToGodotObject(in godot_variant p_var) => InteropUtils.UnmanagedGetManaged(ConvertToGodotObjectPtr(p_var)); - public static string ConvertToStringObject(in godot_variant p_var) + public static string ConvertToString(in godot_variant p_var) { switch (p_var.Type) { @@ -455,65 +482,65 @@ namespace Godot.NativeInterop } } - public static godot_string_name ConvertToStringName(in godot_variant p_var) + public static godot_string_name ConvertToNativeStringName(in godot_variant p_var) => p_var.Type == Variant.Type.StringName ? NativeFuncs.godotsharp_string_name_new_copy(p_var.StringName) : NativeFuncs.godotsharp_variant_as_string_name(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static StringName ConvertToStringNameObject(in godot_variant p_var) - => StringName.CreateTakingOwnershipOfDisposableValue(ConvertToStringName(p_var)); + public static StringName ConvertToStringName(in godot_variant p_var) + => StringName.CreateTakingOwnershipOfDisposableValue(ConvertToNativeStringName(p_var)); - public static godot_node_path ConvertToNodePath(in godot_variant p_var) + public static godot_node_path ConvertToNativeNodePath(in godot_variant p_var) => p_var.Type == Variant.Type.NodePath ? NativeFuncs.godotsharp_node_path_new_copy(p_var.NodePath) : NativeFuncs.godotsharp_variant_as_node_path(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static NodePath ConvertToNodePathObject(in godot_variant p_var) - => NodePath.CreateTakingOwnershipOfDisposableValue(ConvertToNodePath(p_var)); + public static NodePath ConvertToNodePath(in godot_variant p_var) + => NodePath.CreateTakingOwnershipOfDisposableValue(ConvertToNativeNodePath(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static godot_callable ConvertToCallable(in godot_variant p_var) + public static godot_callable ConvertToNativeCallable(in godot_variant p_var) => NativeFuncs.godotsharp_variant_as_callable(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Callable ConvertToCallableManaged(in godot_variant p_var) - => Marshaling.ConvertCallableToManaged(ConvertToCallable(p_var)); + public static Callable ConvertToCallable(in godot_variant p_var) + => Marshaling.ConvertCallableToManaged(ConvertToNativeCallable(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static godot_signal ConvertToSignal(in godot_variant p_var) + public static godot_signal ConvertToNativeSignal(in godot_variant p_var) => NativeFuncs.godotsharp_variant_as_signal(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Signal ConvertToSignalManaged(in godot_variant p_var) - => Marshaling.ConvertSignalToManaged(ConvertToSignal(p_var)); + public static Signal ConvertToSignal(in godot_variant p_var) + => Marshaling.ConvertSignalToManaged(ConvertToNativeSignal(p_var)); - public static godot_array ConvertToArray(in godot_variant p_var) + public static godot_array ConvertToNativeArray(in godot_variant p_var) => p_var.Type == Variant.Type.Array ? NativeFuncs.godotsharp_array_new_copy(p_var.Array) : NativeFuncs.godotsharp_variant_as_array(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Collections.Array ConvertToArrayObject(in godot_variant p_var) - => Collections.Array.CreateTakingOwnershipOfDisposableValue(ConvertToArray(p_var)); + public static Collections.Array ConvertToArray(in godot_variant p_var) + => Collections.Array.CreateTakingOwnershipOfDisposableValue(ConvertToNativeArray(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Array<T> ConvertToArrayObject<T>(in godot_variant p_var) - => Array<T>.CreateTakingOwnershipOfDisposableValue(ConvertToArray(p_var)); + public static Array<T> ConvertToArray<T>(in godot_variant p_var) + => Array<T>.CreateTakingOwnershipOfDisposableValue(ConvertToNativeArray(p_var)); - public static godot_dictionary ConvertToDictionary(in godot_variant p_var) + public static godot_dictionary ConvertToNativeDictionary(in godot_variant p_var) => p_var.Type == Variant.Type.Dictionary ? NativeFuncs.godotsharp_dictionary_new_copy(p_var.Dictionary) : NativeFuncs.godotsharp_variant_as_dictionary(p_var); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ConvertToDictionaryObject(in godot_variant p_var) - => Dictionary.CreateTakingOwnershipOfDisposableValue(ConvertToDictionary(p_var)); + public static Dictionary ConvertToDictionary(in godot_variant p_var) + => Dictionary.CreateTakingOwnershipOfDisposableValue(ConvertToNativeDictionary(p_var)); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary<TKey, TValue> ConvertToDictionaryObject<TKey, TValue>(in godot_variant p_var) - => Dictionary<TKey, TValue>.CreateTakingOwnershipOfDisposableValue(ConvertToDictionary(p_var)); + public static Dictionary<TKey, TValue> ConvertToDictionary<TKey, TValue>(in godot_variant p_var) + => Dictionary<TKey, TValue>.CreateTakingOwnershipOfDisposableValue(ConvertToNativeDictionary(p_var)); public static byte[] ConvertAsPackedByteArrayToSystemArray(in godot_variant p_var) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs index 9a3ed85e66..3d64533269 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs @@ -92,6 +92,9 @@ public partial class VariantUtils if (typeof(T) == typeof(Transform2D)) return CreateFromTransform2D(UnsafeAs<Transform2D>(from)); + if (typeof(T) == typeof(Projection)) + return CreateFromProjection(UnsafeAs<Projection>(from)); + if (typeof(T) == typeof(Vector3)) return CreateFromVector3(UnsafeAs<Vector3>(from)); @@ -293,6 +296,9 @@ public partial class VariantUtils if (typeof(T) == typeof(Transform3D)) return UnsafeAsT(ConvertToTransform3D(variant)); + if (typeof(T) == typeof(Projection)) + return UnsafeAsT(ConvertToProjection(variant)); + if (typeof(T) == typeof(Vector4)) return UnsafeAsT(ConvertToVector4(variant)); @@ -309,13 +315,13 @@ public partial class VariantUtils return UnsafeAsT(ConvertToPlane(variant)); if (typeof(T) == typeof(Callable)) - return UnsafeAsT(ConvertToCallableManaged(variant)); + return UnsafeAsT(ConvertToCallable(variant)); if (typeof(T) == typeof(Signal)) - return UnsafeAsT(ConvertToSignalManaged(variant)); + return UnsafeAsT(ConvertToSignal(variant)); if (typeof(T) == typeof(string)) - return UnsafeAsT(ConvertToStringObject(variant)); + return UnsafeAsT(ConvertToString(variant)); if (typeof(T) == typeof(byte[])) return UnsafeAsT(ConvertAsPackedByteArrayToSystemArray(variant)); @@ -354,19 +360,19 @@ public partial class VariantUtils return UnsafeAsT(ConvertToSystemArrayOfRID(variant)); if (typeof(T) == typeof(StringName)) - return UnsafeAsT(ConvertToStringNameObject(variant)); + return UnsafeAsT(ConvertToStringName(variant)); if (typeof(T) == typeof(NodePath)) - return UnsafeAsT(ConvertToNodePathObject(variant)); + return UnsafeAsT(ConvertToNodePath(variant)); if (typeof(T) == typeof(RID)) return UnsafeAsT(ConvertToRID(variant)); if (typeof(T) == typeof(Godot.Collections.Dictionary)) - return UnsafeAsT(ConvertToDictionaryObject(variant)); + return UnsafeAsT(ConvertToDictionary(variant)); if (typeof(T) == typeof(Godot.Collections.Array)) - return UnsafeAsT(ConvertToArrayObject(variant)); + return UnsafeAsT(ConvertToArray(variant)); if (typeof(T) == typeof(Variant)) return UnsafeAsT(Variant.CreateCopyingBorrowed(variant)); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs index 8b1b73fcc3..fd37f8d9e8 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs @@ -652,7 +652,7 @@ namespace Godot /// added to the first and second values of the final column respectively. /// </summary> /// <param name="offset">The offset to apply to the projection.</param> - /// <returns>The offseted projection.</returns> + /// <returns>The offsetted projection.</returns> public readonly Projection JitterOffseted(Vector2 offset) { Projection proj = this; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs index c4c53a39f9..da12309217 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs @@ -212,7 +212,7 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public string AsString() => - VariantUtils.ConvertToStringObject((godot_variant)NativeVar); + VariantUtils.ConvertToString((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 AsVector2() => @@ -280,11 +280,11 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public Callable AsCallable() => - VariantUtils.ConvertToCallableManaged((godot_variant)NativeVar); + VariantUtils.ConvertToCallable((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Signal AsSignal() => - VariantUtils.ConvertToSignalManaged((godot_variant)NativeVar); + VariantUtils.ConvertToSignal((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public byte[] AsByteArray() => @@ -329,11 +329,11 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public Collections.Dictionary<TKey, TValue> AsGodotDictionary<TKey, TValue>() => - VariantUtils.ConvertToDictionaryObject<TKey, TValue>((godot_variant)NativeVar); + VariantUtils.ConvertToDictionary<TKey, TValue>((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Collections.Array<T> AsGodotArray<T>() => - VariantUtils.ConvertToArrayObject<T>((godot_variant)NativeVar); + VariantUtils.ConvertToArray<T>((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public StringName[] AsSystemArrayOfStringName() => @@ -353,11 +353,11 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public StringName AsStringName() => - VariantUtils.ConvertToStringNameObject((godot_variant)NativeVar); + VariantUtils.ConvertToStringName((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public NodePath AsNodePath() => - VariantUtils.ConvertToNodePathObject((godot_variant)NativeVar); + VariantUtils.ConvertToNodePath((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public RID AsRID() => @@ -365,11 +365,11 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public Collections.Dictionary AsGodotDictionary() => - VariantUtils.ConvertToDictionaryObject((godot_variant)NativeVar); + VariantUtils.ConvertToDictionary((godot_variant)NativeVar); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Collections.Array AsGodotArray() => - VariantUtils.ConvertToArrayObject((godot_variant)NativeVar); + VariantUtils.ConvertToArray((godot_variant)NativeVar); // Explicit conversion operators to supported types diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index c471eceded..4c60080ee9 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -139,7 +139,7 @@ namespace Godot /// <returns>The angle between the two vectors, in radians.</returns> public readonly real_t AngleToPoint(Vector2 to) { - return Mathf.Atan2(y - to.y, x - to.x); + return Mathf.Atan2(to.y - y, to.x - x); } /// <summary> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index 08f2a3a8af..91be548a21 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -123,7 +123,7 @@ namespace Godot /// <returns>The angle between the two vectors, in radians.</returns> public readonly real_t AngleToPoint(Vector2i to) { - return Mathf.Atan2(y - to.y, x - to.x); + return Mathf.Atan2(to.y - y, to.x - x); } /// <summary> diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index 338e5a0147..a3280a0739 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -514,6 +514,13 @@ void godotsharp_callable_call_deferred(Callable *p_callable, const Variant **p_a p_callable->call_deferredp(p_args, p_arg_count); } +godot_color godotsharp_color_from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) { + godot_color ret; + Color *dest = (Color *)&ret; + memnew_placement(dest, Color(Color::from_ok_hsl(p_h, p_s, p_l, p_alpha))); + return ret; +} + // GDNative functions // gdnative.h @@ -1345,6 +1352,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_callable_get_data_for_marshalling, (void *)godotsharp_callable_call, (void *)godotsharp_callable_call_deferred, + (void *)godotsharp_color_from_ok_hsl, (void *)godotsharp_method_bind_ptrcall, (void *)godotsharp_method_bind_call, (void *)godotsharp_variant_new_string_name, |