-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[Core] Reformat structure string operators #34668
Conversation
c6e7a01
to
20ab6c2
Compare
20ab6c2
to
24f2680
Compare
I updated this PR with C# changes that match the behavior above. This should be good to merge any time, the sooner the better. |
core/ustring.cpp
Outdated
@@ -1325,8 +1325,10 @@ String String::num_real(double p_num) { | |||
dec_int /= 10; | |||
} | |||
sd = '.' + decimal; | |||
} else { | |||
} else if (p_trailing) { |
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.
Do we really want to make this optional though? IMO it would be just as well to enforce it, so that it's always clear that it's a real and not an integer.
Edit: I'm not asking to change it for now, just putting this up for debate.
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.
Either is fine to me. I made it this way because it's the existing behavior for floats, but maybe it's better to always show it to make it clear that it's a float.
P.S. In C#, the default behavior of converting numbers to string does not include the trailing decimals, so if we want them I'd add a format specifier ("0.0#############"
).
EDIT: Actually, the C# bindings generator currently depends on it not having trailing decimals. This could be fixed in the bindings generator, though.
af9f0d5
to
e69c3b6
Compare
a4bae90
to
392a061
Compare
9353c1d
to
6100b5c
Compare
321c14a
to
9ac5ae8
Compare
9ac5ae8
to
70fbc5b
Compare
70fbc5b
to
81fcc0c
Compare
@akien-mga @aaronfranke i put this in the accompanying proposal already, but this is important so im leaving it here too. This can't be merged as-is Printing mtiple lines is npt an option. Often times, you want to coalesce the string representation into another string. Most importantly though, it makes it unusable in log lines (for instance in server logs that are consumed by a log consumer such as fluentd) |
97ed42f
to
5e32536
Compare
5e32536
to
197830b
Compare
197830b
to
b972ae0
Compare
49be736
to
73d3f4d
Compare
The order of numbers is not changed except for Transform2D. All logic is done inside of their structures (and not in Variant). For the number of decimals printed, they now use String::num_real which works best with real_t, except for Color which is fixed at 4 decimals (this is a reliable number of float digits when converting from 16-bpc so it seems like a good choice)
Thanks! |
Legendary PR. |
Implements and closes godotengine/godot-proposals#1819
Explanation in bullets below each set of outputs. Test code:
Output with current master:
The current output is a bit confusing and inconsistent:
Color is lacking spaces after the commas.
AABB and Transform both contain a dash, which can be mistaken for a minus sign.
Some things have parenthesis, some don't, and Basis/Transform2D have nested parenthesis.
Transform2D prints out column-major, while Basis prints out row-major, and Transform is row major except the origin is last.
The current internal code is a bit strange, with some of the string logic being inside of Variant and some being in the class.
Output with this PR:
I've moved all the code to the classes and out of Variant.
No dashes anywhere, parenthesis used for grouping with commas for separation.
Transforms and Basis are now printed consistently and with explicit labels to avoid any confusion.
Since they store
real_t
, I decided to useString::num_real
, but normally this adds a trailing.0
to whole numbers, so I added a new bool to include it or not calledp_trailing
, which defaults to true so its current uses are the same.Color is an exception to the above, it uses
String::num
with a fixed amount of decimals (4 seems like a good value, but maybe 5, 3 or 2 would be better).