-
-
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
Better number format for memory usage #13246
Conversation
editor/script_editor_debugger.cpp
Outdated
@@ -642,7 +642,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da | |||
v /= 1024.0; | |||
} | |||
tt += " bytes"; | |||
vs = rtos(v) + " " + unit; | |||
vs = rtos(Math::round(v * 100) * 0.01) + " " + unit; |
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 pretty sure we have a built-in and more reliable way to do this. You could still get 32.00001 MB
with this method. There should be simple C float formatting instructions available.
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.
There is static String::num()
, which takes in the number of decimals, and there is static String::sprintf()
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.
Well maybe I spoke too fast, I don't find a simpler way to do this. The alternative would be snprintf with two buffers...
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 of course in String yeah, I was looking at Math...
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.
so... what would be the best for it?
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.
String::num(v, 2)
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 couldn't find this beautiful method on GDscript.
why didn't this bind to gdscript?
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.
@volzhs there's String.pad_decimals()
in GDScript, but you can also use format string to achieve this.
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.
@vnen Thanks for the tip. I'm using format string. but I'm not aware of pad_decimals
5c317e7
to
452af98
Compare
@@ -642,7 +643,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da | |||
v /= 1024.0; | |||
} | |||
tt += " bytes"; | |||
vs = rtos(v) + " " + unit; | |||
vs = String::num(v, 2) + " " + unit; | |||
} break; | |||
case Performance::MONITOR_TYPE_TIME: { | |||
tt += " seconds"; |
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.
ugh, i forgot to TTR this.
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 thought about that also. but I doubted if it's necessary.
before
after