Commit graph

26 commits

Author SHA1 Message Date
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
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
Rémi Verschelde b5334d14f7
Update copyright statements to 2021
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 🎆
2021-01-01 20:19:21 +01:00
Ignacio Etcheverry 7439b5595d Mono: Make Godot provide its own WASM m2n trampolines
This depends on a custom Mono patch from this commit:
godotengine/godot-mono-builds@0e312939bd
2020-12-14 21:16:01 +01:00
reduz 127458ed17 Reorganized core/ directory, it was too fatty already
-Removed FuncRef, since Callable makes it obsolete
-Removed int_types.h as its obsolete in c++11+
-Changed color names code
2020-11-07 20:17:12 -03:00
Yuri Roubinsky 156e4043b4 [Mono] Added Shuffle method to Array 2020-11-07 11:26:54 +03:00
Aaron Franke a4dcd48d16
Add concatenation support and a new ctor to Godot.Collections.Array 2020-09-12 18:15:24 -04:00
Ignacio Etcheverry 2511c43972 Mono/C#: Fix several clang-tidy warnings and cleanup 2020-07-05 19:19:36 +02:00
lupoDharkael 95a1400a2a Replace NULL with nullptr 2020-04-02 13:38:00 +02:00
Rémi Verschelde a7f49ac9a1 Update copyright statements to 2020
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.
2020-01-01 11:16:22 +01:00
Ignacio Etcheverry 3797f19926 C#: Add Duplicate method to the Array and Dictionary bindings 2019-12-04 15:22:30 +01:00
Ignacio Etcheverry de7c2ad21b Mono/C#: WebAssembly support 2019-11-13 21:41:11 +01:00
Ignacio Etcheverry 3abe6961dc Mono: Fix Array IndexOutOfRangeException not being thrown 2019-07-03 17:56:08 +02:00
Ignacio Etcheverry 66b930a266 Replace call to 'mono_runtime_object_init' with manual ctor invoking 2019-05-21 00:06:04 +02:00
Ignacio Etcheverry 2b9557c920 C#: Add missing ToString() override methods
Godot.Object, Array, Dictionary and RID were missing ToString() override methods
2019-04-18 14:48:13 +02:00
Ignacio Etcheverry 92b02cb027 C#: Some important Array and Dictionary interface changes
Array now implements IList instead of IList<object, object>.
Dictionary now implements IDictionary instead of IDictionary<object, object>.
2019-04-06 11:00:40 +02:00
Ignacio Etcheverry bb6814aef0 C#: Add DynamicGodotObject class
Expands to Object.call, Object.set and Object.get for accessing members. This means it can also access members from scripts written in other languages, like GDScript.
2019-03-29 00:53:48 +01:00
Ignacio Etcheverry b69569415f
Merge pull request #26411 from neikeq/issue-26195
C#: Add Array.Resize(int) method
2019-02-28 18:53:14 +01:00
Ignacio Etcheverry 32cd8ba9bd C#: Add Array.Resize(int) method 2019-02-28 18:33:42 +01:00
marxin e5f665c718 Fix -Wsign-compare warnings.
I decided to modify code in a defensive way. Ideally functions
like size() or length() should return an unsigned type.
2019-02-27 07:45:57 +01:00
Rémi Verschelde b16c309f82 Update copyright statements to 2019
Happy new year to the wonderful Godot community!
2019-01-01 12:58:10 +01:00
Ignacio Etcheverry 50fd5ef3b5 Mono: Fix not creating generic Array or Dictionary where expected 2018-09-27 00:11:31 +02:00
Ignacio Etcheverry b1356a3590 Cleanup of c# api files and bindings generator
- We no longer generate RID and NodePath C# classes. Both will be maintained manually.
- We no longer generate C# declarations and runtime registration of internal calls for the following classes: RID, NodePath, String, GD, SignalAwaiter and Godot.Object (partial base).
- We no longer auto-generate the base members of Godot.Object. They will be maintained manually as a partial class.

This makes it easier to maintain these C# classes and their internal calls, as well as the bindings generator which no longer generates C# classes that don't derive from Godot Object, and it no longer generates the Godot.Object base members (which where unreadable in the bindings generator code).

- Added missing 'RID(Object from)' constructor to the RID C# class.
- Replaced MONO_GLUE_DISABLED constant macro with MONO_GLUE_ENABLED.
- Add sources in module/mono/glue even if glue is disabled, but surround glue files with ifdef MONO_GLUE_ENABLED.
2018-09-12 03:23:45 +02:00
exts 035d498af2 Added Collections namespace to Array & Dictionary 2018-08-25 17:19:37 -05:00
Ignacio Etcheverry 21d285e30f Dictionary: remove erase_checked(key), make erase(key) return bool 2018-08-14 19:19:05 +02:00
Ignacio Etcheverry ee3c476c9a Add Array and Dictionary wrapper classes to C# 2018-07-20 01:44:30 +02:00