-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Unify and streamline connecting to Resource changes #78993
The head ref may contain hidden characters: "making_connections\u{1F91D}"
Conversation
0503be2
to
7d5a521
Compare
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.
Looks good but I only looked at the resource changes.
I can't think of a better design.
Edited:
Some documentation changes needed.
Right, the |
7d5a521
to
50e7def
Compare
Ok, the methods were deprecated. They are just callbacks that should be called by the resource, they were never meant to be used in script. I added some generic description. |
Question: Does that PR allow to add "Synchronize Resource Changes" in play mode the same way script and editor changes right now can have effect when game is played? Right now if you change image (resource) you need to reload game. Maybe that PR could be first step to change it? |
This PR just makes it easier to connect signals. It might help with implementation, but doesn't make anything new possible. |
50e7def
to
6cc3d2a
Compare
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.
It makes sense on the surface. Needs a rebase though.
Maybe @reduz can tell us something about the idea behind the owners, but to me it looks like some legacy system that can be safely replaced by signals.
6cc3d2a
to
de4a3fa
Compare
Thanks! |
curve->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->disconnect(Curve::SIGNAL_RANGE_CHANGED, callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->disconnect_changed(callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->disconnect_changed(callable_mp(this, &CurveEdit::_curve_changed)); |
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.
Is that right?
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.
no .-.
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.
According to a crude regex, these are the only two
(checked for removed lines with ^-(.*)connect\(("changed"|CoreStringNames|SNAME\("changed")
, 270 total, 268 matching this regex)
curve->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->connect(Curve::SIGNAL_RANGE_CHANGED, callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->connect_changed(callable_mp(this, &CurveEdit::_curve_changed)); | ||
curve->connect_changed(callable_mp(this, &CurveEdit::_curve_changed)); |
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.
Here too :)
Resource's
changed
signal is one of the most used signals in the codebase. So far there was no standard way to use it, editors and nodes just connected them however they pleased:connect(CoreStringNames::get_singleton()->changed
connect(SNAME("changed"
connect("changed"
There was also a weird and underused concept of "resource owners". The idea is that you do
register_owner(this)
and then Resource callsnotify_change_to_owners()
and you get notified. The problem is that you need to manually register and deregister the resource. Also the callback is a hard-coded"resource_changed"
method. On top of that, this mechanism was used in a few 3D-related classes. Some used it instead thechanged
signal, which made it impossible to listen to changes normally (the resource_changed thing is not exposed). Some classes used both the signal and notify. And then there isShapeCast3D
, which both connected to signal and to the notify, which means that it reacted twice to each change, running the same code in 2 separate methods xdAnother thing is that it's often good practice to use
is_connected()
before connecting the signal, to avoid errors. This resulted in code likeor in worse cases the callable was just repeated twice ¯\_( •_•)_/¯
This PR resolves all aforementioned issues by:
connect_changed()
anddisconnect_changed()
methods to Resource, which always connect with CoreStringNamescore_string_names
include in some filesconnect_changed()
andemit_changed()
emit_changed()
is now public, so it can be called outside the resource (just like in GDScript xdd)The new methods are not exposed (yet?).