-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add get_property_list
, property_can_revert
and property_get_revert
virtual methods
#621
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-621 |
Nice, thanks! It may be possible that multiple threads call Thread A Storage Thread B
|
+<--- get ---+
| |
| |
| +--- get --->+
| | |
| | |
v v |
+--- free -->| |
| |
| |
|<-- free ---+
v This has two implications for
There's an unlikely chance that Godot already takes some measures to ensure this is always called from the main thread, which would of course make this easier. We should probably test this 😉 |
that's true, i'll look into that a bit more.
This is one of the main use-cases of
I mean the
Part of the issue here is that we need to keep Like the only reason |
I noticed that multi-threaded access may also be an issue for other virtual functions like So it's also fine if we handle the single-threaded case well here, and think about the multithreaded one in a separate issue/PR.
We do that in other places, e.g. script_instance.rs -- but there's usually a user-data Here, we'd probably need to construct the struct "around" the pointer -- which is possible, but would need to assume the addresses before/after it are occupied in a certain way? |
I think i found something that should work. I'll add two methods to Then in Finally in |
Probably interesting: godotengine/godot#89055 👀 To me it's also fine to only support this in Godot 4.3+, then we don't need to maintain 2 implementations. |
@Bromeon I think this actually pertains to the We probably need another PR for Godot, which would be convenient to do now, because we already have a EDIT: Or maybe I'm wrong and this is about script instances? I'm not great at interpreting the Rust code here. :-) I guess let me know and we can figure out if there's another struct that needs updating |
So if the free property list function gets updated in 4.3 to pass the length of the property list, should we then:
It would be a bit unfortunate to need both the <4.3 version as well as the 4.3+ version, but the 4.3+ version will likely be a lot simpler so it'd also be unfortunate to only use the more complicated solution. We dont currently support property lists for <4.3 anyway so maybe it's fine to just not support that? |
i have an idea actually, we add a const value const PROPERTY_LIST_CAPACITY: usize = 16;
// or some other reasonable default in godot <4.3 we always ensure that the property has a capacity (and length?) of the value that returns is exactly 16, and so we can always just assume that that's the size. in 4.3+ we can depracate this and just use the length returned by godot thus most of the code can be the same for the two versions, they largely just differ in where they get the length from. |
Yep, that's what I meant with this: 🙂
No one has asked for this feature, so it's well possible that any extra effort to support it for Godot 4.2 is wasted. We already invest a lot of extra time to maintain compatibility with previous Godot minor versions (more than the other bindings), not sure if we should always backport new features as well. So I wouldn't go any extra lengths here (not even |
Any update on this? |
I dont think there's been any upstream progress on adding a count to the property list for gdextension classes. So without that we can do something like what was done in #650 or wait until that happens. I may possibly be able to make a PR upstream for that myself but i am not very experienced with c++ so it'd be a bigger commitment. |
Maybe before committing a lot of time, you could open an upstream issue first and see what others think about it? Doesn't have to be you to do the entire implementation 🙂 |
I guess this would be a proposal not a bug report, arguably you could say that it's a bug that script instance passes count to the free methods and gdextension does not. but i think it is a bit more of a stretch than saying it's a proposal/enhancement. |
i made this issue godotengine/godot-proposals#9462 |
Closing this for now so it doesn't perpertually show up as a PR, opening the issue #665 instead. |
get_property_list
in godot requires us to pass a pointer + length ofGDExtensionPropertyInfo
, so i needed to add some mechanism to store such an array ofPropertyInfo
until it gets freed byfree_property_list
. I added this in theStorage
trait.I also added
new_var
andnew_export
methods toPropertyInfo
so people can more easily construct the property info when they need it, rather than needing to fill in all the fields manually.I need to add some more tests and test it manually a bit more before i mark as ready for review.
A couple of alternatives to the storage method that i decided against would be:
Have the user be responsible for keeping this list of property infos alive
This would require some unsafe code and be quite unergonomic
Use some pointer shenanigans into a custom DST struct
Make a struct like
then pass a pointer to
sys_info
to godot, then reconstruct this struct from the pointer godot gives us back by using pointer arithmetic to find theproperty_info
field.This is probably doable, but it requires a lot of unsafe finageling and seems unneccesarily complicated.
Directly free the vec from the pointer godot gives us in the free method
We have no good way of getting the length and capacity from just the pointer, so this isn't really feasible.