summaryrefslogtreecommitdiff
path: root/modules/mono
AgeCommit message (Collapse)Author
2022-12-02C#: Always convert float Variants to System.DoubleRaul Santos
Godot floats are always 64-bit. The real_t feature only affects vectors, not scalars.
2022-12-02Merge pull request #69391 from NeilKleistGao/slnRémi Verschelde
Fix C# Solution Directory Project Settings
2022-12-02Fix C# solution directory settingsNeilKleistGao
Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
2022-12-02C#: Cleanup Variant marshaling code in source/bindings generatorsIgnacio Roldán Etcheverry
This change aims to reduce the number of places that need to be changed when adding or editing a Godot type to the bindings. Since the addition of `Variant.From<T>/As<T>` and `VariantUtils.CreateFrom<T>/ConvertTo<T>`, we can now replace a lot of the previous code in the bindings generator and the source generators that specify these conversions for each type manually. The only exceptions are the generic Godot collections (`Array<T>` and `Dictionary<TKey, TValue>`) which still use the old version, as that one cannot be matched by our new conversion methods (limitation in the language with generics, forcing us to use delegate pointers). The cleanup applies to: - Bindings generator: - `TypeInterface.cs_variant_to_managed` - `TypeInterface.cs_managed_to_variant` - Source generators: - `MarshalUtils.AppendNativeVariantToManagedExpr` - `MarshalUtils.AppendManagedToNativeVariantExpr` - `MarshalUtils.AppendVariantToManagedExpr` - `MarshalUtils.AppendManagedToVariantExpr`
2022-12-02C#: Replace most conversions between Variant and System.ObjectIgnacio Roldán Etcheverry
This commit replaces most usages of `ConvertManagedObjectToVariant` and `ConvertVariantToManagedObjectOfType`, by using the `Godot.Variant` struct instead of `System.Object`. The most notable change is to the `GetGodotPropertyDefaultValues` method that's generated for scripts. The dictionary it returns now stores `Godot.Variant` values. Remaining usages are: - The `DelegateUtils` class, for the serialization of closure display classes during assembly reloading by the editor. These display classes are compiler generated classes to store values captured by a closure. Since it's generated by the compiler, the only way we have to access the fields is through reflection. This leads to using `System.Object`. - Converting parameters when invoking constructors from the engine. This will be replaced with source generators in the future. - Legacy support for old `GetGodotPropertyDefaultValues` return values. We need to keep supporting the old version of this generated method for some time. Otherwise, if loading a project built with the previous version, it could lead to the loss of exported property values. Ideally, we should remove this legacy support before a stable release.
2022-12-02C#: Remove `ConvertVariantToManagedObject`Ignacio Roldán Etcheverry
Its two usages were: - The Array `ICollection.CopyTo` implementation. It's possible that this class shouldn't be implementing the non-generic `ICollection`, but this commit doesn't change that. The new implementation stores the elements as boxed `Variant` values. - The `Variant.Obj` property. I'm not sure if this property's existence is justified, but for now I rewrote it as a simpler version of `ConvertVariantToManagedObject`.
2022-12-02Merge pull request #67023 from raulsntos/dotnet/fix-signal-callback-generationIgnacio Roldán Etcheverry
C#: Fix signature of generated signal callbacks
2022-11-30Merge pull request #69278 from rhofour/remove-namespacesIgnacio Roldán Etcheverry
Remove unnecessary namespaces in generated PropertyDefVal files.
2022-11-29Remove unnecessary namespaces in generated PropertyDefVal files.R. Alex Hofer
2022-11-30Merge pull request #65905 from raulsntos/dotnet/marshaling-collectionsIgnacio Roldán Etcheverry
C#: Fix marshaling generic Godot collections
2022-11-29Use forward-declarations in big editor classestrollodel
2022-11-28Merge pull request #67031 from raulsntos/dotnet/string-extensionsRémi Verschelde
C#: Cleanup and sync StringExtensions with core
2022-11-28Merge pull request #65907 from magian1127/4.0FixPropertiesGeneratorIgnacio Roldán Etcheverry
C#: Fix Generated ScriptProperty Error.
2022-11-27C#: Remove/deprecate unnecessary string extensionsRaul Santos
- Removed `UnicodeAt` - Removed `EndsWith` - Removed `LPad` and `RPad` - Deprecated `BeginsWith` in favor of `string.StartsWith` - Deprecated `LStrip` and `RStrip` in favor of `string.TrimStart` and `string.TrimEnd`
2022-11-27C#: Fix Generated ScriptProperty Error.Magian
1. Add "this." to prevent errors caused by duplicate variable names. 2. Try to find the default value of property getters.
2022-11-27Merge pull request #69194 from raulsntos/dotnet/begone-variant-disposerIgnacio Roldán Etcheverry
C#: Remove VariantSpanDisposer and use constants in stackalloc
2022-11-27C#: Remove VariantSpanDisposer and use constants in stackallocRaul Santos
- Remove `VariantSpanDisposer`, no need to dispose of the Variant Spans since we are now borrowing the Variants instead of copying them. - Remove `VariantSpanExtensions.Cleared` that was only used so the Span was initialized for `VariantSpanDisposer` to know what to dispose. - Fix stackalloc Spans to use constant VarArgsSpanThreshold and avoid bound checks.
2022-11-26Merge pull request #69191 from raulsntos/dotnet/no-throwIgnacio Roldán Etcheverry
Fix `VariantUtils.UnsupportedType` method throwing
2022-11-26Merge pull request #69088 from raulsntos/dotnet/globalIgnacio Roldán Etcheverry
C#: Add `global::` namespace to generated source
2022-11-26Fix `VariantUtils.UnsupportedType` method throwingRaul Santos
This method was not supposed to throw, just return the new constructed exception so it can be thrown by the caller.
2022-11-26C#: Add `global::` namespace to generated sourceRaul Santos
Adds `global::` to the fully qualified types in source generators to prevent ambiguity.
2022-11-25Merge pull request #68310 from neikeq/csharp-opt-variant-generic-convRémi Verschelde
C#: Optimize Variant conversion callbacks
2022-11-25C#: Cleanup and sync crypto/buffer StringExtensions with coreRaul Santos
- Replaced `MD5Buffer`, `MD5Text`, `SHA256Buffer` and `SHA256Text` implementation to use the `System.Security.Cryptography` classes and avoid marshaling. - Added `SHA1Buffer` and `SHA1Text`. - Renamed `ToUTF8` to `ToUTF8Buffer`. - Renamed `ToAscii` to `ToASCIIBuffer`. - Added `ToUTF16Buffer` and `ToUTF32Buffer`. - Added `GetStringFromUTF16` and `GetStringFromUTF32`.
2022-11-25C#: Cleanup and sync `IsValid*` StringExtensions with coreRaul Santos
- Renamed `IsValidInteger` to `IsValidInt`. - Added `IsValidFileName`. - Added `IsValidHexNumber`. - Added support for IPv6 to `IsValidIPAddress`. - Added `ValidateNodeName`. - Updated the documentation of the `IsValid*` methods.
2022-11-25C#: Cleanup and sync StringExtensions with coreRaul Santos
- Moved `GetBaseName` to keep methods alphabetically sorted. - Removed `Length`, users should just use the Length property. - Removed `Insert`, string already has a method with the same signature that takes precedence. - Removed `Erase`. - Removed `ToLower` and `ToUpper`, string already has methods with the same signature that take precedence. - Removed `FindLast` in favor of `RFind`. - Replaced `RFind` and `RFindN` implemenation with a ca ll to `string.LastIndexOf` to avoid marshaling. - Added `LPad` and `RPad`. - Added `StripEscapes`. - Replaced `LStrip` and `RStrip` implementation with a call to `string.TrimStart` and `string.TrimEnd`. - Added `TrimPrefix` and `TrimSuffix`. - Renamed `OrdAt` to `UnicodeAt`. - Added `CountN` and move the `caseSensitive` parameter of `Count` to the end. - Added `Indent` and `Dedent`.
2022-11-25Merge pull request #67511 from neikeq/issue-66060Rémi Verschelde
C#: Load assemblies as collectible only in the Godot editor
2022-11-25C#: Optimize Variant conversion callbacksIgnacio Roldán Etcheverry
These callbacks are used for marshaling by callables and generic Godot collections. C# generics don't support specialization the way C++ templates do. I knew NativeAOT could optimize away many type checks when the types are known at compile time, but I didn't trust the JIT would do as good a job, so I initially went with cached function pointers. Well, it turns out the JIT is also very good at optimizing in this scenario, so I'm changing the methods to do the conversion directly, rather than returning a function pointer for the conversion. The methods were moved to `VariantUtils`, and were renamed from `GetFromVariantCallback/GetToVariantCallback` to `ConvertTo/CreateFrom`. The new implementation looks like it goes through many `if` checks at runtime to find the right branch for the type, but in practice it works pretty much like template specialization. The JIT only generates code for the relevant branch. Together with inlining, the result is very close or the same as doing the conversion manually: ```cs godot_variant variant; int foo = variant.Int; int bar = VariantUtils.ConvertTo<int>(variant); ``` If the type is a generic Godot collection, the conversion still goes through a function pointer call. The new code happens to be much shorter as well, with the file going from 1057 lines to 407. Side note: `Variant.cs` was mistakenly created in the wrong folder, so I moved it to the `Core` folder.
2022-11-25C#: Add Projection documentationRaul Santos
- Add documentation to Projection type - Reorder Projection members to be consistent with other C# types
2022-11-24Merge pull request #69125 from raulsntos/dotnet/bezier_derivativeRémi Verschelde
C#: Implement BezierDerivative
2022-11-24C#: Implement BezierDerivativeRaul Santos
Adds `BezierDerivative` method to Mathf, Vector2 and Vector3 (already exposed in Core).
2022-11-24Refactor interpolating functions in some classes to use Math classSilc Renew
2022-11-23Merge pull request #68580 from rhofour/fix-source-generationRémi Verschelde
First attempt at fully qualifying the default values of C# properties.
2022-11-22Fully qualify C# default values in exported fields.R. Alex Hofer
This avoids issues when the default values rely on using namespaces.
2022-11-19Merge pull request #68866 from raulsntos/dotnet/godot-enumsRémi Verschelde
C#: Synchronize Godot enums with core
2022-11-19C#: Synchronize Godot enums with coreRaul Santos
2022-11-18Merge pull request #66816 from raulsntos/dotnet/readonlyRémi Verschelde
Add `readonly` to C# methods and types that don't mutate
2022-11-15C#: Remove "?" from CEscape and CUnescapeRaul Santos
2022-11-14Add `readonly` to C# methods and types that don't mutateRaul Santos
Also removes a few unnecessary temp variables
2022-11-04Merge pull request #68253 from dzil123/fix_array_shuffleIgnacio Roldán Etcheverry
Fix c# Array.Shuffle incorrect mono bindings
2022-11-04Fix c# Array.Shuffle incorrect mono bindingsdzil123
2022-11-03Merge pull request #68092 from raulsntos/dotnet/variant-from-arrayIgnacio Roldán Etcheverry
C#: Add implicit conversion from arrays to Variant
2022-11-02Allow getting Quaternion rotation in different Euler ordersAaron Franke
2022-11-02C#: Add implicit conversion from arrays to VariantRaul Santos
Adds an implicit conversion from supported array types (the ones that are equivalent to `Packed*Array` types in Godot) to Variant.
2022-11-02Move EulerOrder enum to math_defs.h and global scopeAaron Franke
2022-11-02Merge pull request #68118 from aaronfranke/quat-from-eulerRémi Verschelde
Replace Quaternion Euler constructor with `from_euler` method
2022-11-02Add missed Quaternion constructor to C#Yuri Rubinsky
2022-11-01Replace Quaternion Euler constructor with `from_euler` methodAaron Franke
2022-10-31Merge pull request #67578 from KoBeWi/GEDITORRémi Verschelde
Unify usage of GLOBAL/EDITOR_GET
2022-10-30C#: Add Variant conversion callbacks for generic Godot collectionsIgnacio Roldán Etcheverry
This allows using generic Godot collections as type arguments for other generic Godot collections. This also allows generic Godot collections as parameter or return type in dynamic Callable invocations.
2022-10-30C#: Remove need for reflection to invoking callable delegatesIgnacio Roldán Etcheverry
We aim to make the C# API reflection-free, mainly for concerns about performance, and to be able to target NativeAOT in refletion-free mode, which reduces the binary size. One of the main usages of reflection still left was the dynamic invokation of callable delegates, and for some time I wasn't sure I would find an alternative solution that I'd be happy with. The new solution uses trampoline functions to invoke the delegates: ``` static void Trampoline(object delegateObj, NativeVariantPtrArgs args, out godot_variant ret) { if (args.Count != 1) throw new ArgumentException($"Callable expected 1 arguments but received {args.Count}."); string res = ((Func<int, string>)delegateObj)( VariantConversionCallbacks.GetToManagedCallback<int>()(args[0]) ); ret = VariantConversionCallbacks.GetToVariantCallback<string>()(res); } Callable.CreateWithUnsafeTrampoline((int num) => "Foo" + num, &Trampoline); ``` Of course, this is too much boilerplate for user code. To improve this, the `Callable.From` methods were added. These are overloads that take `Action` and `Func` delegates, which covers the most common use cases: lambdas and method groups: ``` // Lambda Callable.From((int num) => "Foo" + num); // Method group string AppendNum(int num) => "Foo" + num; Callable.From(AppendNum); ``` Unfortunately, due to limitations in the C# language, implicit conversions from delegates to `Callable` are not supported. `Callable.From` does not support custom delegates. These should be uncommon, but the Godot C# API actually uses them for event signals. As such, the bindings generator was updated to generate trampoline functions for event signals. It was also optimized to use `Action` instead of a custom delegate for parameterless signals, which removes the need for the trampoline functions for those signals. The change to reflection-free invokation removes one of the last needs for `ConvertVariantToManagedObjectOfType`. The only remaining usage is from calling script constructors with parameters from the engine (`CreateManagedForGodotObjectScriptInstance`). Once that one is made reflection-free, `ConvertVariantToManagedObjectOfType` can be removed.