summaryrefslogtreecommitdiffstats
path: root/modules/mono/csharp_script.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* C#: Add source generator for properties and exports default valuesIgnacio Roldán Etcheverry2022-08-221-455/+68
| | | | | | | | | | | | | | The editor no longer needs to create temporary instances to get the default values. The initializer values of the exported properties are still evaluated at runtime. For example, in the following example, `GetInitialValue()` will be called when first looks for default values: ``` [Export] int MyValue = GetInitialValue(); ``` Exporting fields with a non-supported type now results in a compiler error rather than a runtime error when the script is used.
* C#/netcore: Add base desktop game export implementationIgnacio Roldán Etcheverry2022-08-221-23/+16
| | | | | | | | | This base implementation is still very barebones but it defines the path for how exporting will work (at least when embedding the .NET runtime). Many manual steps are still needed, which should be automatized in the future. For example, in addition to the API assemblies, now you also need to copy the GodotPlugins assembly to each game project.
* C#: Ensure native handles are freed after switch to .NET CoreIgnacio Roldán Etcheverry2022-08-221-0/+1
| | | | | | | | | 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#: Code cleanup and greatly reduce use of C# pointersIgnacio Roldán Etcheverry2022-08-221-1/+1
|
* C#: Begin move to .NET CoreIgnacio Roldán Etcheverry2022-08-221-296/+101
| | | | | | | | | | | | 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-221-802/+509
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-13/+8
|
* C#: Re-write Array, Dictionary, NodePath, String icalls as P/InvokeIgnacio Roldán Etcheverry2022-08-221-1/+1
|
* C#: Move marshaling logic and generated glue to C#Ignacio Roldán Etcheverry2022-08-221-21/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Make `property_*_revert` methods multilevel and expose them for scriptingYuri Sizov2022-08-181-0/+70
|
* Removed faulty function update after get_property_list.Hristo Stamenov2022-08-031-11/+34
| | | | The function tried to rearrange properties but that lead to problems with duplication or deleted properties. Implemented the logic that that function did inside the get_property_list both for tool scripts and non-tool scripts.
* Swap arguments of ResourceSaver.save()kobewi2022-07-291-1/+1
|
* [Net] Modularize multiplayer, expose MultiplayerAPI to extensions.Fabio Alessandrelli2022-07-261-22/+17
| | | | | | | | | - RPC configurations are now dictionaries. - Script.get_rpc_methods renamed to Script.get_rpc_config. - Node.rpc[_id] and Callable.rpc now return an Error. - Refactor MultiplayerAPI to allow extension. - New MultiplayerAPI.rpc method with Array argument (for scripts). - Move the default MultiplayerAPI implementation to a module.
* Implement Vector4, Vector4i, Projectionreduz2022-07-231-0/+3
| | | | | | | | | | | | | 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.
* Merge pull request #62805 from raulsntos/csharp-rpcRémi Verschelde2022-07-071-17/+16
|\
| * C#: New `RPCAttribute`Raul Santos2022-07-071-17/+16
| | | | | | | | | | Replace old RPC attributes with a new single `RPCAttribute` which works like the GDScript `@rpc` annotation.
* | C#: Enable exporting nodes to the inspectorRaul Santos2022-07-061-0/+6
|/
* Support explicit values in flag properties, add C# flags supportRaul Santos2022-06-031-2/+4
| | | | | | | | | - 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`.
* Add a new HashSet templatereduz2022-05-201-9/+9
| | | | | * Intended to replace RBSet in most cases. * Optimized for iteration speed
* Replace most uses of Map by HashMapreduz2022-05-161-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-121-4/+4
| | | | | | | | | | | | | | | | | 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<>
* Remove `RES` and `REF` typedefs in favor of spelled out `Ref<>`Hugo Locurcio2022-05-031-8/+8
| | | | | | These typedefs don't save much typing compared to the full `Ref<Resource>` and `Ref<RefCounted>`, yet they sometimes introduce confusion among new contributors.
* Narrow FileAccess scope to prevent deadlocks.bruvzg2022-04-121-6/+8
|
* Make FileAccess and DirAccess classes reference counted.bruvzg2022-04-111-5/+1
|
* String: Remove TTR and DTR defines in non-tools buildRémi Verschelde2022-03-281-1/+1
| | | | | This ensures we don't use TTR in runtime code, as it's specifically meant to source translations for the editor.
* Refactor GDScript/C# script templates logic to be editor-onlyRémi Verschelde2022-03-281-2/+4
| | | | | Not a full refactor as it still goes through ScriptLanguage so it's hacky, but at least it can now compile without this.
* Remove VARIANT_ARG* macrosreduz2022-03-091-3/+3
| | | | | | | | * Very old macros from the time Godot was created. * Limited arguments to 5 (then later changed to 8) in many places. * They were replaced by C++11 Variadic Templates. * Renamed methods that take argument pointers to have a "p" suffix. This was used in some places and not in others, so made it standard. * Also added a dereference check for Variant*. Helped catch a couple of bugs.
* Remove duplicate editor settings definitionskobewi2022-03-061-2/+2
|
* Attach mono thread before getting nativeName fieldRaul Santos2022-02-071-2/+2
| | | | | In order to access the `nativeName` constant field from a C# class, the mono scope thread must be attached or the mono domain will be null.
* Store panels and docks singletons in their own classestrollodel2022-01-201-2/+2
|
* Merge pull request #55679 from raulsntos/script_reload_fixIgnacio Roldán Etcheverry2022-01-161-5/+7
|\ | | | | C# scripts reload in editor fixed
| * C# script reload fixedRaul Santos2021-12-061-5/+7
| | | | | | | | | | Co-authored-by: Michael Bickel <mib@developium.net> Co-authored-by: Germanrc <german_1995a@hotmail.com>
* | Update copyright statements to 2022Rémi Verschelde2022-01-031-2/+2
| | | | | | | | Happy new year to the wonderful Godot community!
* | Merge pull request #53957 from fabriceci/new-template-workflowRémi Verschelde2022-01-031-44/+21
|\ \
| * | Improve editor template workflowfabriceci2022-01-021-44/+21
| |/ | | | | | | Co-Authored-By: jmb462 <jmb462@gmail.com>
* / Fix getting properties state when reloading C#Raul Santos2021-12-281-1/+10
|/ | | | | | | | When reloading C# classes and keep their properties values they are retrieved and stored in a state list. Retrieving the properties was only getting the fields of the C# class and not inherited fields so those properties values were lost on reload. Now we also try to find the field in the parent classes.
* Move logic for saving project features to ProjectSettings save_customAaron Franke2021-11-251-5/+1
|
* Use "enum class" for input enumsAaron Franke2021-11-121-1/+1
|
* Rename `PROPERTY_USAGE_NOEDITOR` to `PROPERTY_USAGE_NO_EDITOR`Hugo Locurcio2021-11-031-1/+1
| | | | | This is consistent with other constants that include `NO`, such as `PROPERTY_HINT_COLOR_NO_ALPHA`.
* Ensure C# script properties are added to the endRaul Santos2021-10-301-4/+15
| | | | | | Ensures that the `get_property_list` and `get_script_property_list` methods push the script properties to the end of the given list, this prevents the script property from appearing after the script variables.
* clang-format: Enable `BreakBeforeTernaryOperators`Rémi Verschelde2021-10-281-4/+4
| | | | | 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-18/+17
| | | | | | | | | 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`.
* Keep order for C# exported membersRaul Santos2021-10-221-8/+8
|
* C#: Fix property set call boxing value when unboxed was expectedIgnacio Roldán Etcheverry2021-10-191-1/+1
|
* [Net] Rename RPC constants and annotation arguments.Fabio Alessandrelli2021-10-011-2/+2
| | | | | | | | | 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-281-2/+2
| | | | Update attribute class references in mono cache
* Merge pull request #51835 from magian1127/patch1Rémi Verschelde2021-09-171-4/+16
|\
| * check that the element type is indeed StringMagian2021-08-201-6/+13
| |
| * C# Array<String> Export Support Enum(String)Magian2021-08-181-2/+7
| |
* | Merge pull request #52633 from lewiji/mono-build-solution-shortcut-4.0Rémi Verschelde2021-09-141-0/+3
|\ \