Commit graph

1227 commits

Author SHA1 Message Date
Ignacio Roldán Etcheverry 50b603c7dc C#: Begin move to .NET Core
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.
2021-09-22 08:27:12 +02:00
Ignacio Roldán Etcheverry f744d99179 C#: Restructure code prior move to .NET Core
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.
2021-09-22 06:38:00 +02:00
Ignacio Roldán Etcheverry 3f1a620102 C#: Re-write GD and some other icalls as P/Invoke 2021-09-22 06:38:00 +02:00
Ignacio Roldán Etcheverry bbde1b1f09 C#: Re-write Array, Dictionary, NodePath, String icalls as P/Invoke 2021-09-12 19:49:39 +02:00
Ignacio Roldán Etcheverry 66a89c7925 C#: Remove DynamicGodotObject/Object.DynamicObject
We are moving in the direction of no dynamic code generation,
so this is no longer desired.

The feature can still be easily implemented by any project that
still want it.
2021-09-12 19:49:23 +02:00
Ignacio Roldán Etcheverry 483071716e C#: Move marshaling logic and generated glue to C#
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.
2021-08-20 10:24:56 +02:00
Max Hilbrunner 81f7d1890b Namespaces instead of underscore prefix for binds
Thanks to neikeq for the initial work.

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
2021-08-17 16:10:09 +02:00
Rémi Verschelde cfdac0973c
Merge pull request #51698 from Paulb23/text-editor-settings
Reorganise text editor settings
2021-08-16 18:48:58 +02:00
Paulb23 bcfc591f86 Reorganise text editor settings 2021-08-16 17:18:49 +01:00
Ignacio Roldán Etcheverry 5ea500e599 Fix C# native instance bindings after recent re-write
This was needed after: 4469144891
2021-08-16 17:16:36 +02:00
Aaron Franke 03e2544d50
Use real_t and double where appropriate in Particles 2021-08-12 11:35:31 -05:00
Raul Santos f20db58271 Ensure MSBuildPanel buttons are instantiated 2021-08-06 22:30:38 +02:00
Rémi Verschelde ba0982c51c
Merge pull request #51008 from raulsntos/csharp-renames 2021-08-06 09:07:02 +02:00
Raul Santos 2deefd938f Reduce C# Dictionary internal calls
- Implements new `KeyValuePairs` and `KeyValuePairAt` internal calls
to get the `key` and the `value` in one call.
- Caches the `DictionaryEntry` to reuse properties without repeating
internal calls.
2021-08-05 17:30:28 +02:00
Raul Santos 0669ffcd15 Add documentation to Dictionary in C#
Adds documentation to `Godot.Collections.Dictionary` in C#.
2021-08-05 17:30:27 +02:00
Raul Santos d2655cb131 Rename RotationQuaternion to be more similar to get_rotation_quaternion
Renames `RotationQuaternion` to be more consistent with `get_rotation_quaternion`
2021-08-05 17:29:55 +02:00
Raul Santos 5330c83690 Rename RandSeed to RandFromSeed and use ref param
Renames `RandSeed` method to be more consistent with `Math::rand_from_seed`
2021-08-05 17:29:55 +02:00
31 6fd2edddc0 Fix 'script_class' null access when reloading a deleted C# script 2021-08-03 22:43:42 -05:00
Raul Santos ad460cde79 Simplify C# print methods
- Extracts the parameters logic to a single method
- Simplify the handling of null parameters
2021-08-03 23:12:27 +02:00
Yuri Sizov d3e413c659 Fix the editor theme application for the Mono build log 2021-08-03 22:13:32 +03:00
Aaron Franke 2733b9abd8
Remove obsolete "dectime" method
Replaced by "move_toward"
2021-07-30 16:41:28 -05:00
Rémi Verschelde bdcc8741e4
Merge pull request #51009 from raulsntos/fix-csharp-split
Use `allowEmpty` parameter in Split
2021-07-29 23:04:39 +02:00
Raul Santos 37d8f8c92b Use C# interpolated strings
Uses interpolated strings wherever possible.
String concatenations are still left where used for breaking long lines.
2021-07-29 17:20:44 +02:00
Raul Santos b7a66a820b Use allowEmpty parameter in Split 2021-07-29 12:57:35 +02:00
Rémi Verschelde 7cbdb9b4c3
Merge pull request #50917 from raulsntos/more-iterators 2021-07-27 08:05:15 +02:00
Raul Santos d636ebbfe9 Ignore paths with invalid chars in PathWhich 2021-07-27 04:16:20 +02:00
Raul Santos 3fe67fb5ad Use C++ iterators in the Mono module 2021-07-27 02:48:28 +02:00
Rémi Verschelde 92299989bd
Use Ref<T> references as iterators where relevant
And const when possible.
2021-07-26 19:27:11 +02:00
Ignacio Roldán Etcheverry 0c68ccecda
Merge pull request #50867 from aaronfranke/cs-array-empty
Add documentation to Array in C#
2021-07-26 04:46:35 +02:00
Raul Santos accd05f4ad Use Array.Empty instead of allocating a every time
Use `System.Array.Empty<T>` to get an empty array instead of allocating
a new one every time. Since arrays are immutable there is no need to
allocate them every time.
2021-07-26 03:52:31 +02:00
Aaron Franke 080f44a3b7
Add documentation to Array in C# 2021-07-25 18:04:18 -04:00
Raul Santos b3274a7064 Fix bindings generator range iterator errors 2021-07-25 21:32:54 +02:00
Rémi Verschelde ac3322b0af
Use const references where possible for List range iterators 2021-07-25 12:22:25 +02:00
Raul Santos ba99387bf3 Fix documentation in StringExtensions 2021-07-24 22:58:41 +02:00
Ignacio Roldán Etcheverry 2ee395a277
Merge pull request #50757 from aaronfranke/simple-cs-editorconfig
Add a simple C# `.editorconfig`
2021-07-24 21:48:41 +02:00
Aaron Franke 4e6efd1b07
Use C++ iterators for Lists in many situations 2021-07-23 17:38:28 -04:00
Aaron Franke 5f8275d9ac
Add a simple C# .editorconfig 2021-07-23 17:04:53 -04:00
Fabio Alessandrelli ddb68f76ff [Net] Single rpc annotation. "sync" no longer part of mode.
- 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).
2021-07-20 11:17:59 +02:00
reduz 6631f66c2a Optimize StringName usage
* Added a new macro SNAME() that constructs and caches a local stringname.
* Subsequent usages use the cached version.
* Since these use a global static variable, a second refcounter of static usages need to be kept for cleanup time.
* Replaced all theme usages by this new macro.
* Replace all signal emission usages by this new macro.
* Replace all call_deferred usages by this new macro.

This is part of ongoing work to optimize GUI and the editor.
2021-07-18 21:20:02 -03:00
Rémi Verschelde 671467b888
Mono: Remove info dialog discouraging use in production
While there are still various bugs to solve and features to implement, the C#
support as of Godot 3.4 is fairly mature and already used by a number of users
in production. Now that we default to dotnet CLI as build tool, it also seems
to be more reliable than MSBuild.

The documentation can (and does for the most part) point out some caveats that
users should be aware of, but this info dialog has outlived its intended
purpose.
2021-07-15 11:48:19 +02:00
reduz 5ad4f26659 Implement the ability to disable classes
* This PR adds the ability to disable classes when building.
* For now it's only possible to do this via command like:
  `scons disable_classes=RayCast2D,Area3D`
* Eventually, a proper UI will be implemented to create a build config file to do this at large scale, as well as detect what is used in the project.
2021-07-13 09:25:14 -03:00
Fabio Alessandrelli 88d68346ee [Net] Rename NetworkedMultiplayerPeer to MultiplayerPeer. 2021-07-12 16:36:34 +02:00
reduz 4469144891 Redo how instance bindings work
* The harcoded 8 slots are no more and impose limits in the new extension system.
* New system is limitless, although it will impose small performance hit with a mutex.
* Use a token to request the instance binding.

**Warning**: Mono will most likely break as a result of this, will need to be modified to use the new system.
2021-07-08 17:08:12 -03:00
Hugo Locurcio 257a8a337e
Remove unused code related to Travis CI 2021-07-01 18:02:00 +02:00
Grzegorz Puławski fa82727f5b Fixing mono build after instance() -> instanciate() name change 2021-06-23 16:07:23 +02:00
Lightning_A e28fd07b2b Rename instance()->instantiate() when it's a verb 2021-06-19 20:49:18 -06:00
Rémi Verschelde 9b7c963d19
Merge pull request #48804 from EricEzaM/scripting-multi-error-support
Added support for scripts reporting multiple errors to ScriptTextEditor
2021-06-20 00:38:49 +02:00
Eric M d0e78c86d7 Added support for scripts reporting multiple errors to ScriptTextEditor
Scripts can now report multiple errors to the scripting editors in the engine. UI elements were added to support multiple errors.
2021-06-19 22:20:30 +10:00
Marcel Admiraal 2bafcd3422 Consolidate JSON, JSONParseResults and JSONParser into JSON
Renames JSON.parse_string() to parse()
Renames JSON.decode_data() to stringify()
2021-06-19 08:01:40 +01:00
Rémi Verschelde 7aebb8f81c
Merge pull request #44156 from aaronfranke/quat-angle-to
Add Quaternion angle_to method
2021-06-18 12:35:58 +02:00