Skip to content

Commit

Permalink
Merge pull request #43456 from akien-mga/3.2-cherrypicks
Browse files Browse the repository at this point in the history
Cherry-picks for the 3.2 branch (future 3.2.4) - 7th batch
  • Loading branch information
akien-mga committed Nov 11, 2020
2 parents 941e2f2 + a57b6eb commit adf2dab
Show file tree
Hide file tree
Showing 72 changed files with 643 additions and 251 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ project.properties
platform/android/java/app/libs/*
platform/android/java/libs/*
platform/android/java/lib/.cxx/
platform/android/java/nativeSrcsConfigs/.cxx/

# General c++ generated files
*.lib
Expand Down
5 changes: 5 additions & 0 deletions core/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ void Array::push_back(const Variant &p_value) {
_p->array.push_back(p_value);
}

void Array::append_array(const Array &p_array) {

_p->array.append_array(p_array._p->array);
}

Error Array::resize(int p_new_size) {

return _p->array.resize(p_new_size);
Expand Down
1 change: 1 addition & 0 deletions core/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Array {

void push_back(const Variant &p_value);
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
void append_array(const Array &p_array);
Error resize(int p_new_size);

void insert(int p_pos, const Variant &p_value);
Expand Down
10 changes: 10 additions & 0 deletions core/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,7 @@ ImageMemLoadFunc Image::_png_mem_loader_func = NULL;
ImageMemLoadFunc Image::_jpg_mem_loader_func = NULL;
ImageMemLoadFunc Image::_webp_mem_loader_func = NULL;
ImageMemLoadFunc Image::_tga_mem_loader_func = NULL;
ImageMemLoadFunc Image::_bmp_mem_loader_func = NULL;

void (*Image::_image_compress_bc_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::CompressSource) = NULL;
Expand Down Expand Up @@ -2784,6 +2785,7 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_jpg_from_buffer", "buffer"), &Image::load_jpg_from_buffer);
ClassDB::bind_method(D_METHOD("load_webp_from_buffer", "buffer"), &Image::load_webp_from_buffer);
ClassDB::bind_method(D_METHOD("load_tga_from_buffer", "buffer"), &Image::load_tga_from_buffer);
ClassDB::bind_method(D_METHOD("load_bmp_from_buffer", "buffer"), &Image::load_bmp_from_buffer);

ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "_set_data", "_get_data");

Expand Down Expand Up @@ -3104,6 +3106,14 @@ Error Image::load_tga_from_buffer(const PoolVector<uint8_t> &p_array) {
return _load_from_buffer(p_array, _tga_mem_loader_func);
}

Error Image::load_bmp_from_buffer(const PoolVector<uint8_t> &p_array) {
ERR_FAIL_NULL_V_MSG(
_bmp_mem_loader_func,
ERR_UNAVAILABLE,
"The BMP module isn't enabled. Recompile the Godot editor or export template binary with the `module_bmp_enabled=yes` SCons option.");
return _load_from_buffer(p_array, _bmp_mem_loader_func);
}

Error Image::_load_from_buffer(const PoolVector<uint8_t> &p_array, ImageMemLoadFunc p_loader) {
int buffer_size = p_array.size();

Expand Down
2 changes: 2 additions & 0 deletions core/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Image : public Resource {
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
static ImageMemLoadFunc _tga_mem_loader_func;
static ImageMemLoadFunc _bmp_mem_loader_func;

static void (*_image_compress_bc_func)(Image *, float, CompressSource p_source);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source);
Expand Down Expand Up @@ -333,6 +334,7 @@ class Image : public Resource {
Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_webp_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_tga_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_bmp_from_buffer(const PoolVector<uint8_t> &p_array);

Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
Expand Down
3 changes: 2 additions & 1 deletion core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ HTTPClient::HTTPClient() {
ssl = false;
blocking = false;
handshaking = false;
read_chunk_size = 4096;
// 64 KiB by default (favors fast download speeds at the cost of memory usage).
read_chunk_size = 65536;
}

HTTPClient::~HTTPClient() {
Expand Down
5 changes: 4 additions & 1 deletion core/math/random_number_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ RandomNumberGenerator::RandomNumberGenerator() {}
void RandomNumberGenerator::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &RandomNumberGenerator::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &RandomNumberGenerator::get_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");

ClassDB::bind_method(D_METHOD("randi"), &RandomNumberGenerator::randi);
ClassDB::bind_method(D_METHOD("randf"), &RandomNumberGenerator::randf);
ClassDB::bind_method(D_METHOD("randfn", "mean", "deviation"), &RandomNumberGenerator::randfn, DEFVAL(0.0), DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("randf_range", "from", "to"), &RandomNumberGenerator::randf_range);
ClassDB::bind_method(D_METHOD("randi_range", "from", "to"), &RandomNumberGenerator::randi_range);
ClassDB::bind_method(D_METHOD("randomize"), &RandomNumberGenerator::randomize);

ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
// Default value is non-deterministic, override it for doc generation purposes.
ADD_PROPERTY_DEFAULT("seed", 0);
}
2 changes: 1 addition & 1 deletion core/math/transform_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t

real_t dot = v1.dot(v2);

dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1]
dot = CLAMP(dot, -1.0, 1.0);

Vector2 v;

Expand Down
2 changes: 2 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Array, pop_back);
VCALL_LOCALMEM0R(Array, pop_front);
VCALL_LOCALMEM1(Array, append);
VCALL_LOCALMEM1(Array, append_array);
VCALL_LOCALMEM1(Array, resize);
VCALL_LOCALMEM2(Array, insert);
VCALL_LOCALMEM1(Array, remove);
Expand Down Expand Up @@ -1799,6 +1800,7 @@ void register_variant_methods() {
ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, append_array, ARRAY, "array", varray());
ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray());
ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray());
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1174,10 +1174,10 @@
[codeblock]
var err = method_that_returns_error()
if err != OK:
print("Failure!)
print("Failure!")
# Or, equivalent:
if err:
print("Still failing!)
print("Still failing!")
[/codeblock]
</constant>
<constant name="FAILED" value="1" enum="Error">
Expand Down
14 changes: 14 additions & 0 deletions doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var array2 = [3, "Four"]
print(array1 + array2) # ["One", 2, 3, "Four"]
[/codeblock]
Note that concatenating with [code]+=[/code] operator will create a new array. If you want to append another array to an existing array, [method append_array] is more efficient.
[b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate].
</description>
<tutorials>
Expand Down Expand Up @@ -95,6 +96,19 @@
Appends an element at the end of the array (alias of [method push_back]).
</description>
</method>
<method name="append_array">
<argument index="0" name="array" type="Array">
</argument>
<description>
Appends another array at the end of this array.
[codeblock]
var array1 = [1, 2, 3]
var array2 = [4, 5, 6]
array1.append_array(array2)
print(array1) # Prints [1, 2, 3, 4, 5, 6].
[/codeblock]
</description>
</method>
<method name="back">
<return type="Variant">
</return>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CanvasItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
</signal>
<signal name="item_rect_changed">
<description>
Emitted when the item rect has changed.
Emitted when the item's [Rect2] boundaries (position or size) have changed, or when an action is taking place that may have impacted these boundaries (e.g. changing [member Sprite.texture]).
</description>
</signal>
<signal name="visibility_changed">
Expand Down
22 changes: 16 additions & 6 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,26 @@
</description>
</method>
<method name="_make_custom_tooltip" qualifiers="virtual">
<return type="Object">
<return type="Control">
</return>
<argument index="0" name="for_text" type="String">
</argument>
<description>
Virtual method to be implemented by the user. Returns a [Control] node that should be used as a tooltip instead of the default one. Use [code]for_text[/code] parameter to determine what text the tooltip should contain (likely the contents of [member hint_tooltip]).
The returned node must be of type [Control] or Control-derieved. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance, not e.g. a node from scene. When [code]null[/code] or non-Control node is returned, the default tooltip will be used instead.
Virtual method to be implemented by the user. Returns a [Control] node that should be used as a tooltip instead of the default one. The [code]for_text[/code] includes the contents of the [member hint_tooltip] property.
The returned node must be of type [Control] or Control-derived. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance (if you want to use a pre-existing node from your scene tree, you can duplicate it and pass the duplicated instance).When [code]null[/code] or a non-Control node is returned, the default tooltip will be used instead.
The returned node will be added as child to a [PopupPanel], so you should only provide the contents of that panel. That [PopupPanel] can be themed using [method Theme.set_stylebox] for the type [code]"TooltipPanel"[/code] (see [member hint_tooltip] for an example).
[b]Note:[/b] The tooltip is shrunk to minimal size. If you want to ensure it's fully visible, you might want to set its [member rect_min_size] to some non-zero value.
Example of usage with custom-constructed node:
Example of usage with a custom-constructed node:
[codeblock]
func _make_custom_tooltip(for_text):
var label = Label.new()
label.text = for_text
return label
[/codeblock]
Example of usage with custom scene instance:
Example of usage with a custom scene instance:
[codeblock]
func _make_custom_tooltip(for_text):
var tooltip = preload("SomeTooltipScene.tscn").instance()
var tooltip = preload("res://SomeTooltipScene.tscn").instance()
tooltip.get_node("Label").text = for_text
return tooltip
[/codeblock]
Expand Down Expand Up @@ -846,6 +847,15 @@
</member>
<member name="hint_tooltip" type="String" setter="set_tooltip" getter="_get_tooltip" default="&quot;&quot;">
Changes the tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that the [member mouse_filter] property is not [constant MOUSE_FILTER_IGNORE]. You can change the time required for the tooltip to appear with [code]gui/timers/tooltip_delay_sec[/code] option in Project Settings.
The tooltip popup will use either a default implementation, or a custom one that you can provide by overriding [method _make_custom_tooltip]. The default tooltip includes a [PopupPanel] and [Label] whose theme properties can be customized using [Theme] methods with the [code]"TooltipPanel"[/code] and [code]"TooltipLabel"[/code] respectively. For example:
[codeblock]
var style_box = StyleBoxFlat.new()
style_box.set_bg_color(Color(1, 1, 0))
style_box.set_border_width_all(2)
# We assume here that the `theme` property has been assigned a custom Theme beforehand.
theme.set_stylebox("panel", "TooltipPanel", style_box)
theme.set_color("font_color", "TooltipLabel", Color(0, 1, 1))
[/codeblock]
</member>
<member name="margin_bottom" type="float" setter="set_margin" getter="get_margin" default="0.0">
Distance between the node's bottom edge and its parent control, based on [member anchor_bottom].
Expand Down
49 changes: 48 additions & 1 deletion doc/classes/EditorPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@
<argument index="0" name="overlay" type="Control">
</argument>
<description>
Called by the engine when the 2D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays].
[codeblock]
func forward_canvas_draw_over_viewport(overlay):
# Draw a circle at cursor position.
overlay.draw_circle(overlay.get_local_mouse_position(), 64)

func forward_canvas_gui_input(event):
if event is InputEventMouseMotion:
# Redraw viewport when cursor is moved.
update_overlays()
return true
return false
[/codeblock]
</description>
</method>
<method name="forward_canvas_force_draw_over_viewport" qualifiers="virtual">
Expand All @@ -200,6 +213,8 @@
<argument index="0" name="overlay" type="Control">
</argument>
<description>
This method is the same as [method forward_canvas_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else.
You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled].
</description>
</method>
<method name="forward_canvas_gui_input" qualifiers="virtual">
Expand All @@ -226,6 +241,37 @@
[/codeblock]
</description>
</method>
<method name="forward_spatial_draw_over_viewport" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="overlay" type="Control">
</argument>
<description>
Called by the engine when the 3D editor's viewport is updated. Use the [code]overlay[/code] [Control] for drawing. You can update the viewport manually by calling [method update_overlays].
[codeblock]
func forward_spatial_draw_over_viewport(overlay):
# Draw a circle at cursor position.
overlay.draw_circle(overlay.get_local_mouse_position(), 64)

func forward_spatial_gui_input(camera, event):
if event is InputEventMouseMotion:
# Redraw viewport when cursor is moved.
update_overlays()
return true
return false
[/codeblock]
</description>
</method>
<method name="forward_spatial_force_draw_over_viewport" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="overlay" type="Control">
</argument>
<description>
This method is the same as [method forward_spatial_draw_over_viewport], except it draws on top of everything. Useful when you need an extra layer that shows over anything else.
You need to enable calling of this method by using [method set_force_draw_over_forwarding_enabled].
</description>
</method>
<method name="forward_spatial_gui_input" qualifiers="virtual">
<return type="bool">
</return>
Expand Down Expand Up @@ -475,6 +521,7 @@
<return type="void">
</return>
<description>
Enables calling of [method forward_canvas_force_draw_over_viewport] for the 2D editor and [method forward_spatial_force_draw_over_viewport] for the 3D editor when their viewports are updated. You need to call this method only once and it will work permanently for this plugin.
</description>
</method>
<method name="set_input_event_forwarding_always_enabled">
Expand Down Expand Up @@ -506,7 +553,7 @@
<return type="int">
</return>
<description>
Updates the overlays of the editor (2D/3D) viewport.
Updates the overlays of the 2D and 3D editor viewport. Causes methods [method forward_canvas_draw_over_viewport], [method forward_canvas_force_draw_over_viewport], [method forward_spatial_draw_over_viewport] and [method forward_spatial_force_draw_over_viewport] to be called.
</description>
</method>
</methods>
Expand Down
3 changes: 2 additions & 1 deletion doc/classes/HTTPClient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
A [HTTPClient] should be reused between multiple requests or to connect to different hosts instead of creating one client per request. Supports SSL and SSL server certificate verification. HTTP status codes in the 2xx range indicate success, 3xx redirection (i.e. "try again, but over here"), 4xx something was wrong with the request, and 5xx something went wrong on the server's side.
For more information on HTTP, see https://developer.mozilla.org/en-US/docs/Web/HTTP (or read RFC 2616 to get it straight from the source: https://tools.ietf.org/html/rfc2616).
[b]Note:[/b] When performing HTTP requests from a project exported to HTML5, keep in mind the remote server may not allow requests from foreign origins due to [url=https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS]CORS[/url]. If you host the server in question, you should modify its backend to allow requests from foreign origins by adding the [code]Access-Control-Allow-Origin: *[/code] HTTP header.
[b]Note:[/b] SSL/TLS support is currently limited to TLS 1.0, TLS 1.1, and TLS 1.2. Attempting to connect to a TLS 1.3-only server will return an error.
</description>
<tutorials>
<link>https://docs.godotengine.org/en/3.2/tutorials/networking/http_client_class.html</link>
Expand Down Expand Up @@ -180,7 +181,7 @@
<member name="connection" type="StreamPeer" setter="set_connection" getter="get_connection">
The connection to use for this client.
</member>
<member name="read_chunk_size" type="int" setter="set_read_chunk_size" getter="get_read_chunk_size" default="4096">
<member name="read_chunk_size" type="int" setter="set_read_chunk_size" getter="get_read_chunk_size" default="65536">
The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].
</member>
</members>
Expand Down
7 changes: 4 additions & 3 deletions doc/classes/HTTPRequest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Note: Don't make simultaneous requests using a single HTTPRequest node.
# The snippet below is provided for reference only.
var body = {"name": "Godette"}
var error = http_request.request("https://httpbin.org/post", [], true, HTTPClient.METHOD_POST, body)
error = http_request.request("https://httpbin.org/post", [], true, HTTPClient.METHOD_POST, body)
if error != OK:
push_error("An error occurred in the HTTP request.")

Expand Down Expand Up @@ -65,6 +65,7 @@
texture_rect.texture = texture
[/codeblock]
[b]Note:[/b] When performing HTTP requests from a project exported to HTML5, keep in mind the remote server may not allow requests from foreign origins due to [url=https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS]CORS[/url]. If you host the server in question, you should modify its backend to allow requests from foreign origins by adding the [code]Access-Control-Allow-Origin: *[/code] HTTP header.
[b]Note:[/b] SSL/TLS support is currently limited to TLS 1.0, TLS 1.1, and TLS 1.2. Attempting to connect to a TLS 1.3-only server will return an error.
</description>
<tutorials>
<link>https://docs.godotengine.org/en/3.2/tutorials/networking/http_request_class.html</link>
Expand Down Expand Up @@ -124,9 +125,9 @@
<member name="body_size_limit" type="int" setter="set_body_size_limit" getter="get_body_size_limit" default="-1">
Maximum allowed size for response bodies.
</member>
<member name="download_chunk_size" type="int" setter="set_download_chunk_size" getter="get_download_chunk_size" default="4096">
<member name="download_chunk_size" type="int" setter="set_download_chunk_size" getter="get_download_chunk_size" default="65536">
The size of the buffer used and maximum bytes to read per iteration. See [member HTTPClient.read_chunk_size].
Set this to a higher value (e.g. 65536 for 64 KiB) when downloading large files to achieve better speeds at the cost of memory.
Set this to a lower value (e.g. 4096 for 4 KiB) when downloading small files to decrease memory usage at the cost of download speeds.
</member>
<member name="download_file" type="String" setter="set_download_file" getter="get_download_file" default="&quot;&quot;">
The file to download into. Will output any received file into it.
Expand Down
10 changes: 10 additions & 0 deletions doc/classes/Image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,16 @@
Loads an image from file [code]path[/code]. See [url=https://docs.godotengine.org/en/3.2/getting_started/workflow/assets/importing_images.html#supported-image-formats]Supported image formats[/url] for a list of supported image formats and limitations.
</description>
</method>
<method name="load_bmp_from_buffer">
<return type="int" enum="Error">
</return>
<argument index="0" name="buffer" type="PoolByteArray">
</argument>
<description>
Loads an image from the binary contents of a BMP file.
[b]Note:[/b] Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
</description>
</method>
<method name="load_jpg_from_buffer">
<return type="int" enum="Error">
</return>
Expand Down
Loading

0 comments on commit adf2dab

Please sign in to comment.