Commit graph

58 commits

Author SHA1 Message Date
David Snopek 4d0b989bb8 Allow registering "runtime classes" in modules (not just GDExtension) 2024-02-22 14:50:41 -06:00
David Snopek ea75307a11 Allow registering "runtime classes" 2024-02-20 09:20:58 -06:00
Rémi Verschelde 306dd5be3f
Merge pull request #87758 from dsnopek/gdextension-register-virtual-method
Allow GDExtensions to register virtual methods and call them on scripts
2024-02-12 23:29:37 +01:00
David Snopek be11002e41 Allow GDExtensions to register virtual methods and call them on scripts 2024-02-12 13:29:18 -06:00
vittorioromeo 55ed34e37c Use '_v' shorthand for type traits and 'if constexpr' where appropriate 2024-02-02 15:43:21 +01:00
Pedro J. Estébanez a1d8fc1af9 Polish & fix editor help cache generation
- Isolated the generation of extensions's docs. They're now not cached and refreshed as needed.
- Removed superfluous sorting of the class list.
- Removed some superfluous/unused elements.
- Renamed some items for clarity.
2023-11-02 13:46:37 +01:00
Rémi Verschelde 017541bcec
Merge pull request #80527 from raulsntos/dotnet/generate-compat-methods-from-classdb
C#: Generate and use compat methods
2023-09-26 13:44:52 +02:00
David Snopek 2733a6f762 Implement reloading of GDExtensions 2023-09-25 22:10:17 -05:00
Raul Santos 5f6082a96b
C#: Generate and use compat methods
- Implements `ClassDB::get_method_list_with_compatibility` to retrieve all methods from a class including compat methods.
- C# bindings generator now also generates compat methods.
- All generated C# methods now use `ClassDB::get_method_with_compatibility`.
2023-09-19 20:35:11 +02:00
A Thousand Ships 893f889d74 [Core] Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable 2023-09-11 19:45:49 +02:00
Daylily-Zeleen 41ffe5461f Allow GDExtension to register unexposed class. 2023-09-04 10:18:20 +08:00
A Thousand Ships c638238fae Add check to ensure registered classes are declared
Checks that all classes registered to `ClassDB` have been properly
declared with `GDCLASS`
2023-08-28 12:16:49 +02:00
Pedro J. Estébanez cac4d44cde Re-enable docs cache with fixes 2023-07-05 10:44:58 +02:00
Juan Linietsky d8078d3f4c Add a backwards-compatibility system for GDExtension method
This adds a way to ensure that methods that were modified in the Godot API will continue working in older builds of GDExtension even if the new signature is different.

```C++
// New version (changed)
ClassDB::bind_method(D_METHOD("add_sphere","radius","position"),&MyShapes::add_sphere);
// Compatibility version (still available to extensions).
ClassDB::bind_compatibility_method(D_METHOD("add_sphere","radius"),&MyShapes::_compat_add_sphere);
```

**Q**: If I add an extra argument and provide a default value (hence can still be called the same), do I still have to provide the compatibility version?
**A**: Yes, you must still provide a compatibility method. Most language bindings use the raw method pointer to do the call and process the default parameters in the binding language, hence if the actual method signature changes it will no longer work.

**Q**: If I removed a method, can I still bind a compatibility version even though the main method no longer exists?
**A**: Yes, for methods that were removed or renamed, compatibility versions can still be provided.

**Q**: Would it be possible to automate checking that methods were removed by mistake?
**A**: Yes, as part of a future PR, the idea is to add a a command line option to Godot that can be run like : `$ godot --test-api-compatibility older_api_dump.json`, which will also be integrated to the CI runs.
2023-05-15 12:05:40 +02:00
Pedro J. Estébanez e1ce0340b7 Improve reliability of editor docs cache 2023-04-25 11:40:56 +02:00
Pedro J. Estébanez 0bcc7bb5c7 Avoid losing references to objects in the native-scripting boundary 2023-02-03 17:48:41 +01:00
Rémi Verschelde 1816f49886
Merge pull request #64253 from heppocogne/Fix-native-enum-release-1
Register enum type names in release build
2023-01-06 00:10:31 +01:00
Rémi Verschelde d95794ec8a
One Copyright Update to rule them all
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".
2023-01-05 13:25:55 +01:00
heppocogne 6f31f7b0bc Register native base class name of enum types when release build 2022-12-30 00:30:18 +09:00
Gilles Roudière be1c9d677d Rename all gdnative occurences to gdextension
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
2022-12-12 11:04:57 +01:00
reduz 0351a0908f Clean-up array editing 2022-08-02 23:36:02 +02:00
reduz 6236a688b7 Implement Feature Build Profiles
This PR is a continuation of #50381 (which was implemented exactly a year ago!)

* Add a visual interface to select which classes should not be built into Godot (well, they are built if something else uses them, but if not used the optimizer will remove them out).
* Add a detection system to scan the project and figure out the actual classes used.
* Added the ability for SCons to load build profiles.

Obligatory Screen:

A simple test with a couple of nodes in the scene resulted in a 25% reduction for the final binary size

TODO:

* Script languages need to implement used class detection (left for another PR).
* Options to disable servers or server functionalities (like 2D or 3D physics, navigation, etc). Are missing, that should also greatly aid in reducing binary size.
* Options to disable some modules would be desired.
* More options to disable drivers (OpenGL, Vulkan, etc) would be desired.

In general this PR is a starting point for more contributors to improve and enhance this functionality.
2022-07-22 10:53:23 +02:00
reduz 5ac42cf576 Implement a BitField hint
Allows to specify the binder that an enum must be treated as a bitfield.
2022-07-05 22:13:37 +02:00
bruvzg 860e24683f
Make enum/constant binds 64-bit. 2022-06-17 16:36:26 +03:00
reduz 45af29da80 Add a new HashSet template
* Intended to replace RBSet in most cases.
* Optimized for iteration speed
2022-05-20 22:40:38 +02:00
reduz 746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +02:00
kobewi 6f0b63f794 Change D_METHOD to variadic template 2022-04-30 17:30:33 +02:00
George Marques 62ad18a3a1
Remove argument name strings from release builds
They are not needed in release, so we can remove them to reduce the
binary size.
2022-04-05 20:40:07 -03:00
Rémi Verschelde f8ab79e68a Zero initialize all pointer class and struct members
This prevents the pitfall of UB when checking if they have been
assigned something valid by comparing to nullptr.
2022-04-04 19:49:50 +02:00
Rémi Verschelde 5371009d8e Object: Remove unused category boilerplate
We might want to re-add something like this if/when we find a good use case
for it and do the effort to categorize all objects in the API properly.

Until then, it's better to remove that boilerplate since it's not needed.

Closes #18711.
2022-03-26 15:46:01 +01:00
reduz 2f651277da Add static method support to ClassDB
* Based on the work done for Variant in the past.
* Added `ClassDB::bind_static_method`
* Cleaned up ClassDB::bind_method to use variadic templates.

This adds support for having static methods in Object derived classes.
Note that this does not make it work yet in GDScript or Mono and, while it works for GDExtension, GodotCPP needs to be updated.
2022-03-22 16:27:34 +01:00
reduz 8b547331be Create GDExtension clases for PhysicsServer3D
* Allows creating a GDExtension based 3D Physics Server (for Bullet, PhysX, etc. support)
* Some changes on native struct binding for PhysicsServer

This allows a 3D Physics server created entirely from GDExtension. Once it works, the idea is to port the 2D one to it.
2022-03-15 18:39:31 +01:00
reduz 6f51eca1e3 Discern between virtual and abstract class bindings
* Previous "virtual" classes (which can't be instantiated) are not corretly named "abstract".
* Added a new "virtual" category for classes, they can't be instantiated from the editor, but can be inherited from script and extensions.
* Converted a large amount of classes from "abstract" to "virtual" where it makes sense.

Most classes that make sense have been converted. Missing:

* Physics servers
* VideoStream
* Script* classes.

which will go in a separate PR due to the complexity involved.
2022-03-10 12:28:11 +01:00
Yuri Sizov 107b6f299c Reorganize inspector layout workflow for Control nodes 2022-02-10 20:29:34 +03:00
Rémi Verschelde fe52458154
Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
Gilles Roudière 4fc0fb826a Change gdnative interface so that Godot object initialization should be triggered from the extension side 2021-11-30 16:55:48 +01:00
Gilles Roudière a51f92273a Remove ItemList editor and replace it by a property array 2021-10-28 10:16:51 +02:00
Rémi Verschelde b48c6418fe
Merge pull request #52293 from neikeq/class-db-api-type-bug
Fix ClassDB API type mismatch bug between --editor and player
2021-10-12 22:34:21 +02:00
George Marques fafa8c7f6e
Enable method type information on release builds
This is needed to ensure GDScript compilation works properly on release
builds and make use of optimized typed instructions.
2021-10-07 16:13:44 -03:00
Fabio Alessandrelli f9ce9a8e10 [ClassDB] Unify construct/extension retrieval. 2021-09-22 18:33:29 +02:00
Fabio Alessandrelli f724bd1880 [Core] Add ClassDB functions to retrieve/construct extensions.
Calling the constructor alone is not enough if the class to be
instantiated is not a base class.

This commit adds two functions, one for retrieving the the extension
class reference, the other to construct an instance using the
constructor and the extension class reference.
2021-09-22 17:46:08 +02:00
Gilles Roudière 4bd7700e89 Implement properties arrays in the Inspector. 2021-09-07 09:51:28 +02:00
Ignacio Roldán Etcheverry cca26cc83f Fix ClassDB API type mismatch bug between --editor and player
There are two ways a class can be added to ClassDB:

- `A`: When an instance of the class is created for the first time. When
  this happends the class is not registered/exposed to scripts.
- `B`: When calling `GDREGISTER_CLASS(ClassName)` or similar. When this
  happens the class is registered/exposed to scripts.

ClassDB has an API type property to differentiate between the core
and editor APIs. Up until now the API type was determined whenever
the class is added to ClassDB (either `A` or `B`).

The problem comes when a class is instantiated (`A`) before
being registered (`B`).
If at this point the current defined API is not the same as when the
class is later registered, this will result in a mismatch between
`--editor` and non-editor apps.
This is specially bad for C# as it makes the editor player abort.

This was happening with `EditorPaths` which, while being registered
during the editor API classes registrations, it was also being
instantiated earlier when running the editor or the project manager,
via a call to `EditorPaths::create()`. This regression was introduced
in 1074017f04.

This commit fixes this simply by re-assigning the class API type when
the class is registered (`B`).
This is correct because API type describes registered/exposed classes.
It shouldn't cause any regressions as the API type should not be
accessed of classes that are not (or not yet) registered/exposed.

Code locations for reference:
- Method to add a class to ClassDB: `ClassDB::_add_class2`
- Code that adds classes to ClassDB post first initialization (`A`):
  `memnew` macros -> `Object::_postinitialize` ->
  `Object::initialize_class` -> `ClassDB::_add_class2`.
- Code adds class to ClassDB and registers/exposes it to scripts:
  `GDREGISTER_CLASS` macros -> `ClassDB::register_class<T>` ->
  `Object::initialize_class` -> `ClassDB::_add_class2`.
2021-08-31 22:35:32 +02:00
reduz 96f8254b24 Implement error return documetation
Adds ability to add error return documetation to the binder and class reference.
Usage example:

```C++
void MyClass::_bind_method() {
	[..]
	BIND_METHOD_ERR_RETURN_DOC("load", ERR_FILE_CANT_OPEN, ERR_FILE_UNRECOGNIZED);
}
```

One function of ConfigFile was changed as example.
2021-08-24 15:28:29 -03:00
reduz 5cecdfa8af Entirely removes BIND_VMETHOD in favor of GDVIRTUAL
* `_gui_input`, `_input`, `_unhandled_input` and `_unhandled_key_input` are now regular C++ virutal functions.
* Everything else converted to GDVIRTUAL
* BIND_VMETHOD is gone, always use the new syntax from now on.

Creating `_gui_input` method and using the binder to register events will no longer work, simply override the virtual function now.
2021-08-23 08:10:13 -03:00
reduz 3682978aee Replace BIND_VMETHOD by new GDVIRTUAL syntax
* New syntax is type safe.
* New syntax allows for type safe virtuals in native extensions.
* New syntax permits extremely fast calling.

Note: Everything was replaced where possible except for `_gui_input` `_input` and `_unhandled_input`.
These will require API rework on a separate PR as they work different than the rest of the functions.

Added a new method flag METHOD_FLAG_OBJECT_CORE, used internally. Allows to not dump the core virtuals like `_notification` to the json API, since each language will implement those as it is best fits.
2021-08-22 08:23:58 -03:00
PouleyKetchoupp 645bc94bfc Fix capsule height/radius setters with linked properties
Capsule height and radius setters can modify each other, rather than
using clamping, to avoid cases where values are not set correctly when
loading a scene (depending on the order of properties).

Inspector undo/redo:
Added the possibility to link properties together in the editor, so
they can be undone together, for cases where a property can modify
another one.

Gizmo undo/redo:
Capsule handles pass both radius and height values so they can be undone
together.
2021-08-19 10:31:19 -07: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
George Marques 626c0b6905
Add a instance callback for extensions
This sends the Godot object instance back to the extension so they can
keep a pointer for function calls.

Incidentally fix argument order on instance bindings callback for free()
2021-08-05 14:56:13 -03:00
reduz 32b43cfeb3 Implement Resource UIDs
* Most resource types now have unique identifiers.
* Applies to text, binary and imported resources.
* File formats reference both by text and UID (when available). UID always has priority.
* Resource UIDs are 64 bits for better compatibility with the engine.
* Can be represented and used textually, example `uuid://dapwmgsmnl28u`.
* A special binary cache file is used and exported, containing the mappings.

Example of how it looks:

```GDScript
[gd_scene load_steps=2 format=3 uid="uid://dw86wq31afig2"]

[ext_resource type="PackedScene" uid="uid://bt36ojelx8q6c" path="res://subscene.scn" id="1_t56hs"]
```

GDScript, shaders and other special resource files can't currently provide UIDs, but this should be doable with special keywords on the files.
This will be reserved for future PRs.
2021-07-24 09:16:52 -03:00