Commit graph

5538 commits

Author SHA1 Message Date
Ignacio Roldán Etcheverry 50b603c7dc C#: Begin move to .NET Core
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.
2021-09-22 08:27:12 +02:00
Ignacio Roldán Etcheverry f744d99179 C#: Restructure code prior move to .NET Core
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.
2021-09-22 06:38:00 +02:00
Ignacio Roldán Etcheverry 3f1a620102 C#: Re-write GD and some other icalls as P/Invoke 2021-09-22 06:38:00 +02:00
Ignacio Roldán Etcheverry bbde1b1f09 C#: Re-write Array, Dictionary, NodePath, String icalls as P/Invoke 2021-09-12 19:49:39 +02:00
Ignacio Roldán Etcheverry 66a89c7925 C#: Remove DynamicGodotObject/Object.DynamicObject
We are moving in the direction of no dynamic code generation,
so this is no longer desired.

The feature can still be easily implemented by any project that
still want it.
2021-09-12 19:49:23 +02:00
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
Rémi Verschelde c0bdea6a67
Merge pull request #51859 from nekomatata/bullet-body-motion-fixes
Fixes in Bullet body_test_motion
2021-08-18 22:46:10 +02:00
PouleyKetchoupp 45bc97b8b8 Fixes in Bullet body_test_motion
Synchronize fixes from the 3.x branch to keep Bullet code in sync for
later, even if it's disabled for now.
2021-08-18 13:18:19 -07:00
Max Hilbrunner 5161c97c9c Remove underscore hacks
Way less cruft. :)

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
2021-08-17 16:10:28 +02:00
Max Hilbrunner 81f7d1890b Namespaces instead of underscore prefix for binds
Thanks to neikeq for the initial work.

Co-authored-by: Ignacio Roldán Etcheverry <neikeq@users.noreply.github.com>
2021-08-17 16:10:09 +02:00
Rémi Verschelde 21a0af2686
Merge pull request #51762 from nekomatata/fix-crash-gdscript-cache
Fix crash when failing to load script from cache
2021-08-17 13:34:07 +02:00
PouleyKetchoupp 9973bf93ed Fix crash when failing to load script from cache 2021-08-16 16:27:25 -07:00
Rémi Verschelde cfdac0973c
Merge pull request #51698 from Paulb23/text-editor-settings
Reorganise text editor settings
2021-08-16 18:48:58 +02:00
Paulb23 bcfc591f86 Reorganise text editor settings 2021-08-16 17:18:49 +01:00
Ignacio Roldán Etcheverry 5ea500e599 Fix C# native instance bindings after recent re-write
This was needed after: 4469144891
2021-08-16 17:16:36 +02:00
Ricard Rovira Cubeles a8d12b5a61 Add constant to vector function parameters that don't actually modify their input.
Add more overloads of vector multiplication, required by templates to compile with float=64.
2021-08-15 16:45:37 +02:00
Rémi Verschelde 81512a3732
Style: Cleanup code using text_editor/completion/use_single_quotes 2021-08-13 21:27:57 +02:00
Rémi Verschelde 9e37336124
Merge pull request #51508 from AndreaCatania/mem-placement
Refactors the memnew_placement.
2021-08-13 14:58:02 +02:00
Rémi Verschelde 85e315d6e8
Merge pull request #51607 from aaronfranke/includes
Fix some unnecessary includes
2021-08-13 14:38:56 +02:00
AndreaCatania 98ceb60eb4 Refactors the memnew_placement.
With this commit the macro `memnew_placement` uses the standard memory
placement syntax: `new (mem) TheClass()`, and removes the outdated and
not used syntax:
```
_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
```

Thanks to this change, the function `memnew_placement` call is compatible with
any class, and can also initialize classes with non-empty constructor:
```
// This is valid, like before.
memnew_placement(mem, Variant);

// This works too:
memnew_placement(mem, Variant(123));
```
2021-08-13 10:18:34 +02:00
Anilforextra d73d8b8d78 Fix duplicate conditions. 2021-08-13 12:22:38 +05:45
Aaron Franke eb4902a455
Fix some unnecessary includes 2021-08-13 00:27:38 -05:00
Aaron Franke 03e2544d50
Use real_t and double where appropriate in Particles 2021-08-12 11:35:31 -05:00
Rémi Verschelde c89ad92c96
Merge pull request #51532 from nekomatata/layer-mask-accessors
Uniformize layer names, script methods and documentation
2021-08-12 17:55:11 +02:00
PouleyKetchoupp 989acbbe81 Uniformize layer names, script methods and documentation
- Back to 1-based layer names to make it clearer in editor UI
- Layer bit accessors are renamed to layer value and 1-based too
- Uniform errors and documentation in render and physics
- Fix a few remaining collision_layer used in place of collision_mask
2021-08-12 08:06:42 -07:00
Rémi Verschelde 6e9439198c
Resource: Remove unused _use_builtin_script() virtual method
And another piece of dead code found while searching for "use_builtin".
2021-08-12 12:16:17 +02:00
Marcel Admiraal cf771342cb Fix multiple issues with CSGPolygon 2021-08-12 09:52:38 +01:00
PouleyKetchoupp f9176a39ce Make radius & height in CapsuleShape3D independent
Also changed CapsuleMesh to make settings consistent between render and
physics.
2021-08-11 14:54:53 -07:00
Rémi Verschelde a57d420224
Merge pull request #51500 from timothyqiu/navmesh-doc 2021-08-11 14:12:56 +02:00
Haoyu Qiu 60298328ca Improve NavigationMesh typing, parameter validation and documentation 2021-08-11 18:18:10 +08:00
Rémi Verschelde c00303ff55
Merge pull request #47378 from aaronfranke/use-input-enums
Use key enum instead of plain integers for input code
2021-08-11 11:20:45 +02:00
Rémi Verschelde 2c88e1c15d
Merge pull request #51178 from Geometror/layout-options-textline-textparagraph
Various text layout improvements (TextLine, TextParagraph, Label, TextServer)
2021-08-11 07:51:57 +02:00
Hendrik Brucker 403f4902d0 Various text layout improvements (TextLine, TextParagraph, Label, TextServer) 2021-08-11 00:09:48 +02:00
Aaron Franke fa3a32a2d6
Use Key enum instead of plain integers 2021-08-10 16:26:55 -05:00
K. S. Ernest (iFire) Lee 18bd0fee5a
Merge pull request #49343 from theoway/node_auto_arrangement_graph_edit
Node Auto Arrangement in GraphEdit/VisualScript/VisualShader
2021-08-10 15:42:04 -04:00
Umang Kalra 12fc3f1eef Automatic arrangement of nodes in VisualScript/VisualShaders editors
This PR and commit adds the functionality to arrange nodes in VisualScript/VisualShader editor. The layout generated by this 
feature is compact, with minimum crossings between connections
& uniform horizontal & vertical gaps between the nodes. 

This work has been sponsored by GSoC '21.

Full list of additions/changes:
• Added arrange_nodes() method in GraphEdit module.
    • This method computes new positions for all the selected
      nodes by forming blocks and compressing them.
      The nodes are moved to these new positions. 
    • Adding this method to GraphEdit makes it available for 
      use in VisualScript/VisualShaders editors and its other
      subclasses. 
• Button with an icon has been added to call arrange_nodes() in GraphEdit. 
    • This button is inherited by VisualScript/VisualShaders editors
       to invoke the method.
• Undo/redo is functional with this method.
    • By using signals in arrange_nodes(), position changes are registered 
       in undo/redo stack of the subclass that is using the method. 
• Metadata of the method has been updated in ClassDB
• Method description has been added to class reference of GraphEdit
2021-08-11 00:44:28 +05:30
kobewi e0572f7ef7 Fix crash when parsing Dictionary 2021-08-10 15:57:56 +02:00
Rémi Verschelde 50d5569ad4
Merge pull request #51457 from nekomatata/moving-platforms-3d
Fix 3D moving platform logic
2021-08-10 14:12:01 +02:00
PouleyKetchoupp ec9fed69f4 Fix 3D moving platform logic
Same thing that was already done in 2D, applies moving platform motion
by using a call to move_and_collide that excludes the platform itself,
instead of making it part of the body motion.

Helps with handling walls and slopes correctly when the character walks
on the moving platform.

Also made some minor adjustments to the 2D version and documentation.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-08-09 20:21:04 -07:00
Aaron Franke 430ad75963
Some work on double support 2021-08-09 17:43:48 -05:00
Rémi Verschelde c68b109f27
Merge pull request #51453 from Blackiris/fix-new-inherited-script
Fix infinite loop when creating a newly inherited GDScript file
2021-08-10 00:38:16 +02:00
Julien Nguyen 51b7179b5a Fix infinite loop when creating a newly inherited GdScript file 2021-08-09 23:52:31 +02:00
Rémi Verschelde 2de5d2361a
Merge pull request #51446 from nekomatata/fix-moving-platform-rotation
Fix applied rotation from moving platforms in move_and_slide
2021-08-09 23:20:44 +02:00
PouleyKetchoupp 5650c83e4b Fix applied rotation from moving platforms in move_and_slide
When synchronizing CharacterBody motion with moving the platform using
direct body state, only the linear velocity was taken into account.

This change exposes velocity at local point in direct body state and
uses it in move_and_slide to get the proper velocity that includes
rotations.
2021-08-09 12:30:17 -07:00
Aaron Franke 84f720966c
Use doubles for time in many other places 2021-08-09 14:05:42 -05:00
Rémi Verschelde 6e11017401
Merge pull request #51338 from V-Sekai/gltf-lights
Continue when glTF2 lights fail to parse.
2021-08-09 09:31:31 +02:00
Rémi Verschelde fa1a66dd68
Merge pull request #51180 from RandomShaper/native_script_inherits
Implement inherits_script() for NativeScript and PluginScript
2021-08-09 09:18:57 +02:00
K. S. Ernest (iFire) Lee 0c79a8fa22 Continue when glTF2 lights fail to parse. 2021-08-09 00:09:19 -07:00
bruvzg 7c3c5603d0 [Text Server] Improve object (image/table) inline alignment. 2021-08-08 22:35:47 +03:00
Rémi Verschelde 35b08b7cbc
Merge pull request #51322 from raulsntos/fix-msbuild-exception
Ensure MSBuildPanel buttons are instantiated
2021-08-07 12:19:26 +02:00