summaryrefslogtreecommitdiffstats
path: root/modules/mono/mono_gd/gd_mono_marshal.cpp
Commit message (Collapse)AuthorAgeFilesLines
* C#: Restructure code prior move to .NET CoreIgnacio Roldán Etcheverry2022-08-221-151/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main focus here was to remove the majority of code that relied on Mono's embedding APIs, specially the reflection APIs. The embedding APIs we still use are the bare minimum we need for things to work. A lot of code was moved to C#. We no longer deal with any managed objects (`MonoObject*`, and such) in native code, and all marshaling is done in C#. The reason for restructuring the code and move away from embedding APIs is that once we move to .NET Core, we will be limited by the much more minimal .NET hosting. PERFORMANCE REGRESSIONS ----------------------- Some parts of the code were written with little to no concern about performance. This includes code that calls into script methods and accesses script fields, properties and events. The reason for this is that all of that will be moved to source generators, so any work prior to that would be a waste of time. DISABLED FEATURES ----------------- Some code was removed as it no longer makes sense (or won't make sense in the future). Other parts were commented out with `#if 0`s and TODO warnings because it doesn't make much sense to work on them yet as those parts will change heavily when we switch to .NET Core but also when we start introducing source generators. As such, the following features were disabled temporarily: - Assembly-reloading (will be done with ALCs in .NET Core). - Properties/fields exports and script method listing (will be handled by source generators in the future). - Exception logging in the editor and stack info for errors. - Exporting games. - Building of C# projects. We no longer copy the Godot API assemblies to the project directory, so MSBuild won't be able to find them. The idea is to turn them into NuGet packages in the future, which could also be obtained from local NuGet sources during development.
* C#: Re-write GD and some other icalls as P/InvokeIgnacio Roldán Etcheverry2022-08-221-56/+1
|
* C#: Move marshaling logic and generated glue to C#Ignacio Roldán Etcheverry2022-08-221-1677/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We will be progressively moving most code to C#. The plan is to only use Mono's embedding APIs to set things at launch. This will make it much easier to later support CoreCLR too which doesn't have rich embedding APIs. Additionally the code in C# is more maintainable and makes it easier to implement new features, e.g.: runtime codegen which we could use to avoid using reflection for marshaling everytime a field, property or method is accessed. SOME NOTES ON INTEROP We make the same assumptions as GDNative about the size of the Godot structures we use. We take it a bit further by also assuming the layout of fields in some cases, which is riskier but let's us squeeze out some performance by avoiding unnecessary managed to native calls. Code that deals with native structs is less safe than before as there's no RAII and copy constructors in C#. It's like using the GDNative C API directly. One has to take special care to free values they own. Perhaps we could use roslyn analyzers to check this, but I don't know any that uses attributes to determine what's owned or borrowed. As to why we maily use pointers for native structs instead of ref/out: - AFAIK (and confirmed with a benchmark) ref/out are pinned during P/Invoke calls and that has a cost. - Native struct fields can't be ref/out in the first place. - A `using` local can't be passed as ref/out, only `in`. Calling a method or property on an `in` value makes a silent copy, so we want to avoid `in`. REGARDING THE BUILD SYSTEM There's no longer a `mono_glue=yes/no` SCons options. We no longer need to build with `mono_glue=no`, generate the glue and then build again with `mono_glue=yes`. We build only once and generate the glue (which is in C# now). However, SCons no longer builds the C# projects for us. Instead one must run `build_assemblies.py`, e.g.: ```sh %godot_src_root%/modules/mono/build_scripts/build_assemblies.py \ --godot-output-dir=%godot_src_root%/bin \ --godot-target=release_debug` ``` We could turn this into a custom build target, but I don't know how to do that with SCons (it's possible with Meson). OTHER NOTES Most of the moved code doesn't follow the C# naming convention and still has the word Mono in the names despite no longer dealing with Mono's embedding APIs. This is just temporary while transitioning, to make it easier to understand what was moved where.
* Implement Vector4, Vector4i, Projectionreduz2022-07-231-1/+22
| | | | | | | | | | | | | Implement built-in classes Vector4, Vector4i and Projection. * Two versions of Vector4 (float and integer). * A Projection class, which is a 4x4 matrix specialized in projection types. These types have been requested for a long time, but given they were very corner case they were not added before. Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity. **Q**: Why Projection and not Matrix4? **A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
* Update copyright statements to 2022Rémi Verschelde2022-01-031-2/+2
| | | | Happy new year to the wonderful Godot community!
* clang-format: Enable `BreakBeforeTernaryOperators`Rémi Verschelde2021-10-281-12/+12
| | | | | clang-format keeps breaking the way it handles break *after* ternary operators, so I give up and go with the only style they seem to actually test.
* clang-format: Disable alignment of operands, too unreliableRémi Verschelde2021-10-281-30/+20
| | | | | | | | | Sets `AlignOperands` to `DontAlign`. `clang-format` developers seem to mostly care about space-based indentation and every other version of clang-format breaks the bad mismatch of tabs and spaces that it seems to use for operand alignment. So it's better without, so that it respects our two-tabs `ContinuationIndentWidth`.
* Fix marshaling generic Godot.Object in C#Raul Santos2021-10-181-0/+11
|
* Fix hint_string for C# enum arraysRaul Santos2021-10-151-18/+21
|
* Merge pull request #53627 from raulsntos/fix-list-marshalRémi Verschelde2021-10-151-2/+4
|\
| * Fix C# List<T> marshallingRaul Santos2021-10-101-2/+4
| |
* | Merge pull request #53581 from raulsntos/mono-marshal-genericsRémi Verschelde2021-10-151-0/+11
|\ \
| * | Support marshaling generic Godot.ObjectRaul Santos2021-10-081-0/+11
| |/ | | | | | | | | Allows using generic C# types in signals as long as they inherit from `Godot.Object`.
* / Support arrays of StringName, NodePath and RID in monoRaul Santos2021-10-081-0/+36
|/
* C#: Fix bindings generator for Callable argument default valueIgnacio Roldán Etcheverry2021-08-201-2/+6
| | | | | Previously there weren't any Callable arguments with a default value, but d4dd859991205e6cecfa9a0553b89db47c983d0b introduced one.
* Rename Reference to RefCountedPedro J. Estébanez2021-06-111-2/+2
|
* Rename Quat to QuaternionMarcel Admiraal2021-06-041-10/+10
|
* Rename Variant TRANSFORM to TRANSFORM3DAaron Franke2021-06-031-7/+7
| | | Also _transform to _transform3d
* Rename Transform to Transform3D in coreAaron Franke2021-06-031-3/+3
|
* Merge pull request #45029 from neikeq/issue-40023Rémi Verschelde2021-01-261-4/+11
|\ | | | | C#: Fix System.Collections.Generic.List marshalling
| * C#: Fix System.Collections.Generic.List marshallingIgnacio Etcheverry2021-01-081-4/+11
| |
* | CI: Update to clang-format 11 and apply ternary operator changesRémi Verschelde2021-01-121-4/+4
|/
* Update copyright statements to 2021Rémi Verschelde2021-01-011-2/+2
| | | | | | | | | | | | | | Happy new year to the wonderful Godot community! 2020 has been a tough year for most of us personally, but a good year for Godot development nonetheless with a huge amount of work done towards Godot 4.0 and great improvements backported to the long-lived 3.2 branch. We've had close to 400 contributors to engine code this year, authoring near 7,000 commit! (And that's only for the `master` branch and for the engine code, there's a lot more when counting docs, demos and other first-party repos.) Here's to a great year 2021 for all Godot users 🎆
* Don't box params on Native->C# calls with Variant paramsIgnacio Etcheverry2020-12-061-376/+576
| | | | | | | | | Godot uses Variant parameters for calls to script methods. Up until now we were boxing such parameters when marshalling them for invokation, even if they were value types. Now Godot allocates the marshalled parameters on the stack, reducing the GC allocations resulted from boxing.
* Remove empty lines around braces with the formatting scriptAaron Franke2020-11-161-1/+0
|
* Variant: Rename Type::_RID to Type::RIDRémi Verschelde2020-11-091-4/+4
| | | | | | | | The underscore prefix was used to avoid the conflict between the `RID` class name and the matching enum value in `Variant::Type`. This can be fixed differently by prefixing uses of the `RID` class in `Variant` with the scope resolution operator, as done already for `AABB`.
* [Complex Test Layouts] Change `String` to use UTF-32 encoding on all platforms.bruvzg2020-09-031-38/+0
|
* Fix Mono PackedArray MarshallingDaniel Doran2020-07-051-16/+16
|
* Merge pull request #40137 from neikeq/fix-clangtidy-warnings-monoRémi Verschelde2020-07-051-125/+184
|\ | | | | Mono/C#: Fix several clang-tidy warnings and cleanup
| * Mono/C#: Fix several clang-tidy warnings and cleanupIgnacio Etcheverry2020-07-051-125/+184
| |
* | fix crash when pass null in print array in GD.printendlesstravel2020-07-031-0/+4
|/ | | | | | | | fix crash when pass null in print array in GD.print 2 fix crash when pass null in print array in GD.print 3 fix space
* return boxed long when marshalling a godot int to mono runtime in dynamic ↵Michael Belousov2020-06-171-2/+2
| | | | contexts
* Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocksRémi Verschelde2020-05-141-1/+0
| | | | | | | | | | | | | | Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027.
* C#: Revert marshalling of IDictionary/IEnumerable implementing typesIgnacio Etcheverry2020-04-231-123/+153
| | | | | Added marshalling for `System.Collections.Generic.List<T>` and `System.Collections.Generic.Dictionary<TKey, TValue>`.
* Mono/C#: Allow exporting System.Array of type Godot.ObjectIgnacio Etcheverry2020-04-221-0/+31
|
* Replace NULL with nullptrlupoDharkael2020-04-021-21/+21
|
* [Mono] Marshaling for Vector2i, Vector3i, and Rect2iAaron Franke2020-03-171-0/+45
|
* Fix C# bindings after recent breaking changesIgnacio Etcheverry2020-03-171-71/+297
| | | | | | | | | | | | | Implementation for new Variant types Callable, Signal, StringName. Added support for PackedInt64Array and PackedFloat64Array. Add generation of signal members as events, as well as support for user created signals as events. NOTE: As of now, raising such events will not emit the signal. As such, one must use `EmitSignal` instead of raising the event directly. Removed old ThreadLocal fallback class. It's safe to use thread_local now since it's supported on all minimum versions of compilers we support.
* Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.Juan Linietsky2020-02-251-19/+19
| | | | | | | | | | | | | | | | | | | | | - Renames PackedIntArray to PackedInt32Array. - Renames PackedFloatArray to PackedFloat32Array. - Adds PackedInt64Array and PackedFloat64Array. - Renames Variant::REAL to Variant::FLOAT for consistency. Packed arrays are for storing large amount of data and creating stuff like meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of memory. That said, many users requested the ability to have 64 bits packed arrays for their games, so this is just an optional added type. For Variant, the float datatype is always 64 bits, and exposed as `float`. We still have `real_t` which is the datatype that can change from 32 to 64 bits depending on a compile flag (not entirely working right now, but that's the idea). It affects math related datatypes and code only. Neither Variant nor PackedArray make use of real_t, which is only intended for math precision, so the term is removed from there to keep only float.
* PoolVector is gone, replaced by VectorJuan Linietsky2020-02-181-70/+70
| | | | | Typed `PoolTypeArray` types are now renamed `PackedTypeArray` and are sugar for `Vector<Type>`.
* Remove duplicate ERR_PRINT macro.Marcel Admiraal2020-02-051-1/+1
|
* Mono/C#: Make 'GD.Print' and its variants fallback to 'ToString()'Ignacio Etcheverry2020-01-021-18/+66
| | | | | | | | | | Up until now, 'GD.Print' would convert parameters first to Variant and only then to String. This meant parameters that cannot be converted to Variant would be printed as "Null". This commit makes 'GD.Print' fallback to 'System.Object.ToString()' if the parameter could not be converted to Variant. The same applies to all 'GD.Print' variants: 'GD.PrintS', 'GD.PrintT', 'GD.PrintErr' and 'GD.PrintRaw'.
* Update copyright statements to 2020Rémi Verschelde2020-01-011-2/+2
| | | | | | | | | | | Happy new year to the wonderful Godot community! We're starting a new decade with a well-established, non-profit, free and open source game engine, and tons of further improvements in the pipeline from hundreds of contributors. Godot will keep getting better, and we're looking forward to all the games that the community will keep developing and releasing with it.
* Mono/C#: Fix Variant -> MonoString* when type is Variant:NILIgnacio Etcheverry2019-12-191-0/+2
| | | | | | | `Variant::operator String()` returns "Null" if the type is `Variant:NIL`. We must consider that and return a null `MonoString*` instead when marshalling. This was also causing a "Null" error to be displayed when exporting a game because null string members would be set to "Null" during hot-reload.
* Mono/C#: Several android fixesIgnacio Etcheverry2019-12-041-0/+2
| | | | | | | - Added correct config file for android dllmaps. - Fix __Internal DllImports with a dlopen fallback. - Add missing P/Invoke functions and internal calls expected by the monodroid BCL and our custom version of the 'Android.Runtime.AndroidEnvironment' class (this last one can be found in the godot-mono-builds repo). - Make sure to set 'btls' instead of 'legacy' as the default TLS provider on Android.
* Mono/C#: WebAssembly supportIgnacio Etcheverry2019-11-131-4/+5
|
* Replace 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG' in 'modules/mono'Ignacio Etcheverry2019-08-091-13/+8
| | | | | | And 'CRASH_*_MSG' as well. Also make error messages puntuation and quotation more consistent.
* Re-write mono module editor code in C#Ignacio Etcheverry2019-07-051-14/+22
| | | | | | | | Make the build system automatically build the C# Api assemblies to be shipped with the editor. Make the editor, editor player and debug export templates use Api assemblies built with debug symbols. Always run MSBuild to build the editor tools and Api assemblies when building Godot. Several bugs fixed related to assembly hot reloading and restoring state. Fix StringExtensions internal calls not being registered correctly, resulting in MissingMethodException.
* Android build and export for the mono moduleIgnacio Etcheverry2019-06-031-1/+1
|
* Fix C# build error in MarshalUtils debug codeIgnacio Etcheverry2019-05-211-16/+8
|