summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/io/multiplayer_api.cpp4
-rw-r--r--core/io/multiplayer_peer.cpp24
-rw-r--r--core/io/multiplayer_peer.h1
-rw-r--r--doc/classes/AcceptDialog.xml5
-rw-r--r--doc/classes/Control.xml3
-rw-r--r--doc/classes/Image.xml1
-rw-r--r--doc/classes/MultiplayerPeer.xml7
-rw-r--r--doc/classes/Window.xml9
-rw-r--r--editor/editor_plugin_settings.cpp10
-rw-r--r--editor/editor_run.cpp1
-rw-r--r--editor/editor_themes.cpp12
-rw-r--r--editor/inspector_dock.cpp5
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp40
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp7
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp57
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp2
-rw-r--r--editor/project_export.cpp4
-rw-r--r--editor/script_create_dialog.cpp4
-rw-r--r--methods.py11
-rw-r--r--misc/dist/linux/org.godotengine.Godot.xml15
-rwxr-xr-xmisc/scripts/make_tarball.sh66
-rw-r--r--modules/csg/csg_shape.cpp66
-rw-r--r--modules/enet/config.py2
-rw-r--r--modules/enet/doc_classes/ENetConnection.xml240
-rw-r--r--modules/enet/doc_classes/ENetMultiplayerPeer.xml159
-rw-r--r--modules/enet/doc_classes/ENetPacketPeer.xml210
-rw-r--r--modules/enet/enet_connection.cpp470
-rw-r--r--modules/enet/enet_connection.h138
-rw-r--r--modules/enet/enet_multiplayer_peer.cpp1084
-rw-r--r--modules/enet/enet_multiplayer_peer.h91
-rw-r--r--modules/enet/enet_packet_peer.cpp263
-rw-r--r--modules/enet/enet_packet_peer.h131
-rw-r--r--modules/enet/register_types.cpp4
-rw-r--r--modules/gltf/gltf_document.cpp5
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs8
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs4
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs4
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs2
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs8
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs10
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs12
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs14
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs14
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp20
-rw-r--r--modules/websocket/websocket_multiplayer_peer.h1
-rw-r--r--modules/websocket/wsl_server.cpp2
-rw-r--r--platform/android/export/export.cpp2
-rw-r--r--scene/2d/physics_body_2d.cpp3
-rw-r--r--scene/3d/visual_instance_3d.cpp12
-rw-r--r--scene/3d/visual_instance_3d.h1
-rw-r--r--scene/animation/animation_tree.cpp2
-rw-r--r--scene/gui/button.cpp4
-rw-r--r--scene/gui/control.cpp22
-rw-r--r--scene/gui/control.h6
-rw-r--r--scene/gui/dialogs.cpp3
-rw-r--r--scene/gui/label.cpp4
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/popup_menu.cpp12
-rw-r--r--scene/gui/tab_container.cpp7
-rw-r--r--scene/gui/tabs.cpp6
-rw-r--r--scene/main/viewport.cpp10
-rw-r--r--scene/main/window.cpp182
-rw-r--r--scene/main/window.h6
-rw-r--r--scene/resources/default_theme/default_theme.cpp11
-rw-r--r--scene/resources/default_theme/dialog_bg.pngbin0 -> 1314 bytes
-rw-r--r--scene/resources/default_theme/popup_window.pngbin903 -> 921 bytes
-rw-r--r--scene/resources/default_theme/theme_data.h6
-rw-r--r--scene/resources/texture.cpp6
-rw-r--r--thirdparty/enet/enet/godot_ext.h4
-rw-r--r--thirdparty/enet/godot.cpp35
75 files changed, 2441 insertions, 1217 deletions
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 80610e12cb..d4f09b2135 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -63,7 +63,7 @@ const MultiplayerAPI::RPCConfig _get_rpc_config(const Node *p_node, const String
const Vector<MultiplayerAPI::RPCConfig> node_config = p_node->get_node_rpc_methods();
for (int i = 0; i < node_config.size(); i++) {
if (node_config[i].name == p_method) {
- r_id = ((uint16_t)i) & (1 << 15);
+ r_id = ((uint16_t)i) | (1 << 15);
return node_config[i];
}
}
@@ -89,7 +89,7 @@ const MultiplayerAPI::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_i
config = p_node->get_script_instance()->get_rpc_methods();
}
if (id < config.size()) {
- return config[p_id];
+ return config[id];
}
return MultiplayerAPI::RPCConfig();
}
diff --git a/core/io/multiplayer_peer.cpp b/core/io/multiplayer_peer.cpp
index 8126b4cea3..8b3b1eef8e 100644
--- a/core/io/multiplayer_peer.cpp
+++ b/core/io/multiplayer_peer.cpp
@@ -30,6 +30,29 @@
#include "multiplayer_peer.h"
+#include "core/os/os.h"
+
+uint32_t MultiplayerPeer::generate_unique_id() const {
+ uint32_t hash = 0;
+
+ while (hash == 0 || hash == 1) {
+ hash = hash_djb2_one_32(
+ (uint32_t)OS::get_singleton()->get_ticks_usec());
+ hash = hash_djb2_one_32(
+ (uint32_t)OS::get_singleton()->get_unix_time(), hash);
+ hash = hash_djb2_one_32(
+ (uint32_t)OS::get_singleton()->get_user_data_dir().hash64(), hash);
+ hash = hash_djb2_one_32(
+ (uint32_t)((uint64_t)this), hash); // Rely on ASLR heap
+ hash = hash_djb2_one_32(
+ (uint32_t)((uint64_t)&hash), hash); // Rely on ASLR stack
+
+ hash = hash & 0x7FFFFFFF; // Make it compatible with unsigned, since negative ID is used for exclusion
+ }
+
+ return hash;
+}
+
void MultiplayerPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &MultiplayerPeer::set_transfer_mode);
ClassDB::bind_method(D_METHOD("get_transfer_mode"), &MultiplayerPeer::get_transfer_mode);
@@ -41,6 +64,7 @@ void MultiplayerPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_connection_status"), &MultiplayerPeer::get_connection_status);
ClassDB::bind_method(D_METHOD("get_unique_id"), &MultiplayerPeer::get_unique_id);
+ ClassDB::bind_method(D_METHOD("generate_unique_id"), &MultiplayerPeer::generate_unique_id);
ClassDB::bind_method(D_METHOD("set_refuse_new_connections", "enable"), &MultiplayerPeer::set_refuse_new_connections);
ClassDB::bind_method(D_METHOD("is_refusing_new_connections"), &MultiplayerPeer::is_refusing_new_connections);
diff --git a/core/io/multiplayer_peer.h b/core/io/multiplayer_peer.h
index 432f47280f..91a3ad7954 100644
--- a/core/io/multiplayer_peer.h
+++ b/core/io/multiplayer_peer.h
@@ -72,6 +72,7 @@ public:
virtual bool is_refusing_new_connections() const = 0;
virtual ConnectionStatus get_connection_status() const = 0;
+ uint32_t generate_unique_id() const;
MultiplayerPeer() {}
};
diff --git a/doc/classes/AcceptDialog.xml b/doc/classes/AcceptDialog.xml
index fd1e2ba104..ec276ed227 100644
--- a/doc/classes/AcceptDialog.xml
+++ b/doc/classes/AcceptDialog.xml
@@ -105,4 +105,9 @@
</signals>
<constants>
</constants>
+ <theme_items>
+ <theme_item name="panel" type="StyleBox">
+ Panel that fills up the background of the window.
+ </theme_item>
+ </theme_items>
</class>
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml
index 5c0856cb6a..4753b34efb 100644
--- a/doc/classes/Control.xml
+++ b/doc/classes/Control.xml
@@ -1081,6 +1081,9 @@
<member name="anchor_top" type="float" setter="_set_anchor" getter="get_anchor" default="0.0">
Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top offset updates when the node moves or changes size. You can use one of the [enum Anchor] constants for convenience.
</member>
+ <member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true">
+ Toggles if any text should automatically change to its translated version depending on the current locale.
+ </member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" enum="Control.FocusMode" default="0">
The focus access mode for the control (None, Click or All). Only one Control can be focused at the same time, and it will receive keyboard signals.
</member>
diff --git a/doc/classes/Image.xml b/doc/classes/Image.xml
index fd80841a63..37a96fef3d 100644
--- a/doc/classes/Image.xml
+++ b/doc/classes/Image.xml
@@ -465,6 +465,7 @@
</argument>
<description>
Saves the image as an EXR file to [code]path[/code]. If [code]grayscale[/code] is [code]true[/code] and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return [constant ERR_UNAVAILABLE] if Godot was compiled without the TinyEXR module.
+ [b]Note:[/b] The TinyEXR module is disabled in non-editor builds, which means [method save_exr] will return [constant ERR_UNAVAILABLE] when it is called from an exported project.
</description>
</method>
<method name="save_png" qualifiers="const">
diff --git a/doc/classes/MultiplayerPeer.xml b/doc/classes/MultiplayerPeer.xml
index 713cd64b82..fa8f0e2de9 100644
--- a/doc/classes/MultiplayerPeer.xml
+++ b/doc/classes/MultiplayerPeer.xml
@@ -12,6 +12,13 @@
<link title="WebRTC Signaling Demo">https://godotengine.org/asset-library/asset/537</link>
</tutorials>
<methods>
+ <method name="generate_unique_id" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns a randomly generated integer that can be used as a network unique ID.
+ </description>
+ </method>
<method name="get_connection_status" qualifiers="const">
<return type="int" enum="MultiplayerPeer.ConnectionStatus">
</return>
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index c8efaca1fc..7b21d99d10 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -323,6 +323,9 @@
<members>
<member name="always_on_top" type="bool" setter="set_flag" getter="get_flag" default="false">
</member>
+ <member name="auto_translate" type="bool" setter="set_auto_translate" getter="is_auto_translating" default="true">
+ Toggles if any text should automatically change to its translated version depending on the current locale.
+ </member>
<member name="borderless" type="bool" setter="set_flag" getter="get_flag" default="false">
</member>
<member name="content_scale_aspect" type="int" setter="set_content_scale_aspect" getter="get_content_scale_aspect" enum="Window.ContentScaleAspect" default="0">
@@ -469,11 +472,11 @@
</theme_item>
<theme_item name="close_h_ofs" type="int" default="18">
</theme_item>
- <theme_item name="close_highlight" type="Texture2D">
+ <theme_item name="close_pressed" type="Texture2D">
</theme_item>
<theme_item name="close_v_ofs" type="int" default="18">
</theme_item>
- <theme_item name="panel" type="StyleBox">
+ <theme_item name="embedded_border" type="StyleBox">
</theme_item>
<theme_item name="resize_margin" type="int" default="4">
</theme_item>
@@ -494,7 +497,5 @@
<theme_item name="title_outline_size" type="int" default="0">
The size of the title outline.
</theme_item>
- <theme_item name="window_panel" type="StyleBox">
- </theme_item>
</theme_items>
</class>
diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp
index a8b08dc9ed..aa313f0c50 100644
--- a/editor/editor_plugin_settings.cpp
+++ b/editor/editor_plugin_settings.cpp
@@ -208,11 +208,11 @@ EditorPluginSettings::EditorPluginSettings() {
plugin_list->set_v_size_flags(SIZE_EXPAND_FILL);
plugin_list->set_columns(5);
plugin_list->set_column_titles_visible(true);
- plugin_list->set_column_title(0, TTR("Name:"));
- plugin_list->set_column_title(1, TTR("Version:"));
- plugin_list->set_column_title(2, TTR("Author:"));
- plugin_list->set_column_title(3, TTR("Status:"));
- plugin_list->set_column_title(4, TTR("Edit:"));
+ plugin_list->set_column_title(0, TTR("Name"));
+ plugin_list->set_column_title(1, TTR("Version"));
+ plugin_list->set_column_title(2, TTR("Author"));
+ plugin_list->set_column_title(3, TTR("Status"));
+ plugin_list->set_column_title(4, TTR("Edit"));
plugin_list->set_column_expand(0, true);
plugin_list->set_column_clip_content(0, true);
plugin_list->set_column_expand(1, false);
diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp
index 4fadbf5922..8a7ec9aa82 100644
--- a/editor/editor_run.cpp
+++ b/editor/editor_run.cpp
@@ -270,6 +270,7 @@ void EditorRun::stop() {
for (const OS::ProcessID &E : pids) {
OS::get_singleton()->kill(E);
}
+ pids.clear();
}
status = STATUS_STOP;
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index 0c908be441..c230bdcb73 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -582,6 +582,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
// Focus
theme->set_stylebox("Focus", "EditorStyles", style_widget_focus);
+ // Use a less opaque color to be less distracting for the 2D and 3D editor viewports.
+ Ref<StyleBoxFlat> style_widget_focus_viewport = style_widget_focus->duplicate();
+ style_widget_focus_viewport->set_border_color(accent_color * Color(1, 1, 1, 0.5));
+ theme->set_stylebox("FocusViewport", "EditorStyles", style_widget_focus_viewport);
// Menu
Ref<StyleBoxFlat> style_menu = style_widget->duplicate();
@@ -1086,17 +1090,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0);
// Prevent visible line between window title and body.
style_window_title->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE);
- theme->set_stylebox("panel", "Window", style_window_title);
Ref<StyleBoxFlat> style_window = style_popup->duplicate();
style_window->set_border_color(base_color);
style_window->set_border_width(SIDE_TOP, 24 * EDSCALE);
style_window->set_expand_margin_size(SIDE_TOP, 24 * EDSCALE);
- theme->set_stylebox("panel_window", "Window", style_window);
+ theme->set_stylebox("embedded_border", "Window", style_window);
theme->set_color("title_color", "Window", font_color);
theme->set_icon("close", "Window", theme->get_icon("GuiClose", "EditorIcons"));
- theme->set_icon("close_highlight", "Window", theme->get_icon("GuiClose", "EditorIcons"));
+ theme->set_icon("close_pressed", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_constant("close_h_ofs", "Window", 22 * EDSCALE);
theme->set_constant("close_v_ofs", "Window", 20 * EDSCALE);
theme->set_constant("title_height", "Window", 24 * EDSCALE);
@@ -1112,6 +1115,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window);
theme->set_stylebox("panel", "EditorAbout", style_complex_window);
+ // AcceptDialog
+ theme->set_stylebox("panel", "AcceptDialog", style_window_title);
+
// HScrollBar
Ref<Texture2D> empty_icon = memnew(ImageTexture);
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
index 1973494a2a..a566afb597 100644
--- a/editor/inspector_dock.cpp
+++ b/editor/inspector_dock.cpp
@@ -409,6 +409,7 @@ void InspectorDock::update(Object *p_object) {
current = p_object;
if (!p_object) {
+ open_docs_button->set_disabled(true);
object_menu->set_disabled(true);
warning->hide();
search->set_editable(false);
@@ -424,7 +425,7 @@ void InspectorDock::update(Object *p_object) {
editor_path->enable_path();
resource_save_button->set_disabled(!is_resource);
- open_docs_button->set_visible(is_resource || is_node);
+ open_docs_button->set_disabled(!is_resource && !is_node);
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
@@ -575,7 +576,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
open_docs_button = memnew(Button);
open_docs_button->set_flat(true);
- open_docs_button->set_visible(false);
+ open_docs_button->set_disabled(true);
open_docs_button->set_tooltip(TTR("Open documentation for this object."));
open_docs_button->set_icon(get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons")));
open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation")));
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index fae10c7b7a..cd16353d6a 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2655,7 +2655,7 @@ void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_posi
void CanvasItemEditor::_draw_focus() {
// Draw the focus around the base viewport
if (viewport->has_focus()) {
- get_theme_stylebox(SNAME("Focus"), SNAME("EditorStyles"))->draw(viewport->get_canvas_item(), Rect2(Point2(), viewport->get_size()));
+ get_theme_stylebox(SNAME("FocusViewport"), SNAME("EditorStyles"))->draw(viewport->get_canvas_item(), Rect2(Point2(), viewport->get_size()));
}
}
@@ -2921,7 +2921,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
Point2 text_pos = (begin + end) / 2 - Vector2(text_width / 2, text_height / 2);
text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5);
text_pos.y = CLAMP(text_pos.y, text_height * 1.5, viewport->get_rect().size.y - text_height * 1.5);
- viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color);
+ viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color);
if (draw_secondary_lines) {
const float horizontal_angle_rad = atan2(length_vector.y, length_vector.x);
@@ -2931,16 +2931,16 @@ void CanvasItemEditor::_draw_ruler_tool() {
Point2 text_pos2 = text_pos;
text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2);
- viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.y)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
+ viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
Point2 v_angle_text_pos = Point2();
v_angle_text_pos.x = CLAMP(begin.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width);
v_angle_text_pos.y = begin.y < end.y ? MIN(text_pos2.y - 2 * text_height, begin.y - text_height * 0.5) : MAX(text_pos2.y + text_height * 3, begin.y + text_height * 1.5);
- viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), vertical_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
+ viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat(String::utf8("%d°"), vertical_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
text_pos2 = text_pos;
text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y - text_height / 2) : MAX(text_pos.y + text_height * 2, end.y - text_height / 2);
- viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.x)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
+ viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
Point2 h_angle_text_pos = Point2();
h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width);
@@ -2957,7 +2957,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height));
}
}
- viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), horizontal_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
+ viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat(String::utf8("%d°"), horizontal_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color);
// Angle arcs
int arc_point_count = 8;
@@ -5763,11 +5763,14 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
preview_node->add_child(sprite);
label->show();
label_desc->show();
+ label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node.\nHold Alt when dropping to add as a different node type."));
} else {
if (scene.is_valid()) {
Node *instance = scene->instantiate();
if (instance) {
preview_node->add_child(instance);
+ label_desc->show();
+ label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node."));
}
}
}
@@ -6066,6 +6069,7 @@ bool CanvasItemEditorViewport::_only_packed_scenes_selected() const {
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
+ bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL);
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
selected_files.clear();
@@ -6077,24 +6081,25 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
return;
}
- List<Node *> list = editor->get_editor_selection()->get_selected_node_list();
- if (list.size() == 0) {
- Node *root_node = editor->get_edited_scene();
+ List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list();
+ Node *root_node = editor->get_edited_scene();
+ if (selected_nodes.size() > 0) {
+ Node *selected_node = selected_nodes[0];
+ target_node = root_node;
+ if (is_ctrl) {
+ target_node = selected_node;
+ } else if (is_shift && selected_node != root_node) {
+ target_node = selected_node->get_parent();
+ }
+ } else {
if (root_node) {
- list.push_back(root_node);
+ target_node = root_node;
} else {
drop_pos = p_point;
target_node = nullptr;
}
}
- if (list.size() > 0) {
- target_node = list[0];
- if (is_shift && target_node != editor->get_edited_scene()) {
- target_node = target_node->get_parent();
- }
- }
-
drop_pos = p_point;
if (is_alt && !_only_packed_scenes_selected()) {
@@ -6175,7 +6180,6 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
canvas_item_editor->get_controls_container()->add_child(label);
label_desc = memnew(Label);
- label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type"));
label_desc->add_theme_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1));
label_desc->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
label_desc->add_theme_constant_override("shadow_as_outline", 1 * EDSCALE);
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index 9ee1fcb325..9a2b222f21 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -332,7 +332,7 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) {
Vector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2];
if (uv.size() == 0) {
- err_dialog->set_text(TTR("Model has no UV in this layer"));
+ err_dialog->set_text(vformat(TTR("Mesh has no UV in layer %d."), p_layer + 1));
err_dialog->popup_centered();
return;
}
@@ -382,9 +382,10 @@ void MeshInstance3DEditor::_debug_uv_draw() {
}
debug_uv->set_clip_contents(true);
- debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), Color(0.2, 0.2, 0.0));
+ debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), get_theme_color(SNAME("dark_color_3"), SNAME("Editor")));
debug_uv->draw_set_transform(Vector2(), 0, debug_uv->get_size());
- debug_uv->draw_multiline(uv_lines, Color(1.0, 0.8, 0.7));
+ // Use a translucent color to allow overlapping triangles to be visible.
+ debug_uv->draw_multiline(uv_lines, get_theme_color(SNAME("mono_color"), SNAME("Editor")) * Color(1, 1, 1, 0.5), Math::round(EDSCALE));
}
void MeshInstance3DEditor::_create_outline_mesh() {
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 7fd75705cb..b1f4baac13 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -942,14 +942,18 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
- Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST);
+ // Allow some tolerance to make the plane easier to click,
+ // even if the click is actually slightly outside the plane.
+ const Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667);
Vector3 r;
Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
if (plane.intersects_ray(ray_pos, ray, &r)) {
float dist = r.distance_to(grabber_pos);
- if (dist < (gs * GIZMO_PLANE_SIZE)) {
+ // Allow some tolerance to make the plane easier to click,
+ // even if the click is actually slightly outside the plane.
+ if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) {
float d = ray_pos.distance_to(r);
if (d < col_d) {
col_d = d;
@@ -1042,14 +1046,18 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
- Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST);
+ // Allow some tolerance to make the plane easier to click,
+ // even if the click is actually slightly outside the plane.
+ Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667);
Vector3 r;
Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
if (plane.intersects_ray(ray_pos, ray, &r)) {
float dist = r.distance_to(grabber_pos);
- if (dist < (gs * GIZMO_PLANE_SIZE)) {
+ // Allow some tolerance to make the plane easier to click,
+ // even if the click is actually slightly outside the plane.
+ if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) {
float d = ray_pos.distance_to(r);
if (d < col_d) {
col_d = d;
@@ -2863,7 +2871,7 @@ void Node3DEditorViewport::_draw() {
if (surface->has_focus()) {
Size2 size = surface->get_size();
Rect2 r = Rect2(Point2(), size);
- get_theme_stylebox(SNAME("Focus"), SNAME("EditorStyles"))->draw(surface->get_canvas_item(), r);
+ get_theme_stylebox(SNAME("FocusViewport"), SNAME("EditorStyles"))->draw(surface->get_canvas_item(), r);
}
if (cursor.region_select) {
@@ -2909,9 +2917,7 @@ void Node3DEditorViewport::_draw() {
handle_color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
break;
}
- handle_color.a = 1.0;
- const float brightness = 1.3;
- handle_color *= Color(brightness, brightness, brightness);
+ handle_color = handle_color.from_hsv(handle_color.get_h(), 0.25, 1.0, 1);
RenderingServer::get_singleton()->canvas_item_add_line(
ci,
@@ -4060,6 +4066,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_
}
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
+ bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL);
selected_files.clear();
Dictionary d = p_data;
@@ -4067,29 +4074,32 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_
selected_files = d["files"];
}
- List<Node *> list = editor->get_editor_selection()->get_selected_node_list();
- if (list.size() == 0) {
- Node *root_node = editor->get_edited_scene();
+ List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list();
+ Node *root_node = editor->get_edited_scene();
+ if (selected_nodes.size() == 1) {
+ Node *selected_node = selected_nodes[0];
+ target_node = root_node;
+ if (is_ctrl) {
+ target_node = selected_node;
+ } else if (is_shift && selected_node != root_node) {
+ target_node = selected_node->get_parent();
+ }
+ } else if (selected_nodes.size() == 0) {
if (root_node) {
- list.push_back(root_node);
+ target_node = root_node;
} else {
- accept->set_text(TTR("No parent to instance a child at."));
+ accept->set_text(TTR("Cannot drag and drop into scene with no root node."));
accept->popup_centered();
_remove_preview();
return;
}
- }
- if (list.size() != 1) {
- accept->set_text(TTR("This operation requires a single selected node."));
+ } else {
+ accept->set_text(TTR("Cannot drag and drop into multiple selected nodes."));
accept->popup_centered();
_remove_preview();
return;
}
- target_node = list[0];
- if (is_shift && target_node != editor->get_edited_scene()) {
- target_node = target_node->get_parent();
- }
drop_pos = p_point;
_perform_drop_data();
@@ -5638,8 +5648,7 @@ void fragment() {
gizmo_color[i] = mat;
Ref<StandardMaterial3D> mat_hl = mat->duplicate();
- const float brightness = 1.3;
- const Color albedo = Color(col.r * brightness, col.g * brightness, col.b * brightness);
+ const Color albedo = col.from_hsv(col.get_h(), 0.25, 1.0, 1);
mat_hl->set_albedo(albedo);
gizmo_color_hl[i] = mat_hl;
@@ -5746,7 +5755,7 @@ void fragment() {
surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
int n = 128; // number of circle segments
- int m = 6; // number of thickness segments
+ int m = 3; // number of thickness segments
real_t step = Math_TAU / n;
for (int j = 0; j < n; ++j) {
@@ -5954,7 +5963,7 @@ void fragment() {
surftool->commit(scale_plane_gizmo[i]);
Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate();
- plane_mat_hl->set_albedo(Color(col.r * 1.3, col.g * 1.3, col.b * 1.3));
+ plane_mat_hl->set_albedo(col.from_hsv(col.get_h(), 0.25, 1.0, 1));
plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides
}
}
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index 4a4e81dae3..e70aed8ed6 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -1756,7 +1756,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {
paint_tool_button->set_flat(true);
paint_tool_button->set_toggle_mode(true);
paint_tool_button->set_button_group(tool_buttons_group);
- paint_tool_button->set_shortcut(ED_SHORTCUT("tiles_editor/paint_tool", "Paint", KEY_E));
+ paint_tool_button->set_shortcut(ED_SHORTCUT("tiles_editor/paint_tool", "Paint", KEY_D));
paint_tool_button->connect("pressed", callable_mp(this, &TileMapEditorTilesPlugin::_update_toolbar));
tilemap_tiles_tools_buttons->add_child(paint_tool_button);
diff --git a/editor/project_export.cpp b/editor/project_export.cpp
index fcb714bdf7..14158b02c8 100644
--- a/editor/project_export.cpp
+++ b/editor/project_export.cpp
@@ -1171,7 +1171,7 @@ ProjectExportDialog::ProjectExportDialog() {
script_key = memnew(LineEdit);
script_key->connect("text_changed", callable_mp(this, &ProjectExportDialog::_script_encryption_key_changed));
script_key_error = memnew(Label);
- script_key_error->set_text("- " + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)"));
+ script_key_error->set_text(String::utf8("• ") + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)"));
script_key_error->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor")));
sec_vb->add_margin_child(TTR("Encryption Key (256-bits as hexadecimal):"), script_key);
sec_vb->add_child(script_key_error);
@@ -1250,7 +1250,7 @@ ProjectExportDialog::ProjectExportDialog() {
Label *export_error2 = memnew(Label);
export_templates_error->add_child(export_error2);
export_error2->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor")));
- export_error2->set_text(" - " + TTR("Export templates for this platform are missing:") + " ");
+ export_error2->set_text(String::utf8("• ") + TTR("Export templates for this platform are missing:") + " ");
error_dialog = memnew(AcceptDialog);
error_dialog->set_title(TTR("Error"));
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 9a4b38db74..4cbc859e0c 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -604,7 +604,7 @@ void ScriptCreateDialog::_path_submitted(const String &p_path) {
}
void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) {
- error_label->set_text("- " + p_msg);
+ error_label->set_text(String::utf8("• ") + p_msg);
if (valid) {
error_label->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor")));
} else {
@@ -613,7 +613,7 @@ void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) {
}
void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) {
- path_error_label->set_text("- " + p_msg);
+ path_error_label->set_text(String::utf8("• ") + p_msg);
if (valid) {
path_error_label->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor")));
} else {
diff --git a/methods.py b/methods.py
index fd9978657e..12f9db37e7 100644
--- a/methods.py
+++ b/methods.py
@@ -61,10 +61,9 @@ def add_module_version_string(self, s):
def update_version(module_version_string=""):
-
build_name = "custom_build"
if os.getenv("BUILD_NAME") != None:
- build_name = os.getenv("BUILD_NAME")
+ build_name = str(os.getenv("BUILD_NAME"))
print("Using custom build name: " + build_name)
import version
@@ -79,7 +78,13 @@ def update_version(module_version_string=""):
f.write("#define VERSION_MAJOR " + str(version.major) + "\n")
f.write("#define VERSION_MINOR " + str(version.minor) + "\n")
f.write("#define VERSION_PATCH " + str(version.patch) + "\n")
- f.write('#define VERSION_STATUS "' + str(version.status) + '"\n')
+ # For dev snapshots (alpha, beta, RC, etc.) we do not commit status change to Git,
+ # so this define provides a way to override it without having to modify the source.
+ godot_status = str(version.status)
+ if os.getenv("GODOT_VERSION_STATUS") != None:
+ godot_status = str(os.getenv("GODOT_VERSION_STATUS"))
+ print("Using version status '%s', overriding the original '%s'.".format(godot_status, str(version.status)))
+ f.write('#define VERSION_STATUS "' + godot_status + '"\n')
f.write('#define VERSION_BUILD "' + str(build_name) + '"\n')
f.write('#define VERSION_MODULE_CONFIG "' + str(version.module_config) + module_version_string + '"\n')
f.write("#define VERSION_YEAR " + str(version.year) + "\n")
diff --git a/misc/dist/linux/org.godotengine.Godot.xml b/misc/dist/linux/org.godotengine.Godot.xml
index e51179cd61..d4452018c4 100644
--- a/misc/dist/linux/org.godotengine.Godot.xml
+++ b/misc/dist/linux/org.godotengine.Godot.xml
@@ -2,20 +2,21 @@
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-godot-project">
<comment>Godot Engine project</comment>
- <icon name="x-godot-project" />
- <glob pattern="*.godot"/>
+ <sub-class-of type="text/plain"/>
+ <icon name="x-godot-project"/>
+ <glob pattern="project.godot"/>
</mime-type>
<mime-type type="application/x-godot-resource">
<comment>Godot Engine resource</comment>
- <icon name="x-godot-resource" />
+ <icon name="x-godot-resource"/>
<glob pattern="*.res"/>
<glob pattern="*.tres"/>
</mime-type>
<mime-type type="application/x-godot-scene">
<comment>Godot Engine scene</comment>
- <icon name="x-godot-scene" />
+ <icon name="x-godot-scene"/>
<glob pattern="*.scn"/>
<glob pattern="*.tscn"/>
<glob pattern="*.escn"/>
@@ -23,13 +24,15 @@
<mime-type type="application/x-godot-shader">
<comment>Godot Engine shader</comment>
- <icon name="x-godot-shader" />
+ <sub-class-of type="text/plain"/>
+ <icon name="x-godot-shader"/>
<glob pattern="*.gdshader"/>
</mime-type>
<mime-type type="application/x-gdscript">
<comment>GDScript script</comment>
- <icon name="x-gdscript" />
+ <sub-class-of type="text/plain"/>
+ <icon name="x-gdscript"/>
<glob pattern="*.gd"/>
</mime-type>
</mime-info>
diff --git a/misc/scripts/make_tarball.sh b/misc/scripts/make_tarball.sh
new file mode 100755
index 0000000000..9e02b80af1
--- /dev/null
+++ b/misc/scripts/make_tarball.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+if [ ! -e "version.py" ]; then
+ echo "This script should be ran from the root folder of the Godot repository."
+ exit 1
+fi
+
+while getopts "h?sv:g:" opt; do
+ case "$opt" in
+ h|\?)
+ echo "Usage: $0 [OPTIONS...]"
+ echo
+ echo " -s script friendly file name (godot.tar.gz)"
+ echo " -v godot version for file name (e.g. 4.0-stable)"
+ echo " -g git treeish to archive (e.g. master)"
+ echo
+ exit 1
+ ;;
+ s)
+ script_friendly_name=1
+ ;;
+ v)
+ godot_version=$OPTARG
+ ;;
+ g)
+ git_treeish=$OPTARG
+ ;;
+ esac
+done
+
+if [ ! -z "$git_treeish" ]; then
+ HEAD=$(git rev-parse $git_treeish)
+else
+ HEAD=$(git rev-parse HEAD)
+fi
+
+if [ ! -z "$script_friendly_name" ]; then
+ NAME=godot
+else
+ if [ ! -z "$godot_version" ]; then
+ NAME=godot-$godot_version
+ else
+ NAME=godot-$HEAD
+ fi
+fi
+
+CURDIR=$(pwd)
+TMPDIR=$(mktemp -d -t godot-XXXXXX)
+
+echo "Generating tarball for revision $HEAD with folder name '$NAME'."
+echo
+echo "The tarball will be written to the parent folder:"
+echo " $(dirname $CURDIR)/$NAME.tar.gz"
+
+git archive $HEAD --prefix=$NAME/ -o $TMPDIR/$NAME.tar
+
+# Adding custom .git/HEAD to tarball so that we can generate VERSION_HASH.
+cd $TMPDIR
+mkdir -p $NAME/.git
+echo $HEAD > $NAME/.git/HEAD
+tar -uf $NAME.tar $NAME
+
+cd $CURDIR
+gzip -c $TMPDIR/$NAME.tar > ../$NAME.tar.gz
+
+rm -rf $TMPDIR
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index 73c1ba554c..b47fa35f1a 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -923,36 +923,40 @@ CSGBrush *CSGSphere3D::_build_brush() {
Ref<Material> *materialsw = materials.ptrw();
bool *invertw = invert.ptrw();
- const double lat_step = 1.0 / rings;
- const double lon_step = 1.0 / radial_segments;
+ // We want to follow an order that's convenient for UVs.
+ // For latitude step we start at the top and move down like in an image.
+ const double latitude_step = -Math_PI / rings;
+ const double longitude_step = Math_TAU / radial_segments;
int face = 0;
- for (int i = 1; i <= rings; i++) {
- double lat0 = Math_PI * (0.5 - (i - 1) * lat_step);
- double c0 = Math::cos(lat0);
- double s0 = Math::sin(lat0);
- double v0 = double(i - 1) / rings;
-
- double lat1 = Math_PI * (0.5 - i * lat_step);
- double c1 = Math::cos(lat1);
- double s1 = Math::sin(lat1);
- double v1 = double(i) / rings;
-
- for (int j = 1; j <= radial_segments; j++) {
- double lng0 = Math_TAU * (0.5 - (j - 1) * lon_step);
- double x0 = Math::cos(lng0);
- double y0 = Math::sin(lng0);
- double u0 = double(j - 1) / radial_segments;
-
- double lng1 = Math_TAU * (0.5 - j * lon_step);
- double x1 = Math::cos(lng1);
- double y1 = Math::sin(lng1);
- double u1 = double(j) / radial_segments;
+ for (int i = 0; i < rings; i++) {
+ double latitude0 = latitude_step * i + Math_TAU / 4;
+ double cos0 = Math::cos(latitude0);
+ double sin0 = Math::sin(latitude0);
+ double v0 = double(i) / rings;
+
+ double latitude1 = latitude_step * (i + 1) + Math_TAU / 4;
+ double cos1 = Math::cos(latitude1);
+ double sin1 = Math::sin(latitude1);
+ double v1 = double(i + 1) / rings;
+
+ for (int j = 0; j < radial_segments; j++) {
+ double longitude0 = longitude_step * j;
+ // We give sin to X and cos to Z on purpose.
+ // This allows UVs to be CCW on +X so it maps to images well.
+ double x0 = Math::sin(longitude0);
+ double z0 = Math::cos(longitude0);
+ double u0 = double(j) / radial_segments;
+
+ double longitude1 = longitude_step * (j + 1);
+ double x1 = Math::sin(longitude1);
+ double z1 = Math::cos(longitude1);
+ double u1 = double(j + 1) / radial_segments;
Vector3 v[4] = {
- Vector3(x0 * c0, s0, y0 * c0) * radius,
- Vector3(x1 * c0, s0, y1 * c0) * radius,
- Vector3(x1 * c1, s1, y1 * c1) * radius,
- Vector3(x0 * c1, s1, y0 * c1) * radius,
+ Vector3(x0 * cos0, sin0, z0 * cos0) * radius,
+ Vector3(x1 * cos0, sin0, z1 * cos0) * radius,
+ Vector3(x1 * cos1, sin1, z1 * cos1) * radius,
+ Vector3(x0 * cos1, sin1, z0 * cos1) * radius,
};
Vector2 u[4] = {
@@ -962,8 +966,8 @@ CSGBrush *CSGSphere3D::_build_brush() {
Vector2(u0, v1),
};
- if (i < rings) {
- //face 1
+ // Draw the first face, but skip this at the north pole (i == 0).
+ if (i > 0) {
facesw[face * 3 + 0] = v[0];
facesw[face * 3 + 1] = v[1];
facesw[face * 3 + 2] = v[2];
@@ -979,8 +983,8 @@ CSGBrush *CSGSphere3D::_build_brush() {
face++;
}
- if (i > 1) {
- //face 2
+ // Draw the second face, but skip this at the south pole (i == rings - 1).
+ if (i < rings - 1) {
facesw[face * 3 + 0] = v[2];
facesw[face * 3 + 1] = v[3];
facesw[face * 3 + 2] = v[0];
diff --git a/modules/enet/config.py b/modules/enet/config.py
index 3662b2d94e..9102c74579 100644
--- a/modules/enet/config.py
+++ b/modules/enet/config.py
@@ -9,6 +9,8 @@ def configure(env):
def get_doc_classes():
return [
"ENetMultiplayerPeer",
+ "ENetConnection",
+ "ENetPacketPeer",
]
diff --git a/modules/enet/doc_classes/ENetConnection.xml b/modules/enet/doc_classes/ENetConnection.xml
new file mode 100644
index 0000000000..523f2ad165
--- /dev/null
+++ b/modules/enet/doc_classes/ENetConnection.xml
@@ -0,0 +1,240 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="ENetConnection" inherits="RefCounted" version="4.0">
+ <brief_description>
+ A wrapper class for an [url=http://enet.bespin.org/group__host.html]ENetHost[/url].
+ </brief_description>
+ <description>
+ ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).
+ </description>
+ <tutorials>
+ <link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link>
+ </tutorials>
+ <methods>
+ <method name="bandwidth_limit">
+ <return type="void">
+ </return>
+ <argument index="0" name="in_bandwidth" type="int" default="0">
+ </argument>
+ <argument index="1" name="out_bandwidth" type="int" default="0">
+ </argument>
+ <description>
+ Adjusts the bandwidth limits of a host.
+ </description>
+ </method>
+ <method name="broadcast">
+ <return type="void">
+ </return>
+ <argument index="0" name="channel" type="int">
+ </argument>
+ <argument index="1" name="packet" type="PackedByteArray">
+ </argument>
+ <argument index="2" name="flags" type="int">
+ </argument>
+ <description>
+ Queues a [code]packet[/code] to be sent to all peers associated with the host over the specified [code]channel[/code]. See [ENetPacketPeer] [code]FLAG_*[/code] constants for available packet flags.
+ </description>
+ </method>
+ <method name="channel_limit">
+ <return type="void">
+ </return>
+ <argument index="0" name="limit" type="int">
+ </argument>
+ <description>
+ Limits the maximum allowed channels of future incoming connections.
+ </description>
+ </method>
+ <method name="compress">
+ <return type="void">
+ </return>
+ <argument index="0" name="mode" type="int" enum="ENetConnection.CompressionMode">
+ </argument>
+ <description>
+ Sets the compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all.
+ [b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets.
+ </description>
+ </method>
+ <method name="connect_to_host">
+ <return type="ENetPacketPeer">
+ </return>
+ <argument index="0" name="address" type="String">
+ </argument>
+ <argument index="1" name="port" type="int">
+ </argument>
+ <argument index="2" name="channels" type="int" default="0">
+ </argument>
+ <argument index="3" name="data" type="int" default="0">
+ </argument>
+ <description>
+ Initiates a connection to a foreign [code]address[/code] using the specified [code]port[/code] and allocting the requested [code]channels[/code]. Optional [code]data[/code] can be passed during connection in the form of a 32 bit integer.
+ Note: You must call either [method create_host] or [method create_host_bound] before calling this method.
+ </description>
+ </method>
+ <method name="create_host">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="max_peers" type="int" default="32">
+ </argument>
+ <argument index="1" name="max_channels" type="int" default="0">
+ </argument>
+ <argument index="2" name="in_bandwidth" type="int" default="0">
+ </argument>
+ <argument index="3" name="out_bandwidth" type="int" default="0">
+ </argument>
+ <description>
+ Create an ENetHost that will allow up to [code]max_peers[/code] connected peers, each allocating up to [code]max_channels[/code] channels, optionally limiting bandwith to [code]in_bandwidth[/code] and [code]out_bandwidth[/code].
+ </description>
+ </method>
+ <method name="create_host_bound">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="bind_address" type="String">
+ </argument>
+ <argument index="1" name="bind_port" type="int">
+ </argument>
+ <argument index="2" name="max_peers" type="int" default="32">
+ </argument>
+ <argument index="3" name="max_channels" type="int" default="0">
+ </argument>
+ <argument index="4" name="in_bandwidth" type="int" default="0">
+ </argument>
+ <argument index="5" name="out_bandwidth" type="int" default="0">
+ </argument>
+ <description>
+ Create an ENetHost like [method create_host] which is also bound to the given [code]bind_address[/code] and [code]bind_port[/code].
+ </description>
+ </method>
+ <method name="destroy">
+ <return type="void">
+ </return>
+ <description>
+ Destroys the host and all resources associated with it.
+ </description>
+ </method>
+ <method name="dtls_client_setup">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="certificate" type="X509Certificate">
+ </argument>
+ <argument index="1" name="hostname" type="String">
+ </argument>
+ <argument index="2" name="verify" type="bool" default="true">
+ </argument>
+ <description>
+ Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet clients. Call this before [method connect_to_host] to have ENet connect using DTLS with [code]certificate[/code] and [code]hostname[/code] verification. Verification can be optionally turned off via the [code]verify[/code] parameter.
+ </description>
+ </method>
+ <method name="dtls_server_setup">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="key" type="CryptoKey">
+ </argument>
+ <argument index="1" name="certificate" type="X509Certificate">
+ </argument>
+ <description>
+ Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet servers. Call this right after [method create_host_bound] to have ENet expect peers to connect using DTLS.
+ </description>
+ </method>
+ <method name="flush">
+ <return type="void">
+ </return>
+ <description>
+ Sends any queued packets on the host specified to its designated peers.
+ </description>
+ </method>
+ <method name="get_local_port" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the local port to which this peer is bound.
+ </description>
+ </method>
+ <method name="get_max_channels" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the maximum number of channels allowed for connected peers.
+ </description>
+ </method>
+ <method name="get_peers">
+ <return type="Array">
+ </return>
+ <description>
+ Returns the list of peers associated with this host.
+ Note: This list might include some peers that are not fully connected or are still being disconnected.
+ </description>
+ </method>
+ <method name="pop_statistic">
+ <return type="float">
+ </return>
+ <argument index="0" name="statistic" type="int" enum="ENetConnection.HostStatistic">
+ </argument>
+ <description>
+ Returns and resets host statistics. See [enum HostStatistic] for more info.
+ </description>
+ </method>
+ <method name="refuse_new_connections">
+ <return type="void">
+ </return>
+ <argument index="0" name="refuse" type="bool">
+ </argument>
+ <description>
+ Configures the DTLS server to automatically drop new connections.
+ Note: This method is only relevant after calling [method dtls_server_setup].
+ </description>
+ </method>
+ <method name="service">
+ <return type="Array">
+ </return>
+ <argument index="0" name="timeout" type="int" default="0">
+ </argument>
+ <description>
+ Waits for events on the host specified and shuttles packets between the host and its peers. The returned [Array] will have 4 elements. An [enum EventType], the [ENetPacketPeer] which generated the event, the event associated data (if any), the event associated channel (if any). If the generated event is [constant EVENT_RECEIVE], the received packet will be queued to the associated [ENetPacketPeer].
+ Call this function regularly to handle connections, disconnections, and to receive new packets.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ <constant name="COMPRESS_NONE" value="0" enum="CompressionMode">
+ No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier.
+ </constant>
+ <constant name="COMPRESS_RANGE_CODER" value="1" enum="CompressionMode">
+ ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.
+ </constant>
+ <constant name="COMPRESS_FASTLZ" value="2" enum="CompressionMode">
+ [url=http://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth.
+ </constant>
+ <constant name="COMPRESS_ZLIB" value="3" enum="CompressionMode">
+ [url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources.
+ </constant>
+ <constant name="COMPRESS_ZSTD" value="4" enum="CompressionMode">
+ [url=https://facebook.github.io/zstd/]Zstandard[/url] compression. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases.
+ </constant>
+ <constant name="EVENT_ERROR" value="-1" enum="EventType">
+ An error occurred during [method service]. You will likely need to [method destroy] the host and recreate it.
+ </constant>
+ <constant name="EVENT_NONE" value="0" enum="EventType">
+ No event occurred within the specified time limit.
+ </constant>
+ <constant name="EVENT_CONNECT" value="1" enum="EventType">
+ A connection request initiated by enet_host_connect has completed. The array will contain the peer which successfully connected.
+ </constant>
+ <constant name="EVENT_DISCONNECT" value="2" enum="EventType">
+ A peer has disconnected. This event is generated on a successful completion of a disconnect initiated by [method ENetPacketPeer.peer_disconnect], if a peer has timed out, or if a connection request intialized by [method connect_to_host] has timed out. The array will contain the peer which disconnected. The data field contains user supplied data describing the disconnection, or 0, if none is available.
+ </constant>
+ <constant name="EVENT_RECEIVE" value="3" enum="EventType">
+ A packet has been received from a peer. The array will contain the peer which sent the packet, the channel number upon which the packet was received, and the received packet.
+ </constant>
+ <constant name="HOST_TOTAL_SENT_DATA" value="0" enum="HostStatistic">
+ Total data sent.
+ </constant>
+ <constant name="HOST_TOTAL_SENT_PACKETS" value="1" enum="HostStatistic">
+ Total UDP packets sent.
+ </constant>
+ <constant name="HOST_TOTAL_RECEIVED_DATA" value="2" enum="HostStatistic">
+ Total data received.
+ </constant>
+ <constant name="HOST_TOTAL_RECEIVED_PACKETS" value="3" enum="HostStatistic">
+ Total UDP packets received.
+ </constant>
+ </constants>
+</class>
diff --git a/modules/enet/doc_classes/ENetMultiplayerPeer.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml
index 30dec5987b..574010a4a2 100644
--- a/modules/enet/doc_classes/ENetMultiplayerPeer.xml
+++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ENetMultiplayerPeer" inherits="MultiplayerPeer" version="4.0">
<brief_description>
- PacketPeer implementation using the [url=http://enet.bespin.org/index.html]ENet[/url] library.
+ A MultiplayerPeer implementation using the [url=http://enet.bespin.org/index.html]ENet[/url] library.
</brief_description>
<description>
- A PacketPeer implementation that should be passed to [member MultiplayerAPI.network_peer] after being initialized as either a client or server. Events can then be handled by connecting to [SceneTree] signals.
- ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).
+ A MultiplayerPeer implementation that should be passed to [member MultiplayerAPI.network_peer] after being initialized as either a client, server, or mesh. Events can then be handled by connecting to [MultiplayerAPI] signals. See [ENetConnection] for more information on the ENet library wrapper.
[b]Note:[/b] ENet only uses UDP, not TCP. When forwarding the server port to make your server accessible on the public Internet, you only need to forward the server port in UDP. You can use the [UPNP] class to try to forward the server port automatically when starting the server.
</description>
<tutorials>
@@ -13,6 +12,18 @@
<link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link>
</tutorials>
<methods>
+ <method name="add_mesh_peer">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="peer_id" type="int">
+ </argument>
+ <argument index="1" name="host" type="ENetConnection">
+ </argument>
+ <description>
+ Add a new remote peer with the given [code]peer_id[/code] connected to the given [code]host[/code].
+ Note: The [code]host[/code] must have exactly one peer in the [constant ENetPacketPeer.STATE_CONNECTED] state.
+ </description>
+ </method>
<method name="close_connection">
<return type="void">
</return>
@@ -29,79 +40,51 @@
</argument>
<argument index="1" name="port" type="int">
</argument>
- <argument index="2" name="in_bandwidth" type="int" default="0">
+ <argument index="2" name="channel_count" type="int" default="0">
</argument>
- <argument index="3" name="out_bandwidth" type="int" default="0">
+ <argument index="3" name="in_bandwidth" type="int" default="0">
</argument>
- <argument index="4" name="local_port" type="int" default="0">
+ <argument index="4" name="out_bandwidth" type="int" default="0">
+ </argument>
+ <argument index="5" name="local_port" type="int" default="0">
</argument>
<description>
- Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques.
+ Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain name (e.g. [code]"www.example.com"[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]"192.168.1.1"[/code]). The [code]port[/code] is the port the server is listening on. The [code]channel_count[/code] parameter can be used to specify the number of ENet channels allocated for the connection. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [constant OK] if a client was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the client could not be created. If [code]local_port[/code] is specified, the client will also listen to the given port; this is useful for some NAT traversal techniques.
</description>
</method>
- <method name="create_server">
+ <method name="create_mesh">
<return type="int" enum="Error">
</return>
- <argument index="0" name="port" type="int">
- </argument>
- <argument index="1" name="max_clients" type="int" default="32">
- </argument>
- <argument index="2" name="in_bandwidth" type="int" default="0">
- </argument>
- <argument index="3" name="out_bandwidth" type="int" default="0">
+ <argument index="0" name="unique_id" type="int">
</argument>
<description>
- Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created.
+ Initialize this [MultiplayerPeer] in mesh mode. The provided [code]unique_id[/code] will be used as the local peer network unique ID once assigned as the [member MultiplayerAPI.network_peer]. In the mesh configuration you will need to set up each new peer manually using [ENetConnection] before calling [method add_mesh_peer]. While this technique is more advanced, it allows for better control over the connection process (e.g. when dealing with NAT punch-through) and for better distribution of the network load (which would otherwise be more taxing on the server).
</description>
</method>
- <method name="disconnect_peer">
- <return type="void">
+ <method name="create_server">
+ <return type="int" enum="Error">
</return>
- <argument index="0" name="id" type="int">
+ <argument index="0" name="port" type="int">
</argument>
- <argument index="1" name="now" type="bool" default="false">
+ <argument index="1" name="max_clients" type="int" default="32">
</argument>
- <description>
- Disconnect the given peer. If "now" is set to [code]true[/code], the connection will be closed immediately without flushing queued messages.
- </description>
- </method>
- <method name="get_last_packet_channel" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the channel of the last packet fetched via [method PacketPeer.get_packet].
- </description>
- </method>
- <method name="get_local_port" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the local port to which this peer is bound.
- </description>
- </method>
- <method name="get_packet_channel" qualifiers="const">
- <return type="int">
- </return>
- <description>
- Returns the channel of the next packet that will be retrieved via [method PacketPeer.get_packet].
- </description>
- </method>
- <method name="get_peer_address" qualifiers="const">
- <return type="String">
- </return>
- <argument index="0" name="id" type="int">
+ <argument index="2" name="max_channels" type="int" default="0">
+ </argument>
+ <argument index="3" name="in_bandwidth" type="int" default="0">
+ </argument>
+ <argument index="4" name="out_bandwidth" type="int" default="0">
</argument>
<description>
- Returns the IP address of the given peer.
+ Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]"*"[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4095 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [constant OK] if a server was created, [constant ERR_ALREADY_IN_USE] if this ENetMultiplayerPeer instance already has an open connection (in which case you need to call [method close_connection] first) or [constant ERR_CANT_CREATE] if the server could not be created.
</description>
</method>
- <method name="get_peer_port" qualifiers="const">
- <return type="int">
+ <method name="get_peer" qualifiers="const">
+ <return type="ENetPacketPeer">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
- Returns the remote port of the given peer.
+ Return the [ENetPacketPeer] associated to the given [code]id[/code].
</description>
</method>
<method name="set_bind_ip">
@@ -113,83 +96,17 @@
The IP used when creating a server. This is set to the wildcard [code]"*"[/code] by default, which binds to all available interfaces. The given IP needs to be in IPv4 or IPv6 address format, for example: [code]"192.168.1.1"[/code].
</description>
</method>
- <method name="set_dtls_certificate">
- <return type="void">
- </return>
- <argument index="0" name="certificate" type="X509Certificate">
- </argument>
- <description>
- Configure the [X509Certificate] to use when [member use_dtls] is [code]true[/code]. For servers, you must also setup the [CryptoKey] via [method set_dtls_key].
- </description>
- </method>
- <method name="set_dtls_key">
- <return type="void">
- </return>
- <argument index="0" name="key" type="CryptoKey">
- </argument>
- <description>
- Configure the [CryptoKey] to use when [member use_dtls] is [code]true[/code]. Remember to also call [method set_dtls_certificate] to setup your [X509Certificate].
- </description>
- </method>
- <method name="set_peer_timeout">
- <return type="void">
- </return>
- <argument index="0" name="id" type="int">
- </argument>
- <argument index="1" name="timeout_limit" type="int">
- </argument>
- <argument index="2" name="timeout_min" type="int">
- </argument>
- <argument index="3" name="timeout_max" type="int">
- </argument>
- <description>
- Sets the timeout parameters for a peer. The timeout parameters control how and when a peer will timeout from a failure to acknowledge reliable traffic. Timeout values are expressed in milliseconds.
- The [code]timeout_limit[/code] is a factor that, multiplied by a value based on the average round trip time, will determine the timeout limit for a reliable packet. When that limit is reached, the timeout will be doubled, and the peer will be disconnected if that limit has reached [code]timeout_min[/code]. The [code]timeout_max[/code] parameter, on the other hand, defines a fixed timeout for which any packet must be acknowledged or the peer will be dropped.
- </description>
- </method>
</methods>
<members>
- <member name="always_ordered" type="bool" setter="set_always_ordered" getter="is_always_ordered" default="false">
- Enforce ordered packets when using [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant MultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system.
- </member>
- <member name="channel_count" type="int" setter="set_channel_count" getter="get_channel_count" default="3">
- The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per-channel basis. This is done to combat latency and reduces ordering restrictions on packets. The delivery status of a packet in one channel won't stall the delivery of other packets in another channel.
- </member>
- <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="ENetMultiplayerPeer.CompressionMode" default="1">
- The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all.
- [b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets.
- </member>
- <member name="dtls_verify" type="bool" setter="set_dtls_verify_enabled" getter="is_dtls_verify_enabled" default="true">
- Enable or disable certificate verification when [member use_dtls] [code]true[/code].
+ <member name="host" type="ENetConnection" setter="" getter="get_host">
+ The underlying [ENetConnection] created after [method create_client] and [method create_server].
</member>
<member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" />
<member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true">
Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is [code]false[/code], clients won't be automatically notified of other peers and won't be able to send them packets through the server.
</member>
- <member name="transfer_channel" type="int" setter="set_transfer_channel" getter="get_transfer_channel" default="-1">
- Set the default channel to be used to transfer data. By default, this value is [code]-1[/code] which means that ENet will only use 2 channels: one for reliable packets, and one for unreliable packets. The channel [code]0[/code] is reserved and cannot be used. Setting this member to any value between [code]0[/code] and [member channel_count] (excluded) will force ENet to use that channel for sending data. See [member channel_count] for more information about ENet channels.
- </member>
<member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="MultiplayerPeer.TransferMode" default="2" />
- <member name="use_dtls" type="bool" setter="set_dtls_enabled" getter="is_dtls_enabled" default="false">
- When enabled, the client or server created by this peer, will use [PacketPeerDTLS] instead of raw UDP sockets for communicating with the remote peer. This will make the communication encrypted with DTLS at the cost of higher resource usage and potentially larger packet size.
- Note: When creating a DTLS server, make sure you setup the key/certificate pair via [method set_dtls_key] and [method set_dtls_certificate]. For DTLS clients, have a look at the [member dtls_verify] option, and configure the certificate accordingly via [method set_dtls_certificate].
- </member>
</members>
<constants>
- <constant name="COMPRESS_NONE" value="0" enum="CompressionMode">
- No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier.
- </constant>
- <constant name="COMPRESS_RANGE_CODER" value="1" enum="CompressionMode">
- ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.
- </constant>
- <constant name="COMPRESS_FASTLZ" value="2" enum="CompressionMode">
- [url=http://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth.
- </constant>
- <constant name="COMPRESS_ZLIB" value="3" enum="CompressionMode">
- [url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources.
- </constant>
- <constant name="COMPRESS_ZSTD" value="4" enum="CompressionMode">
- [url=https://facebook.github.io/zstd/]Zstandard[/url] compression. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases.
- </constant>
</constants>
</class>
diff --git a/modules/enet/doc_classes/ENetPacketPeer.xml b/modules/enet/doc_classes/ENetPacketPeer.xml
new file mode 100644
index 0000000000..5c9f692974
--- /dev/null
+++ b/modules/enet/doc_classes/ENetPacketPeer.xml
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="ENetPacketPeer" inherits="PacketPeer" version="4.0">
+ <brief_description>
+ A wrapper class for an [url=http://enet.bespin.org/group__peer.html]ENetPeer[/url].
+ </brief_description>
+ <description>
+ A PacketPeer implementation representing a peer of an [ENetConnection].
+ This class cannot be instantiated directly but can be retrieved during [method ENetConnection.service] or via [method ENetConnection.get_peers].
+ </description>
+ <tutorials>
+ <link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link>
+ </tutorials>
+ <methods>
+ <method name="get_channels" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the number of channels allocated for communication with peer.
+ </description>
+ </method>
+ <method name="get_state" qualifiers="const">
+ <return type="int" enum="ENetPacketPeer.PeerState">
+ </return>
+ <description>
+ Returns the current peer state. See [enum PeerState].
+ </description>
+ </method>
+ <method name="get_statistic">
+ <return type="float">
+ </return>
+ <argument index="0" name="statistic" type="int" enum="ENetPacketPeer.PeerStatistic">
+ </argument>
+ <description>
+ Returns the requested [code]statistic[/code] for this peer. See [enum PeerStatistic].
+ </description>
+ </method>
+ <method name="is_active" qualifiers="const">
+ <return type="bool">
+ </return>
+ <description>
+ Returns [code]true[/code] if the peer is currently active (i.e. the associated [ENetConnection] is still valid).
+ </description>
+ </method>
+ <method name="peer_disconnect">
+ <return type="void">
+ </return>
+ <argument index="0" name="data" type="int" default="0">
+ </argument>
+ <description>
+ Request a disconnection from a peer. An [constant ENetConnection.EVENT_DISCONNECT] will be generated during [method ENetConnection.service] once the disconnection is complete.
+ </description>
+ </method>
+ <method name="peer_disconnect_later">
+ <return type="void">
+ </return>
+ <argument index="0" name="data" type="int" default="0">
+ </argument>
+ <description>
+ Request a disconnection from a peer, but only after all queued outgoing packets are sent. An [constant ENetConnection.EVENT_DISCONNECT] will be generated during [method ENetConnection.service] once the disconnection is complete.
+ </description>
+ </method>
+ <method name="peer_disconnect_now">
+ <return type="void">
+ </return>
+ <argument index="0" name="data" type="int" default="0">
+ </argument>
+ <description>
+ Force an immediate disconnection from a peer. No [constant ENetConnection.EVENT_DISCONNECT] will be generated. The foreign peer is not guaranteed to receive the disconnect notification, and is reset immediately upon return from this function.
+ </description>
+ </method>
+ <method name="ping">
+ <return type="void">
+ </return>
+ <description>
+ Sends a ping request to a peer. ENet automatically pings all connected peers at regular intervals, however, this function may be called to ensure more frequent ping requests.
+ </description>
+ </method>
+ <method name="ping_interval">
+ <return type="void">
+ </return>
+ <argument index="0" name="ping_interval" type="int">
+ </argument>
+ <description>
+ Sets the [code]ping_interval[/code] in milliseconds at which pings will be sent to a peer. Pings are used both to monitor the liveness of the connection and also to dynamically adjust the throttle during periods of low traffic so that the throttle has reasonable responsiveness during traffic spikes.
+ </description>
+ </method>
+ <method name="reset">
+ <return type="void">
+ </return>
+ <description>
+ Forcefully disconnects a peer. The foreign host represented by the peer is not notified of the disconnection and will timeout on its connection to the local host.
+ </description>
+ </method>
+ <method name="send">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="channel" type="int">
+ </argument>
+ <argument index="1" name="packet" type="PackedByteArray">
+ </argument>
+ <argument index="2" name="flags" type="int">
+ </argument>
+ <description>
+ Queues a [code]packet[/code] to be sent over the specified [code]channel[/code]. See [code]FLAG_*[/code] constants for available packet flags.
+ </description>
+ </method>
+ <method name="set_timeout">
+ <return type="void">
+ </return>
+ <argument index="0" name="timeout" type="int">
+ </argument>
+ <argument index="1" name="timeout_min" type="int">
+ </argument>
+ <argument index="2" name="timeout_max" type="int">
+ </argument>
+ <description>
+ Sets the timeout parameters for a peer. The timeout parameters control how and when a peer will timeout from a failure to acknowledge reliable traffic. Timeout values are expressed in milliseconds.
+ The [code]timeout_limit[/code] is a factor that, multiplied by a value based on the average round trip time, will determine the timeout limit for a reliable packet. When that limit is reached, the timeout will be doubled, and the peer will be disconnected if that limit has reached [code]timeout_min[/code]. The [code]timeout_max[/code] parameter, on the other hand, defines a fixed timeout for which any packet must be acknowledged or the peer will be dropped.
+ </description>
+ </method>
+ <method name="throttle_configure">
+ <return type="void">
+ </return>
+ <argument index="0" name="interval" type="int">
+ </argument>
+ <argument index="1" name="acceleration" type="int">
+ </argument>
+ <argument index="2" name="deceleration" type="int">
+ </argument>
+ <description>
+ Configures throttle parameter for a peer.
+ Unreliable packets are dropped by ENet in response to the varying conditions of the Internet connection to the peer. The throttle represents a probability that an unreliable packet should not be dropped and thus sent by ENet to the peer. By measuring fluctuations in round trip times of reliable packets over the specified [code]interval[/code], ENet will either increase the probably by the amount specified in the [code]acceleration[/code] parameter, or decrease it by the amount specified in the [code]deceleration[/code] parameter (both are ratios to [constant PACKET_THROTTLE_SCALE]).
+ When the throttle has a value of [constant PACKET_THROTTLE_SCALE], no unreliable packets are dropped by ENet, and so 100% of all unreliable packets will be sent.
+ When the throttle has a value of 0, all unreliable packets are dropped by ENet, and so 0% of all unreliable packets will be sent.
+ Intermediate values for the throttle represent intermediate probabilities between 0% and 100% of unreliable packets being sent. The bandwidth limits of the local and foreign hosts are taken into account to determine a sensible limit for the throttle probability above which it should not raise even in the best of conditions.
+ </description>
+ </method>
+ </methods>
+ <constants>
+ <constant name="STATE_DISCONNECTED" value="0" enum="PeerState">
+ </constant>
+ <constant name="STATE_CONNECTING" value="1" enum="PeerState">
+ </constant>
+ <constant name="STATE_ACKNOWLEDGING_CONNECT" value="2" enum="PeerState">
+ </constant>
+ <constant name="STATE_CONNECTION_PENDING" value="3" enum="PeerState">
+ </constant>
+ <constant name="STATE_CONNECTION_SUCCEEDED" value="4" enum="PeerState">
+ </constant>
+ <constant name="STATE_CONNECTED" value="5" enum="PeerState">
+ </constant>
+ <constant name="STATE_DISCONNECT_LATER" value="6" enum="PeerState">
+ </constant>
+ <constant name="STATE_DISCONNECTING" value="7" enum="PeerState">
+ </constant>
+ <constant name="STATE_ACKNOWLEDGING_DISCONNECT" value="8" enum="PeerState">
+ </constant>
+ <constant name="STATE_ZOMBIE" value="9" enum="PeerState">
+ </constant>
+ <constant name="PEER_PACKET_LOSS" value="0" enum="PeerStatistic">
+ Mean packet loss of reliable packets as a ratio with respect to the [constant PACKET_LOSS_SCALE].
+ </constant>
+ <constant name="PEER_PACKET_LOSS_VARIANCE" value="1" enum="PeerStatistic">
+ Packet loss variance.
+ </constant>
+ <constant name="PEER_PACKET_LOSS_EPOCH" value="2" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_ROUND_TRIP_TIME" value="3" enum="PeerStatistic">
+ Mean packet round trip time for reliable packets.
+ </constant>
+ <constant name="PEER_ROUND_TRIP_TIME_VARIANCE" value="4" enum="PeerStatistic">
+ Variance of the mean round trip time.
+ </constant>
+ <constant name="PEER_LAST_ROUND_TRIP_TIME" value="5" enum="PeerStatistic">
+ Last recorded round trip time for a reliable packet.
+ </constant>
+ <constant name="PEER_LAST_ROUND_TRIP_TIME_VARIANCE" value="6" enum="PeerStatistic">
+ Variance of the last trip time recorded.
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE" value="7" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_LIMIT" value="8" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_COUNTER" value="9" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_EPOCH" value="10" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_ACCELERATION" value="11" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_DECELERATION" value="12" enum="PeerStatistic">
+ </constant>
+ <constant name="PEER_PACKET_THROTTLE_INTERVAL" value="13" enum="PeerStatistic">
+ </constant>
+ <constant name="PACKET_LOSS_SCALE" value="65536">
+ The reference scale for packet loss. See [method get_statistic] and [constant PEER_PACKET_LOSS].
+ </constant>
+ <constant name="PACKET_THROTTLE_SCALE" value="32">
+ The reference value for throttle configuration. See [method throttle_configure].
+ </constant>
+ <constant name="FLAG_RELIABLE" value="1">
+ Mark the packet to be sent as reliable.
+ </constant>
+ <constant name="FLAG_UNSEQUENCED" value="2">
+ Mark the packet to be sent unsequenced (unreliable).
+ </constant>
+ <constant name="FLAG_UNRELIABLE_FRAGMENT" value="8">
+ Mark the packet to be sent unreliable even if the packet is too big and needs fragmentation (increasing the chance of it being dropped).
+ </constant>
+ </constants>
+</class>
diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp
new file mode 100644
index 0000000000..0bda9402f8
--- /dev/null
+++ b/modules/enet/enet_connection.cpp
@@ -0,0 +1,470 @@
+/*************************************************************************/
+/* enet_connection.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "enet_connection.h"
+
+#include "enet_packet_peer.h"
+
+#include "core/io/compression.h"
+#include "core/io/ip.h"
+
+void ENetConnection::broadcast(enet_uint8 p_channel, ENetPacket *p_packet) {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ ERR_FAIL_COND_MSG(p_channel >= host->channelLimit, vformat("Unable to send packet on channel %d, max channels: %d", p_channel, (int)host->channelLimit));
+ enet_host_broadcast(host, p_channel, p_packet);
+}
+
+Error ENetConnection::create_host_bound(const IPAddress &p_bind_address, int p_port, int p_max_peers, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
+ ERR_FAIL_COND_V_MSG(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER, "Invalid bind IP.");
+ ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive).");
+
+ ENetAddress address;
+ memset(&address, 0, sizeof(address));
+ address.port = p_port;
+#ifdef GODOT_ENET
+ if (p_bind_address.is_wildcard()) {
+ address.wildcard = 1;
+ } else {
+ enet_address_set_ip(&address, p_bind_address.get_ipv6(), 16);
+ }
+#else
+ if (p_bind_address.is_wildcard()) {
+ address.host = 0;
+ } else {
+ ERR_FAIL_COND_V(!p_bind_address.is_ipv4(), ERR_INVALID_PARAMETER);
+ address.host = *(uint32_t *)p_bind_address.get_ipv4();
+ }
+#endif
+ return _create(&address, p_max_peers, p_max_channels, p_in_bandwidth, p_out_bandwidth);
+}
+
+Error ENetConnection::create_host(int p_max_peers, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
+ return _create(nullptr, p_max_peers, p_max_channels, p_in_bandwidth, p_out_bandwidth);
+}
+
+void ENetConnection::destroy() {
+ ERR_FAIL_COND_MSG(!host, "Host already destroyed");
+ for (List<Ref<ENetPacketPeer>>::Element *E = peers.front(); E; E = E->next()) {
+ E->get()->_on_disconnect();
+ }
+ peers.clear();
+ enet_host_destroy(host);
+ host = nullptr;
+}
+
+Ref<ENetPacketPeer> ENetConnection::connect_to_host(const String &p_address, int p_port, int p_channels, int p_data) {
+ Ref<ENetPacketPeer> out;
+ ERR_FAIL_COND_V_MSG(!host, out, "The ENetConnection instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(peers.size(), out, "The ENetConnection is already connected to a peer.");
+ ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, out, "The remote port number must be between 1 and 65535 (inclusive).");
+
+ IPAddress ip;
+ if (p_address.is_valid_ip_address()) {
+ ip = p_address;
+ } else {
+#ifdef GODOT_ENET
+ ip = IP::get_singleton()->resolve_hostname(p_address);
+#else
+ ip = IP::get_singleton()->resolve_hostname(p_address, IP::TYPE_IPV4);
+#endif
+ ERR_FAIL_COND_V_MSG(!ip.is_valid(), out, "Couldn't resolve the server IP address or domain name.");
+ }
+
+ ENetAddress address;
+#ifdef GODOT_ENET
+ enet_address_set_ip(&address, ip.get_ipv6(), 16);
+#else
+ ERR_FAIL_COND_V_MSG(!ip.is_ipv4(), out, "Connecting to an IPv6 server isn't supported when using vanilla ENet. Recompile Godot with the bundled ENet library.");
+ address.host = *(uint32_t *)ip.get_ipv4();
+#endif
+ address.port = p_port;
+
+ // Initiate connection, allocating enough channels
+ ENetPeer *peer = enet_host_connect(host, &address, p_channels, p_data);
+
+ if (peer == nullptr) {
+ return nullptr;
+ }
+ out = Ref<ENetPacketPeer>(memnew(ENetPacketPeer(peer)));
+ peers.push_back(out);
+ return out;
+}
+
+ENetConnection::EventType ENetConnection::service(int p_timeout, Event &r_event) {
+ ERR_FAIL_COND_V_MSG(!host, EVENT_ERROR, "The ENetConnection instance isn't currently active.");
+ ERR_FAIL_COND_V(r_event.peer.is_valid(), EVENT_ERROR);
+
+ // Drop peers that have already been disconnected.
+ // NOTE: Forcibly disconnected peers (i.e. peers disconnected via
+ // enet_peer_disconnect*) do not trigger DISCONNECTED events.
+ List<Ref<ENetPacketPeer>>::Element *E = peers.front();
+ while (E) {
+ if (!E->get()->is_active()) {
+ peers.erase(E->get());
+ }
+ E = E->next();
+ }
+
+ ENetEvent event;
+ int ret = enet_host_service(host, &event, p_timeout);
+
+ if (ret < 0) {
+ return EVENT_ERROR;
+ } else if (ret == 0) {
+ return EVENT_NONE;
+ }
+ switch (event.type) {
+ case ENET_EVENT_TYPE_CONNECT: {
+ if (event.peer->data == nullptr) {
+ Ref<ENetPacketPeer> pp = memnew(ENetPacketPeer(event.peer));
+ peers.push_back(pp);
+ }
+ r_event.peer = Ref<ENetPacketPeer>((ENetPacketPeer *)event.peer->data);
+ r_event.data = event.data;
+ return EVENT_CONNECT;
+ } break;
+ case ENET_EVENT_TYPE_DISCONNECT: {
+ // A peer disconnected.
+ if (event.peer->data != nullptr) {
+ Ref<ENetPacketPeer> pp = Ref<ENetPacketPeer>((ENetPacketPeer *)event.peer->data);
+ pp->_on_disconnect();
+ peers.erase(pp);
+ r_event.peer = pp;
+ r_event.data = event.data;
+ return EVENT_DISCONNECT;
+ }
+ return EVENT_ERROR;
+ } break;
+ case ENET_EVENT_TYPE_RECEIVE: {
+ // Packet reveived.
+ if (event.peer->data != nullptr) {
+ Ref<ENetPacketPeer> pp = Ref<ENetPacketPeer>((ENetPacketPeer *)event.peer->data);
+ r_event.peer = Ref<ENetPacketPeer>((ENetPacketPeer *)event.peer->data);
+ r_event.channel_id = event.channelID;
+ r_event.packet = event.packet;
+ return EVENT_RECEIVE;
+ }
+ return EVENT_ERROR;
+ } break;
+ case ENET_EVENT_TYPE_NONE:
+ return EVENT_NONE;
+ default:
+ return EVENT_NONE;
+ }
+}
+
+void ENetConnection::flush() {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ enet_host_flush(host);
+}
+
+void ENetConnection::bandwidth_limit(int p_in_bandwidth, int p_out_bandwidth) {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ enet_host_bandwidth_limit(host, p_in_bandwidth, p_out_bandwidth);
+}
+
+void ENetConnection::channel_limit(int p_max_channels) {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ enet_host_channel_limit(host, p_max_channels);
+}
+
+void ENetConnection::bandwidth_throttle() {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ enet_host_bandwidth_throttle(host);
+}
+
+void ENetConnection::compress(CompressionMode p_mode) {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ Compressor::setup(host, p_mode);
+}
+
+double ENetConnection::pop_statistic(HostStatistic p_stat) {
+ ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
+ uint32_t *ptr = nullptr;
+ switch (p_stat) {
+ case HOST_TOTAL_SENT_DATA:
+ ptr = &(host->totalSentData);
+ break;
+ case HOST_TOTAL_SENT_PACKETS:
+ ptr = &(host->totalSentPackets);
+ break;
+ case HOST_TOTAL_RECEIVED_DATA:
+ ptr = &(host->totalReceivedData);
+ break;
+ case HOST_TOTAL_RECEIVED_PACKETS:
+ ptr = &(host->totalReceivedPackets);
+ break;
+ }
+ ERR_FAIL_COND_V_MSG(ptr == nullptr, 0, "Invalid statistic: " + itos(p_stat));
+ uint32_t ret = *ptr;
+ *ptr = 0;
+ return ret;
+}
+
+int ENetConnection::get_max_channels() const {
+ ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
+ return host->channelLimit;
+}
+
+int ENetConnection::get_local_port() const {
+ ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(!(host->socket), 0, "The ENetConnection instance isn't currently bound");
+ ENetAddress address;
+ ERR_FAIL_COND_V_MSG(enet_socket_get_address(host->socket, &address), 0, "Unable to get socket address");
+ return address.port;
+}
+
+void ENetConnection::get_peers(List<Ref<ENetPacketPeer>> &r_peers) {
+ for (const Ref<ENetPacketPeer> &I : peers) {
+ r_peers.push_back(I);
+ }
+}
+
+Array ENetConnection::_get_peers() {
+ ERR_FAIL_COND_V_MSG(!host, Array(), "The ENetConnection instance isn't currently active.");
+ Array out;
+ for (const Ref<ENetPacketPeer> &I : peers) {
+ out.push_back(I);
+ }
+ return out;
+}
+
+Error ENetConnection::dtls_server_setup(Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert) {
+#ifdef GODOT_ENET
+ ERR_FAIL_COND_V_MSG(!host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
+ return enet_host_dtls_server_setup(host, p_key.ptr(), p_cert.ptr()) ? FAILED : OK;
+#else
+ ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "ENet DTLS support not available in this build.");
+#endif
+}
+
+void ENetConnection::refuse_new_connections(bool p_refuse) {
+#ifdef GODOT_ENET
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ enet_host_refuse_new_connections(host, p_refuse);
+#else
+ ERR_FAIL_MSG("ENet DTLS support not available in this build.");
+#endif
+}
+
+Error ENetConnection::dtls_client_setup(Ref<X509Certificate> p_cert, const String &p_hostname, bool p_verify) {
+#ifdef GODOT_ENET
+ ERR_FAIL_COND_V_MSG(!host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
+ return enet_host_dtls_client_setup(host, p_cert.ptr(), p_verify, p_hostname.utf8().get_data()) ? FAILED : OK;
+#else
+ ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "ENet DTLS support not available in this build.");
+#endif
+}
+
+Error ENetConnection::_create(ENetAddress *p_address, int p_max_peers, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
+ ERR_FAIL_COND_V_MSG(host != nullptr, ERR_ALREADY_IN_USE, "The ENetConnection instance is already active.");
+ ERR_FAIL_COND_V_MSG(p_max_peers < 1 || p_max_peers > 4095, ERR_INVALID_PARAMETER, "The number of clients must be set between 1 and 4095 (inclusive).");
+ ERR_FAIL_COND_V_MSG(p_max_channels < 0 || p_max_channels > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, ERR_INVALID_PARAMETER, "Invalid channel count. Must be between 0 and 255 (0 means maximum, i.e. 255)");
+ ERR_FAIL_COND_V_MSG(p_in_bandwidth < 0, ERR_INVALID_PARAMETER, "The incoming bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
+ ERR_FAIL_COND_V_MSG(p_out_bandwidth < 0, ERR_INVALID_PARAMETER, "The outgoing bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
+
+ host = enet_host_create(p_address /* the address to bind the server host to */,
+ p_max_peers /* allow up to p_max_peers connections */,
+ p_max_channels /* allow up to p_max_channel to be used */,
+ p_in_bandwidth /* limit incoming bandwidth if > 0 */,
+ p_out_bandwidth /* limit outgoing bandwidth if > 0 */);
+
+ ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create an ENet host.");
+ return OK;
+}
+
+Array ENetConnection::_service(int p_timeout) {
+ Array out;
+ Event event;
+ Ref<ENetPacketPeer> peer;
+ EventType ret = service(p_timeout, event);
+ out.push_back(ret);
+ out.push_back(event.peer);
+ out.push_back(event.data);
+ out.push_back(event.channel_id);
+ if (event.packet && event.peer.is_valid()) {
+ event.peer->_queue_packet(event.packet);
+ }
+ return out;
+}
+
+void ENetConnection::_broadcast(int p_channel, PackedByteArray p_packet, int p_flags) {
+ ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
+ ERR_FAIL_COND_MSG(p_channel < 0 || p_channel > (int)host->channelLimit, "Invalid channel");
+ ERR_FAIL_COND_MSG(p_flags & ~ENetPacketPeer::FLAG_ALLOWED, "Invalid flags");
+ ENetPacket *pkt = enet_packet_create(p_packet.ptr(), p_packet.size(), p_flags);
+ broadcast(p_channel, pkt);
+}
+
+void ENetConnection::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("create_host_bound", "bind_address", "bind_port", "max_peers", "max_channels", "in_bandwidth", "out_bandwidth"), &ENetConnection::create_host_bound, DEFVAL(32), DEFVAL(0), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("create_host", "max_peers", "max_channels", "in_bandwidth", "out_bandwidth"), &ENetConnection::create_host, DEFVAL(32), DEFVAL(0), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("destroy"), &ENetConnection::destroy);
+ ClassDB::bind_method(D_METHOD("connect_to_host", "address", "port", "channels", "data"), &ENetConnection::connect_to_host, DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("service", "timeout"), &ENetConnection::_service, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("flush"), &ENetConnection::flush);
+ ClassDB::bind_method(D_METHOD("bandwidth_limit", "in_bandwidth", "out_bandwidth"), &ENetConnection::bandwidth_limit, DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("channel_limit", "limit"), &ENetConnection::channel_limit);
+ ClassDB::bind_method(D_METHOD("broadcast", "channel", "packet", "flags"), &ENetConnection::_broadcast);
+ ClassDB::bind_method(D_METHOD("compress", "mode"), &ENetConnection::compress);
+ ClassDB::bind_method(D_METHOD("dtls_server_setup", "key", "certificate"), &ENetConnection::dtls_server_setup);
+ ClassDB::bind_method(D_METHOD("dtls_client_setup", "certificate", "hostname", "verify"), &ENetConnection::dtls_client_setup, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("refuse_new_connections", "refuse"), &ENetConnection::refuse_new_connections);
+ ClassDB::bind_method(D_METHOD("pop_statistic", "statistic"), &ENetConnection::pop_statistic);
+ ClassDB::bind_method(D_METHOD("get_max_channels"), &ENetConnection::get_max_channels);
+ ClassDB::bind_method(D_METHOD("get_local_port"), &ENetConnection::get_local_port);
+ ClassDB::bind_method(D_METHOD("get_peers"), &ENetConnection::_get_peers);
+
+ BIND_ENUM_CONSTANT(COMPRESS_NONE);
+ BIND_ENUM_CONSTANT(COMPRESS_RANGE_CODER);
+ BIND_ENUM_CONSTANT(COMPRESS_FASTLZ);
+ BIND_ENUM_CONSTANT(COMPRESS_ZLIB);
+ BIND_ENUM_CONSTANT(COMPRESS_ZSTD);
+
+ BIND_ENUM_CONSTANT(EVENT_ERROR);
+ BIND_ENUM_CONSTANT(EVENT_NONE);
+ BIND_ENUM_CONSTANT(EVENT_CONNECT);
+ BIND_ENUM_CONSTANT(EVENT_DISCONNECT);
+ BIND_ENUM_CONSTANT(EVENT_RECEIVE);
+
+ BIND_ENUM_CONSTANT(HOST_TOTAL_SENT_DATA);
+ BIND_ENUM_CONSTANT(HOST_TOTAL_SENT_PACKETS);
+ BIND_ENUM_CONSTANT(HOST_TOTAL_RECEIVED_DATA);
+ BIND_ENUM_CONSTANT(HOST_TOTAL_RECEIVED_PACKETS);
+}
+
+ENetConnection::~ENetConnection() {
+ if (host) {
+ destroy();
+ }
+}
+
+size_t ENetConnection::Compressor::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
+ Compressor *compressor = (Compressor *)(context);
+
+ if (size_t(compressor->src_mem.size()) < inLimit) {
+ compressor->src_mem.resize(inLimit);
+ }
+
+ int total = inLimit;
+ int ofs = 0;
+ while (total) {
+ for (size_t i = 0; i < inBufferCount; i++) {
+ int to_copy = MIN(total, int(inBuffers[i].dataLength));
+ memcpy(&compressor->src_mem.write[ofs], inBuffers[i].data, to_copy);
+ ofs += to_copy;
+ total -= to_copy;
+ }
+ }
+
+ Compression::Mode mode;
+
+ switch (compressor->mode) {
+ case COMPRESS_FASTLZ: {
+ mode = Compression::MODE_FASTLZ;
+ } break;
+ case COMPRESS_ZLIB: {
+ mode = Compression::MODE_DEFLATE;
+ } break;
+ case COMPRESS_ZSTD: {
+ mode = Compression::MODE_ZSTD;
+ } break;
+ default: {
+ ERR_FAIL_V_MSG(0, vformat("Invalid ENet compression mode: %d", compressor->mode));
+ }
+ }
+
+ int req_size = Compression::get_max_compressed_buffer_size(ofs, mode);
+ if (compressor->dst_mem.size() < req_size) {
+ compressor->dst_mem.resize(req_size);
+ }
+ int ret = Compression::compress(compressor->dst_mem.ptrw(), compressor->src_mem.ptr(), ofs, mode);
+
+ if (ret < 0) {
+ return 0;
+ }
+
+ if (ret > int(outLimit)) {
+ return 0; // Do not bother
+ }
+
+ memcpy(outData, compressor->dst_mem.ptr(), ret);
+
+ return ret;
+}
+
+size_t ENetConnection::Compressor::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
+ Compressor *compressor = (Compressor *)(context);
+ int ret = -1;
+ switch (compressor->mode) {
+ case COMPRESS_FASTLZ: {
+ ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_FASTLZ);
+ } break;
+ case COMPRESS_ZLIB: {
+ ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE);
+ } break;
+ case COMPRESS_ZSTD: {
+ ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_ZSTD);
+ } break;
+ default: {
+ }
+ }
+ if (ret < 0) {
+ return 0;
+ } else {
+ return ret;
+ }
+}
+
+void ENetConnection::Compressor::setup(ENetHost *p_host, CompressionMode p_mode) {
+ ERR_FAIL_COND(!p_host);
+ switch (p_mode) {
+ case COMPRESS_NONE: {
+ enet_host_compress(p_host, nullptr);
+ } break;
+ case COMPRESS_RANGE_CODER: {
+ enet_host_compress_with_range_coder(p_host);
+ } break;
+ case COMPRESS_FASTLZ:
+ case COMPRESS_ZLIB:
+ case COMPRESS_ZSTD: {
+ Compressor *compressor = memnew(Compressor(p_mode));
+ enet_host_compress(p_host, &(compressor->enet_compressor));
+ } break;
+ }
+}
+
+ENetConnection::Compressor::Compressor(CompressionMode p_mode) {
+ mode = p_mode;
+ enet_compressor.context = this;
+ enet_compressor.compress = enet_compress;
+ enet_compressor.decompress = enet_decompress;
+ enet_compressor.destroy = enet_compressor_destroy;
+}
diff --git a/modules/enet/enet_connection.h b/modules/enet/enet_connection.h
new file mode 100644
index 0000000000..0f7744953e
--- /dev/null
+++ b/modules/enet/enet_connection.h
@@ -0,0 +1,138 @@
+/*************************************************************************/
+/* enet_connection.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef ENET_CONNECTION_H
+#define ENET_CONNECTION_H
+
+#include "core/object/ref_counted.h"
+
+#include "core/crypto/crypto.h"
+#include "enet_packet_peer.h"
+
+#include <enet/enet.h>
+
+class ENetConnection : public RefCounted {
+ GDCLASS(ENetConnection, RefCounted);
+
+public:
+ enum CompressionMode {
+ COMPRESS_NONE = 0,
+ COMPRESS_RANGE_CODER,
+ COMPRESS_FASTLZ,
+ COMPRESS_ZLIB,
+ COMPRESS_ZSTD,
+ };
+
+ enum HostStatistic {
+ HOST_TOTAL_SENT_DATA,
+ HOST_TOTAL_SENT_PACKETS,
+ HOST_TOTAL_RECEIVED_DATA,
+ HOST_TOTAL_RECEIVED_PACKETS,
+ };
+
+ enum EventType {
+ EVENT_ERROR = -1,
+ EVENT_NONE = 0,
+ EVENT_CONNECT,
+ EVENT_DISCONNECT,
+ EVENT_RECEIVE,
+ };
+
+ struct Event {
+ Ref<ENetPacketPeer> peer;
+ enet_uint8 channel_id = 0;
+ enet_uint32 data = 0;
+ ENetPacket *packet = nullptr;
+ };
+
+protected:
+ static void _bind_methods();
+
+private:
+ ENetHost *host = nullptr;
+ List<Ref<ENetPacketPeer>> peers;
+
+ Error _create(ENetAddress *p_address, int p_max_peers, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth);
+ Array _service(int p_timeout = 0);
+ void _broadcast(int p_channel, PackedByteArray p_packet, int p_flags);
+ Array _get_peers();
+
+ class Compressor {
+ private:
+ CompressionMode mode = COMPRESS_NONE;
+ Vector<uint8_t> src_mem;
+ Vector<uint8_t> dst_mem;
+ ENetCompressor enet_compressor;
+
+ Compressor(CompressionMode mode);
+
+ static size_t enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit);
+ static size_t enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit);
+ static void enet_compressor_destroy(void *context) {
+ memdelete((Compressor *)context);
+ }
+
+ public:
+ static void setup(ENetHost *p_host, CompressionMode p_mode);
+ };
+
+public:
+ void broadcast(enet_uint8 p_channel, ENetPacket *p_packet);
+ Error create_host_bound(const IPAddress &p_bind_address = IPAddress("*"), int p_port = 0, int p_max_peers = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
+ Error create_host(int p_max_peers = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
+ void destroy();
+ Ref<ENetPacketPeer> connect_to_host(const String &p_address, int p_port, int p_channels, int p_data = 0);
+ EventType service(int p_timeout, Event &r_event);
+ void flush();
+ void bandwidth_limit(int p_in_bandwidth = 0, int p_out_bandwidth = 0);
+ void channel_limit(int p_max_channels);
+ void bandwidth_throttle();
+ void compress(CompressionMode p_mode);
+ double pop_statistic(HostStatistic p_stat);
+ int get_max_channels() const;
+
+ // Extras
+ void get_peers(List<Ref<ENetPacketPeer>> &r_peers);
+ int get_local_port() const;
+
+ // Godot additions
+ Error dtls_server_setup(Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert);
+ Error dtls_client_setup(Ref<X509Certificate> p_cert, const String &p_hostname, bool p_verify = true);
+ void refuse_new_connections(bool p_refuse);
+
+ ENetConnection() {}
+ ~ENetConnection();
+};
+
+VARIANT_ENUM_CAST(ENetConnection::CompressionMode);
+VARIANT_ENUM_CAST(ENetConnection::EventType);
+VARIANT_ENUM_CAST(ENetConnection::HostStatistic);
+
+#endif // ENET_CONNECTION_H
diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp
index b4ca93f4d9..28b6bb035a 100644
--- a/modules/enet/enet_multiplayer_peer.cpp
+++ b/modules/enet/enet_multiplayer_peer.cpp
@@ -46,458 +46,375 @@ void ENetMultiplayerPeer::set_target_peer(int p_peer) {
}
int ENetMultiplayerPeer::get_packet_peer() const {
- ERR_FAIL_COND_V_MSG(!active, 1, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(!_is_active(), 1, "The multiplayer instance isn't currently active.");
ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
return incoming_packets.front()->get().from;
}
-int ENetMultiplayerPeer::get_packet_channel() const {
- ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_V(incoming_packets.size() == 0, -1);
-
- return incoming_packets.front()->get().channel;
-}
-
-int ENetMultiplayerPeer::get_last_packet_channel() const {
- ERR_FAIL_COND_V_MSG(!active, -1, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_V(!current_packet.packet, -1);
+Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) {
+ ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
+ Ref<ENetConnection> host;
+ host.instantiate();
+ Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth);
+ if (err != OK) {
+ return err;
+ }
- return current_packet.channel;
+ active_mode = MODE_SERVER;
+ refuse_connections = false;
+ unique_id = 1;
+ connection_status = CONNECTION_CONNECTED;
+ hosts[0] = host;
+ return OK;
}
-Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_in_bandwidth, int p_out_bandwidth) {
- ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
- ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive).");
- ERR_FAIL_COND_V_MSG(p_max_clients < 1 || p_max_clients > 4095, ERR_INVALID_PARAMETER, "The number of clients must be set between 1 and 4095 (inclusive).");
- ERR_FAIL_COND_V_MSG(p_in_bandwidth < 0, ERR_INVALID_PARAMETER, "The incoming bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
- ERR_FAIL_COND_V_MSG(p_out_bandwidth < 0, ERR_INVALID_PARAMETER, "The outgoing bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
- ERR_FAIL_COND_V(dtls_enabled && (dtls_key.is_null() || dtls_cert.is_null()), ERR_INVALID_PARAMETER);
-
- ENetAddress address;
- memset(&address, 0, sizeof(address));
-
-#ifdef GODOT_ENET
- if (bind_ip.is_wildcard()) {
- address.wildcard = 1;
+Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) {
+ ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
+ Ref<ENetConnection> host;
+ host.instantiate();
+ Error err;
+ if (p_local_port) {
+ err = host->create_host_bound(bind_ip, p_local_port, 1, 0, p_in_bandwidth, p_out_bandwidth);
} else {
- enet_address_set_ip(&address, bind_ip.get_ipv6(), 16);
+ err = host->create_host(1, 0, p_in_bandwidth, p_out_bandwidth);
}
-#else
- if (bind_ip.is_wildcard()) {
- address.host = 0;
- } else {
- ERR_FAIL_COND_V(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER);
- address.host = *(uint32_t *)bind_ip.get_ipv4();
+ if (err != OK) {
+ return err;
}
-#endif
- address.port = p_port;
- host = enet_host_create(&address /* the address to bind the server host to */,
- p_max_clients /* allow up to 32 clients and/or outgoing connections */,
- channel_count /* allow up to channel_count to be used */,
- p_in_bandwidth /* limit incoming bandwidth if > 0 */,
- p_out_bandwidth /* limit outgoing bandwidth if > 0 */);
+ unique_id = generate_unique_id();
- ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create an ENet multiplayer server.");
-#ifdef GODOT_ENET
- if (dtls_enabled) {
- enet_host_dtls_server_setup(host, dtls_key.ptr(), dtls_cert.ptr());
+ Ref<ENetPacketPeer> peer = host->connect_to_host(p_address, p_port, p_channel_count > 0 ? p_channel_count + SYSCH_MAX : 0, unique_id);
+ if (peer.is_null()) {
+ host->destroy();
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Couldn't connect to the ENet multiplayer server.");
}
- enet_host_refuse_new_connections(host, refuse_connections);
-#endif
- _setup_compressor();
- active = true;
- server = true;
+ // Need to wait for CONNECT event.
+ connection_status = CONNECTION_CONNECTING;
+ active_mode = MODE_CLIENT;
refuse_connections = false;
- unique_id = 1;
+ peers[1] = peer;
+ hosts[0] = host;
+
+ return OK;
+}
+
+Error ENetMultiplayerPeer::create_mesh(int p_id) {
+ ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0");
+ ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
+ active_mode = MODE_MESH;
+ refuse_connections = false;
+ unique_id = p_id;
connection_status = CONNECTION_CONNECTED;
return OK;
}
-Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) {
- ERR_FAIL_COND_V_MSG(active, ERR_ALREADY_IN_USE, "The multiplayer instance is already active.");
- ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive).");
- ERR_FAIL_COND_V_MSG(p_local_port < 0 || p_local_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive).");
- ERR_FAIL_COND_V_MSG(p_in_bandwidth < 0, ERR_INVALID_PARAMETER, "The incoming bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
- ERR_FAIL_COND_V_MSG(p_out_bandwidth < 0, ERR_INVALID_PARAMETER, "The outgoing bandwidth limit must be greater than or equal to 0 (0 disables the limit).");
- ENetAddress c_client;
+Error ENetMultiplayerPeer::add_mesh_peer(int p_id, Ref<ENetConnection> p_host) {
+ ERR_FAIL_COND_V(p_host.is_null(), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V_MSG(active_mode != MODE_MESH, ERR_UNCONFIGURED, "The multiplayer instance is not configured as a mesh. Call 'create_mesh' first.");
+ List<Ref<ENetPacketPeer>> host_peers;
+ p_host->get_peers(host_peers);
+ ERR_FAIL_COND_V_MSG(host_peers.size() != 1 || host_peers[0]->get_state() != ENetPacketPeer::STATE_CONNECTED, ERR_INVALID_PARAMETER, "The provided host must have excatly one peer in the connected state.");
+ hosts[p_id] = p_host;
+ peers[p_id] = host_peers[0];
+ emit_signal(SNAME("peer_connected"), p_id);
+ return OK;
+}
-#ifdef GODOT_ENET
- if (bind_ip.is_wildcard()) {
- c_client.wildcard = 1;
- } else {
- enet_address_set_ip(&c_client, bind_ip.get_ipv6(), 16);
- }
-#else
- if (bind_ip.is_wildcard()) {
- c_client.host = 0;
- } else {
- ERR_FAIL_COND_V_MSG(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER, "Wildcard IP addresses are only permitted in IPv4, not IPv6.");
- c_client.host = *(uint32_t *)bind_ip.get_ipv4();
+bool ENetMultiplayerPeer::_poll_server() {
+ for (const KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (!(E.value->is_active())) {
+ emit_signal(SNAME("peer_disconnected"), E.value->get_meta(SNAME("_net_id")));
+ peers.erase(E.key);
+ }
}
-#endif
-
- c_client.port = p_local_port;
-
- host = enet_host_create(&c_client /* create a client host */,
- 1 /* only allow 1 outgoing connection */,
- channel_count /* allow up to channel_count to be used */,
- p_in_bandwidth /* limit incoming bandwidth if > 0 */,
- p_out_bandwidth /* limit outgoing bandwidth if > 0 */);
-
- ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create the ENet client host.");
-#ifdef GODOT_ENET
- if (dtls_enabled) {
- enet_host_dtls_client_setup(host, dtls_cert.ptr(), dtls_verify, p_address.utf8().get_data());
+ ENetConnection::Event event;
+ ENetConnection::EventType ret = hosts[0]->service(0, event);
+ if (ret == ENetConnection::EVENT_ERROR) {
+ return true;
}
- enet_host_refuse_new_connections(host, refuse_connections);
-#endif
+ switch (ret) {
+ case ENetConnection::EVENT_CONNECT: {
+ if (refuse_connections) {
+ event.peer->reset();
+ return false;
+ }
+ // Client joined with invalid ID, probably trying to exploit us.
+ if (event.data < 2 || peers.has((int)event.data)) {
+ event.peer->reset();
+ return false;
+ }
+ int id = event.data;
+ event.peer->set_meta(SNAME("_net_id"), id);
+ peers[id] = event.peer;
- _setup_compressor();
+ emit_signal(SNAME("peer_connected"), id);
+ if (server_relay) {
+ _notify_peers(id, true);
+ }
+ return false;
+ }
+ case ENetConnection::EVENT_DISCONNECT: {
+ int id = event.peer->get_meta(SNAME("_net_id"));
+ if (!peers.has(id)) {
+ // Never fully connected.
+ return false;
+ }
- IPAddress ip;
- if (p_address.is_valid_ip_address()) {
- ip = p_address;
- } else {
-#ifdef GODOT_ENET
- ip = IP::get_singleton()->resolve_hostname(p_address);
-#else
- ip = IP::get_singleton()->resolve_hostname(p_address, IP::TYPE_IPV4);
-#endif
+ emit_signal(SNAME("peer_disconnected"), id);
+ peers.erase(id);
+ if (!server_relay) {
+ _notify_peers(id, false);
+ }
+ return false;
+ }
+ case ENetConnection::EVENT_RECEIVE: {
+ if (event.channel_id == SYSCH_CONFIG) {
+ _destroy_unused(event.packet);
+ ERR_FAIL_V_MSG(false, "Only server can send config messages");
+ } else {
+ if (event.packet->dataLength < 8) {
+ _destroy_unused(event.packet);
+ ERR_FAIL_V_MSG(false, "Invalid packet size");
+ }
- ERR_FAIL_COND_V_MSG(!ip.is_valid(), ERR_CANT_RESOLVE, "Couldn't resolve the server IP address or domain name.");
- }
+ uint32_t source = decode_uint32(&event.packet->data[0]);
+ int target = decode_uint32(&event.packet->data[4]);
- ENetAddress address;
-#ifdef GODOT_ENET
- enet_address_set_ip(&address, ip.get_ipv6(), 16);
-#else
- ERR_FAIL_COND_V_MSG(!ip.is_ipv4(), ERR_INVALID_PARAMETER, "Connecting to an IPv6 server isn't supported when using vanilla ENet. Recompile Godot with the bundled ENet library.");
- address.host = *(uint32_t *)ip.get_ipv4();
-#endif
- address.port = p_port;
+ uint32_t id = event.peer->get_meta(SNAME("_net_id"));
+ // Someone is cheating and trying to fake the source!
+ if (source != id) {
+ _destroy_unused(event.packet);
+ ERR_FAIL_V_MSG(false, "Someone is cheating and trying to fake the source!");
+ }
- unique_id = _gen_unique_id();
+ Packet packet;
+ packet.packet = event.packet;
+ packet.channel = event.channel_id;
+ packet.from = id;
- // Initiate connection, allocating enough channels
- ENetPeer *peer = enet_host_connect(host, &address, channel_count, unique_id);
+ // Even if relaying is disabled, these targets are valid as incoming packets.
+ if (target == 1 || target == 0 || target < -1) {
+ packet.packet->referenceCount++;
+ incoming_packets.push_back(packet);
+ }
- if (peer == nullptr) {
- enet_host_destroy(host);
- ERR_FAIL_COND_V_MSG(!peer, ERR_CANT_CREATE, "Couldn't connect to the ENet multiplayer server.");
+ if (server_relay && target != 1) {
+ packet.packet->referenceCount++;
+ _relay(source, target, event.channel_id, event.packet);
+ packet.packet->referenceCount--;
+ _destroy_unused(event.packet);
+ }
+ // Destroy packet later
+ }
+ return false;
+ }
+ default:
+ return true;
}
-
- // Technically safe to ignore the peer or anything else.
-
- connection_status = CONNECTION_CONNECTING;
- active = true;
- server = false;
- refuse_connections = false;
-
- return OK;
}
-void ENetMultiplayerPeer::poll() {
- ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
-
- _pop_current_packet();
-
- ENetEvent event;
- /* Keep servicing until there are no available events left in queue. */
- while (true) {
- if (!host || !active) { // Might have been disconnected while emitting a notification
- return;
+bool ENetMultiplayerPeer::_poll_client() {
+ if (peers.has(1) && !peers[1]->is_active()) {
+ if (connection_status == CONNECTION_CONNECTED) {
+ // Client just disconnected from server.
+ emit_signal(SNAME("server_disconnected"));
+ } else {
+ emit_signal(SNAME("connection_failed"));
}
-
- int ret = enet_host_service(host, &event, 0);
-
- if (ret < 0) {
- // Error, do something?
- break;
- } else if (ret == 0) {
- break;
+ close_connection();
+ return true;
+ }
+ ENetConnection::Event event;
+ ENetConnection::EventType ret = hosts[0]->service(0, event);
+ if (ret == ENetConnection::EVENT_ERROR) {
+ return true;
+ }
+ switch (ret) {
+ case ENetConnection::EVENT_CONNECT: {
+ emit_signal(SNAME("peer_connected"), 1);
+ connection_status = CONNECTION_CONNECTED;
+ emit_signal(SNAME("connection_succeeded"));
+ return false;
+ }
+ case ENetConnection::EVENT_DISCONNECT: {
+ if (connection_status == CONNECTION_CONNECTED) {
+ // Client just disconnected from server.
+ emit_signal(SNAME("server_disconnected"));
+ } else {
+ emit_signal(SNAME("connection_failed"));
+ }
+ close_connection();
+ return true;
}
+ case ENetConnection::EVENT_RECEIVE: {
+ if (event.channel_id == SYSCH_CONFIG) {
+ // Config message
+ if (event.packet->dataLength != 8) {
+ _destroy_unused(event.packet);
+ ERR_FAIL_V(false);
+ }
- switch (event.type) {
- case ENET_EVENT_TYPE_CONNECT: {
- // Store any relevant client information here.
+ int msg = decode_uint32(&event.packet->data[0]);
+ int id = decode_uint32(&event.packet->data[4]);
- if (server && refuse_connections) {
- enet_peer_reset(event.peer);
- break;
- }
+ switch (msg) {
+ case SYSMSG_ADD_PEER: {
+ peers[id] = Ref<ENetPacketPeer>();
+ emit_signal(SNAME("peer_connected"), id);
- // A client joined with an invalid ID (negative values, 0, and 1 are reserved).
- // Probably trying to exploit us.
- if (server && ((int)event.data < 2 || peer_map.has((int)event.data))) {
- enet_peer_reset(event.peer);
- ERR_CONTINUE(true);
+ } break;
+ case SYSMSG_REMOVE_PEER: {
+ peers.erase(id);
+ emit_signal(SNAME("peer_disconnected"), id);
+ } break;
+ }
+ _destroy_unused(event.packet);
+ } else {
+ if (event.packet->dataLength < 8) {
+ _destroy_unused(event.packet);
+ ERR_FAIL_V_MSG(false, "Invalid packet size");
}
- int *new_id = memnew(int);
- *new_id = event.data;
+ uint32_t source = decode_uint32(&event.packet->data[0]);
+ Packet packet;
+ packet.packet = event.packet;
+ packet.from = source;
+ packet.channel = event.channel_id;
- if (*new_id == 0) { // Data zero is sent by server (ENet won't let you configure this). Server is always 1.
- *new_id = 1;
- }
+ packet.packet->referenceCount++;
+ incoming_packets.push_back(packet);
+ // Destroy packet later
+ }
+ return false;
+ }
+ default:
+ return true;
+ }
+}
- event.peer->data = new_id;
-
- peer_map[*new_id] = event.peer;
-
- connection_status = CONNECTION_CONNECTED; // If connecting, this means it connected to something!
-
- emit_signal(SNAME("peer_connected"), *new_id);
-
- if (server) {
- // Do not notify other peers when server_relay is disabled.
- if (!server_relay) {
- break;
- }
-
- // Someone connected, notify all the peers available
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key() == *new_id) {
- continue;
- }
- // Send existing peers to new peer
- ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
- encode_uint32(E->key(), &packet->data[4]);
- enet_peer_send(event.peer, SYSCH_CONFIG, packet);
- // Send the new peer to existing peers
- packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
- encode_uint32(*new_id, &packet->data[4]);
- enet_peer_send(E->get(), SYSCH_CONFIG, packet);
- }
- } else {
- emit_signal(SNAME("connection_succeeded"));
+bool ENetMultiplayerPeer::_poll_mesh() {
+ for (const KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (!(E.value->is_active())) {
+ emit_signal(SNAME("peer_disconnected"), E.key);
+ peers.erase(E.key);
+ if (hosts.has(E.key)) {
+ hosts.erase(E.key);
+ }
+ }
+ }
+ bool should_stop = true;
+ for (KeyValue<int, Ref<ENetConnection>> &E : hosts) {
+ ENetConnection::Event event;
+ ENetConnection::EventType ret = E.value->service(0, event);
+ if (ret == ENetConnection::EVENT_ERROR) {
+ if (peers.has(E.key)) {
+ emit_signal(SNAME("peer_disconnected"), E.key);
+ peers.erase(E.key);
+ }
+ hosts.erase(E.key);
+ continue;
+ }
+ switch (ret) {
+ case ENetConnection::EVENT_CONNECT:
+ should_stop = false;
+ event.peer->reset();
+ break;
+ case ENetConnection::EVENT_DISCONNECT:
+ should_stop = false;
+ if (peers.has(E.key)) {
+ emit_signal(SNAME("peer_disconnected"), E.key);
+ peers.erase(E.key);
+ }
+ hosts.erase(E.key);
+ break;
+ case ENetConnection::EVENT_RECEIVE: {
+ should_stop = false;
+ if (event.packet->dataLength < 8) {
+ _destroy_unused(event.packet);
+ ERR_CONTINUE_MSG(true, "Invalid packet size");
}
+ Packet packet;
+ packet.packet = event.packet;
+ packet.from = E.key;
+ packet.channel = event.channel_id;
+
+ packet.packet->referenceCount++;
+ incoming_packets.push_back(packet);
} break;
- case ENET_EVENT_TYPE_DISCONNECT: {
- // Reset the peer's client information.
+ default:
+ break; // Nothing to do
+ }
+ }
+ return should_stop;
+}
- int *id = (int *)event.peer->data;
+void ENetMultiplayerPeer::poll() {
+ ERR_FAIL_COND_MSG(!_is_active(), "The multiplayer instance isn't currently active.");
- if (!id) {
- if (!server) {
- emit_signal(SNAME("connection_failed"));
- }
- // Never fully connected.
- break;
- }
+ _pop_current_packet();
- if (!server) {
- // Client just disconnected from server.
- emit_signal(SNAME("server_disconnected"));
- close_connection();
+ while (true) {
+ switch (active_mode) {
+ case MODE_CLIENT:
+ if (_poll_client()) {
return;
- } else if (server_relay) {
- // Server just received a client disconnect and is in relay mode, notify everyone else.
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key() == *id) {
- continue;
- }
-
- ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]);
- encode_uint32(*id, &packet->data[4]);
- enet_peer_send(E->get(), SYSCH_CONFIG, packet);
- }
}
-
- emit_signal(SNAME("peer_disconnected"), *id);
- peer_map.erase(*id);
- memdelete(id);
- } break;
- case ENET_EVENT_TYPE_RECEIVE: {
- if (event.channelID == SYSCH_CONFIG) {
- // Some config message
- ERR_CONTINUE(event.packet->dataLength < 8);
-
- // Only server can send config messages
- ERR_CONTINUE(server);
-
- int msg = decode_uint32(&event.packet->data[0]);
- int id = decode_uint32(&event.packet->data[4]);
-
- switch (msg) {
- case SYSMSG_ADD_PEER: {
- peer_map[id] = nullptr;
- emit_signal(SNAME("peer_connected"), id);
-
- } break;
- case SYSMSG_REMOVE_PEER: {
- peer_map.erase(id);
- emit_signal(SNAME("peer_disconnected"), id);
- } break;
- }
-
- enet_packet_destroy(event.packet);
- } else if (event.channelID < channel_count) {
- Packet packet;
- packet.packet = event.packet;
-
- uint32_t *id = (uint32_t *)event.peer->data;
-
- ERR_CONTINUE(event.packet->dataLength < 8);
-
- uint32_t source = decode_uint32(&event.packet->data[0]);
- int target = decode_uint32(&event.packet->data[4]);
-
- packet.from = source;
- packet.channel = event.channelID;
-
- if (server) {
- // Someone is cheating and trying to fake the source!
- ERR_CONTINUE(source != *id);
-
- packet.from = *id;
-
- if (target == 1) {
- // To myself and only myself
- incoming_packets.push_back(packet);
- } else if (!server_relay) {
- // When relaying is disabled, other destinations will only be processed by the server.
- if (target == 0 || target < -1) {
- incoming_packets.push_back(packet);
- }
- continue;
- } else if (target == 0) {
- // Re-send to everyone but sender :|
-
- incoming_packets.push_back(packet);
- // And make copies for sending
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key()) == source) { // Do not resend to self
- continue;
- }
-
- ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
-
- enet_peer_send(E->get(), event.channelID, packet2);
- }
-
- } else if (target < 0) {
- // To all but one
-
- // And make copies for sending
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key()) == source || E->key() == -target) { // Do not resend to self, also do not send to excluded
- continue;
- }
-
- ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
-
- enet_peer_send(E->get(), event.channelID, packet2);
- }
-
- if (-target != 1) {
- // Server is not excluded
- incoming_packets.push_back(packet);
- } else {
- // Server is excluded, erase packet
- enet_packet_destroy(packet.packet);
- }
-
- } else {
- // To someone else, specifically
- ERR_CONTINUE(!peer_map.has(target));
- enet_peer_send(peer_map[target], event.channelID, packet.packet);
- }
- } else {
- incoming_packets.push_back(packet);
- }
-
- // Destroy packet later
- } else {
- ERR_CONTINUE(true);
+ break;
+ case MODE_SERVER:
+ if (_poll_server()) {
+ return;
}
-
- } break;
- case ENET_EVENT_TYPE_NONE: {
- // Do nothing
- } break;
+ break;
+ case MODE_MESH:
+ if (_poll_mesh()) {
+ return;
+ }
+ break;
+ default:
+ return;
}
}
}
bool ENetMultiplayerPeer::is_server() const {
- ERR_FAIL_COND_V_MSG(!active, false, "The multiplayer instance isn't currently active.");
-
- return server;
+ return active_mode == MODE_SERVER;
}
void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) {
- ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_MSG(!_is_active(), "The multiplayer instance isn't currently active.");
_pop_current_packet();
bool peers_disconnected = false;
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->get()) {
- enet_peer_disconnect_now(E->get(), unique_id);
- int *id = (int *)(E->get()->data);
- memdelete(id);
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.value.is_valid() && E.value->get_state() == ENetPacketPeer::STATE_CONNECTED) {
+ E.value->peer_disconnect_now(unique_id);
peers_disconnected = true;
}
}
if (peers_disconnected) {
- enet_host_flush(host);
+ for (KeyValue<int, Ref<ENetConnection>> &E : hosts) {
+ E.value->flush();
+ }
if (wait_usec > 0) {
OS::get_singleton()->delay_usec(wait_usec); // Wait for disconnection packets to send
}
}
- enet_host_destroy(host);
- active = false;
+ active_mode = MODE_NONE;
incoming_packets.clear();
- peer_map.clear();
- unique_id = 1; // Server is 1
+ peers.clear();
+ hosts.clear();
+ unique_id = 0;
connection_status = CONNECTION_DISCONNECTED;
}
-void ENetMultiplayerPeer::disconnect_peer(int p_peer, bool now) {
- ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_MSG(!is_server(), "Can't disconnect a peer when not acting as a server.");
- ERR_FAIL_COND_MSG(!peer_map.has(p_peer), vformat("Peer ID %d not found in the list of peers.", p_peer));
-
- if (now) {
- int *id = (int *)peer_map[p_peer]->data;
- enet_peer_disconnect_now(peer_map[p_peer], 0);
-
- // enet_peer_disconnect_now doesn't generate ENET_EVENT_TYPE_DISCONNECT,
- // notify everyone else, send disconnect signal & remove from peer_map like in poll()
- if (server_relay) {
- for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key() == p_peer) {
- continue;
- }
-
- ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
- encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]);
- encode_uint32(p_peer, &packet->data[4]);
- enet_peer_send(E->get(), SYSCH_CONFIG, packet);
- }
- }
-
- if (id) {
- memdelete(id);
- }
-
- emit_signal(SNAME("peer_disconnected"), p_peer);
- peer_map.erase(p_peer);
- } else {
- enet_peer_disconnect_later(peer_map[p_peer], 0);
- }
-}
-
int ENetMultiplayerPeer::get_available_packet_count() const {
return incoming_packets.size();
}
@@ -517,19 +434,17 @@ Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_si
}
Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
- ERR_FAIL_COND_V_MSG(!active, ERR_UNCONFIGURED, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(!_is_active(), ERR_UNCONFIGURED, "The multiplayer instance isn't currently active.");
ERR_FAIL_COND_V_MSG(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client.");
+ ERR_FAIL_COND_V_MSG(target_peer != 0 && !peers.has(ABS(target_peer)), ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer));
+ ERR_FAIL_COND_V(active_mode == MODE_CLIENT && !peers.has(1), ERR_BUG);
int packet_flags = 0;
int channel = SYSCH_RELIABLE;
switch (transfer_mode) {
case TRANSFER_MODE_UNRELIABLE: {
- if (always_ordered) {
- packet_flags = 0;
- } else {
- packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
- }
+ packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
channel = SYSCH_UNRELIABLE;
} break;
case TRANSFER_MODE_UNRELIABLE_ORDERED: {
@@ -542,52 +457,55 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size
} break;
}
- if (transfer_channel > SYSCH_CONFIG) {
- channel = transfer_channel;
- }
-
- Map<int, ENetPeer *>::Element *E = nullptr;
-
- if (target_peer != 0) {
- E = peer_map.find(ABS(target_peer));
- ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer));
- }
-
ENetPacket *packet = enet_packet_create(nullptr, p_buffer_size + 8, packet_flags);
encode_uint32(unique_id, &packet->data[0]); // Source ID
encode_uint32(target_peer, &packet->data[4]); // Dest ID
memcpy(&packet->data[8], p_buffer, p_buffer_size);
- if (server) {
+ if (is_server()) {
if (target_peer == 0) {
- enet_host_broadcast(host, channel, packet);
- } else if (target_peer < 0) {
- // Send to all but one
- // and make copies for sending
+ hosts[0]->broadcast(channel, packet);
+ } else if (target_peer < 0) {
+ // Send to all but one and make copies for sending.
int exclude = -target_peer;
-
- for (Map<int, ENetPeer *>::Element *F = peer_map.front(); F; F = F->next()) {
- if (F->key() == exclude) { // Exclude packet
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == exclude) {
continue;
}
+ E.value->send(channel, packet);
+ }
+ _destroy_unused(packet);
+ } else {
+ peers[target_peer]->send(channel, packet);
+ }
+ ERR_FAIL_COND_V(!hosts.has(0), ERR_BUG);
+ hosts[0]->flush();
- ENetPacket *packet2 = enet_packet_create(packet->data, packet->dataLength, packet_flags);
+ } else if (active_mode == MODE_CLIENT) {
+ peers[1]->send(channel, packet); // Send to server for broadcast.
+ ERR_FAIL_COND_V(!hosts.has(0), ERR_BUG);
+ hosts[0]->flush();
- enet_peer_send(F->get(), channel, packet2);
+ } else {
+ if (target_peer <= 0) {
+ int exclude = ABS(target_peer);
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == exclude) {
+ continue;
+ }
+ E.value->send(channel, packet);
+ ERR_CONTINUE(!hosts.has(E.key));
+ hosts[E.key]->flush();
}
-
- enet_packet_destroy(packet); // Original packet no longer needed
+ _destroy_unused(packet);
} else {
- enet_peer_send(E->get(), channel, packet);
+ peers[target_peer]->send(channel, packet);
+ ERR_FAIL_COND_V(!hosts.has(target_peer), ERR_BUG);
+ hosts[target_peer]->flush();
}
- } else {
- ERR_FAIL_COND_V(!peer_map.has(1), ERR_BUG);
- enet_peer_send(peer_map[1], channel, packet); // Send to server for broadcast
}
- enet_host_flush(host);
-
return OK;
}
@@ -597,7 +515,8 @@ int ENetMultiplayerPeer::get_max_packet_size() const {
void ENetMultiplayerPeer::_pop_current_packet() {
if (current_packet.packet) {
- enet_packet_destroy(current_packet.packet);
+ current_packet.packet->referenceCount--;
+ _destroy_unused(current_packet.packet);
current_packet.packet = nullptr;
current_packet.from = 0;
current_packet.channel = -1;
@@ -608,37 +527,18 @@ MultiplayerPeer::ConnectionStatus ENetMultiplayerPeer::get_connection_status() c
return connection_status;
}
-uint32_t ENetMultiplayerPeer::_gen_unique_id() const {
- uint32_t hash = 0;
-
- while (hash == 0 || hash == 1) {
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_ticks_usec());
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_unix_time(), hash);
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_user_data_dir().hash64(), hash);
- hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)this), hash); // Rely on ASLR heap
- hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)&hash), hash); // Rely on ASLR stack
-
- hash = hash & 0x7FFFFFFF; // Make it compatible with unsigned, since negative ID is used for exclusion
- }
-
- return hash;
-}
-
int ENetMultiplayerPeer::get_unique_id() const {
- ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active.");
+ ERR_FAIL_COND_V_MSG(!_is_active(), 0, "The multiplayer instance isn't currently active.");
return unique_id;
}
void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) {
refuse_connections = p_enable;
#ifdef GODOT_ENET
- if (active) {
- enet_host_refuse_new_connections(host, p_enable);
+ if (_is_active()) {
+ for (KeyValue<int, Ref<ENetConnection>> &E : hosts) {
+ E.value->refuse_new_connections(p_enable);
+ }
}
#endif
}
@@ -647,244 +547,122 @@ bool ENetMultiplayerPeer::is_refusing_new_connections() const {
return refuse_connections;
}
-void ENetMultiplayerPeer::set_compression_mode(CompressionMode p_mode) {
- compression_mode = p_mode;
+void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) {
+ ERR_FAIL_COND_MSG(_is_active(), "Server relaying can't be toggled while the multiplayer instance is active.");
+
+ server_relay = p_enabled;
}
-ENetMultiplayerPeer::CompressionMode ENetMultiplayerPeer::get_compression_mode() const {
- return compression_mode;
+bool ENetMultiplayerPeer::is_server_relay_enabled() const {
+ return server_relay;
}
-size_t ENetMultiplayerPeer::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
- ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context);
+Ref<ENetConnection> ENetMultiplayerPeer::get_host() const {
+ ERR_FAIL_COND_V(!_is_active(), nullptr);
+ ERR_FAIL_COND_V(active_mode == MODE_MESH, nullptr);
+ return hosts[0];
+}
- if (size_t(enet->src_compressor_mem.size()) < inLimit) {
- enet->src_compressor_mem.resize(inLimit);
- }
+Ref<ENetPacketPeer> ENetMultiplayerPeer::get_peer(int p_id) const {
+ ERR_FAIL_COND_V(!_is_active(), nullptr);
+ ERR_FAIL_COND_V(!peers.has(p_id), nullptr);
+ ERR_FAIL_COND_V(active_mode == MODE_CLIENT && p_id != 1, nullptr);
+ return peers[p_id];
+}
- int total = inLimit;
- int ofs = 0;
- while (total) {
- for (size_t i = 0; i < inBufferCount; i++) {
- int to_copy = MIN(total, int(inBuffers[i].dataLength));
- memcpy(&enet->src_compressor_mem.write[ofs], inBuffers[i].data, to_copy);
- ofs += to_copy;
- total -= to_copy;
- }
+void ENetMultiplayerPeer::_destroy_unused(ENetPacket *p_packet) {
+ if (p_packet->referenceCount == 0) {
+ enet_packet_destroy(p_packet);
}
+}
- Compression::Mode mode;
+void ENetMultiplayerPeer::_relay(int p_from, int p_to, enet_uint8 p_channel, ENetPacket *p_packet) {
+ if (p_to == 0) {
+ // Re-send to everyone but sender :|
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == p_from) {
+ continue;
+ }
- switch (enet->compression_mode) {
- case COMPRESS_FASTLZ: {
- mode = Compression::MODE_FASTLZ;
- } break;
- case COMPRESS_ZLIB: {
- mode = Compression::MODE_DEFLATE;
- } break;
- case COMPRESS_ZSTD: {
- mode = Compression::MODE_ZSTD;
- } break;
- default: {
- ERR_FAIL_V_MSG(0, vformat("Invalid ENet compression mode: %d", enet->compression_mode));
+ E.value->send(p_channel, p_packet);
}
- }
-
- int req_size = Compression::get_max_compressed_buffer_size(ofs, mode);
- if (enet->dst_compressor_mem.size() < req_size) {
- enet->dst_compressor_mem.resize(req_size);
- }
- int ret = Compression::compress(enet->dst_compressor_mem.ptrw(), enet->src_compressor_mem.ptr(), ofs, mode);
-
- if (ret < 0) {
- return 0;
- }
-
- if (ret > int(outLimit)) {
- return 0; // Do not bother
- }
-
- memcpy(outData, enet->dst_compressor_mem.ptr(), ret);
-
- return ret;
-}
+ } else if (p_to < 0) {
+ // Re-send to everyone but excluded and sender.
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == p_from || E.key == -p_to) { // Do not resend to self, also do not send to excluded
+ continue;
+ }
-size_t ENetMultiplayerPeer::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) {
- ENetMultiplayerPeer *enet = (ENetMultiplayerPeer *)(context);
- int ret = -1;
- switch (enet->compression_mode) {
- case COMPRESS_FASTLZ: {
- ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_FASTLZ);
- } break;
- case COMPRESS_ZLIB: {
- ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE);
- } break;
- case COMPRESS_ZSTD: {
- ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_ZSTD);
- } break;
- default: {
+ E.value->send(p_channel, p_packet);
}
- }
- if (ret < 0) {
- return 0;
} else {
- return ret;
+ // To someone else, specifically
+ ERR_FAIL_COND(!peers.has(p_to));
+ ENetPacket *packet = enet_packet_create(p_packet->data, p_packet->dataLength, p_packet->flags);
+ peers[p_to]->send(p_channel, packet);
}
}
-void ENetMultiplayerPeer::_setup_compressor() {
- switch (compression_mode) {
- case COMPRESS_NONE: {
- enet_host_compress(host, nullptr);
- } break;
- case COMPRESS_RANGE_CODER: {
- enet_host_compress_with_range_coder(host);
- } break;
- case COMPRESS_FASTLZ:
- case COMPRESS_ZLIB:
- case COMPRESS_ZSTD: {
- enet_host_compress(host, &enet_compressor);
- } break;
+void ENetMultiplayerPeer::_notify_peers(int p_id, bool p_connected) {
+ if (p_connected) {
+ ERR_FAIL_COND(!peers.has(p_id));
+ // Someone connected, notify all the peers available.
+ Ref<ENetPacketPeer> peer = peers[p_id];
+ ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
+ encode_uint32(p_id, &packet->data[4]);
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == p_id) {
+ continue;
+ }
+ // Send new peer to existing peer.
+ E.value->send(SYSCH_CONFIG, packet);
+ // Send existing peer to new peer.
+ // This packet will be automatically destroyed by ENet after send.
+ ENetPacket *packet2 = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_ADD_PEER, &packet2->data[0]);
+ encode_uint32(E.key, &packet2->data[4]);
+ peer->send(SYSCH_CONFIG, packet2);
+ }
+ _destroy_unused(packet);
+ } else {
+ // Server just received a client disconnect and is in relay mode, notify everyone else.
+ ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
+ encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]);
+ encode_uint32(p_id, &packet->data[4]);
+ for (KeyValue<int, Ref<ENetPacketPeer>> &E : peers) {
+ if (E.key == p_id) {
+ continue;
+ }
+ E.value->send(SYSCH_CONFIG, packet);
+ }
+ _destroy_unused(packet);
}
}
-void ENetMultiplayerPeer::enet_compressor_destroy(void *context) {
- // Nothing to do
-}
-
-IPAddress ENetMultiplayerPeer::get_peer_address(int p_peer_id) const {
- ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IPAddress(), vformat("Peer ID %d not found in the list of peers.", p_peer_id));
- ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, IPAddress(), "Can't get the address of peers other than the server (ID -1) when acting as a client.");
- ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, IPAddress(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id));
-
- IPAddress out;
-#ifdef GODOT_ENET
- out.set_ipv6((uint8_t *)&(peer_map[p_peer_id]->address.host));
-#else
- out.set_ipv4((uint8_t *)&(peer_map[p_peer_id]->address.host));
-#endif
-
- return out;
-}
-
-int ENetMultiplayerPeer::get_peer_port(int p_peer_id) const {
- ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), 0, vformat("Peer ID %d not found in the list of peers.", p_peer_id));
- ERR_FAIL_COND_V_MSG(!is_server() && p_peer_id != 1, 0, "Can't get the address of peers other than the server (ID -1) when acting as a client.");
- ERR_FAIL_COND_V_MSG(peer_map[p_peer_id] == nullptr, 0, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id));
-#ifdef GODOT_ENET
- return peer_map[p_peer_id]->address.port;
-#else
- return peer_map[p_peer_id]->address.port;
-#endif
-}
-
-int ENetMultiplayerPeer::get_local_port() const {
- ERR_FAIL_COND_V_MSG(!active || !host, 0, "The multiplayer instance isn't currently active.");
- return host->address.port;
-}
-
-void ENetMultiplayerPeer::set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max) {
- ERR_FAIL_COND_MSG(!peer_map.has(p_peer_id), vformat("Peer ID %d not found in the list of peers.", p_peer_id));
- ERR_FAIL_COND_MSG(!is_server() && p_peer_id != 1, "Can't change the timeout of peers other then the server when acting as a client.");
- ERR_FAIL_COND_MSG(peer_map[p_peer_id] == nullptr, vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id));
- ERR_FAIL_COND_MSG(p_timeout_limit > p_timeout_min || p_timeout_min > p_timeout_max, "Timeout limit must be less than minimum timeout, which itself must be less then maximum timeout");
- enet_peer_timeout(peer_map[p_peer_id], p_timeout_limit, p_timeout_min, p_timeout_max);
-}
-
-void ENetMultiplayerPeer::set_transfer_channel(int p_channel) {
- ERR_FAIL_COND_MSG(p_channel < -1 || p_channel >= channel_count, vformat("The transfer channel must be set between 0 and %d, inclusive (got %d).", channel_count - 1, p_channel));
- ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, vformat("The channel %d is reserved.", SYSCH_CONFIG));
- transfer_channel = p_channel;
-}
-
-int ENetMultiplayerPeer::get_transfer_channel() const {
- return transfer_channel;
-}
-
-void ENetMultiplayerPeer::set_channel_count(int p_channel) {
- ERR_FAIL_COND_MSG(active, "The channel count can't be set while the multiplayer instance is active.");
- ERR_FAIL_COND_MSG(p_channel < SYSCH_MAX, vformat("The channel count must be greater than or equal to %d to account for reserved channels (got %d).", SYSCH_MAX, p_channel));
- channel_count = p_channel;
-}
-
-int ENetMultiplayerPeer::get_channel_count() const {
- return channel_count;
-}
-
-void ENetMultiplayerPeer::set_always_ordered(bool p_ordered) {
- always_ordered = p_ordered;
-}
-
-bool ENetMultiplayerPeer::is_always_ordered() const {
- return always_ordered;
-}
-
-void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) {
- ERR_FAIL_COND_MSG(active, "Server relaying can't be toggled while the multiplayer instance is active.");
-
- server_relay = p_enabled;
-}
-
-bool ENetMultiplayerPeer::is_server_relay_enabled() const {
- return server_relay;
-}
-
void ENetMultiplayerPeer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &ENetMultiplayerPeer::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0));
- ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "local_port"), &ENetMultiplayerPeer::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "max_channels", "in_bandwidth", "out_bandwidth"), &ENetMultiplayerPeer::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("create_client", "address", "port", "channel_count", "in_bandwidth", "out_bandwidth", "local_port"), &ENetMultiplayerPeer::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("create_mesh", "unique_id"), &ENetMultiplayerPeer::create_mesh);
+ ClassDB::bind_method(D_METHOD("add_mesh_peer", "peer_id", "host"), &ENetMultiplayerPeer::add_mesh_peer);
ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &ENetMultiplayerPeer::close_connection, DEFVAL(100));
- ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "now"), &ENetMultiplayerPeer::disconnect_peer, DEFVAL(false));
- ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &ENetMultiplayerPeer::set_compression_mode);
- ClassDB::bind_method(D_METHOD("get_compression_mode"), &ENetMultiplayerPeer::get_compression_mode);
ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &ENetMultiplayerPeer::set_bind_ip);
- ClassDB::bind_method(D_METHOD("set_dtls_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_enabled);
- ClassDB::bind_method(D_METHOD("is_dtls_enabled"), &ENetMultiplayerPeer::is_dtls_enabled);
- ClassDB::bind_method(D_METHOD("set_dtls_key", "key"), &ENetMultiplayerPeer::set_dtls_key);
- ClassDB::bind_method(D_METHOD("set_dtls_certificate", "certificate"), &ENetMultiplayerPeer::set_dtls_certificate);
- ClassDB::bind_method(D_METHOD("set_dtls_verify_enabled", "enabled"), &ENetMultiplayerPeer::set_dtls_verify_enabled);
- ClassDB::bind_method(D_METHOD("is_dtls_verify_enabled"), &ENetMultiplayerPeer::is_dtls_verify_enabled);
- ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &ENetMultiplayerPeer::get_peer_address);
- ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &ENetMultiplayerPeer::get_peer_port);
- ClassDB::bind_method(D_METHOD("get_local_port"), &ENetMultiplayerPeer::get_local_port);
- ClassDB::bind_method(D_METHOD("set_peer_timeout", "id", "timeout_limit", "timeout_min", "timeout_max"), &ENetMultiplayerPeer::set_peer_timeout);
-
- ClassDB::bind_method(D_METHOD("get_packet_channel"), &ENetMultiplayerPeer::get_packet_channel);
- ClassDB::bind_method(D_METHOD("get_last_packet_channel"), &ENetMultiplayerPeer::get_last_packet_channel);
- ClassDB::bind_method(D_METHOD("set_transfer_channel", "channel"), &ENetMultiplayerPeer::set_transfer_channel);
- ClassDB::bind_method(D_METHOD("get_transfer_channel"), &ENetMultiplayerPeer::get_transfer_channel);
- ClassDB::bind_method(D_METHOD("set_channel_count", "channels"), &ENetMultiplayerPeer::set_channel_count);
- ClassDB::bind_method(D_METHOD("get_channel_count"), &ENetMultiplayerPeer::get_channel_count);
- ClassDB::bind_method(D_METHOD("set_always_ordered", "ordered"), &ENetMultiplayerPeer::set_always_ordered);
- ClassDB::bind_method(D_METHOD("is_always_ordered"), &ENetMultiplayerPeer::is_always_ordered);
+
ClassDB::bind_method(D_METHOD("set_server_relay_enabled", "enabled"), &ENetMultiplayerPeer::set_server_relay_enabled);
ClassDB::bind_method(D_METHOD("is_server_relay_enabled"), &ENetMultiplayerPeer::is_server_relay_enabled);
+ ClassDB::bind_method(D_METHOD("get_host"), &ENetMultiplayerPeer::get_host);
+ ClassDB::bind_method(D_METHOD("get_peer", "id"), &ENetMultiplayerPeer::get_peer);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "transfer_channel"), "set_transfer_channel", "get_transfer_channel");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_count"), "set_channel_count", "get_channel_count");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "always_ordered"), "set_always_ordered", "is_always_ordered");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "server_relay"), "set_server_relay_enabled", "is_server_relay_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dtls_verify"), "set_dtls_verify_enabled", "is_dtls_verify_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_dtls"), "set_dtls_enabled", "is_dtls_enabled");
-
- BIND_ENUM_CONSTANT(COMPRESS_NONE);
- BIND_ENUM_CONSTANT(COMPRESS_RANGE_CODER);
- BIND_ENUM_CONSTANT(COMPRESS_FASTLZ);
- BIND_ENUM_CONSTANT(COMPRESS_ZLIB);
- BIND_ENUM_CONSTANT(COMPRESS_ZSTD);
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "host", PROPERTY_HINT_RESOURCE_TYPE, "ENetConnection", PROPERTY_USAGE_NONE), "", "get_host");
}
ENetMultiplayerPeer::ENetMultiplayerPeer() {
- enet_compressor.context = this;
- enet_compressor.compress = enet_compress;
- enet_compressor.decompress = enet_decompress;
- enet_compressor.destroy = enet_compressor_destroy;
-
bind_ip = IPAddress("*");
}
ENetMultiplayerPeer::~ENetMultiplayerPeer() {
- if (active) {
+ if (_is_active()) {
close_connection();
}
}
@@ -896,31 +674,3 @@ void ENetMultiplayerPeer::set_bind_ip(const IPAddress &p_ip) {
bind_ip = p_ip;
}
-
-void ENetMultiplayerPeer::set_dtls_enabled(bool p_enabled) {
- ERR_FAIL_COND(active);
- dtls_enabled = p_enabled;
-}
-
-bool ENetMultiplayerPeer::is_dtls_enabled() const {
- return dtls_enabled;
-}
-
-void ENetMultiplayerPeer::set_dtls_verify_enabled(bool p_enabled) {
- ERR_FAIL_COND(active);
- dtls_verify = p_enabled;
-}
-
-bool ENetMultiplayerPeer::is_dtls_verify_enabled() const {
- return dtls_verify;
-}
-
-void ENetMultiplayerPeer::set_dtls_key(Ref<CryptoKey> p_key) {
- ERR_FAIL_COND(active);
- dtls_key = p_key;
-}
-
-void ENetMultiplayerPeer::set_dtls_certificate(Ref<X509Certificate> p_cert) {
- ERR_FAIL_COND(active);
- dtls_cert = p_cert;
-}
diff --git a/modules/enet/enet_multiplayer_peer.h b/modules/enet/enet_multiplayer_peer.h
index 63f2ec5870..703396d0cb 100644
--- a/modules/enet/enet_multiplayer_peer.h
+++ b/modules/enet/enet_multiplayer_peer.h
@@ -32,23 +32,14 @@
#define NETWORKED_MULTIPLAYER_ENET_H
#include "core/crypto/crypto.h"
-#include "core/io/compression.h"
#include "core/io/multiplayer_peer.h"
+#include "enet_connection.h"
#include <enet/enet.h>
class ENetMultiplayerPeer : public MultiplayerPeer {
GDCLASS(ENetMultiplayerPeer, MultiplayerPeer);
-public:
- enum CompressionMode {
- COMPRESS_NONE,
- COMPRESS_RANGE_CODER,
- COMPRESS_FASTLZ,
- COMPRESS_ZLIB,
- COMPRESS_ZSTD
- };
-
private:
enum {
SYSMSG_ADD_PEER,
@@ -62,27 +53,27 @@ private:
SYSCH_MAX
};
- bool active = false;
- bool server = false;
+ enum Mode {
+ MODE_NONE,
+ MODE_SERVER,
+ MODE_CLIENT,
+ MODE_MESH,
+ };
+
+ Mode active_mode = MODE_NONE;
uint32_t unique_id = 0;
int target_peer = 0;
TransferMode transfer_mode = TRANSFER_MODE_RELIABLE;
- int transfer_channel = -1;
- int channel_count = SYSCH_MAX;
- bool always_ordered = false;
-
- ENetEvent event;
- ENetPeer *peer = nullptr;
- ENetHost *host = nullptr;
bool refuse_connections = false;
bool server_relay = true;
ConnectionStatus connection_status = CONNECTION_DISCONNECTED;
- Map<int, ENetPeer *> peer_map;
+ Map<int, Ref<ENetConnection>> hosts;
+ Map<int, Ref<ENetPacketPeer>> peers;
struct Packet {
ENetPacket *packet = nullptr;
@@ -90,31 +81,21 @@ private:
int channel = 0;
};
- CompressionMode compression_mode = COMPRESS_RANGE_CODER;
-
List<Packet> incoming_packets;
Packet current_packet;
- uint32_t _gen_unique_id() const;
void _pop_current_packet();
-
- Vector<uint8_t> src_compressor_mem;
- Vector<uint8_t> dst_compressor_mem;
-
- ENetCompressor enet_compressor;
- static size_t enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit);
- static size_t enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit);
- static void enet_compressor_destroy(void *context);
- void _setup_compressor();
+ bool _poll_server();
+ bool _poll_client();
+ bool _poll_mesh();
+ void _relay(int p_from, int p_to, enet_uint8 p_channel, ENetPacket *p_packet);
+ void _notify_peers(int p_id, bool p_connected);
+ void _destroy_unused(ENetPacket *p_packet);
+ _FORCE_INLINE_ bool _is_active() const { return active_mode != MODE_NONE; }
IPAddress bind_ip;
- bool dtls_enabled = false;
- Ref<CryptoKey> dtls_key;
- Ref<X509Certificate> dtls_cert;
- bool dtls_verify = true;
-
protected:
static void _bind_methods();
@@ -125,13 +106,10 @@ public:
virtual int get_packet_peer() const override;
- virtual IPAddress get_peer_address(int p_peer_id) const;
- virtual int get_peer_port(int p_peer_id) const;
- virtual int get_local_port() const;
- void set_peer_timeout(int p_peer_id, int p_timeout_limit, int p_timeout_min, int p_timeout_max);
-
- Error create_server(int p_port, int p_max_clients = 32, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
- Error create_client(const String &p_address, int p_port, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0);
+ Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0);
+ Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0);
+ Error create_mesh(int p_id);
+ Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host);
void close_connection(uint32_t wait_usec = 100);
@@ -154,32 +132,15 @@ public:
virtual int get_unique_id() const override;
- void set_compression_mode(CompressionMode p_mode);
- CompressionMode get_compression_mode() const;
-
- int get_packet_channel() const;
- int get_last_packet_channel() const;
- void set_transfer_channel(int p_channel);
- int get_transfer_channel() const;
- void set_channel_count(int p_channel);
- int get_channel_count() const;
- void set_always_ordered(bool p_ordered);
- bool is_always_ordered() const;
+ void set_bind_ip(const IPAddress &p_ip);
void set_server_relay_enabled(bool p_enabled);
bool is_server_relay_enabled() const;
+ Ref<ENetConnection> get_host() const;
+ Ref<ENetPacketPeer> get_peer(int p_id) const;
+
ENetMultiplayerPeer();
~ENetMultiplayerPeer();
-
- void set_bind_ip(const IPAddress &p_ip);
- void set_dtls_enabled(bool p_enabled);
- bool is_dtls_enabled() const;
- void set_dtls_verify_enabled(bool p_enabled);
- bool is_dtls_verify_enabled() const;
- void set_dtls_key(Ref<CryptoKey> p_key);
- void set_dtls_certificate(Ref<X509Certificate> p_cert);
};
-VARIANT_ENUM_CAST(ENetMultiplayerPeer::CompressionMode);
-
#endif // NETWORKED_MULTIPLAYER_ENET_H
diff --git a/modules/enet/enet_packet_peer.cpp b/modules/enet/enet_packet_peer.cpp
new file mode 100644
index 0000000000..d7d2ec9ebe
--- /dev/null
+++ b/modules/enet/enet_packet_peer.cpp
@@ -0,0 +1,263 @@
+/*************************************************************************/
+/* enet_packet_peer.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "enet_packet_peer.h"
+
+void ENetPacketPeer::peer_disconnect(int p_data) {
+ ERR_FAIL_COND(!peer);
+ enet_peer_disconnect(peer, p_data);
+}
+
+void ENetPacketPeer::peer_disconnect_later(int p_data) {
+ ERR_FAIL_COND(!peer);
+ enet_peer_disconnect_later(peer, p_data);
+}
+
+void ENetPacketPeer::peer_disconnect_now(int p_data) {
+ ERR_FAIL_COND(!peer);
+ enet_peer_disconnect_now(peer, p_data);
+ _on_disconnect();
+}
+
+void ENetPacketPeer::ping() {
+ ERR_FAIL_COND(!peer);
+ enet_peer_ping(peer);
+}
+
+void ENetPacketPeer::ping_interval(int p_interval) {
+ ERR_FAIL_COND(!peer);
+ enet_peer_ping_interval(peer, p_interval);
+}
+
+int ENetPacketPeer::send(uint8_t p_channel, ENetPacket *p_packet) {
+ ERR_FAIL_COND_V(peer == nullptr, -1);
+ ERR_FAIL_COND_V(p_packet == nullptr, -1);
+ ERR_FAIL_COND_V_MSG(p_channel >= peer->channelCount, -1, vformat("Unable to send packet on channel %d, max channels: %d", p_channel, (int)peer->channelCount));
+ return enet_peer_send(peer, p_channel, p_packet);
+}
+
+void ENetPacketPeer::reset() {
+ ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
+ enet_peer_reset(peer);
+ _on_disconnect();
+}
+
+void ENetPacketPeer::throttle_configure(int p_interval, int p_acceleration, int p_deceleration) {
+ ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
+ enet_peer_throttle_configure(peer, p_interval, p_acceleration, p_deceleration);
+}
+
+void ENetPacketPeer::set_timeout(int p_timeout, int p_timeout_min, int p_timeout_max) {
+ ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
+ ERR_FAIL_COND_MSG(p_timeout > p_timeout_min || p_timeout_min > p_timeout_max, "Timeout limit must be less than minimum timeout, which itself must be less then maximum timeout");
+ enet_peer_timeout(peer, p_timeout, p_timeout_min, p_timeout_max);
+}
+
+int ENetPacketPeer::get_max_packet_size() const {
+ return 1 << 24;
+}
+
+int ENetPacketPeer::get_available_packet_count() const {
+ return packet_queue.size();
+}
+
+Error ENetPacketPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
+ ERR_FAIL_COND_V(!peer, ERR_UNCONFIGURED);
+ ERR_FAIL_COND_V(!packet_queue.size(), ERR_UNAVAILABLE);
+ if (last_packet) {
+ enet_packet_destroy(last_packet);
+ last_packet = nullptr;
+ }
+ last_packet = packet_queue.front()->get();
+ packet_queue.pop_front();
+ *r_buffer = (const uint8_t *)(last_packet->data);
+ r_buffer_size = last_packet->dataLength;
+ return OK;
+}
+
+Error ENetPacketPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
+ ERR_FAIL_COND_V(!peer, ERR_UNCONFIGURED);
+ ENetPacket *packet = enet_packet_create(p_buffer, p_buffer_size, ENET_PACKET_FLAG_RELIABLE);
+ return send(0, packet) < 0 ? FAILED : OK;
+}
+
+IPAddress ENetPacketPeer::get_remote_address() const {
+ ERR_FAIL_COND_V(!peer, IPAddress());
+ IPAddress out;
+#ifdef GODOT_ENET
+ out.set_ipv6((uint8_t *)&(peer->address.host));
+#else
+ out.set_ipv4((uint8_t *)&(peer->address.host));
+#endif
+ return out;
+}
+
+int ENetPacketPeer::get_remote_port() const {
+ ERR_FAIL_COND_V(!peer, 0);
+ return peer->address.port;
+}
+
+bool ENetPacketPeer::is_active() const {
+ return peer != nullptr;
+}
+
+double ENetPacketPeer::get_statistic(PeerStatistic p_stat) {
+ ERR_FAIL_COND_V(!peer, 0);
+ switch (p_stat) {
+ case PEER_PACKET_LOSS:
+ return peer->packetLoss;
+ case PEER_PACKET_LOSS_VARIANCE:
+ return peer->packetLossVariance;
+ case PEER_PACKET_LOSS_EPOCH:
+ return peer->packetLossEpoch;
+ case PEER_ROUND_TRIP_TIME:
+ return peer->roundTripTime;
+ case PEER_ROUND_TRIP_TIME_VARIANCE:
+ return peer->roundTripTimeVariance;
+ case PEER_LAST_ROUND_TRIP_TIME:
+ return peer->lastRoundTripTime;
+ case PEER_LAST_ROUND_TRIP_TIME_VARIANCE:
+ return peer->lastRoundTripTimeVariance;
+ case PEER_PACKET_THROTTLE:
+ return peer->packetThrottle;
+ case PEER_PACKET_THROTTLE_LIMIT:
+ return peer->packetThrottleLimit;
+ case PEER_PACKET_THROTTLE_COUNTER:
+ return peer->packetThrottleCounter;
+ case PEER_PACKET_THROTTLE_EPOCH:
+ return peer->packetThrottleEpoch;
+ case PEER_PACKET_THROTTLE_ACCELERATION:
+ return peer->packetThrottleAcceleration;
+ case PEER_PACKET_THROTTLE_DECELERATION:
+ return peer->packetThrottleDeceleration;
+ case PEER_PACKET_THROTTLE_INTERVAL:
+ return peer->packetThrottleInterval;
+ }
+ ERR_FAIL_V(0);
+}
+
+ENetPacketPeer::PeerState ENetPacketPeer::get_state() const {
+ if (!is_active()) {
+ return STATE_DISCONNECTED;
+ }
+ return (PeerState)peer->state;
+}
+
+int ENetPacketPeer::get_channels() const {
+ ERR_FAIL_COND_V_MSG(!peer, 0, "The ENetConnection instance isn't currently active.");
+ return peer->channelCount;
+}
+
+void ENetPacketPeer::_on_disconnect() {
+ if (peer) {
+ peer->data = nullptr;
+ }
+ peer = nullptr;
+}
+
+void ENetPacketPeer::_queue_packet(ENetPacket *p_packet) {
+ ERR_FAIL_COND(!peer);
+ packet_queue.push_back(p_packet);
+}
+
+Error ENetPacketPeer::_send(int p_channel, PackedByteArray p_packet, int p_flags) {
+ ERR_FAIL_COND_V_MSG(peer == nullptr, ERR_UNCONFIGURED, "Peer not connected");
+ ERR_FAIL_COND_V_MSG(p_channel < 0 || p_channel > (int)peer->channelCount, ERR_INVALID_PARAMETER, "Invalid channel");
+ ERR_FAIL_COND_V_MSG(p_flags & ~FLAG_ALLOWED, ERR_INVALID_PARAMETER, "Invalid flags");
+ ENetPacket *packet = enet_packet_create(p_packet.ptr(), p_packet.size(), p_flags);
+ return send(p_channel, packet) == 0 ? OK : FAILED;
+}
+
+void ENetPacketPeer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("peer_disconnect", "data"), &ENetPacketPeer::peer_disconnect, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("peer_disconnect_later", "data"), &ENetPacketPeer::peer_disconnect_later, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("peer_disconnect_now", "data"), &ENetPacketPeer::peer_disconnect_now, DEFVAL(0));
+
+ ClassDB::bind_method(D_METHOD("ping"), &ENetPacketPeer::ping);
+ ClassDB::bind_method(D_METHOD("ping_interval", "ping_interval"), &ENetPacketPeer::ping_interval);
+ ClassDB::bind_method(D_METHOD("reset"), &ENetPacketPeer::reset);
+ ClassDB::bind_method(D_METHOD("send", "channel", "packet", "flags"), &ENetPacketPeer::_send);
+ ClassDB::bind_method(D_METHOD("throttle_configure", "interval", "acceleration", "deceleration"), &ENetPacketPeer::throttle_configure);
+ ClassDB::bind_method(D_METHOD("set_timeout", "timeout", "timeout_min", "timeout_max"), &ENetPacketPeer::set_timeout);
+ ClassDB::bind_method(D_METHOD("get_statistic", "statistic"), &ENetPacketPeer::get_statistic);
+ ClassDB::bind_method(D_METHOD("get_state"), &ENetPacketPeer::get_state);
+ ClassDB::bind_method(D_METHOD("get_channels"), &ENetPacketPeer::get_channels);
+ ClassDB::bind_method(D_METHOD("is_active"), &ENetPacketPeer::is_active);
+
+ BIND_ENUM_CONSTANT(STATE_DISCONNECTED);
+ BIND_ENUM_CONSTANT(STATE_CONNECTING);
+ BIND_ENUM_CONSTANT(STATE_ACKNOWLEDGING_CONNECT);
+ BIND_ENUM_CONSTANT(STATE_CONNECTION_PENDING);
+ BIND_ENUM_CONSTANT(STATE_CONNECTION_SUCCEEDED);
+ BIND_ENUM_CONSTANT(STATE_CONNECTED);
+ BIND_ENUM_CONSTANT(STATE_DISCONNECT_LATER);
+ BIND_ENUM_CONSTANT(STATE_DISCONNECTING);
+ BIND_ENUM_CONSTANT(STATE_ACKNOWLEDGING_DISCONNECT);
+ BIND_ENUM_CONSTANT(STATE_ZOMBIE);
+
+ BIND_ENUM_CONSTANT(PEER_PACKET_LOSS);
+ BIND_ENUM_CONSTANT(PEER_PACKET_LOSS_VARIANCE);
+ BIND_ENUM_CONSTANT(PEER_PACKET_LOSS_EPOCH);
+ BIND_ENUM_CONSTANT(PEER_ROUND_TRIP_TIME);
+ BIND_ENUM_CONSTANT(PEER_ROUND_TRIP_TIME_VARIANCE);
+ BIND_ENUM_CONSTANT(PEER_LAST_ROUND_TRIP_TIME);
+ BIND_ENUM_CONSTANT(PEER_LAST_ROUND_TRIP_TIME_VARIANCE);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_LIMIT);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_COUNTER);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_EPOCH);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_ACCELERATION);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_DECELERATION);
+ BIND_ENUM_CONSTANT(PEER_PACKET_THROTTLE_INTERVAL);
+
+ BIND_CONSTANT(PACKET_LOSS_SCALE);
+ BIND_CONSTANT(PACKET_THROTTLE_SCALE);
+
+ BIND_CONSTANT(FLAG_RELIABLE);
+ BIND_CONSTANT(FLAG_UNSEQUENCED);
+ BIND_CONSTANT(FLAG_UNRELIABLE_FRAGMENT);
+}
+
+ENetPacketPeer::ENetPacketPeer(ENetPeer *p_peer) {
+ peer = p_peer;
+ peer->data = this;
+}
+
+ENetPacketPeer::~ENetPacketPeer() {
+ _on_disconnect();
+ if (last_packet) {
+ enet_packet_destroy(last_packet);
+ last_packet = nullptr;
+ }
+ for (List<ENetPacket *>::Element *E = packet_queue.front(); E; E = E->next()) {
+ enet_packet_destroy(E->get());
+ }
+ packet_queue.clear();
+}
diff --git a/modules/enet/enet_packet_peer.h b/modules/enet/enet_packet_peer.h
new file mode 100644
index 0000000000..9af004de2f
--- /dev/null
+++ b/modules/enet/enet_packet_peer.h
@@ -0,0 +1,131 @@
+/*************************************************************************/
+/* enet_packet_peer.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef ENET_PACKET_PEER_H
+#define ENET_PACKET_PEER_H
+
+#include "core/io/packet_peer.h"
+
+#include <enet/enet.h>
+
+class ENetPacketPeer : public PacketPeer {
+ GDCLASS(ENetPacketPeer, PacketPeer);
+
+private:
+ ENetPeer *peer = nullptr;
+ List<ENetPacket *> packet_queue;
+ ENetPacket *last_packet = nullptr;
+
+ static void _bind_methods();
+ Error _send(int p_channel, PackedByteArray p_packet, int p_flags);
+
+protected:
+ friend class ENetConnection;
+ // Internally used by ENetConnection during service, destroy, etc.
+ void _on_disconnect();
+ void _queue_packet(ENetPacket *p_packet);
+
+public:
+ enum {
+ PACKET_THROTTLE_SCALE = ENET_PEER_PACKET_THROTTLE_SCALE,
+ PACKET_LOSS_SCALE = ENET_PEER_PACKET_LOSS_SCALE,
+ };
+
+ enum {
+ FLAG_RELIABLE = ENET_PACKET_FLAG_RELIABLE,
+ FLAG_UNSEQUENCED = ENET_PACKET_FLAG_UNSEQUENCED,
+ FLAG_UNRELIABLE_FRAGMENT = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT,
+ FLAG_ALLOWED = ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_UNSEQUENCED | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT,
+ };
+
+ enum PeerState {
+ STATE_DISCONNECTED = ENET_PEER_STATE_DISCONNECTED,
+ STATE_CONNECTING = ENET_PEER_STATE_CONNECTING,
+ STATE_ACKNOWLEDGING_CONNECT = ENET_PEER_STATE_ACKNOWLEDGING_CONNECT,
+ STATE_CONNECTION_PENDING = ENET_PEER_STATE_CONNECTION_PENDING,
+ STATE_CONNECTION_SUCCEEDED = ENET_PEER_STATE_CONNECTION_SUCCEEDED,
+ STATE_CONNECTED = ENET_PEER_STATE_CONNECTED,
+ STATE_DISCONNECT_LATER = ENET_PEER_STATE_DISCONNECT_LATER,
+ STATE_DISCONNECTING = ENET_PEER_STATE_DISCONNECTING,
+ STATE_ACKNOWLEDGING_DISCONNECT = ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT,
+ STATE_ZOMBIE = ENET_PEER_STATE_ZOMBIE,
+ };
+
+ enum PeerStatistic {
+ PEER_PACKET_LOSS,
+ PEER_PACKET_LOSS_VARIANCE,
+ PEER_PACKET_LOSS_EPOCH,
+ PEER_ROUND_TRIP_TIME,
+ PEER_ROUND_TRIP_TIME_VARIANCE,
+ PEER_LAST_ROUND_TRIP_TIME,
+ PEER_LAST_ROUND_TRIP_TIME_VARIANCE,
+ PEER_PACKET_THROTTLE,
+ PEER_PACKET_THROTTLE_LIMIT,
+ PEER_PACKET_THROTTLE_COUNTER,
+ PEER_PACKET_THROTTLE_EPOCH,
+ PEER_PACKET_THROTTLE_ACCELERATION,
+ PEER_PACKET_THROTTLE_DECELERATION,
+ PEER_PACKET_THROTTLE_INTERVAL,
+ };
+
+ int get_max_packet_size() const override;
+ int get_available_packet_count() const override;
+ Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet
+ Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
+
+ void peer_disconnect(int p_data = 0);
+ void peer_disconnect_later(int p_data = 0);
+ void peer_disconnect_now(int p_data = 0);
+
+ void ping();
+ void ping_interval(int p_interval);
+ void reset();
+ int send(uint8_t p_channel, ENetPacket *p_packet);
+ void throttle_configure(int interval, int acceleration, int deceleration);
+ void set_timeout(int p_timeout, int p_timeout_min, int p_timeout_max);
+ double get_statistic(PeerStatistic p_stat);
+ PeerState get_state() const;
+ int get_channels() const;
+
+ // Extras
+ IPAddress get_remote_address() const;
+ int get_remote_port() const;
+
+ // Used by ENetMultiplayer (TODO use meta? If only they where StringNames)
+ bool is_active() const;
+
+ ENetPacketPeer(ENetPeer *p_peer);
+ ~ENetPacketPeer();
+};
+
+VARIANT_ENUM_CAST(ENetPacketPeer::PeerState);
+VARIANT_ENUM_CAST(ENetPacketPeer::PeerStatistic);
+
+#endif // ENET_PACKET_PEER_H
diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp
index 38870316e4..7570f5b643 100644
--- a/modules/enet/register_types.cpp
+++ b/modules/enet/register_types.cpp
@@ -30,7 +30,9 @@
#include "register_types.h"
#include "core/error/error_macros.h"
+#include "enet_connection.h"
#include "enet_multiplayer_peer.h"
+#include "enet_packet_peer.h"
static bool enet_ok = false;
@@ -42,6 +44,8 @@ void register_enet_types() {
}
GDREGISTER_CLASS(ENetMultiplayerPeer);
+ GDREGISTER_VIRTUAL_CLASS(ENetPacketPeer);
+ GDREGISTER_CLASS(ENetConnection);
}
void unregister_enet_types() {
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index 30d023606f..24d43858b5 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -5531,7 +5531,10 @@ struct EditorSceneImporterGLTFInterpolate<Quaternion> {
template <class T>
T GLTFDocument::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) {
ERR_FAIL_COND_V(!p_values.size(), T());
- ERR_FAIL_COND_V(p_times.size() != p_values.size(), p_values[0]);
+ if (p_times.size() != p_values.size()) {
+ ERR_PRINT_ONCE("The interpolated values are not corresponding to its times.");
+ return p_values[0];
+ }
//could use binary search, worth it?
int idx = -1;
for (int i = 0; i < p_times.size(); i++) {
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
index 061c572c32..1a3b81487f 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
@@ -670,20 +670,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(),
- _size.ToString()
- });
+ return $"{_position}, {_size}";
}
public string ToString(string format)
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(format),
- _size.ToString(format)
- });
+ return $"{_position.ToString(format)}, {_size.ToString(format)}";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
index cef343e152..8271b43b48 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
@@ -863,16 +863,12 @@ namespace Godot
public override string ToString()
{
- return "[X: " + x.ToString() +
- ", Y: " + y.ToString() +
- ", Z: " + z.ToString() + "]";
+ return $"[X: {x}, Y: {y}, Z: {z}]";
}
public string ToString(string format)
{
- return "[X: " + x.ToString(format) +
- ", Y: " + y.ToString(format) +
- ", Z: " + z.ToString(format) + "]";
+ return $"[X: {x.ToString(format)}, Y: {y.ToString(format)}, Z: {z.ToString(format)}]";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
index 155ffcff32..b9a98ba9c7 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
@@ -1010,12 +1010,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1}, {2}, {3})", r.ToString(), g.ToString(), b.ToString(), a.ToString());
+ return $"({r}, {g}, {b}, {a})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1}, {2}, {3})", r.ToString(format), g.ToString(format), b.ToString(format), a.ToString(format));
+ return $"({r.ToString(format)}, {g.ToString(format)}, {b.ToString(format)}, {a.ToString(format)})";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs
index 1278fb53c2..6972102730 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs
@@ -355,20 +355,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("{0}, {1}", new object[]
- {
- _normal.ToString(),
- D.ToString()
- });
+ return $"{_normal}, {D}";
}
public string ToString(string format)
{
- return String.Format("{0}, {1}", new object[]
- {
- _normal.ToString(format),
- D.ToString(format)
- });
+ return $"{_normal.ToString(format)}, {D.ToString(format)}";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
index 35f8217432..0fed55cc30 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
@@ -547,12 +547,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1}, {2}, {3})", x.ToString(), y.ToString(), z.ToString(), w.ToString());
+ return $"({x}, {y}, {z}, {w})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1}, {2}, {3})", x.ToString(format), y.ToString(format), z.ToString(format), w.ToString(format));
+ return $"({x.ToString(format)}, {y.ToString(format)}, {z.ToString(format)}, {w.ToString(format)})";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
index 1053baaa26..dec69c7f94 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
@@ -405,20 +405,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(),
- _size.ToString()
- });
+ return $"{_position}, {_size}";
}
public string ToString(string format)
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(format),
- _size.ToString(format)
- });
+ return $"{_position.ToString(format)}, {_size.ToString(format)}";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
index c27af74866..7fb6614d2c 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
@@ -383,20 +383,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(),
- _size.ToString()
- });
+ return $"{_position}, {_size}";
}
public string ToString(string format)
{
- return String.Format("{0}, {1}", new object[]
- {
- _position.ToString(format),
- _size.ToString(format)
- });
+ return $"{_position.ToString(format)}, {_size.ToString(format)}";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
index b182f1f15e..d9665cbf2b 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs
@@ -1108,7 +1108,7 @@ namespace Godot
/// </summary>
public static string[] Split(this string instance, string divisor, bool allowEmpty = true)
{
- return instance.Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
+ return instance.Split(new[] { divisor }, allowEmpty ? StringSplitOptions.None : StringSplitOptions.RemoveEmptyEntries);
}
/// <summary>
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs
index c135eb137f..62a6fe6959 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs
@@ -492,16 +492,12 @@ namespace Godot
public override string ToString()
{
- return "[X: " + x.ToString() +
- ", Y: " + y.ToString() +
- ", O: " + origin.ToString() + "]";
+ return $"[X: {x}, Y: {y}, O: {origin}]";
}
public string ToString(string format)
{
- return "[X: " + x.ToString(format) +
- ", Y: " + y.ToString(format) +
- ", O: " + origin.ToString(format) + "]";
+ return $"[X: {x.ToString(format)}, Y: {y.ToString(format)}, O: {origin.ToString(format)}]";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs
index 5c57203ca7..1b717fb4ae 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs
@@ -393,18 +393,12 @@ namespace Godot
public override string ToString()
{
- return "[X: " + basis.x.ToString() +
- ", Y: " + basis.y.ToString() +
- ", Z: " + basis.z.ToString() +
- ", O: " + origin.ToString() + "]";
+ return $"[X: {basis.x}, Y: {basis.y}, Z: {basis.z}, O: {origin}]";
}
public string ToString(string format)
{
- return "[X: " + basis.x.ToString(format) +
- ", Y: " + basis.y.ToString(format) +
- ", Z: " + basis.z.ToString(format) +
- ", O: " + origin.ToString(format) + "]";
+ return $"[X: {basis.x.ToString(format)}, Y: {basis.y.ToString(format)}, Z: {basis.z.ToString(format)}, O: {origin.ToString(format)}]";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
index a0948d8b10..8bb5e90a68 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
@@ -751,20 +751,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1})", new object[]
- {
- x.ToString(),
- y.ToString()
- });
+ return $"({x}, {y})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1})", new object[]
- {
- x.ToString(format),
- y.ToString(format)
- });
+ return $"({x.ToString(format)}, {y.ToString(format)})";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs
index b4c631608e..959f262f52 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs
@@ -508,20 +508,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1})", new object[]
- {
- this.x.ToString(),
- this.y.ToString()
- });
+ return $"({x}, {y})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1})", new object[]
- {
- this.x.ToString(format),
- this.y.ToString(format)
- });
+ return $"({x.ToString(format)}, {y.ToString(format)})";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
index a02a0d2dd9..bdf64159e9 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
@@ -845,22 +845,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1}, {2})", new object[]
- {
- x.ToString(),
- y.ToString(),
- z.ToString()
- });
+ return $"({x}, {y}, {z})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1}, {2})", new object[]
- {
- x.ToString(format),
- y.ToString(format),
- z.ToString(format)
- });
+ return $"({x.ToString(format)}, {y.ToString(format)}, {z.ToString(format)})";
}
}
}
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs
index 80bad061b2..c96a7cf1b0 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs
@@ -511,22 +511,12 @@ namespace Godot
public override string ToString()
{
- return String.Format("({0}, {1}, {2})", new object[]
- {
- this.x.ToString(),
- this.y.ToString(),
- this.z.ToString()
- });
+ return $"({x}, {y}, {z})";
}
public string ToString(string format)
{
- return String.Format("({0}, {1}, {2})", new object[]
- {
- this.x.ToString(format),
- this.y.ToString(format),
- this.z.ToString(format)
- });
+ return $"({x.ToString(format)}, {y.ToString(format)}, {z.ToString(format)})";
}
}
}
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index 589bb8931a..52d9a602a1 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -39,26 +39,6 @@ WebSocketMultiplayerPeer::~WebSocketMultiplayerPeer() {
_clear();
}
-int WebSocketMultiplayerPeer::_gen_unique_id() const {
- uint32_t hash = 0;
-
- while (hash == 0 || hash == 1) {
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_ticks_usec());
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_unix_time(), hash);
- hash = hash_djb2_one_32(
- (uint32_t)OS::get_singleton()->get_data_path().hash64(), hash);
- hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)this), hash); //rely on aslr heap
- hash = hash_djb2_one_32(
- (uint32_t)((uint64_t)&hash), hash); //rely on aslr stack
- hash = hash & 0x7FFFFFFF; // make it compatible with unsigned, since negative id is used for exclusion
- }
-
- return hash;
-}
-
void WebSocketMultiplayerPeer::_clear() {
_peer_map.clear();
if (_current_packet.data != nullptr) {
diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h
index e3ccd1a795..4e80f876d6 100644
--- a/modules/websocket/websocket_multiplayer_peer.h
+++ b/modules/websocket/websocket_multiplayer_peer.h
@@ -75,7 +75,6 @@ protected:
void _send_add(int32_t p_peer_id);
void _send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id);
void _send_del(int32_t p_peer_id);
- int _gen_unique_id() const;
public:
/* MultiplayerPeer */
diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp
index c6eb3d44b4..7402bbb46e 100644
--- a/modules/websocket/wsl_server.cpp
+++ b/modules/websocket/wsl_server.cpp
@@ -207,7 +207,7 @@ void WSLServer::poll() {
continue;
}
// Creating new peer
- int32_t id = _gen_unique_id();
+ int32_t id = generate_unique_id();
WSLPeer::PeerData *data = memnew(struct WSLPeer::PeerData);
data->obj = this;
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 956b59ce80..e5d1c2020a 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -2068,6 +2068,8 @@ public:
if (!installed_android_build_template) {
r_missing_templates = !exists_export_template("android_source.zip", &err);
err += TTR("Android build template not installed in the project. Install it from the Project menu.") + "\n";
+ } else {
+ r_missing_templates = false;
}
valid = installed_android_build_template && !r_missing_templates;
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 561207c24c..9b4da2a77a 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1187,9 +1187,6 @@ void CharacterBody2D::move_and_slide() {
}
void CharacterBody2D::_set_collision_direction(const PhysicsServer2D::MotionResult &p_result) {
- on_floor = false;
- on_ceiling = false;
- on_wall = false;
if (up_direction == Vector2()) {
//all is a wall
on_wall = true;
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index 70a7021f22..c155819159 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -153,6 +153,7 @@ Ref<Material> GeometryInstance3D::get_material_override() const {
void GeometryInstance3D::set_visibility_range_begin(float p_dist) {
visibility_range_begin = p_dist;
RS::get_singleton()->instance_geometry_set_visibility_range(get_instance(), visibility_range_begin, visibility_range_end, visibility_range_begin_margin, visibility_range_end_margin);
+ update_configuration_warnings();
}
float GeometryInstance3D::get_visibility_range_begin() const {
@@ -162,6 +163,7 @@ float GeometryInstance3D::get_visibility_range_begin() const {
void GeometryInstance3D::set_visibility_range_end(float p_dist) {
visibility_range_end = p_dist;
RS::get_singleton()->instance_geometry_set_visibility_range(get_instance(), visibility_range_begin, visibility_range_end, visibility_range_begin_margin, visibility_range_end_margin);
+ update_configuration_warnings();
}
float GeometryInstance3D::get_visibility_range_end() const {
@@ -351,6 +353,16 @@ bool GeometryInstance3D::is_ignoring_occlusion_culling() {
return ignore_occlusion_culling;
}
+TypedArray<String> GeometryInstance3D::get_configuration_warnings() const {
+ TypedArray<String> warnings = Node::get_configuration_warnings();
+
+ if (!Math::is_zero_approx(visibility_range_end) && visibility_range_end <= visibility_range_begin) {
+ warnings.push_back(TTR("The GeometryInstance3D visibility range's End distance is set to a non-zero value, but is lower than the Begin distance.\nThis means the GeometryInstance3D will never be visible.\nTo resolve this, set the End distance to 0 or to a value greater than the Begin distance."));
+ }
+
+ return warnings;
+}
+
void GeometryInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance3D::set_material_override);
ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance3D::get_material_override);
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index 2d5699859b..97aac149a1 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -177,6 +177,7 @@ public:
void set_ignore_occlusion_culling(bool p_enabled);
bool is_ignoring_occlusion_culling();
+ TypedArray<String> get_configuration_warnings() const override;
GeometryInstance3D();
};
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 00b847168d..e623309888 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -137,7 +137,7 @@ void AnimationNode::make_invalid(const String &p_reason) {
if (state->invalid_reasons != String()) {
state->invalid_reasons += "\n";
}
- state->invalid_reasons += "- " + p_reason;
+ state->invalid_reasons += String::utf8("• ") + p_reason;
}
float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) {
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 4b6c0ef697..9cdf3bf210 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -79,7 +79,7 @@ void Button::_notification(int p_what) {
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- xl_text = tr(text);
+ xl_text = atr(text);
_shape();
minimum_size_changed();
@@ -355,7 +355,7 @@ void Button::_shape() {
void Button::set_text(const String &p_text) {
if (text != p_text) {
text = p_text;
- xl_text = tr(text);
+ xl_text = atr(text);
_shape();
update();
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index c19ee849d3..4179c8b246 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -495,6 +495,20 @@ bool Control::is_layout_rtl() const {
return data.is_rtl;
}
+void Control::set_auto_translate(bool p_enable) {
+ if (p_enable == data.auto_translate) {
+ return;
+ }
+
+ data.auto_translate = p_enable;
+
+ notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
+}
+
+bool Control::is_auto_translating() const {
+ return data.auto_translate;
+}
+
void Control::_clear_size_warning() {
data.size_warning = false;
}
@@ -2784,6 +2798,9 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction);
ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl);
+ ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
+ ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
+
BIND_VMETHOD(MethodInfo("_structured_text_parser", PropertyInfo(Variant::ARRAY, "args"), PropertyInfo(Variant::STRING, "text")));
BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
@@ -2848,10 +2865,13 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
+
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
- ADD_GROUP("", "");
+
+ ADD_GROUP("Auto Translate", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
BIND_ENUM_CONSTANT(FOCUS_NONE);
BIND_ENUM_CONSTANT(FOCUS_CLICK);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 3779f9b308..8d669c7a6d 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -182,6 +182,8 @@ private:
bool is_rtl_dirty = true;
bool is_rtl = false;
+ bool auto_translate = true;
+
real_t rotation = 0.0;
Vector2 scale = Vector2(1, 1);
Vector2 pivot_offset;
@@ -351,6 +353,10 @@ public:
LayoutDirection get_layout_direction() const;
virtual bool is_layout_rtl() const;
+ void set_auto_translate(bool p_enable);
+ bool is_auto_translating() const;
+ _FORCE_INLINE_ String atr(const String p_string) const { return is_auto_translating() ? tr(p_string) : p_string; };
+
/* POSITIONING */
void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true);
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index f5c764e9cc..da858e8e83 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -72,13 +72,10 @@ void AcceptDialog::_notification(int p_what) {
parent_visible = nullptr;
}
}
-
} break;
-
case NOTIFICATION_THEME_CHANGED: {
bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
-
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 06faf3fa3e..1603989243 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -221,7 +221,7 @@ void Label::_update_visible() {
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- String new_text = tr(text);
+ String new_text = atr(text);
if (new_text == xl_text) {
return; //nothing new
}
@@ -509,7 +509,7 @@ void Label::set_text(const String &p_string) {
return;
}
text = p_string;
- xl_text = tr(p_string);
+ xl_text = atr(p_string);
dirty = true;
if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 19ffcfca6d..68e9171c15 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -597,7 +597,7 @@ void LineEdit::_notification(int p_what) {
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- placeholder_translated = tr(placeholder);
+ placeholder_translated = atr(placeholder);
_shape();
update();
} break;
@@ -1364,7 +1364,7 @@ String LineEdit::get_text() const {
void LineEdit::set_placeholder(String p_text) {
placeholder = p_text;
- placeholder_translated = tr(placeholder);
+ placeholder_translated = atr(placeholder);
_shape();
update();
}
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 7790a0970c..490548fce0 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -722,7 +722,7 @@ void PopupMenu::_notification(int p_what) {
case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
for (int i = 0; i < items.size(); i++) {
- items.write[i].xl_text = tr(items[i].text);
+ items.write[i].xl_text = atr(items[i].text);
items.write[i].dirty = true;
_shape_item(i);
}
@@ -807,7 +807,7 @@ void PopupMenu::_notification(int p_what) {
#define ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel) \
item.text = p_label; \
- item.xl_text = tr(p_label); \
+ item.xl_text = atr(p_label); \
item.id = p_id == -1 ? items.size() : p_id; \
item.accel = p_accel;
@@ -887,7 +887,7 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
ERR_FAIL_COND_MSG(p_shortcut.is_null(), "Cannot add item with invalid Shortcut."); \
_ref_shortcut(p_shortcut); \
item.text = p_shortcut->get_name(); \
- item.xl_text = tr(item.text); \
+ item.xl_text = atr(item.text); \
item.id = p_id == -1 ? items.size() : p_id; \
item.shortcut = p_shortcut; \
item.shortcut_is_global = p_global;
@@ -956,7 +956,7 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons
void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) {
Item item;
item.text = p_label;
- item.xl_text = tr(p_label);
+ item.xl_text = atr(p_label);
item.id = p_id == -1 ? items.size() : p_id;
item.submenu = p_submenu;
items.push_back(item);
@@ -973,7 +973,7 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu,
void PopupMenu::set_item_text(int p_idx, const String &p_text) {
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].text = p_text;
- items.write[p_idx].xl_text = tr(p_text);
+ items.write[p_idx].xl_text = atr(p_text);
_shape_item(p_idx);
control->update();
@@ -1402,7 +1402,7 @@ void PopupMenu::add_separator(const String &p_text, int p_id) {
sep.id = p_id;
if (p_text != String()) {
sep.text = p_text;
- sep.xl_text = tr(p_text);
+ sep.xl_text = atr(p_text);
}
items.push_back(sep);
control->update();
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 8f84585f9b..4b8c4b3e16 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -550,7 +550,7 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in
// Draw the tab contents.
Control *control = Object::cast_to<Control>(tabs[p_index]);
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
int x_content = tab_rect.position.x + p_tab_style->get_margin(SIDE_LEFT);
int top_margin = p_tab_style->get_margin(SIDE_TOP);
@@ -584,7 +584,8 @@ void TabContainer::_refresh_texts() {
int font_size = get_theme_font_size(SNAME("font_size"));
for (int i = 0; i < tabs.size(); i++) {
Control *control = Object::cast_to<Control>(tabs[i]);
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
+
Ref<TextLine> name;
name.instantiate();
name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
@@ -648,7 +649,7 @@ int TabContainer::_get_tab_width(int p_index) const {
// Get the width of the text displayed on the tab.
Ref<Font> font = get_theme_font(SNAME("font"));
int font_size = get_theme_font_size(SNAME("font_size"));
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
int width = font->get_string_size(text, font_size).width;
// Add space for a tab icon.
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 9e8fe27ffb..103860ad78 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -239,7 +239,7 @@ void Tabs::_shape(int p_tab) {
Ref<Font> font = get_theme_font(SNAME("font"));
int font_size = get_theme_font_size(SNAME("font_size"));
- tabs.write[p_tab].xl_text = tr(tabs[p_tab].text);
+ tabs.write[p_tab].xl_text = atr(tabs[p_tab].text);
tabs.write[p_tab].text_buf->clear();
if (tabs[p_tab].text_direction == Control::TEXT_DIRECTION_INHERITED) {
tabs.write[p_tab].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
@@ -529,7 +529,7 @@ bool Tabs::get_offset_buttons_visible() const {
void Tabs::set_tab_title(int p_tab, const String &p_title) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].text = p_title;
- tabs.write[p_tab].xl_text = tr(p_title);
+ tabs.write[p_tab].xl_text = atr(p_title);
_shape(p_tab);
update();
minimum_size_changed();
@@ -742,7 +742,7 @@ void Tabs::_on_mouse_exited() {
void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
Tab t;
t.text = p_str;
- t.xl_text = tr(p_str);
+ t.xl_text = atr(p_str);
t.text_buf.instantiate();
t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
t.text_buf->add_string(t.xl_text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 27e42db1bd..8e7182df46 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -249,7 +249,7 @@ void Viewport::_sub_window_update(Window *p_window) {
Rect2i r = Rect2i(p_window->get_position(), sw.window->get_size());
if (!p_window->get_flag(Window::FLAG_BORDERLESS)) {
- Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("panel_window"));
+ Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("embedded_border"));
panel->draw(sw.canvas_item, r);
// Draw the title bar text.
@@ -260,7 +260,7 @@ void Viewport::_sub_window_update(Window *p_window) {
int close_h_ofs = p_window->get_theme_constant(SNAME("close_h_ofs"));
int close_v_ofs = p_window->get_theme_constant(SNAME("close_v_ofs"));
- TextLine title_text = TextLine(p_window->get_title(), title_font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
+ TextLine title_text = TextLine(p_window->atr(p_window->get_title()), title_font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
title_text.set_width(r.size.width - panel->get_minimum_size().x - close_h_ofs);
title_text.set_direction(p_window->is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
int x = (r.size.width - title_text.get_size().x) / 2;
@@ -273,9 +273,8 @@ void Viewport::_sub_window_update(Window *p_window) {
}
title_text.draw(sw.canvas_item, r.position + Point2(x, y), title_color);
- bool hl = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
-
- Ref<Texture2D> close_icon = p_window->get_theme_icon(hl ? "close_highlight" : "close");
+ bool pressed = gui.subwindow_focused == sw.window && gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE && gui.subwindow_drag_close_inside;
+ Ref<Texture2D> close_icon = p_window->get_theme_icon(pressed ? "close_pressed" : "close");
close_icon->draw(sw.canvas_item, r.position + Vector2(r.size.width - close_h_ofs, -close_v_ofs));
}
@@ -1559,6 +1558,7 @@ void Viewport::_gui_show_tooltip() {
// If no custom tooltip is given, use a default implementation.
if (!base_tooltip) {
gui.tooltip_label = memnew(TooltipLabel);
+ gui.tooltip_label->set_auto_translate(gui.tooltip_control->is_auto_translating());
gui.tooltip_label->set_text(tooltip_text);
base_tooltip = gui.tooltip_label;
panel->connect("mouse_entered", callable_mp(this, &Viewport::_gui_cancel_tooltip));
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index ab1846660b..1f1da7cefb 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -42,9 +42,8 @@ void Window::set_title(const String &p_title) {
if (embedder) {
embedder->_sub_window_update(this);
-
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
- DisplayServer::get_singleton()->window_set_title(p_title, window_id);
+ DisplayServer::get_singleton()->window_set_title(atr(p_title), window_id);
}
}
@@ -233,7 +232,7 @@ void Window::_make_window() {
DisplayServer::get_singleton()->window_set_current_screen(current_screen, window_id);
DisplayServer::get_singleton()->window_set_max_size(max_size, window_id);
DisplayServer::get_singleton()->window_set_min_size(min_size, window_id);
- DisplayServer::get_singleton()->window_set_title(tr(title), window_id);
+ DisplayServer::get_singleton()->window_set_title(atr(title), window_id);
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
_update_window_size();
@@ -700,93 +699,98 @@ Viewport *Window::_get_embedder() const {
}
void Window::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- bool embedded = false;
- {
- embedder = _get_embedder();
-
- if (embedder) {
- embedded = true;
-
- if (!visible) {
- embedder = nullptr; //not yet since not visible
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ bool embedded = false;
+ {
+ embedder = _get_embedder();
+
+ if (embedder) {
+ embedded = true;
+
+ if (!visible) {
+ embedder = nullptr; //not yet since not visible
+ }
}
}
- }
- if (embedded) {
- //create as embedded
- if (embedder) {
- embedder->_sub_window_register(this);
- RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
- _update_window_size();
- }
-
- } else {
- if (get_parent() == nullptr) {
- //it's the root window!
- visible = true; //always visible
- window_id = DisplayServer::MAIN_WINDOW_ID;
- DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
- _update_from_window();
- //since this window already exists (created on start), we must update pos and size from it
- {
- position = DisplayServer::get_singleton()->window_get_position(window_id);
- size = DisplayServer::get_singleton()->window_get_size(window_id);
+ if (embedded) {
+ //create as embedded
+ if (embedder) {
+ embedder->_sub_window_register(this);
+ RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
+ _update_window_size();
}
- _update_viewport_size(); //then feed back to the viewport
- _update_window_callbacks();
- RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
+
} else {
- //create
- if (visible) {
- _make_window();
+ if (get_parent() == nullptr) {
+ //it's the root window!
+ visible = true; //always visible
+ window_id = DisplayServer::MAIN_WINDOW_ID;
+ DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
+ _update_from_window();
+ //since this window already exists (created on start), we must update pos and size from it
+ {
+ position = DisplayServer::get_singleton()->window_get_position(window_id);
+ size = DisplayServer::get_singleton()->window_get_size(window_id);
+ }
+ _update_viewport_size(); //then feed back to the viewport
+ _update_window_callbacks();
+ RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
+ } else {
+ //create
+ if (visible) {
+ _make_window();
+ }
}
}
- }
-
- if (transient) {
- _make_transient();
- }
- if (visible) {
- notification(NOTIFICATION_VISIBILITY_CHANGED);
- emit_signal(SceneStringNames::get_singleton()->visibility_changed);
- RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
- }
- }
- if (p_what == NOTIFICATION_READY) {
- if (wrap_controls) {
- _update_child_controls();
- }
- }
-
- if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- child_controls_changed();
- }
+ if (transient) {
+ _make_transient();
+ }
+ if (visible) {
+ notification(NOTIFICATION_VISIBILITY_CHANGED);
+ emit_signal(SceneStringNames::get_singleton()->visibility_changed);
+ RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
+ }
+ } break;
+ case NOTIFICATION_READY: {
+ if (wrap_controls) {
+ _update_child_controls();
+ }
+ } break;
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ if (embedder) {
+ embedder->_sub_window_update(this);
+ } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
+ DisplayServer::get_singleton()->window_set_title(atr(title), window_id);
+ }
- if (p_what == NOTIFICATION_EXIT_TREE) {
- if (transient) {
- _clear_transient();
- }
+ child_controls_changed();
+ } break;
+ case NOTIFICATION_EXIT_TREE: {
+ if (transient) {
+ _clear_transient();
+ }
- if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) {
- if (window_id == DisplayServer::MAIN_WINDOW_ID) {
- RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
- _update_window_callbacks();
+ if (!is_embedded() && window_id != DisplayServer::INVALID_WINDOW_ID) {
+ if (window_id == DisplayServer::MAIN_WINDOW_ID) {
+ RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
+ _update_window_callbacks();
+ } else {
+ _clear_window();
+ }
} else {
- _clear_window();
- }
- } else {
- if (embedder) {
- embedder->_sub_window_remove(this);
- embedder = nullptr;
- RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
+ if (embedder) {
+ embedder->_sub_window_remove(this);
+ embedder = nullptr;
+ RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
+ }
+ _update_viewport_size(); //called by clear and make, which does not happen here
}
- _update_viewport_size(); //called by clear and make, which does not happen here
- }
- RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
+ RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
+ } break;
}
}
@@ -1342,6 +1346,20 @@ bool Window::is_layout_rtl() const {
}
}
+void Window::set_auto_translate(bool p_enable) {
+ if (p_enable == auto_translate) {
+ return;
+ }
+
+ auto_translate = p_enable;
+
+ notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
+}
+
+bool Window::is_auto_translating() const {
+ return auto_translate;
+}
+
void Window::_validate_property(PropertyInfo &property) const {
if (property.name == "theme_type_variation") {
List<StringName> names;
@@ -1468,6 +1486,9 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_layout_direction"), &Window::get_layout_direction);
ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Window::is_layout_rtl);
+ ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Window::set_auto_translate);
+ ClassDB::bind_method(D_METHOD("is_auto_translating"), &Window::is_auto_translating);
+
ClassDB::bind_method(D_METHOD("popup", "rect"), &Window::popup, DEFVAL(Rect2i()));
ClassDB::bind_method(D_METHOD("popup_on_parent", "parent_rect"), &Window::popup_on_parent);
ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Window::popup_centered_ratio, DEFVAL(0.8));
@@ -1479,6 +1500,7 @@ void Window::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen"), "set_mode", "get_mode");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_screen"), "set_current_screen", "get_current_screen");
+
ADD_GROUP("Flags", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_controls"), "set_wrap_controls", "is_wrapping_controls");
@@ -1489,17 +1511,23 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "always_on_top"), "set_flag", "get_flag", FLAG_ALWAYS_ON_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "transparent"), "set_flag", "get_flag", FLAG_TRANSPARENT);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unfocusable"), "set_flag", "get_flag", FLAG_NO_FOCUS);
+
ADD_GROUP("Limits", "");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size"), "set_min_size", "get_min_size");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "max_size"), "set_max_size", "get_max_size");
+
ADD_GROUP("Content Scale", "content_scale_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_mode", PROPERTY_HINT_ENUM, "Disabled,Canvas Items,Viewport"), "set_content_scale_mode", "get_content_scale_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
+
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
+ ADD_GROUP("Auto Translate", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
+
ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
diff --git a/scene/main/window.h b/scene/main/window.h
index e92b5e22ed..7013694a06 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -103,6 +103,8 @@ private:
LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED;
+ bool auto_translate = true;
+
void _update_child_controls();
Size2i content_scale_size;
@@ -256,6 +258,10 @@ public:
LayoutDirection get_layout_direction() const;
bool is_layout_rtl() const;
+ void set_auto_translate(bool p_enable);
+ bool is_auto_translating() const;
+ _FORCE_INLINE_ String atr(const String p_string) const { return is_auto_translating() ? tr(p_string) : p_string; };
+
Rect2i get_usable_parent_rect() const;
Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 1bbb84f43d..a4e126fcc6 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -571,10 +571,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
empty.instantiate();
theme->set_stylebox("bg", "ScrollContainer", empty);
- // WindowDialog
+ // Window
- theme->set_stylebox("panel", "Window", default_style);
- theme->set_stylebox("window_panel", "Window", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
+ theme->set_stylebox("embedded_border", "Window", sb_expand(make_stylebox(popup_window_png, 10, 26, 10, 8), 8, 24, 8, 6));
theme->set_constant("scaleborder_size", "Window", 4 * scale);
theme->set_font("title_font", "Window", large_font);
@@ -588,10 +587,14 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("resize_margin", "Window", 4 * scale);
theme->set_icon("close", "Window", make_icon(close_png));
- theme->set_icon("close_highlight", "Window", make_icon(close_hl_png));
+ theme->set_icon("close_pressed", "Window", make_icon(close_hl_png));
theme->set_constant("close_h_ofs", "Window", 18 * scale);
theme->set_constant("close_v_ofs", "Window", 18 * scale);
+ // AcceptDialog
+
+ theme->set_stylebox("panel", "AcceptDialog", make_stylebox(dialog_bg_png, 0, 0, 0, 0));
+
// File Dialog
theme->set_icon("parent_folder", "FileDialog", make_icon(icon_parent_folder_png));
diff --git a/scene/resources/default_theme/dialog_bg.png b/scene/resources/default_theme/dialog_bg.png
new file mode 100644
index 0000000000..a23a10b48a
--- /dev/null
+++ b/scene/resources/default_theme/dialog_bg.png
Binary files differ
diff --git a/scene/resources/default_theme/popup_window.png b/scene/resources/default_theme/popup_window.png
index 174a29ef45..442084049d 100644
--- a/scene/resources/default_theme/popup_window.png
+++ b/scene/resources/default_theme/popup_window.png
Binary files differ
diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h
index 7d747e3c9e..cdb1bc527b 100644
--- a/scene/resources/default_theme/theme_data.h
+++ b/scene/resources/default_theme/theme_data.h
@@ -70,6 +70,10 @@ static const unsigned char color_picker_sample_png[] = {
0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x14, 0x8, 0x0, 0x0, 0x0, 0x0, 0x47, 0x29, 0xbc, 0x83, 0x0, 0x0, 0x0, 0x3c, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0xd5, 0x21, 0x11, 0x0, 0x30, 0xc, 0x4, 0xc1, 0xfa, 0x57, 0x53, 0x87, 0xed, 0x4, 0x45, 0xc4, 0xed, 0xa3, 0xc3, 0x4b, 0xfe, 0xbc, 0xd9, 0x9d, 0x35, 0x2b, 0xe, 0x0, 0x0, 0x0, 0x80, 0xed, 0x66, 0xc5, 0x1, 0x0, 0x0, 0x0, 0xe0, 0x6, 0x1, 0x0, 0x0, 0x90, 0x6, 0x70, 0x83, 0x0, 0x0, 0x0, 0x28, 0x3, 0x7c, 0x54, 0x93, 0xd6, 0xf1, 0xd1, 0x16, 0x8a, 0x17, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
+static const unsigned char dialog_bg_png[] = {
+ 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x26, 0x8, 0x3, 0x0, 0x0, 0x0, 0xf7, 0x10, 0x9b, 0xa4, 0x0, 0x0, 0x2, 0xf5, 0x7a, 0x54, 0x58, 0x74, 0x52, 0x61, 0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x65, 0x78, 0x69, 0x66, 0x0, 0x0, 0x78, 0xda, 0xb5, 0x95, 0x6d, 0x72, 0xe4, 0x28, 0xc, 0x86, 0xff, 0x73, 0x8a, 0x3d, 0x2, 0xfa, 0x42, 0x70, 0x1c, 0xc, 0xa6, 0x6a, 0x6f, 0xb0, 0xc7, 0x9f, 0x17, 0xec, 0x38, 0xd9, 0x4c, 0x57, 0xda, 0x49, 0xcf, 0x40, 0xb5, 0xa5, 0x92, 0x5, 0x12, 0x3c, 0x92, 0x3b, 0xec, 0xff, 0xfd, 0x3b, 0xc2, 0x3f, 0x18, 0xa4, 0x39, 0x6, 0x35, 0xcf, 0xa9, 0xa4, 0x14, 0x31, 0xb4, 0x68, 0xe1, 0xa, 0x25, 0xc7, 0xf7, 0xb1, 0x9f, 0xf2, 0xb0, 0x51, 0xd4, 0xf5, 0x5c, 0xa3, 0xe8, 0xf9, 0x8e, 0x22, 0x85, 0x8f, 0x2f, 0x2e, 0x8d, 0x21, 0x5, 0x52, 0xe, 0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a, 0x44, 0x43, 0x42, 0x4c, 0x43, 0x40, 0x4c, 0x3e, 0x3b, 0x46, 0x3b, 0x39, 0x43, 0x43, 0x3f, 0x4c, 0x43, 0x3f, 0x4b, 0x3a, 0x38, 0x42, 0x42, 0x3e, 0x4b, 0x42, 0x3e, 0x49, 0x3a, 0x37, 0x41, 0x39, 0x37, 0x41, 0x3f, 0x3e, 0x48, 0x39, 0x37, 0x40, 0x38, 0x36, 0x40, 0x3e, 0x3d, 0x48, 0x38, 0x36, 0x3f, 0x3e, 0x3d, 0x47, 0x3a, 0x38, 0x41, 0x38, 0x35, 0x3f, 0x37, 0x35, 0x3e, 0x39, 0x36, 0x40, 0x37, 0x34, 0x3e, 0x3d, 0x3a, 0x46, 0x36, 0x34, 0x3d, 0x3d, 0x3a, 0x44, 0x37, 0x35, 0x3f, 0x35, 0x33, 0x3c, 0x6b, 0xff, 0x8f, 0xb1, 0x0, 0x0, 0x0, 0x1, 0x62, 0x4b, 0x47, 0x44, 0x0, 0x88, 0x5, 0x1d, 0x48, 0x0, 0x0, 0x0, 0x9, 0x70, 0x48, 0x59, 0x73, 0x0, 0x0, 0xb, 0x13, 0x0, 0x0, 0xb, 0x13, 0x1, 0x0, 0x9a, 0x9c, 0x18, 0x0, 0x0, 0x0, 0x7, 0x74, 0x49, 0x4d, 0x45, 0x7, 0xe5, 0x7, 0x1b, 0x17, 0x11, 0x18, 0xe6, 0xb9, 0x22, 0xac, 0x0, 0x0, 0x0, 0x3f, 0x49, 0x44, 0x41, 0x54, 0x28, 0xcf, 0x63, 0xf4, 0x64, 0xc0, 0x6, 0x98, 0x18, 0x68, 0x27, 0xcc, 0xc2, 0x88, 0x5d, 0x98, 0x99, 0x24, 0x61, 0x26, 0x52, 0x84, 0x71, 0xb9, 0x84, 0x89, 0x76, 0xc2, 0xb8, 0xac, 0x64, 0x21, 0x49, 0x35, 0x33, 0x15, 0x54, 0xe3, 0xa, 0x6f, 0x26, 0x6a, 0xa8, 0x26, 0xc9, 0x4a, 0xaa, 0x44, 0x3, 0x89, 0x89, 0x8d, 0x99, 0xee, 0xe9, 0x1b, 0x87, 0x30, 0x0, 0x20, 0x4, 0x0, 0xed, 0x48, 0xa7, 0x26, 0x6c, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
+};
+
static const unsigned char dropdown_png[] = {
0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x8, 0x8, 0x4, 0x0, 0x0, 0x0, 0x6e, 0x6, 0x76, 0x0, 0x0, 0x0, 0x0, 0x4c, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0x63, 0x60, 0x60, 0xf8, 0xc0, 0xcc, 0x0, 0x2, 0x60, 0x16, 0x98, 0x78, 0x67, 0x8, 0x81, 0x6f, 0x4d, 0xde, 0x9a, 0x0, 0x5, 0xde, 0x3a, 0x3d, 0xfc, 0x8f, 0x80, 0xaf, 0xba, 0x18, 0xde, 0x29, 0x2, 0x19, 0xbf, 0x61, 0x2, 0x6f, 0x62, 0x18, 0x3e, 0xb0, 0xbd, 0x97, 0x4, 0x32, 0xff, 0x80, 0xb9, 0xb1, 0x20, 0x93, 0xc0, 0x42, 0x8, 0x2e, 0x54, 0xe8, 0x9d, 0xdc, 0x9b, 0x54, 0x10, 0xb, 0x21, 0xc4, 0x4, 0x63, 0x1, 0x0, 0x86, 0x1f, 0x3b, 0x1e, 0x92, 0x22, 0x3f, 0x40, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
@@ -283,7 +287,7 @@ static const unsigned char popup_bg_disabled_png[] = {
};
static const unsigned char popup_window_png[] = {
- 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49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aa, 0xea, 0x34, 0x5a, 0xf7, 0xcc, 0xd8, 0xa0, 0x7a, 0x5c, 0x34, 0x23, 0x82, 0x1d, 0xd2, 0xda, 0x11, 0x3d, 0xaf, 0x45, 0xdd, 0x35, 0x89, 0x5c, 0x6, 0x1f, 0x9d, 0x2, 0xfb, 0xaa, 0x98, 0x1d, 0x98, 0x2, 0x68, 0x13, 0x32, 0x90, 0xf5, 0xd7, 0xdb, 0x6, 0xd4, 0x8, 0x0, 0xf4, 0xd, 0x3, 0xc5, 0xcb, 0xfa, 0xa5, 0xe, 0x1c, 0x34, 0xad, 0xff, 0xe7, 0x72, 0x44, 0x14, 0x40, 0x97, 0x46, 0x3a, 0x8c, 0x63, 0xcd, 0x9e, 0x69, 0x41, 0x2d, 0x34, 0x6c, 0xe6, 0xa3, 0xb0, 0x50, 0x64, 0xab, 0x86, 0x3f, 0x82, 0xb3, 0xc6, 0xc7, 0x7e, 0x88, 0x66, 0x42, 0x78, 0x82, 0x31, 0x94, 0x22, 0x77, 0xd4, 0x2d, 0xbe, 0x9e, 0x25, 0x9d, 0x7b, 0xb0, 0x59, 0x6d, 0x9f, 0xd7, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
static const unsigned char progress_bar_png[] = {
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 38042d84fd..2ea55843ad 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -354,11 +354,11 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
}
Ref<Image> img;
- if (data_format == DATA_FORMAT_BASIS_UNIVERSAL) {
+ if (data_format == DATA_FORMAT_BASIS_UNIVERSAL && Image::basis_universal_unpacker) {
img = Image::basis_universal_unpacker(pv);
- } else if (data_format == DATA_FORMAT_PNG) {
+ } else if (data_format == DATA_FORMAT_PNG && Image::png_unpacker) {
img = Image::png_unpacker(pv);
- } else {
+ } else if (data_format == DATA_FORMAT_WEBP && Image::webp_unpacker) {
img = Image::webp_unpacker(pv);
}
diff --git a/thirdparty/enet/enet/godot_ext.h b/thirdparty/enet/enet/godot_ext.h
index 84a23b1c85..648f3d2f24 100644
--- a/thirdparty/enet/enet/godot_ext.h
+++ b/thirdparty/enet/enet/godot_ext.h
@@ -11,8 +11,8 @@
*/
ENET_API void enet_address_set_ip(ENetAddress * address, const uint8_t * ip, size_t size);
-ENET_API void enet_host_dtls_server_setup (ENetHost *, void *, void *);
-ENET_API void enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *);
+ENET_API int enet_host_dtls_server_setup (ENetHost *, void *, void *);
+ENET_API int enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *);
ENET_API void enet_host_refuse_new_connections (ENetHost *, int);
#endif // __ENET_GODOT_EXT_H__
diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp
index 3e353d7eec..d0b381ea51 100644
--- a/thirdparty/enet/godot.cpp
+++ b/thirdparty/enet/godot.cpp
@@ -52,6 +52,7 @@ public:
virtual int set_option(ENetSocketOption p_option, int p_value) = 0;
virtual void close() = 0;
virtual void set_refuse_new_connections(bool p_enable) {} /* Only used by dtls server */
+ virtual bool can_upgrade() { return false; } /* Only true in ENetUDP */
virtual ~ENetGodotSocket() {}
};
@@ -79,6 +80,10 @@ public:
sock->close();
}
+ bool can_upgrade() {
+ return true;
+ }
+
Error bind(IPAddress p_ip, uint16_t p_port) {
local_address = p_ip;
bound = true;
@@ -86,7 +91,11 @@ public:
}
Error get_socket_address(IPAddress *r_ip, uint16_t *r_port) {
- return sock->get_socket_address(r_ip, r_port);
+ Error err = sock->get_socket_address(r_ip, r_port);
+ if (bound) {
+ *r_ip = local_address;
+ }
+ return err;
}
Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) {
@@ -195,7 +204,9 @@ public:
Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) {
if (!connected) {
udp->connect_to_host(p_ip, p_port);
- dtls->connect_to_peer(udp, verify, for_hostname, cert);
+ if (dtls->connect_to_peer(udp, verify, for_hostname, cert)) {
+ return FAILED;
+ }
connected = true;
}
dtls->poll();
@@ -424,16 +435,24 @@ ENetSocket enet_socket_create(ENetSocketType type) {
return socket;
}
-void enet_host_dtls_server_setup(ENetHost *host, void *p_key, void *p_cert) {
- ENetUDP *sock = (ENetUDP *)host->socket;
- host->socket = memnew(ENetDTLSServer(sock, Ref<CryptoKey>((CryptoKey *)p_key), Ref<X509Certificate>((X509Certificate *)p_cert)));
+int enet_host_dtls_server_setup(ENetHost *host, void *p_key, void *p_cert) {
+ ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
+ if (!sock->can_upgrade()) {
+ return -1;
+ }
+ host->socket = memnew(ENetDTLSServer((ENetUDP *)sock, Ref<CryptoKey>((CryptoKey *)p_key), Ref<X509Certificate>((X509Certificate *)p_cert)));
memdelete(sock);
+ return 0;
}
-void enet_host_dtls_client_setup(ENetHost *host, void *p_cert, uint8_t p_verify, const char *p_for_hostname) {
- ENetUDP *sock = (ENetUDP *)host->socket;
- host->socket = memnew(ENetDTLSClient(sock, Ref<X509Certificate>((X509Certificate *)p_cert), p_verify, String(p_for_hostname)));
+int enet_host_dtls_client_setup(ENetHost *host, void *p_cert, uint8_t p_verify, const char *p_for_hostname) {
+ ENetGodotSocket *sock = (ENetGodotSocket *)host->socket;
+ if (!sock->can_upgrade()) {
+ return -1;
+ }
+ host->socket = memnew(ENetDTLSClient((ENetUDP *)sock, Ref<X509Certificate>((X509Certificate *)p_cert), p_verify, String::utf8(p_for_hostname)));
memdelete(sock);
+ return 0;
}
void enet_host_refuse_new_connections(ENetHost *host, int p_refuse) {