-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bind Array and Packed*Array get
and set
functions
#95930
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes sense to me!
For the case of Packed*Array [] Set in engine: The only value returned by
[]
is const so it can't be used for setting. I'm not sure if I should change this so I've left it as-is in this PR.
This is an interesting case. The current pattern in Godot is to use vector.write[i] = x;
to make it very explicit when we're doing copy-on-write. Is this really needed? And, if so, perhaps we should be replicating this pattern in godot-cpp? I don't know we've been accidentally triggering CoW when getting items out of a packed array in godot-cpp?
Actually, backporting this to 3.x may fix a bug report I opened a long time ago: #40046 |
a7565fe
to
1f15ecd
Compare
cfeb86c
to
519c97a
Compare
Could you elaborate? Why couldn't one use this operator for packed array setting? godot/core/extension/gdextension_interface.h Lines 2038 to 2049 in 99a7a9c
And for arrays, these? Plus the equivalent godot/core/extension/gdextension_interface.h Lines 2298 to 2309 in 99a7a9c
|
@Bromeon This code doesn't compile: PackedInt32Array arr;
arr.resize(5);
arr[0] = 7;
|
But this is something to be fixed in the C++ code... where does GDExtension come into play here? It seems both mut/const index operators are already exposed, for both packed and normal arrays? |
@Bromeon As per the table in the OP, |
Sorry if I keep asking stupid questions 😬 maybe I'm missing something about the inner workings, but why can the missing Because functionally, the API in GDExtension is already present, so duplicating it may raise more questions than it answers -- from the perspective of someone who writes a new binding. Or not? |
@Bromeon Sorry, what do you mean by implemented? If you mean using Anyway, the stated goal of GDExtension is to allow code to be written similarly to engine code, extending the engine. This was the whole point of rebranding it from the old name GDNative. This PR brings us closer to that goal. |
get
and set
functions
@aaronfranke I think the point that @Bromeon is trying to make, is that we don't necessarily need to bind This doesn't apply to the functions that are in GDExtension but missing Godot, though - those either need to be added to Godot or removed from godot-cpp in order to have parity. |
So we're happy to merge as is? Needs a rebase. |
519c97a
to
cc9f2b5
Compare
Thanks! |
These must be bound to ensure feature parity between both Array and Packed*Array, in-engine and GDExtension.
Current situation:
With this PR (assuming GDExtension C++ extension API JSON is updated):
This means that you can safely use
.get()
and.set()
and have it be compatible with everything. Before this PR, you would have to use a mish-mash of the[]
operator and the functions in order to make it work in both places (you'd have to use[]
most places but you'd have to use the function for Packed*Arrays setting). I'm labeling as an enhancement because it could be worked around before but making this consistent will help out a lot.For Array Func Get/Set, it was a simple matter of adding two
bind_method
lines and then writing the docs.For Packed*Arrays Func Get in GDExtension, I had to add an extra shim function in the bindings to resolve this ambiguity:
For the case of Packed*Array [] Set in engine: The only value returned by
[]
is const so it can't be used for setting. I'm not sure if I should change this so I've left it as-is in this PR. The error it gives if you try: