Skip to content
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

Merged
merged 1 commit into from
Nov 26, 2017

Conversation

volzhs
Copy link
Contributor

@volzhs volzhs commented Nov 24, 2017

before
screenshot from 2017-11-24 22-53-51

after
screenshot from 2017-11-24 22-52-50

@volzhs volzhs added this to the 3.0 milestone Nov 24, 2017
@ghost ghost added the enhancement label Nov 24, 2017
@@ -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;
Copy link
Member

@akien-mga akien-mga Nov 24, 2017

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.

Copy link
Contributor

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()

Copy link
Member

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...

Copy link
Member

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...

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String::num(v, 2)

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

@@ -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";
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@akien-mga akien-mga merged commit 89313d8 into godotengine:master Nov 26, 2017
@volzhs volzhs deleted the memory-format branch December 16, 2017 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants