summaryrefslogtreecommitdiffstats
path: root/modules/mono/csharp_script.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge pull request #76659 from ↵Yuri Sizov2023-05-191-0/+6
|\ | | | | | | | | shana/shana/75152-fix-crash-when-initializing-glue-generation Skip initializing the C# runtime when generating glue bindings
| * Skip initializing the C# runtime when generating glue bindingsAndreia Gaita2023-05-181-0/+6
| | | | | | | | | | | | | | | | | | The bindings generator doesn't require the C# runtime in order to generate the glue, and when it the glue generation runs, it exits immediately afterwards, so we can skip this initialization when the `--generate-mono-glue` flag is passed in. Fixes issue 75152
* | Merge pull request #72288 from MewPurPur/use-string-repeatClay John2023-05-051-6/+1
|\ \ | |/ |/| Use `String.repeat()` to optimize several String methods
| * Use String.repeat() in more placesVolTer2023-05-011-6/+1
| |
* | Fix "hides member" warnings in `csharp_script.cpp`Ninni Pipping2023-03-251-66/+66
| |
* | Prevent crashing on startup if project has scripted theme typesYuri Sizov2023-03-081-8/+0
| | | | | | | | Also avoid order of operation conflicts by moving C# binding generation hook to main.cpp
* | Validate that C# class names are valid identifiersAleks Rutins2023-03-041-0/+5
| |
* | C#: Fix crash when errors occur before language initialization.RedworkDE2023-03-011-1/+3
| |
* | Remove unused `ScriptLanguage` methodsvoidedWarranties2023-02-261-5/+0
| |
* | [macOS] Replace all `Alt/Option+Letter/Number` default shortcuts to avoid ↵bruvzg2023-02-201-0/+1
| | | | | | | | conflicts with special character input.
* | C#: Rename `Object` to `GodotObject`Raul Santos2023-01-271-1/+1
| |
* | C#: Renames to follow .NET naming conventionsRaul Santos2023-01-271-28/+34
|/ | | | Renamed C# types and members to use PascalCase and follow .NET naming conventions.
* Support script global resource name in EditorFileSystemJuan Linietsky2023-01-211-0/+4
| | | | | | | | | | * 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.
* C#: Move `GLOBAL_DEF`s to CSharpLanguage ctorRaul Santos2023-01-181-0/+5
| | | | Also documents the .NET project settings.
* Refactor ProjectSetting overridesJuan Linietsky2023-01-131-1/+1
| | | | | | | | | | | | | * 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.
* One Copyright Update to rule them allRémi Verschelde2023-01-051-29/+29
| | | | | | | | | | | | | | | | | | | | 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".
* C#: Rename `ConvertToX` methodsRaul Santos2022-12-231-1/+1
| | | | | | | - Renamed `ConvertToX` to `ConvertToNativeX`. - Renamed `ConvertToXObject` to `ConvertToX`. - Renamed `ConvertToXManaged` to `ConvertToX`. - Fix `Signal` name in bindings generator and csharp script.
* C#: Add note about the class name in instantiate errorRaul Santos2022-12-171-1/+1
| | | | | Adds a note about the requirement that a C# class name must match the script filename in which the they are defined to the instantiate error.
* Rename all gdnative occurences to gdextensionGilles Roudière2022-12-121-3/+3
| | | | | | | | | | | | | 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
* Merge pull request #67023 from raulsntos/dotnet/fix-signal-callback-generationIgnacio Roldán Etcheverry2022-12-021-7/+7
|\ | | | | C#: Fix signature of generated signal callbacks
| * C#: Fix signature of generated signal callbacksRaul Santos2022-10-071-7/+7
| | | | | | | | | | - 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.
* | Use forward-declarations in big editor classestrollodel2022-11-291-0/+1
| |
* | C#: Load assemblies as collectible only in the Godot editorIgnacio Roldán Etcheverry2022-10-171-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | GDScript/C#: Tweak error message for invalid script type for objectRémi Verschelde2022-10-041-2/+2
|/ | | | See #66870.
* Rename and expose `RefCounted::get_reference_count()`Marc Gilleron2022-09-211-4/+4
|
* C#: Fix module builds for Windows 32-bit with mingw-w64Ignacio Roldán Etcheverry2022-09-081-41/+48
| | | | The lambda was giving issues, so I re-wrote it as a static function.
* Merge pull request #65266 from raulsntos/dotnet/reload-non-tool-scriptsRémi Verschelde2022-09-051-5/+39
|\ | | | | | | Create script instance of reloaded scripts even if they're not tools
| * C#: Create script instance of reloaded scripts even if they're not toolsRaul Santos2022-09-041-5/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Scripts that are instantiated at some point will always be recreated if they ever become placeholders to prevent non-tool scripts instantiated manually by users to become placeholders, if they do become placeholders due to errors that prevent instantiation (such as a missing parameterless constructor) these scripts will also be recreated replacing the temporary placeholder. If a script is marked as a tool but becomes a non-tool script in a rebuild, the script will become a placeholder and will no longer be considered applicable to be replaced by an instance since the user explicitly removed the Tool attribute.
* | C#: Connect only once for each signal of a scriptRaul Santos2022-09-031-12/+8
|/ | | | | | | Since the list of signals in `CSharpScript::event_signals` retrieved from calling `ScriptManagerBridge.UpdateScriptClassInfo` already includes the signals from base scripts there is no need to iterate the hierarchy again on `CSharpInstance::connect_event_signals`.
* Rename String `plus_file` to `path_join`Aaron Franke2022-08-291-2/+2
|
* C#: Replace P/Invoke with delegate pointersIgnacio Roldán Etcheverry2022-08-221-14/+5
| | | | | | | | | | | | | | | | - Moves interop functions to UnmanagedCallbacks struct that contains the function pointers and is passed to C#. - Implements UnmanagedCallbacksGenerator, a C# source generator that generates the UnmanagedCallbacks struct in C# and the body for the NativeFuncs methods (their implementation just calls the function pointer in the UnmanagedCallbacks). The generated methods are needed because .NET pins byref parameters of native calls, even if they are 'ref struct's, which don't need pinning. The generated methods use `Unsafe.AsPointer` so that we can benefit from byref parameters without suffering overhead of pinning. Co-authored-by: Raul Santos <raulsntos@gmail.com>
* C#: Use custom project setting for C# project files nameIgnacio Roldán Etcheverry2022-08-221-14/+9
| | | | | | | | | The setting is initially assigned the name of the Godot project, but it's kept freezed to prevent issues when renaming the Godot project. The user can always rename the C# project and solution manually and change the setting to the new name.
* C#: Add dedicated Variant struct, replacing System.ObjectIgnacio Roldán Etcheverry2022-08-221-1/+1
|
* C#: Add source generator for method listIgnacio Roldán Etcheverry2022-08-221-51/+58
|
* C#: Add source generator for signals as eventsIgnacio Roldán Etcheverry2022-08-221-39/+71
| | | | | | | | | Changed the signal declaration signal to: ``` // The following generates a MySignal event [Signal] public delegate void MySignalEventHandler(int param); ```
* C#: Re-implement assembly reloading with ALCsIgnacio Roldán Etcheverry2022-08-221-243/+108
|
* C#: Initial NativeAOT supportIgnacio Roldán Etcheverry2022-08-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds initial support for games exported as NativeAOT shared libraries. At this moment, the NativeAOT runtime is experimental. Additionally, Godot is not trim-safe as it still makes some use of reflection. For the time being, a rd.xml file is needed to prevent code triming: ``` <Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata"> <Application> <Assembly Name="GodotSharp" Dynamic="Required All" /> <Assembly Name="GAME_ASSEMBLY" Dynamic="Required All" /> </Application> </Directives> ``` These are the csproj changes for publishing: ``` <PropertyGroup> <NativeLib>Shared</NativeLib> </PropertyGroup> <ItemGroup> <RdXmlFile Include="rd.xml" /> <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" /> </ItemGroup> ``` More info: - https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/compiling.md - https://github.com/dotnet/runtimelab/tree/feature/NativeAOT/samples/NativeLibrary - https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/rd-xml-format.md
* C#: Re-introduce exception logging and error stack traces in editorIgnacio Roldán Etcheverry2022-08-221-77/+5
| | | | | These two had been disabled while moving to .NET 5, as the previous implementation relied on Mono embedding APIs.
* C#: Ensure we only create one CSharpScript per typeIgnacio Roldán Etcheverry2022-08-221-15/+35
| | | | | | | | Previously, for each scripts class instance that was created from code rather than by the engine, we were constructing, configuring and assigning a new CSharpScript. This has changed now and we make sure there's only one CSharpScript associated to each type.
* C#: Add source generator for properties and exports default valuesIgnacio Roldán Etcheverry2022-08-221-455/+68
| | | | | | | | | | | | | | The editor no longer needs to create temporary instances to get the default values. The initializer values of the exported properties are still evaluated at runtime. For example, in the following example, `GetInitialValue()` will be called when first looks for default values: ``` [Export] int MyValue = GetInitialValue(); ``` Exporting fields with a non-supported type now results in a compiler error rather than a runtime error when the script is used.
* C#/netcore: Add base desktop game export implementationIgnacio Roldán Etcheverry2022-08-221-23/+16
| | | | | | | | | This base implementation is still very barebones but it defines the path for how exporting will work (at least when embedding the .NET runtime). Many manual steps are still needed, which should be automatized in the future. For example, in addition to the API assemblies, now you also need to copy the GodotPlugins assembly to each game project.
* C#: Ensure native handles are freed after switch to .NET CoreIgnacio Roldán Etcheverry2022-08-221-0/+1
| | | | | | | | | Finalizers are longer guaranteed to be called on exit now that we switched to .NET Core. This results in native instances leaking. The only solution I can think of so far is to keep a list of all instances alive to dispose when the AssemblyLoadContext.Unloading event is raised.
* C#: Code cleanup and greatly reduce use of C# pointersIgnacio Roldán Etcheverry2022-08-221-1/+1
|
* C#: Begin move to .NET CoreIgnacio Roldán Etcheverry2022-08-221-296/+101
| | | | | | | | | | | | 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.
* C#: Restructure code prior move to .NET CoreIgnacio Roldán Etcheverry2022-08-221-802/+509
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* C#: Re-write GD and some other icalls as P/InvokeIgnacio Roldán Etcheverry2022-08-221-13/+8
|
* C#: Re-write Array, Dictionary, NodePath, String icalls as P/InvokeIgnacio Roldán Etcheverry2022-08-221-1/+1
|
* C#: Move marshaling logic and generated glue to C#Ignacio Roldán Etcheverry2022-08-221-21/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Make `property_*_revert` methods multilevel and expose them for scriptingYuri Sizov2022-08-181-0/+70
|
* Removed faulty function update after get_property_list.Hristo Stamenov2022-08-031-11/+34
| | | | The function tried to rearrange properties but that lead to problems with duplication or deleted properties. Implemented the logic that that function did inside the get_property_list both for tool scripts and non-tool scripts.