Commit Graph

64 Commits (1696c8315454d092630d6f38a9752e37d1ac5fd8)

Author SHA1 Message Date
Fabio Alessandrelli 78cbae910d Fix "_instance_bindings != nullptr" for Wrapped objects.
This is an attempt to make the lifecycle of wrapped objects clearer.
Godot keeps track of bindings' userdata for each object it creates.
This allows allocating the memory of the wrapper only once per object
even if that object is passed multiple times between binding code and
godot code.

The binding information is composed of multiple functions, this includes
a callback for when the userdata is to be allocated (called once) and
for when the userdata is to be deallocated (again, called once).

When allocating data with "memnew" we set the object bindings during the
postinitialize phase, but surely we shouldn't do that when allocating
the userdata as a result of bindings callback themselves.

Additionally, since we let Godot handle (and track) raw memory
allocation and de-allocation, we need to manually call the deconstructor
of the wrapper class during the free callback, to ensure that its
non-trivial members are correctly de-initialized.
2022-07-29 02:36:12 +02:00
Fabio Alessandrelli 8d4de1b537
Merge pull request #677 from lukas-toenne/fix_object_ptr_args
Fixed pointer indirection in the PtrToArg template for Object arguments.
2022-07-29 01:17:34 +02:00
Rémi Verschelde 1632322ce0 Update copyright year 2022-03-15 10:17:53 +01:00
Marc Gilleron 6fdcb18f6a Fix GDCLASS when inherited class is in another namespace 2022-02-20 19:33:00 +00:00
Lukas Tönne 836cc4d3dc Fix for pointer indirection in the Ref<T> template.
Patch by Nana Sakisaka (saki7).
2022-01-07 09:20:05 +01:00
Gilles Roudière adbbf1a3a1 Fix object_set_instance being wrongly called for built-in wrapped classes 2021-12-06 15:40:19 +01:00
Gilles Roudière 3fcb8a4d1e Make extension instances create the corresponding godot object in their constructor 2021-12-03 15:37:49 +01:00
Bastiaan Olij ef528d3a86 Rename interface to gdn_interface because it's a defined keyword under windows 2021-10-28 19:44:20 +11:00
Fabio Alessandrelli b90d0ac555 Add Ref<T> binding support.
Added PtrToArg and GetTypeInfo adapted from Godot.
2021-09-28 15:49:08 +02:00
Bastiaan Olij fad6329699 Implement Ref copy constructor 2021-09-27 23:08:12 +10:00
Fabio Alessandrelli b4632e317d Fix creation (and godot-side deletion) of extended objects.
Proper initialization for godot-cpp classes with memnew.

Extension classes (i.e. the `GDCLASS` macro) behave differently from
regular wrapped classes, and requires Godot to initialize them during
object construction.

This commit update the GDCLASS macro to not create/destroy the instance
during the bindings callback, but during the extension callbacks.

When setting the object instance, the bindings instance is set to the
pointer of the extension instance so that it can later be retrieved
normally via `object_get_instance_bindings`.
2021-09-27 23:08:11 +10:00
George Marques 38ee8bfcf7 Change constructor/destructor management of extension classes
This makes sure custom constructors are always called on extension
classes. However, note that constructors should not take any parameters,
since Godot doesn't support that. Parameters are ignore in memnew macro.

Use memnew(MyClass()) instead of memnew(MyClass) since it now needs a
value instead of a class name. This macro calls MyClass::_new() (define
in GDCLASS macro) which ultimately calls Godot to create the object,
ensuring that both the Godot and the extension instances are created.

Non Godot classes (that don't derive godot::Object) are constructed as
usual an can have parameters.

memdelete is also changed for the same reason, as it needs to destroy
the Godot object as well, and that automatically frees the bound
extension instance.
2021-09-27 23:08:11 +10:00
George Marques a0634cca3f Auto-bind virtual method overrides 2021-09-27 23:08:08 +10:00
George Marques e4ed48976a Replace bindgins to work with extensions 2021-09-27 23:08:08 +10:00