diff options
-rw-r--r-- | core/ustring.cpp | 6 | ||||
-rw-r--r-- | core/ustring.h | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 2 | ||||
-rw-r--r-- | doc/classes/StreamPeer.xml | 8 | ||||
-rw-r--r-- | doc/classes/String.xml | 14 | ||||
-rw-r--r-- | main/main.cpp | 7 |
6 files changed, 32 insertions, 7 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 07caa3a018..f029ae4200 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3288,9 +3288,7 @@ String String::simplify_path() const { static int _humanize_digits(int p_num) { - if (p_num < 10) - return 2; - else if (p_num < 100) + if (p_num < 100) return 2; else if (p_num < 1024) return 1; @@ -3298,7 +3296,7 @@ static int _humanize_digits(int p_num) { return 0; } -String String::humanize_size(size_t p_size) { +String String::humanize_size(uint64_t p_size) { uint64_t _div = 1; Vector<String> prefixes; diff --git a/core/ustring.h b/core/ustring.h index 87a14bfad7..15e2c07d9f 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -322,7 +322,7 @@ public: String path_to_file(const String &p_path) const; String get_base_dir() const; String get_file() const; - static String humanize_size(size_t p_size); + static String humanize_size(uint64_t p_size); String simplify_path() const; String xml_escape(bool p_escape_quotes = false) const; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 53f64fcde6..1b5ca9d3e5 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -284,6 +284,7 @@ struct _VariantCall { VCALL_LOCALMEM0R(String, sha1_buffer); VCALL_LOCALMEM0R(String, sha256_buffer); VCALL_LOCALMEM0R(String, empty); + VCALL_LOCALMEM1R(String, humanize_size); VCALL_LOCALMEM0R(String, is_abs_path); VCALL_LOCALMEM0R(String, is_rel_path); VCALL_LOCALMEM0R(String, get_base_dir); @@ -1561,6 +1562,7 @@ void register_variant_methods() { ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha1_buffer, varray()); ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha256_buffer, varray()); ADDFUNC0R(STRING, BOOL, String, empty, varray()); + ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray()); ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray()); ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray()); ADDFUNC0R(STRING, STRING, String, get_base_dir, varray()); diff --git a/doc/classes/StreamPeer.xml b/doc/classes/StreamPeer.xml index 678c587f8d..2a1919071a 100644 --- a/doc/classes/StreamPeer.xml +++ b/doc/classes/StreamPeer.xml @@ -211,6 +211,10 @@ </argument> <description> Puts a zero-terminated ASCII string into the stream prepended by a 32-bit unsigned integer representing its size. + Note: To put an ASCII string without prepending its size, you can use [method put_data]: + [codeblock] + put_data("Hello world".to_ascii()) + [/codeblock] </description> </method> <method name="put_u16"> @@ -256,6 +260,10 @@ </argument> <description> Puts a zero-terminated UTF-8 string into the stream prepended by a 32 bits unsigned integer representing its size. + Note: To put an UTF-8 string without prepending its size, you can use [method put_data]: + [codeblock] + put_data("Hello world".to_utf8()) + [/codeblock] </description> </method> <method name="put_var"> diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 03bc2095c0..cf152e716e 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -437,6 +437,20 @@ [/codeblock] </description> </method> + <method name="humanize_size"> + <return type="String"> + </return> + <argument index="0" name="size" type="int"> + </argument> + <description> + Converts [code]size[/code] represented as number of bytes to human-readable format using internationalized set of data size units, namely: B, KiB, MiB, GiB, TiB, PiB, EiB. Note that the next smallest unit is picked automatically to hold at most 1024 units. + [codeblock] + var bytes = 133790307 + var size = String.humanize_size(bytes) + print(size) # prints "127.5 MiB" + [/codeblock] + </description> + </method> <method name="insert"> <return type="String"> </return> diff --git a/main/main.cpp b/main/main.cpp index 6df02af3a5..42c90fc027 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -982,10 +982,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph video_mode.height = GLOBAL_GET("display/window/size/height"); if (globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) { + int tw = globals->get("display/window/size/test_width"); - int th = globals->get("display/window/size/test_height"); - if (tw > 0 && th > 0) { + if (tw > 0) { video_mode.width = tw; + } + int th = globals->get("display/window/size/test_height"); + if (th > 0) { video_mode.height = th; } } |