- `GodotSynchronizationContext`
- Implements `IDisposable` to dispose of the disposable field `_queue`.
- Makes the class sealed.
- `GodotTaskScheduler`
- Implements `IDisposable` to dispose of the disposable property `Context`.
- Makes the class sealed.
- `Dispatcher`
- Dispose of previous `GodotTaskScheduler` instances before creating a new one.
- Add overloads to print methods that take a single `string`.
- Use `StringBuilder` to append print parameters.
- Remove `PrintStack` method.
- Add `ErrorString`.
- Remove `Str` method.
- Add exception to `Range` when step is 0.
- Add `VarToBytesWithObjects` and `BytesToVarWithObjects`.
- Remove optional boolean parameter from `VarToBytes` and `BytesToVar`.
- Move `InstanceFromId` to `Godot.Object`.
- Add `Godot.Object.IsInstanceIdValid`.
- Update documentation.
- Add `float` and `double` overloads to all methods of `Mathf`.
This allows the methods to be usable with `float`, `double` or `real_t`.
- Use `System.MathF` in the `float` overloads which may result in
better performance.
- Constants remain as `real_t` for the time being.
- Add aggresive inlining for methods that wrap `System.Math` calls.
[codeblocks] for Keep only the [CSharp] part.
[param] is changed to <c>.
[b] for bold text.
[i] for italic text.
4.0 now uses variant, so [variant] to <see cref="Godot.Variant"/>.
since Rider does not support [u], only comments have been modified.
The editor will use .NET 7 if it is installed and fall back to .NET 6 otherwise.
Exported projects will use .NET 7 or .NET 6 depending on the value of TargetFramework in the csproj.
* Works for binary and text files.
* Makes EditorQuickOpen work with custom resources again.
* Information is cached and easily accessible.
Properly fixes#66179. Supersedes #66215 and supersedes #62417
**WARNING**: This required breaking backwards binary compatibility (.res and .scn files). Files saved after this PR is merged will no longer open in any earlier versions of Godot.
- Remove `Vector2.Lerp` overload that takes a weight parameter of type `Vector2`.
- Remove `Vector3.Lerp` overload that takes a weight parameter of type `Vector3`.
- Remove `Color.Lerp` overload that takes a weight parameter of type `Color`.
- Remove `Angle` method from `Vector2i`.
- Remove `AngleTo` method from `Vector2i`.
- Remove `AngleToPoint` method from `Vector2i`.
- Remove `Cross` method from `Vector2i`.
- Remove `DistanceSquaredTo` method from `Vector2i` and `Vector3i`.
- Remove `DistanceTo` method from `Vector2i` and `Vector3i`.
- Remove `Dot` method from `Vector2i` and `Vector3i`.
- Remove `PosMod` method from `Vector2i` and `Vector3i`.
- Remove `Orthogonal` method from `Vector2i`.
- Remove `&` operator from `Vector2i` and `Vector3i`.
Implement `Mathf.SinCos` that wraps a call to `System.Math.SinCos`,
this allows us to use the `SinCos` method more conveniently with
`real_t`.
Using `Math.SinCos` is often cheaper than separate calls to `Math.Sin`
and `Math.Cos`, and they are often used together.
- Add `Plane(Vector3)` constructor.
- Rename `IntersectRay` to `IntersectsRay`.
- Rename `IntersectSegment` to `IntersectsSegment`.
- Replace `Center` property with `GetCenter` method.
- Add and fix documentation about the _normal_ parameter
to Core and C# documentation.
- Remove `Transform3D(Quaternion, Vector3)` constructor from C#.
- Add `Transform3D(Projection)` constructor to C#.
- Add documentation to the `Transform3D(Projection)` constructor in Core.
- Add `Transform3D` constructor with only real_t params to C# that mirrors `Transform2D`.
- Expose `Basis` constructor with only real_t params in C#.
- Add `Transform2D(real_t, Vector2, real_t, Vector2)` constructor to C#.
- Replace `Rotation` property with `GetRotation` method in `Transform2D`.
- Replace `Scale` property with `GetScale` method in `Transform2D`.
- Replace `Scale` property with `GetScale` method in `Basis`.
Core does not expose set methods.
The `Length` and `LengthSquared` members are implemented as methods
in every other C# struct, `Quaternion` was the only one implementing
them as properties.
* Overrides no longer happen for set/get.
* They must be checked with a new function: `ProjectSettings::get_setting_with_override()`.
* GLOBAL_DEF/GLOBAL_GET updated to use this
This change solves many problems:
* General confusion about getting the actual or overriden setting.
* Feature tags available after settings are loaded were being ignored, they are now considered.
* Hacks required for the Project Settings editor to work.
Fixes#64100. Fixes#64014. Fixes#61908.
* Remove unused `EditorPropertyMember` and related hints, previouly used by
VisualScript. Such logic should be implemented in the VS module itself.
* As the above broke compatibility with the VS module, clean up the other
hacks that were still in core in support of VisualScript.
* `PROPERTY_USAGE_INTERNATIONALIZED` was only used in Object's
`get_translatable_strings()`, which is a legacy function not used anywhere.
So both are removed.
* Reordered some usage flags after the above removal to minimize the diff.
* General clean up.
Fixes#30203.
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.
It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).
We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).
Also fixed "cf." Frenchism - it's meant as "refer to / see".
- Avoid generic types in `ScriptPathAttributeGenerator`, this
means they won't be added to the `[AssemblyHasScripts]` attribute
and a `[ScriptPath]` attribute won't be added to the class.
Since generic classes can't be used as scripts they shouldn't use
those attributes, this also makes CSharpScript consider those types
invalid since they won't be added to the script/type map.
- Avoid generic types in `ScriptManagerBridge.LookupScriptsInAssembly`.
- Set `outMethodsDest` in `ScriptManagerBridge.UpdateScriptClassInfo`.
- Renamed `ConvertToX` to `ConvertToNativeX`.
- Renamed `ConvertToXObject` to `ConvertToX`.
- Renamed `ConvertToXManaged` to `ConvertToX`.
- Fix `Signal` name in bindings generator and csharp script.
ReadOnly properties are currently not allowed because the generated code
needs to set them, this also apply to `init` properties because they
need to be set after initialization.
Non-exhaustive list of case-sensitive renames:
GDExtension -> GDNative
GDNATIVE -> GDEXTENSION
gdextension -> gdnative
ExtensionExtension ->Extension (for where there was GDNativeExtension)
EXTENSION_EXTENSION ->EXTENSION (for where there was GDNATIVE_EXTENSION)
gdnlib -> gdextension
gdn_interface -> gde_interface
gdni -> gde_interface
This was a regression from 17b2838f39.
`MarshalUtils` was changed in the source generators to use
`ConvertTo<T>` and `CreateFrom<T>`, which don't support `GodotObject[]`
because it would need reflection.
As such, we need to keep the custom cases for `GodotObject[]` in
`MarshalUtils`.
- Exposes the properties of C# attribute so they can be accessed from
reflection, renaming them to PascalCase to follow .NET conventions.
- Added some documentation to the newly exposed members.
- Made attribute properties readonly to avoid giving the impression that
they could be modified.
This change aims to reduce the number of places that need to be changed
when adding or editing a Godot type to the bindings.
Since the addition of `Variant.From<T>/As<T>` and
`VariantUtils.CreateFrom<T>/ConvertTo<T>`, we can now replace a lot of
the previous code in the bindings generator and the source generators
that specify these conversions for each type manually.
The only exceptions are the generic Godot collections (`Array<T>` and
`Dictionary<TKey, TValue>`) which still use the old version, as that
one cannot be matched by our new conversion methods (limitation in the
language with generics, forcing us to use delegate pointers).
The cleanup applies to:
- Bindings generator:
- `TypeInterface.cs_variant_to_managed`
- `TypeInterface.cs_managed_to_variant`
- Source generators:
- `MarshalUtils.AppendNativeVariantToManagedExpr`
- `MarshalUtils.AppendManagedToNativeVariantExpr`
- `MarshalUtils.AppendVariantToManagedExpr`
- `MarshalUtils.AppendManagedToVariantExpr`
This commit replaces most usages of `ConvertManagedObjectToVariant` and
`ConvertVariantToManagedObjectOfType`, by using the `Godot.Variant`
struct instead of `System.Object`.
The most notable change is to the `GetGodotPropertyDefaultValues` method
that's generated for scripts. The dictionary it returns now stores
`Godot.Variant` values.
Remaining usages are:
- The `DelegateUtils` class, for the serialization of closure display
classes during assembly reloading by the editor. These display classes
are compiler generated classes to store values captured by a closure.
Since it's generated by the compiler, the only way we have to access
the fields is through reflection. This leads to using `System.Object`.
- Converting parameters when invoking constructors from the engine.
This will be replaced with source generators in the future.
- Legacy support for old `GetGodotPropertyDefaultValues` return values.
We need to keep supporting the old version of this generated method
for some time. Otherwise, if loading a project built with the previous
version, it could lead to the loss of exported property values.
Ideally, we should remove this legacy support before a stable release.
Its two usages were:
- The Array `ICollection.CopyTo` implementation.
It's possible that this class shouldn't be implementing the
non-generic `ICollection`, but this commit doesn't change that.
The new implementation stores the elements as boxed `Variant` values.
- The `Variant.Obj` property.
I'm not sure if this property's existence is justified, but for now
I rewrote it as a simpler version of `ConvertVariantToManagedObject`.
- Removed `UnicodeAt`
- Removed `EndsWith`
- Removed `LPad` and `RPad`
- Deprecated `BeginsWith` in favor of `string.StartsWith`
- Deprecated `LStrip` and `RStrip` in favor of `string.TrimStart` and `string.TrimEnd`
- Remove `VariantSpanDisposer`, no need to dispose of the Variant Spans
since we are now borrowing the Variants instead of copying them.
- Remove `VariantSpanExtensions.Cleared` that was only used so the
Span was initialized for `VariantSpanDisposer` to know what to dispose.
- Fix stackalloc Spans to use constant VarArgsSpanThreshold
and avoid bound checks.
- Replaced `MD5Buffer`, `MD5Text`, `SHA256Buffer` and `SHA256Text` implementation to use the `System.Security.Cryptography` classes and avoid marshaling.
- Added `SHA1Buffer` and `SHA1Text`.
- Renamed `ToUTF8` to `ToUTF8Buffer`.
- Renamed `ToAscii` to `ToASCIIBuffer`.
- Added `ToUTF16Buffer` and `ToUTF32Buffer`.
- Added `GetStringFromUTF16` and `GetStringFromUTF32`.
- Renamed `IsValidInteger` to `IsValidInt`.
- Added `IsValidFileName`.
- Added `IsValidHexNumber`.
- Added support for IPv6 to `IsValidIPAddress`.
- Added `ValidateNodeName`.
- Updated the documentation of the `IsValid*` methods.
- Moved `GetBaseName` to keep methods alphabetically sorted.
- Removed `Length`, users should just use the Length property.
- Removed `Insert`, string already has a method with the same signature that takes precedence.
- Removed `Erase`.
- Removed `ToLower` and `ToUpper`, string already has methods with the same signature that take precedence.
- Removed `FindLast` in favor of `RFind`.
- Replaced `RFind` and `RFindN` implemenation with a ca ll to `string.LastIndexOf` to avoid marshaling.
- Added `LPad` and `RPad`.
- Added `StripEscapes`.
- Replaced `LStrip` and `RStrip` implementation with a call to `string.TrimStart` and `string.TrimEnd`.
- Added `TrimPrefix` and `TrimSuffix`.
- Renamed `OrdAt` to `UnicodeAt`.
- Added `CountN` and move the `caseSensitive` parameter of `Count` to the end.
- Added `Indent` and `Dedent`.
These callbacks are used for marshaling by callables and generic Godot
collections.
C# generics don't support specialization the way C++ templates do.
I knew NativeAOT could optimize away many type checks when the types
are known at compile time, but I didn't trust the JIT would do as good
a job, so I initially went with cached function pointers.
Well, it turns out the JIT is also very good at optimizing in this
scenario, so I'm changing the methods to do the conversion directly,
rather than returning a function pointer for the conversion.
The methods were moved to `VariantUtils`, and were renamed from
`GetFromVariantCallback/GetToVariantCallback` to `ConvertTo/CreateFrom`.
The new implementation looks like it goes through many `if` checks
at runtime to find the right branch for the type, but in practice it
works pretty much like template specialization. The JIT only generates
code for the relevant branch. Together with inlining, the result is
very close or the same as doing the conversion manually:
```cs
godot_variant variant;
int foo = variant.Int;
int bar = VariantUtils.ConvertTo<int>(variant);
```
If the type is a generic Godot collection, the conversion still goes
through a function pointer call.
The new code happens to be much shorter as well, with the file going
from 1057 lines to 407.
Side note: `Variant.cs` was mistakenly created in the wrong folder,
so I moved it to the `Core` folder.
This allows using generic Godot collections as type arguments for other
generic Godot collections. This also allows generic Godot collections
as parameter or return type in dynamic Callable invocations.
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.
We use collectible AssemblyLoadContexts as that's the only way to allow
reloading assemblies after building. However, collectible assemblies
have some restrictions:
- https://learn.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/collectible-assemblies#restrictions-on-collectible-assemblies
Those restrictions can cause issues with third-party code, such as some
mocking libraries.
In order to work around this problem, we're going to load assemblies
as collectible only in Godot editor, and not when running games.
These issues will still exist in the editor, but this will be enough
for some users.
- Use `long` and `double` types since signals currently only support 64-bit types.
- Fix bug for checking if the type name is a class registered in ClassDB.
Ensures that the versions always match the Godot version, albeit following
SemVer 2.0 so inserting a dot between "beta" and the build number.
For "stable" status, we omit the suffix as this would be interpreted as a
pre-release build too.
So we have:
| Godot version | Nupkg version |
| -------------- | -------------- |
| 4.0.0-beta | 4.0.0-beta |
| 4.0.0-beta2 | 4.0.0-beta.2 |
| 4.0.0-rc1 | 4.0.0-rc.1 |
| 4.0.0-stable | 4.0.0 |
Android was the last platform to still attempt to disable RTTI (for binary
size), but both the Android editor and now the ICU library used by templates
need RTTI.
There could still be the possibility to support this for non-ICU template
builds (i.e. without the TextServerAdvanced module), but since this isn't one
of the build configurations we test regularly it's pretty risky to keep this
option only for that specific use case. And our code is already littered with
`dynamic_cast`s which weren't guarded with `!defined(NO_SAFE_CAST)`.
If the delegate target is an Object, the connected signal will be registered in that object instead of the middleman. So when that object is destroyed, the signal will be properly disconnected.
Implements https://github.com/godotengine/godot-proposals/issues/3371.
New `target` presets
====================
The `tools` option is removed and `target` changes to use three new presets,
which match the builds users are familiar with. These targets control the
default optimization level and enable editor-specific and debugging code:
- `editor`: Replaces `tools=yes target=release_debug`.
* Defines: `TOOLS_ENABLED`, `DEBUG_ENABLED`, `-O2`/`/O2`
- `template_debug`: Replaces `tools=no target=release_debug`.
* Defines: `DEBUG_ENABLED`, `-O2`/`/O2`
- `template_release`: Replaces `tools=no target=release`.
* Defines: `-O3`/`/O2`
New `dev_build` option
======================
The previous `target=debug` is now replaced by a separate `dev_build=yes`
option, which can be used in combination with either of the three targets,
and changes the following:
- `dev_build`: Defines `DEV_ENABLED`, disables optimization (`-O0`/`/0d`),
enables generating debug symbols, does not define `NDEBUG` so `assert()`
works in thirdparty libraries, adds a `.dev` suffix to the binary name.
Note: Unlike previously, `dev_build` defaults to off so that users who
compile Godot from source get an optimized and small build by default.
Engine contributors should now set `dev_build=yes` in their build scripts or
IDE configuration manually.
Changed binary names
====================
The name of generated binaries and object files are changed too, to follow
this format:
`godot.<platform>.<target>[.dev][.double].<arch>[.<extra_suffix>][.<ext>]`
For example:
- `godot.linuxbsd.editor.dev.arm64`
- `godot.windows.template_release.double.x86_64.mono.exe`
Be sure to update your links/scripts/IDE config accordingly.
More flexible `optimize` and `debug_symbols` options
====================================================
The optimization level and whether to generate debug symbols can be further
specified with the `optimize` and `debug_symbols` options. So the default
values listed above for the various `target` and `dev_build` combinations
are indicative and can be replaced when compiling, e.g.:
`scons p=linuxbsd target=template_debug dev_build=yes optimize=debug`
will make a "debug" export template with dev-only code enabled, `-Og`
optimization level for GCC/Clang, and debug symbols. Perfect for debugging
complex crashes at runtime in an exported project.
Ensures the `push_nupkgs_local` argument in build_assemblies.py is an
absolute path so the argument can be
given as a relative path and it will be converted.
- Creates a `Godot.Offline.Config` file to configurate NuGet with
Godot's fallback folder. This is easier because now we can assume we can
override the entire file since user config will likely be in the default
`NuGet.Config` file or an additional `*.config` file.
- Ensure the NuGet fallback folder is created at the same time it is
added to the NuGet configuration so future builds don't fail.
- Add `GodotSharp` and `GodotSharpEditor` packages to the fallback folder.
- Add `.nupkg.metadata` file to packages in fallback folder.
- Refer to `Godot.SourceGenerators` using the specific non-floating version
since floating versions don't seem to work with fallbackPackageFolders.
We want to replace libnethost as it gives us issues with some compilers.
Our implementation tries to mimic libnethost's hostfxr_resolver search
logic. We try to use the same function names for easier comparing in
case we need to update this in the future.