virtualx-engine/modules
Ignacio Roldán Etcheverry 282bd37e5c C#: Remove need for reflection to invoking callable delegates
We aim to make the C# API reflection-free, mainly for concerns about
performance, and to be able to target NativeAOT in refletion-free mode,
which reduces the binary size.

One of the main usages of reflection still left was the dynamic
invokation of callable delegates, and for some time I wasn't sure
I would find an alternative solution that I'd be happy with.

The new solution uses trampoline functions to invoke the delegates:

```
static void Trampoline(object delegateObj, NativeVariantPtrArgs args, out godot_variant ret)
{
    if (args.Count != 1)
        throw new ArgumentException($"Callable expected 1 arguments but received {args.Count}.");

    string res = ((Func<int, string>)delegateObj)(
        VariantConversionCallbacks.GetToManagedCallback<int>()(args[0])
    );

    ret = VariantConversionCallbacks.GetToVariantCallback<string>()(res);
}

Callable.CreateWithUnsafeTrampoline((int num) => "Foo" + num, &Trampoline);
```

Of course, this is too much boilerplate for user code. To improve this,
the `Callable.From` methods were added. These are overloads that take
`Action` and `Func` delegates, which covers the most common use cases:
lambdas and method groups:

```
// Lambda
Callable.From((int num) => "Foo" + num);

// Method group
string AppendNum(int num) => "Foo" + num;
Callable.From(AppendNum);
```

Unfortunately, due to limitations in the C# language, implicit
conversions from delegates to `Callable` are not supported.

`Callable.From` does not support custom delegates. These should be
uncommon, but the Godot C# API actually uses them for event signals.
As such, the bindings generator was updated to generate trampoline
functions for event signals. It was also optimized to use `Action`
instead of a custom delegate for parameterless signals, which removes
the need for the trampoline functions for those signals.

The change to reflection-free invokation removes one of the last needs
for `ConvertVariantToManagedObjectOfType`. The only remaining usage is
from calling script constructors with parameters from the engine
(`CreateManagedForGodotObjectScriptInstance`). Once that one is made
reflection-free, `ConvertVariantToManagedObjectOfType` can be removed.
2022-10-30 01:24:15 +02:00
..
basis_universal Make some Image methods static 2022-10-14 14:34:15 +02:00
bmp Make some Image methods static 2022-10-14 14:34:15 +02:00
camera Make some Image methods static 2022-10-14 14:34:15 +02:00
csg Document collision_priority in the CSGShape3D class 2022-10-24 18:44:30 +02:00
cvtt Make some Image methods static 2022-10-14 14:34:15 +02:00
dds
denoise Make some Image methods static 2022-10-14 14:34:15 +02:00
enet Merge pull request #67909 from Calinou/doc-enetpacketpeer 2022-10-30 00:09:24 +02:00
etcpak Make some Image methods static 2022-10-14 14:34:15 +02:00
freetype SCons: Unify tools/target build type configuration 2022-09-26 16:31:46 +02:00
gdscript Fix built-in script path of GDScript 2022-10-25 03:41:18 +08:00
glslang Let the RD driver itself expose subgroup caps 2022-10-20 19:37:35 +02:00
gltf Add a way to store additional data in GLTFState and GLTFNode 2022-10-15 12:04:36 -05:00
gridmap Fix MSVC warnings, rename shadowed variables, fix uninitialized values, change warnings=all to use /W4. 2022-10-07 11:32:33 +03:00
hdr Make some Image methods static 2022-10-14 14:34:15 +02:00
jpg Make some Image methods static 2022-10-14 14:34:15 +02:00
jsonrpc
lightmapper_rd Make some Image methods static 2022-10-14 14:34:15 +02:00
mbedtls [Net] Rename "ssl" references to "tls" in methods and members. 2022-09-08 03:24:23 +02:00
meshoptimizer
minimp3 Change time parameters and variables to double type 2022-09-26 13:52:54 -05:00
mobile_vr
mono C#: Remove need for reflection to invoking callable delegates 2022-10-30 01:24:15 +02:00
msdfgen
multiplayer [MP] Let MultiplayerAPI handle packet relaying and peer signaling. 2022-10-27 18:08:58 +02:00
navigation Optimize Convex Collision 2022-10-13 19:07:53 +02:00
noise Make some Image methods static 2022-10-14 14:34:15 +02:00
ogg Change Array arguments to TypedArray 2022-09-01 13:13:19 +02:00
openxr Change default OpenXR pose to aim pose 2022-10-28 01:56:06 +11:00
raycast Fix MSVC warnings C4324, C4389, C4456, and C4459 2022-09-28 16:43:09 +02:00
regex Fix small mistakes throughout much of the documentation 2022-10-21 00:20:59 +02:00
squish Make some Image methods static 2022-10-14 14:34:15 +02:00
svg Make some Image methods static 2022-10-14 14:34:15 +02:00
text_server_adv Merge pull request #67521 from nikitalita/speed_up_texture_pos 2022-10-17 17:31:54 +02:00
text_server_fb Merge pull request #67521 from nikitalita/speed_up_texture_pos 2022-10-17 17:31:54 +02:00
tga Make some Image methods static 2022-10-14 14:34:15 +02:00
theora Make some Image methods static 2022-10-14 14:34:15 +02:00
tinyexr Make some Image methods static 2022-10-14 14:34:15 +02:00
upnp Fix Thread usage in UPNP docs. 2022-10-24 17:23:33 -06:00
vhacd
vorbis Fix typos with codespell 2022-09-30 14:23:36 +02:00
webp Change all WEBP strings and comments to WebP 2022-10-28 15:17:49 -03:00
webrtc [MP] Let MultiplayerAPI handle packet relaying and peer signaling. 2022-10-27 18:08:58 +02:00
websocket [MP] Let MultiplayerAPI handle packet relaying and peer signaling. 2022-10-27 18:08:58 +02:00
webxr Add multiview to the opengl3 driver 2022-10-21 21:00:32 -05:00
xatlas_unwrap SCons: Unify tools/target build type configuration 2022-09-26 16:31:46 +02:00
zip Expose minizip API to allow creating zips using scripts 2022-10-14 21:51:38 +02:00
modules_builders.py
register_module_types.h
SCsub