-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Refactor vector editor properties #77135
The head ref may contain hidden characters: "Vector\u221E"
Conversation
editor/editor_properties.cpp
Outdated
if (p_name == COMPONENT_LABELS[i]) { | ||
for (int j = 0; j < ratio.size(); j++) { | ||
if (_get_ratio_component(j, 1) == i) { | ||
for (int k = 0; k < component_count - 1; k++) { | ||
spin_sliders[_get_ratio_component(j + k, 0)]->set_value_no_signal(spin_sliders[_get_ratio_component(j + k, 1)]->get_value() * ratio[j + k]); | ||
} | ||
break; | ||
} | ||
} |
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 needs to be simplified, but it took me too long to even figure it out ;_;
Maybe later >_>
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.
How about this? It's longer but easier to read (command-query separation and reduced number of indentation levels). The name of rc1/rc2 could be more explicit, but it's late and I couldn't come up with something better :)
if (p_name == COMPONENT_LABELS[i]) { | |
for (int j = 0; j < ratio.size(); j++) { | |
if (_get_ratio_component(j, 1) == i) { | |
for (int k = 0; k < component_count - 1; k++) { | |
spin_sliders[_get_ratio_component(j + k, 0)]->set_value_no_signal(spin_sliders[_get_ratio_component(j + k, 1)]->get_value() * ratio[j + k]); | |
} | |
break; | |
} | |
} | |
// Find out which component has changed. | |
int component_idx = -1; | |
for (int i = 0; i < component_count; i++) { | |
if (p_name == COMPONENT_LABELS[i]) { | |
component_idx = i; | |
} | |
} | |
int ratio_component_idx = -1; | |
for (int j = 0; j < ratio.size(); j++) { | |
int ratio_idx = _get_ratio_component(j, 1); | |
if (ratio_idx == component_idx) { | |
ratio_component_idx = j; | |
} | |
} | |
// Update the other components based on the ratio. | |
if (component_idx > 0 && ratio_component_idx > 0) { | |
for (int k = 0; k < component_count - 1; k++) { | |
int rc1 = _get_ratio_component(ratio_component_idx + k, 1); | |
int rc2 = _get_ratio_component(ratio_component_idx + k, 0); | |
double value = ratio[ratio_component_idx + k] * spin_sliders[rc1]->get_value(); | |
spin_sliders[rc2]->set_value_no_signal(value); | |
} | |
} |
9419c45
to
f9885ce
Compare
This needs a rebase. And perhaps incorporating the suggestion. |
3752fce
to
cf45af2
Compare
Rebased. I'm not convinced about the suggestion. It makes the code easier to read, but doesn't simplify the logic, which is convoluted and inefficient. I'll try to do something about it, but it's also something that can be done in a follow-up PR. For now I left a TODO comment. The exact problem is that ratios are packed in an array that looks something like |
@KoBeWi You can try something like this:
It should result in ratios orderings (
|
Something is wrong with linked values. I'm not sure if it's new to this PR or if it's a pre-existing issue, but it's an issue nonetheless. If you have a vector with components which have different signs, things get weird. Sometimes the value and the sign of each component get in sync: godot.windows.editor.dev.x86_64_2023-05-30_14-31-42.mp4godot.windows.editor.dev.x86_64_2023-05-30_14-38-46.mp4And sometimes it's only the values, but the signs are appropriately different: godot.windows.editor.dev.x86_64_2023-05-30_14-40-19.mp4It's a bit harder to test with non-integer vectors, as they are much slower to change, but they are not immune to the issue: godot.windows.editor.dev.x86_64_2023-05-30_14-44-42.mp4Note that it doesn't matter which component you drag, though initially I thought it did matter. What matters is how many times you cross the 0 threshold, and how the big numbers are (the bigger, the longer it takes them to sync). |
Other than that bug, everything seems to be working fine, btw, and I'm sure that code is way better to maintain now :) |
Okay, a correction. I only noticed this with negative numbers at first, so I assumed it was related, but indeed the only problem is that I was crossing the negative-positive boundary. The issue is repeatable even if you start with both positive numbers but a ratio different from 1:1. Crossing the 0 value with one of the components (maybe a few times) breaks the ratio. KoBeWi says this is because when 0 is involved we can't have a valid ratio between components, which is reasonable. Perhaps we could cache the last valid ratio and use that? |
@YuriSizov Currently in When dragging/changing value of a non-zero component, then all components can be scaled properly according to the ratios (at the start of the change), including the zero ones (they'll remain zero). So for The question is what the behavior should be when dragging/changing value of a zero component. I don't think there's an obvious expected behavior, it's rather a matter of making an arbitrary choice.
The decision on the behavior is needed before the implementation of course. 🙃 Also it should be ensured that e.g. when dragging the value in the inspector the |
I like what you suggest and I like the idea of ignoring the ratio when starting the change from a zeroed component. |
I added tooltip and moved the properties to a new file. |
I opened a report for that problem: #77687 |
Thanks! |
Follow-up to #75534 (comment)
The change I mentioned would require a tweak in all vector property classes and I didn't feel like doing the same thing 4 times, so I did a complete refactor. Instead of 6 classes that repeat literally the same thing there is only 1 now. The new class can handle any Vector with 2 or more components .-. Also, as a bonus, Vector4 now supports linking too.
Supersedes #75534
Closes #68165
Closes #73432