-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
ProjectSettings add dirty flag and project_settings_changed signal [3.x] #53296
ProjectSettings add dirty flag and project_settings_changed signal [3.x] #53296
Conversation
475f4e2
to
7842ab4
Compare
main/main.cpp
Outdated
@@ -2325,6 +2325,8 @@ bool Main::iteration() { | |||
} | |||
#endif | |||
|
|||
ProjectSettings::get_singleton()->decrement_dirty_this_frame(); |
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.
I'm not super happy about having something like this injected in the utmost core Main::iteration
. Feels hacky, and not just because it has "dirty" in the name :)
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.
Ah yes fair point, I agree. 👍 There's probably a better place for it I'll try and have a hunt (any suggestions welcome).
I might rename it to update()
so it sounds less dirty. And can be used for anything else that requires an update.
5accd1e
to
be30c65
Compare
I've now moved the I've also noticed that the new I've also included some example code in comments in the |
8020125
to
38d7f7e
Compare
I still feel that it's a weird pattern that the main loop (whether To me a dirty pattern would typically be implemented within the class and transparent to the rest of the codebase. It should update on demand if dirty (e.g. Alternatively, is there a reason why this can't go through |
This may be a limitation on my knowledge / experience of Godot, there may well be a better way of doing this. As you say if the Most objects I've used before are part of the SceneTree, or updated via the servers, but the Singletons don't seem to get an "update", so there's no particular example that I can immediately think of for reference here, so I'm improvising! 😀
I'm a bit lost here, I don't know what you mean. There are two classes, ProjectSettings, and a class which wants to read updates to it. Multiple classes could potentially want to read the same ProjectSetting, so you can't keep a track of individual dirty states for each item in ProjectSettings. Perhaps if the
This is surely what we are trying to avoid - we shouldn't have to call |
You can do something like (pseudo-code): void ProjectSettings::emit_changed() {
if (!dirty) {
return;
}
emit_signal("project_settings_changed");
dirty = false;
}
void ProjectSettings::set(...) {
// blabla something caused a setting to change.
dirty = true;
call_deferred("emit_changed");
} So possible multiple |
This does sound better. To be honest I wasn't aware that we could use |
Ah no joy with It looks like the machinery for Still welcome alternative approaches though. |
Maybe you can bypass the whole dirty/changed system for as long as Otherwise I guess this is something that should be discussed with @reduz who would probably know how to do this in the cleanest way for the engine's current architecture. But that will likely have to wait since he's busy this week. |
38d7f7e
to
084970e
Compare
Yeah but on the other hand there's a big danger that this would end up so hacky, we might just as well have called So yes probably best to just wait till reduz is settled then get his input. There's no huge hurry on this as it's just an enhancement. 🙂 |
71cb8d3
to
c58391c
Compare
Seems ok to me |
Needs a rebase. |
Most frames there will be no change in project settings, and it makes no sense to read settings every frame in case of changes, as a large number of string compares are involved. This PR adds a signal to ProjectSettings that can be subscribed to in order to keep local settings up to date with ProjectSettings. In addition a function `ProjectSettings::has_changes()` is provided for objects outside the signal system (e.g. Rasterizers).
084970e
to
f0af293
Compare
Rebased, just needed an extra:
which had been added since the PR was originally made. So should be good to go now. 👍 |
Thanks! |
I wonder if |
Yes feel free to add this. reduz' PR and the proposal were for a signal but a notification can be simpler to follow in c++ code imo. 👍 (I expect this can be done in the same place it sends the signal.) |
Most frames there will be no change in project settings, and it makes no sense to read settings every frame in case of changes, as a large number of string compares are involved.
This PR adds a signal to ProjectSettings that can be used in most cases to drive reading settings.
In addition a function
ProjectSettings::has_changes()
is provided for objects outside the signal system (e.g. Rasterizers).Alternative version of #45956 for 3.x
Addresses godotengine/godot-proposals#2155
Notes
iteration
AFTER it is read. This could otherwise result in missed changes.