-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Object notification API, engine
intra-doc links
#223
Conversation
5c8d43c
to
1b413a5
Compare
# Conflicts: # itest/rust/src/virtual_methods_test.rs
Bikeshed time!
|
Thanks for the feedback!
What is unfortunate is that the virtual method #[godot_api]
impl MyClass {
fn stuff(&mut self) {
// Send a notification to the tree
self.notification(NodeNotification::PhysicsProcess);
// BUG: completely bypassed Godot, just called the Rust method directly
}
} A
"send" is not great because other such occurrences in Godot are networking- or server-related. "notify" sounds good. I was considering it as well, but thought it might not be clear enough. I didn't think of
There is no easy way to know the If we consider And even if Rust did inherit constants (or duplicate them), we'd still have the problem that a user would not be informed about additions in Godot. If I have an enum, a Then there's also the self-descriptiveness. Numbers are terrible for printing, debugging, etc; whereas enumerators can derive pub const NOTIFICATION_XY: Constant = Constant(73, "XY"); Last, there's also type safety. You cannot accidentally send a But yeah, maybe some of the parts are overkill... |
Hmm, yes, that's nasty. If we name both of them
My argument was that this is rarely, if ever, how For similar reasons, a Incidentally, such a type would also give you a place to put all the constants, i.e. At this point I'm one step away from inventing a single, global |
Independent of Rust's resolution mechanism, 2 names in the "same" scope is a recipe for confusion. This might change dependent on Having two separate names is a much smaller deal in my opinion. I mean, Godot's
Thanks, that's actually a very good point. Maybe the exhaustiveness doesn't matter at all.
This was my first thought and is completely impossible due to godotengine/godot#75839: there are loads of notifications that share the same integer value. Limiting the scope to a single class + its bases addresses most of the problem, but not the entire one (there are still collisions, but they are recognized as a bug and likely fixed at some point). |
So it can't work as a single enum, but can still work as a single newtype struct, albeit without a sensible Debug impl, right? |
But that encounters all the problems I previously mentioned:
In other words, we clearly need a scoped approach, because Godot's constants are not unique. We can use constants instead of enums, but then:
To me it seems while the enum solution I suggested may be a bit overkill, I don't see an alternative that solves these problems elegantly. |
Ow geez, I didn't realize number 2. What a mess. Yeah then your solution is probably best. |
Renamed the two methods from bors r+ |
Build succeeded: |
So far, there was no way to intercept the Godot
_notification
API, and also issuing notifications was very cumbersome, as the constants were spread across several classes.This PR introduces multiple new APIs:
{Class}Notification
enum, which contains all notifications relevant for a given class.Node3DNotification
accumulates allNOTIFICATION_*
constants acrossNode3D
,Node
andObject
classes.Node3D.NOTIF...
and auto-complete will list all candidates. In Rust, constants are not inherited.Virtual method
{Class}Virtual::on_notification(what: {NearestClass}Notification)
._notification
(with underscore), but more meaningfully named. It can be used to intercept low-level notifications for the given class.The method
{Class}::issue_notification(what: {NearestClass}Notification)
.on_notification
to send notifications.notification
(no underscore).Apart from that, there are smaller changes:
Display
is now implemented on allGd<T>
types, by using the Godot string representation.T
'sDisplay
impl is ignored.godot::engine
are now slighly documented and contain intra-doc links to navigate easily:global
,utilities
andnotify