2018-07-21 23:40:34 +02:00
|
|
|
#if REAL_T_IS_DOUBLE
|
|
|
|
using real_t = System.Double;
|
|
|
|
#else
|
|
|
|
using real_t = System.Single;
|
|
|
|
#endif
|
2021-07-23 01:56:37 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
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-05-03 15:21:06 +02:00
|
|
|
using Godot.NativeInterop;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2018-09-04 05:40:41 +02:00
|
|
|
// TODO: Add comments describing what this class does. It is not obvious.
|
2018-03-01 08:51:35 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
namespace Godot
|
|
|
|
{
|
2017-12-24 03:17:48 +01:00
|
|
|
public static partial class GD
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
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-05-03 15:21:06 +02:00
|
|
|
public static unsafe object Bytes2Var(byte[] bytes, bool allowObjects = false)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
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-05-03 15:21:06 +02:00
|
|
|
using var varBytes = Marshaling.mono_array_to_PackedByteArray(bytes);
|
2021-09-12 19:50:13 +02:00
|
|
|
using godot_variant ret = default;
|
2021-09-12 20:23:05 +02:00
|
|
|
NativeFuncs.godotsharp_bytes2var(&varBytes, allowObjects.ToGodotBool(), &ret);
|
2021-09-12 19:50:13 +02:00
|
|
|
return Marshaling.variant_to_mono_object(&ret);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe object Convert(object what, Variant.Type type)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var whatVariant = Marshaling.mono_object_to_variant(what);
|
|
|
|
using godot_variant ret = default;
|
|
|
|
NativeFuncs.godotsharp_convert(&whatVariant, type, &ret);
|
|
|
|
return Marshaling.variant_to_mono_object(&ret);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2018-07-21 23:40:34 +02:00
|
|
|
public static real_t Db2Linear(real_t db)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-07-23 01:56:37 +02:00
|
|
|
return (real_t)Math.Exp(db * 0.11512925464970228420089957273422);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
private static string[] GetPrintParams(object[] parameters)
|
2021-07-29 13:51:54 +02:00
|
|
|
{
|
|
|
|
if (parameters == null)
|
|
|
|
{
|
|
|
|
return new[] { "null" };
|
|
|
|
}
|
|
|
|
|
|
|
|
return Array.ConvertAll(parameters, x => x?.ToString() ?? "null");
|
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe int Hash(object var)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var variant = Marshaling.mono_object_to_variant(var);
|
|
|
|
return NativeFuncs.godotsharp_hash(&variant);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 00:35:19 +01:00
|
|
|
public static Object InstanceFromId(ulong instanceId)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return InteropUtils.UnmanagedGetManaged(NativeFuncs.godotsharp_instance_from_id(instanceId));
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2018-07-21 23:40:34 +02:00
|
|
|
public static real_t Linear2Db(real_t linear)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-07-23 01:56:37 +02:00
|
|
|
return (real_t)(Math.Log(linear) * 8.6858896380650365530225783783321);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:32:19 +01:00
|
|
|
public static Resource Load(string path)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
|
|
|
return ResourceLoader.Load(path);
|
|
|
|
}
|
|
|
|
|
2018-10-05 15:32:33 +02:00
|
|
|
public static T Load<T>(string path) where T : class
|
2018-07-30 13:35:48 +02:00
|
|
|
{
|
2018-10-05 19:39:11 +02:00
|
|
|
return ResourceLoader.Load<T>(path);
|
2018-07-30 13:35:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PushError(string message)
|
2018-10-26 05:32:50 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(message);
|
|
|
|
NativeFuncs.godotsharp_pusherror(&godotStr);
|
2018-10-26 05:32:50 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PushWarning(string message)
|
2018-10-26 05:32:50 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(message);
|
|
|
|
NativeFuncs.godotsharp_pushwarning(&godotStr);
|
2018-10-26 05:32:50 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void Print(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
string str = string.Concat(GetPrintParams(what));
|
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
NativeFuncs.godotsharp_print(&godotStr);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:32:19 +01:00
|
|
|
public static void PrintStack()
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2017-11-21 23:32:19 +01:00
|
|
|
Print(System.Environment.StackTrace);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PrintErr(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
string str = string.Concat(GetPrintParams(what));
|
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
NativeFuncs.godotsharp_printerr(&godotStr);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PrintRaw(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
string str = string.Concat(GetPrintParams(what));
|
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
NativeFuncs.godotsharp_printraw(&godotStr);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PrintS(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
string str = string.Join(' ', GetPrintParams(what));
|
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
NativeFuncs.godotsharp_prints(&godotStr);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe void PrintT(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
string str = string.Join('\t', GetPrintParams(what));
|
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
NativeFuncs.godotsharp_printt(&godotStr);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 20:24:48 +02:00
|
|
|
public static float Randf()
|
2019-02-19 00:35:19 +01:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return NativeFuncs.godotsharp_randf();
|
2019-02-19 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static uint Randi()
|
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return NativeFuncs.godotsharp_randi();
|
2019-02-19 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Randomize()
|
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
NativeFuncs.godotsharp_randomize();
|
2019-02-19 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
public static double RandRange(double from, double to)
|
2019-02-19 00:35:19 +01:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return NativeFuncs.godotsharp_randf_range(from, to);
|
2020-07-26 12:52:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int RandRange(int from, int to)
|
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return NativeFuncs.godotsharp_randi_range(from, to);
|
2019-02-19 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
2021-07-28 15:23:22 +02:00
|
|
|
public static uint RandFromSeed(ref ulong seed)
|
2019-02-19 00:35:19 +01:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return NativeFuncs.godotsharp_rand_from_seed(seed, out seed);
|
2019-02-19 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
public static IEnumerable<int> Range(int end)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2019-02-19 18:30:25 +01:00
|
|
|
return Range(0, end, 1);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
public static IEnumerable<int> Range(int start, int end)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2019-02-19 18:30:25 +01:00
|
|
|
return Range(start, end, 1);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
public static IEnumerable<int> Range(int start, int end, int step)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2019-02-19 18:30:25 +01:00
|
|
|
if (end < start && step > 0)
|
|
|
|
yield break;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
if (end > start && step < 0)
|
|
|
|
yield break;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-02-19 18:30:25 +01:00
|
|
|
if (step > 0)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2019-02-19 18:30:25 +01:00
|
|
|
for (int i = start; i < end; i += step)
|
|
|
|
yield return i;
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-19 18:30:25 +01:00
|
|
|
for (int i = start; i > end; i += step)
|
|
|
|
yield return i;
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 00:35:19 +01:00
|
|
|
public static void Seed(ulong seed)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
NativeFuncs.godotsharp_seed(seed);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe string Str(params object[] what)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var whatGodotArray = Marshaling.mono_array_to_Array(what);
|
|
|
|
using godot_string ret = default;
|
|
|
|
NativeFuncs.godotsharp_str(&whatGodotArray, &ret);
|
2021-09-12 20:21:15 +02:00
|
|
|
return Marshaling.mono_string_from_godot(ret);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe object Str2Var(string str)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var godotStr = Marshaling.mono_string_to_godot(str);
|
|
|
|
using godot_variant ret = default;
|
|
|
|
NativeFuncs.godotsharp_str2var(&godotStr, &ret);
|
|
|
|
return Marshaling.variant_to_mono_object(&ret);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
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-05-03 15:21:06 +02:00
|
|
|
public static unsafe byte[] Var2Bytes(object var, bool fullObjects = false)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var variant = Marshaling.mono_object_to_variant(var);
|
|
|
|
using godot_packed_byte_array varBytes = default;
|
2021-09-12 20:23:05 +02:00
|
|
|
NativeFuncs.godotsharp_var2bytes(&variant, fullObjects.ToGodotBool(), &varBytes);
|
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-05-03 15:21:06 +02:00
|
|
|
using (varBytes)
|
|
|
|
return Marshaling.PackedByteArray_to_mono_array(&varBytes);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 19:50:13 +02:00
|
|
|
public static unsafe string Var2Str(object var)
|
2017-10-02 23:24:00 +02:00
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
using var variant = Marshaling.mono_object_to_variant(var);
|
|
|
|
using godot_string ret = default;
|
|
|
|
NativeFuncs.godotsharp_var2str(&variant, &ret);
|
2021-09-12 20:21:15 +02:00
|
|
|
return Marshaling.mono_string_from_godot(ret);
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
2018-09-04 05:40:41 +02:00
|
|
|
|
2020-03-14 19:20:17 +01:00
|
|
|
public static Variant.Type TypeToVariantType(Type type)
|
|
|
|
{
|
2021-09-12 19:50:13 +02:00
|
|
|
return Marshaling.managed_to_variant_type(type, out bool _);
|
2020-03-14 19:20:17 +01:00
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
}
|