summaryrefslogtreecommitdiffstats
path: root/modules/mono/mono_gd
Commit message (Collapse)AuthorAgeFilesLines
...
* C#: Ensure native handles are freed after switch to .NET CoreIgnacio Roldán Etcheverry2022-08-223-16/+10
| | | | | | | | | Finalizers are longer guaranteed to be called on exit now that we switched to .NET Core. This results in native instances leaking. The only solution I can think of so far is to keep a list of all instances alive to dispose when the AssemblyLoadContext.Unloading event is raised.
* C#: Begin move to .NET CoreIgnacio Roldán Etcheverry2022-08-2215-2644/+276
| | | | | | | | | | | | We're targeting .NET 5 for now to make development easier while .NET 6 is not yet released. TEMPORARY REGRESSIONS --------------------- Assembly unloading is not implemented yet. As such, many Godot resources are leaked at exit. This will be re-implemented later together with assembly hot-reloading.
* C#: Restructure code prior move to .NET CoreIgnacio Roldán Etcheverry2022-08-2226-3582/+194
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-226-83/+20
|
* C#: Re-write Array, Dictionary, NodePath, String icalls as P/InvokeIgnacio Roldán Etcheverry2022-08-221-7/+0
|
* C#: Move marshaling logic and generated glue to C#Ignacio Roldán Etcheverry2022-08-2214-3145/+188
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* create vector4, vector4i and projection for csharpantonWetzel2022-07-311-1/+1
|
* Code quality: Fix header guards consistencyRémi Verschelde2022-07-253-9/+9
| | | | | Adds `header_guards.sh` bash script, used in CI to validate future changes. Can be run locally to fix invalid header guards.
* Implement Vector4, Vector4i, Projectionreduz2022-07-235-4/+123
| | | | | | | | | | | | | 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.
* Rename OSX to macOS and iPhoneOS to iOS.bruvzg2022-07-215-10/+10
|
* C#: New `RPCAttribute`Raul Santos2022-07-072-6/+15
| | | | | Replace old RPC attributes with a new single `RPCAttribute` which works like the GDScript `@rpc` annotation.
* Support explicit values in flag properties, add C# flags supportRaul Santos2022-06-034-0/+12
| | | | | | | | | - Add support for explicit values in properties using `PROPERTY_HINT_FLAGS` that works the same way it does for enums. - Fix enums and flags in VisualScriptEditor (it wasn't considering the explicit value). - Use `PROPERTY_HINT_FLAGS` for C# enums with the FlagsAttribute instead of `PROPERTY_HINT_ENUM`.
* Replace most uses of Map by HashMapreduz2022-05-165-19/+19
| | | | | | | | | | | | * Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated!
* Add a new HashMap implementationreduz2022-05-122-26/+18
| | | | | | | | | | | | | | | | | Adds a new, cleaned up, HashMap implementation. * Uses Robin Hood Hashing (https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing). * Keeps elements in a double linked list for simpler, ordered, iteration. * Allows keeping iterators for later use in removal (Unlike Map<>, it does not do much for performance vs keeping the key, but helps replace old code). * Uses a more modern C++ iterator API, deprecates the old one. * Supports custom allocator (in case there is a wish to use a paged one). This class aims to unify all the associative template usage and replace it by this one: * Map<> (whereas key order does not matter, which is 99% of cases) * HashMap<> * OrderedHashMap<> * OAHashMap<>
* Rename Basis "elements" to "rows"Aaron Franke2022-04-291-3/+3
|
* Rename Transform2D "elements" to "columns"Aaron Franke2022-04-291-3/+3
|
* Narrow FileAccess scope to prevent deadlocks.bruvzg2022-04-121-6/+4
|
* Make FileAccess and DirAccess classes reference counted.bruvzg2022-04-113-16/+10
|
* Zero initialize all pointer class and struct membersRémi Verschelde2022-04-049-100/+100
| | | | | This prevents the pitfall of UB when checking if they have been assigned something valid by comparing to nullptr.
* Fix typos with codespellRémi Verschelde2022-03-311-1/+1
| | | | | | Using codespell 2.2-dev from current git. Fix a couple incorrect uses of gendered pronouns.
* Convert uses of `DirAccess *` to `DirAccessRef` to prevent memleaksRémi Verschelde2022-03-111-2/+1
| | | | | | | | `DirAccess *` needs to be deleted manually, and this is often forgotten especially when doing early returns with `ERR_FAIL_COND`. `DirAccessRef` is deleted automatically when it goes out of scope. Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
* Style: Cleanup single-line blocks, semicolons, dead codeRémi Verschelde2022-02-163-34/+67
| | | | | Remove currently unused implementation of TextureBasisU, could be re-added later on if needed and ported.
* Use EditorFileDialog instead of FileDialog in the project managerHendrik Brucker2022-02-121-9/+5
|
* Update copyright statements to 2022Rémi Verschelde2022-01-0334-68/+68
| | | | Happy new year to the wonderful Godot community!
* Fix get_all_delegates method for generic classesRaul Santos2021-12-045-1/+24
| | | | | If the class is generic, we must get its generic type definition and use it to retrieve the delegates.
* Don't return reference on copy assignment operatorsRémi Verschelde2021-11-301-6/+5
| | | | | | | | | | | | | We prefer to prevent using chained assignment (`T a = b = c = T();`) as this can lead to confusing code and subtle bugs. According to https://en.wikipedia.org/wiki/Assignment_operator_(C%2B%2B), C++ allows any arbitrary return type, so this is standard compliant. This could be re-assessed if/when we have an actual need for a behavior more akin to that of the C++ STL, for now this PR simply changes a handful of cases which were inconsistent with the rest of the codebase (`void` return type was already the most common case prior to this commit).
* Move Mono unhandled exception setting to be located within a subsectionHugo Locurcio2021-11-101-1/+1
| | | | | | | Settings that aren't within a subsection are difficult to reach when other settings do have a subsection. This also adds documentation for the project setting.
* clang-format: Enable `BreakBeforeTernaryOperators`Rémi Verschelde2021-10-282-29/+25
| | | | | 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-286-84/+74
| | | | | | | | | 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`.
* Mono: Fix build after #52940Rémi Verschelde2021-10-201-1/+1
| | | | | Chose to pass unhandled exceptions to the toaster, we might want to reconsider if those are already reported somewhere else (e.g. in the Mono panel).
* C#: Fix property set call boxing value when unboxed was expectedIgnacio Roldán Etcheverry2021-10-192-18/+17
|
* 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
|/
* [Net] Rename RPC constants and annotation arguments.Fabio Alessandrelli2021-10-012-3/+3
| | | | | | | | | any -> any_peer sync -> call_local ordered -> unreliable_ordered Multiplayer.RPC_MODE_ANY -> RPC_MODE_ANY_PEER Multiplayer.TRANSFER_MODE_ORDERED -> TRANSFER_MODE_UNRELIABLE_ORDERED
* Update C# RPC attributes to share new Any/Auth naming conventionEdward Auttonberry2021-09-282-6/+6
| | | | Update attribute class references in mono cache
* [Net] Rename RPC "puppet" to "auth" (authority). Drop "master".Fabio Alessandrelli2021-08-302-3/+0
| | | | | | | | | | | | | | | | | | | | | | This commit completely removes the RPC_MODE_MASTER ("master" keyword), and renames the RPC_MODE_PUPPET to RPC_MODE_AUTHORITY ("auth" keyword). This commit also renames the "Node.[get|set]_network_master" methods to "Node.[get|set]_network_authority". This commit also renames the RPC_MODE_REMOTE constant to RPC_MODE_ANY. RPC_MODE_MASTER in Godot 3.x meant that a given RPC would be callable by any puppet peer on the master, while RPC_MODE_PUPPET meant that it would be callable by the master on any puppet. Beside proving to be very confusing to the user (referring to where it could be called instead of who can call it) the RPC_MODE_MASTER is quite useless. It is almost the same as RPC_MODE_REMOTE (anyone can call) with the exception that the network master cannot. While this could be useful to check in some case, in such a function you would anyway need to check in code who is the caller via get_rpc_sender_id(), so adding the check there for those rare cases does not warrants a dedicated mode.
* Merge pull request #47295 from omegachysis/script-bind-mutexIgnacio Roldán Etcheverry2021-08-241-1/+5
|\ | | | | Fix race condition on `script_binding` in C#
| * Add mutex to protect script bindingsMatthew A. Robinson2021-03-231-1/+5
| |
* | 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.
* | Namespaces instead of underscore prefix for bindsMax Hilbrunner2021-08-172-31/+39
| | | | | | | | | | | | Thanks to neikeq for the initial work. Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
* | Fix C# native instance bindings after recent re-writeIgnacio Roldán Etcheverry2021-08-162-21/+5
| | | | | | | | This was needed after: 44691448911f1d29d4d79dbdd5553734761e57c4
* | Use C++ iterators in the Mono moduleRaul Santos2021-07-272-6/+6
| |
* | Use const references where possible for List range iteratorsRémi Verschelde2021-07-251-1/+1
| |
* | Use C++ iterators for Lists in many situationsAaron Franke2021-07-231-2/+2
| |
* | [Net] Single `rpc` annotation. "sync" no longer part of mode.Fabio Alessandrelli2021-07-202-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Move the "sync" property for RPCs to RPCConfig. - Unify GDScript annotations into a single one: - `@rpc(master)` # default - `@rpc(puppet)` - `@rpc(any)` # former `@remote` - Implement three additional `@rpc` options: - The second parameter is the "sync" option (which also calls the function locally when RPCing). One of "sync", "nosync". - The third parameter is the transfer mode (reliable, unreliable, ordered). - The third parameter is the channel (unused for now).