summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/bullet/area_bullet.cpp3
-rw-r--r--modules/bullet/bullet_types_converter.cpp2
-rw-r--r--modules/bullet/hinge_joint_bullet.cpp5
-rw-r--r--modules/bullet/rigid_body_bullet.cpp14
-rw-r--r--modules/bullet/slider_joint_bullet.cpp1
-rw-r--r--modules/cvtt/image_compress_cvtt.cpp9
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp6
-rw-r--r--modules/etc/image_etc.cpp16
-rw-r--r--modules/gdnative/register_types.cpp12
-rw-r--r--modules/gdscript/gdscript.cpp1
-rw-r--r--modules/gdscript/gdscript.h2
-rw-r--r--modules/gdscript/gdscript_editor.cpp5
-rw-r--r--modules/gdscript/gdscript_function.cpp2
-rw-r--r--modules/gdscript/gdscript_parser.cpp16
-rw-r--r--modules/gdscript/gdscript_parser.h2
-rw-r--r--modules/gridmap/grid_map.cpp33
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp14
-rwxr-xr-xmodules/mbedtls/stream_peer_mbed_tls.cpp8
-rwxr-xr-xmodules/mbedtls/stream_peer_mbed_tls.h12
-rw-r--r--modules/mobile_vr/mobile_vr_interface.cpp6
-rw-r--r--modules/mobile_vr/mobile_vr_interface.h6
-rw-r--r--modules/mono/csharp_script.cpp2
-rw-r--r--modules/mono/glue/Managed/Files/Array.cs22
-rw-r--r--modules/mono/glue/Managed/Files/Dictionary.cs21
-rw-r--r--modules/mono/glue/collections_glue.cpp53
-rw-r--r--modules/mono/glue/collections_glue.h10
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp106
-rw-r--r--modules/mono/mono_gd/gd_mono_header.h11
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.h6
-rw-r--r--modules/opensimplex/simplex_noise.cpp6
-rw-r--r--modules/theora/video_stream_theora.cpp6
-rw-r--r--modules/visual_script/visual_script_editor.cpp19
-rw-r--r--modules/visual_script/visual_script_editor.h3
-rw-r--r--modules/visual_script/visual_script_property_selector.cpp16
-rw-r--r--modules/visual_script/visual_script_property_selector.h3
-rw-r--r--modules/webm/libvpx/SCsub2
-rw-r--r--modules/websocket/doc_classes/WebSocketClient.xml19
-rw-r--r--modules/websocket/doc_classes/WebSocketPeer.xml8
-rw-r--r--modules/websocket/doc_classes/WebSocketServer.xml23
-rw-r--r--modules/websocket/emws_client.cpp9
-rw-r--r--modules/websocket/emws_client.h2
-rw-r--r--modules/websocket/emws_peer.cpp8
-rw-r--r--modules/websocket/emws_peer.h2
-rw-r--r--modules/websocket/emws_server.cpp2
-rw-r--r--modules/websocket/emws_server.h2
-rw-r--r--modules/websocket/lws_client.cpp21
-rw-r--r--modules/websocket/lws_client.h2
-rw-r--r--modules/websocket/lws_peer.cpp58
-rw-r--r--modules/websocket/lws_peer.h8
-rw-r--r--modules/websocket/lws_server.cpp33
-rw-r--r--modules/websocket/lws_server.h2
-rw-r--r--modules/websocket/websocket_client.cpp14
-rw-r--r--modules/websocket/websocket_client.h5
-rw-r--r--modules/websocket/websocket_peer.cpp2
-rw-r--r--modules/websocket/websocket_peer.h2
-rw-r--r--modules/websocket/websocket_server.cpp14
-rw-r--r--modules/websocket/websocket_server.h5
57 files changed, 468 insertions, 234 deletions
diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp
index 3200b4a214..662a477f79 100644
--- a/modules/bullet/area_bullet.cpp
+++ b/modules/bullet/area_bullet.cpp
@@ -94,6 +94,9 @@ void AreaBullet::dispatch_callbacks() {
otherObj.object->on_exit_area(this);
overlappingObjects.remove(i); // Remove after callback
break;
+ case OVERLAP_STATE_DIRTY:
+ case OVERLAP_STATE_INSIDE:
+ break;
}
}
}
diff --git a/modules/bullet/bullet_types_converter.cpp b/modules/bullet/bullet_types_converter.cpp
index a0fe598227..f9b7126173 100644
--- a/modules/bullet/bullet_types_converter.cpp
+++ b/modules/bullet/bullet_types_converter.cpp
@@ -28,8 +28,6 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#pragma once
-
#include "bullet_types_converter.h"
/**
diff --git a/modules/bullet/hinge_joint_bullet.cpp b/modules/bullet/hinge_joint_bullet.cpp
index 86c6a632cd..3a4459a581 100644
--- a/modules/bullet/hinge_joint_bullet.cpp
+++ b/modules/bullet/hinge_joint_bullet.cpp
@@ -117,7 +117,7 @@ void HingeJointBullet::set_param(PhysicsServer::HingeJointParam p_param, real_t
hingeConstraint->setMaxMotorImpulse(p_value);
break;
default:
- ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated");
+ ERR_EXPLAIN("The HingeJoint parameter " + itos(p_param) + " is deprecated.");
WARN_DEPRECATED
break;
}
@@ -143,7 +143,7 @@ real_t HingeJointBullet::get_param(PhysicsServer::HingeJointParam p_param) const
case PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE:
return hingeConstraint->getMaxMotorImpulse();
default:
- ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated");
+ ERR_EXPLAIN("The HingeJoint parameter " + itos(p_param) + " is deprecated.");
WARN_DEPRECATED;
return 0;
}
@@ -159,6 +159,7 @@ void HingeJointBullet::set_flag(PhysicsServer::HingeJointFlag p_flag, bool p_val
case PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR:
hingeConstraint->enableMotor(p_value);
break;
+ case PhysicsServer::HINGE_JOINT_FLAG_MAX: break; // Can't happen, but silences warning
}
}
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp
index f24c8670a3..988f3bc153 100644
--- a/modules/bullet/rigid_body_bullet.cpp
+++ b/modules/bullet/rigid_body_bullet.cpp
@@ -535,20 +535,18 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) {
reload_axis_lock();
_internal_set_mass(0);
break;
- case PhysicsServer::BODY_MODE_RIGID: {
+ case PhysicsServer::BODY_MODE_RIGID:
mode = PhysicsServer::BODY_MODE_RIGID;
reload_axis_lock();
_internal_set_mass(0 == mass ? 1 : mass);
scratch_space_override_modificator();
break;
- }
- case PhysicsServer::BODY_MODE_CHARACTER: {
+ case PhysicsServer::BODY_MODE_CHARACTER:
mode = PhysicsServer::BODY_MODE_CHARACTER;
reload_axis_lock();
_internal_set_mass(0 == mass ? 1 : mass);
scratch_space_override_modificator();
break;
- }
}
btBody->setAngularVelocity(btVector3(0, 0, 0));
@@ -927,10 +925,10 @@ void RigidBodyBullet::reload_space_override_modificator() {
}
switch (currentArea->get_spOv_mode()) {
- ///case PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED:
- /// This area does not affect gravity/damp. These are generally areas
- /// that exist only to detect collisions, and objects entering or exiting them.
- /// break;
+ case PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED:
+ /// This area does not affect gravity/damp. These are generally areas
+ /// that exist only to detect collisions, and objects entering or exiting them.
+ break;
case PhysicsServer::AREA_SPACE_OVERRIDE_COMBINE:
/// This area adds its gravity/damp values to whatever has been
/// calculated so far. This way, many overlapping areas can combine
diff --git a/modules/bullet/slider_joint_bullet.cpp b/modules/bullet/slider_joint_bullet.cpp
index 9e1cd23989..9016ec3bf5 100644
--- a/modules/bullet/slider_joint_bullet.cpp
+++ b/modules/bullet/slider_joint_bullet.cpp
@@ -366,6 +366,7 @@ void SliderJointBullet::set_param(PhysicsServer::SliderJointParam p_param, real_
case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS: setSoftnessOrthoAng(p_value); break;
case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION: setRestitutionOrthoAng(p_value); break;
case PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING: setDampingOrthoAng(p_value); break;
+ case PhysicsServer::SLIDER_JOINT_MAX: break; // Can't happen, but silences warning
}
}
diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp
index 17af6bff09..732b9cf733 100644
--- a/modules/cvtt/image_compress_cvtt.cpp
+++ b/modules/cvtt/image_compress_cvtt.cpp
@@ -118,7 +118,7 @@ static void _digest_row_task(const CVTTCompressionJobParams &p_job_params, const
cvtt::Kernels::EncodeBC7(output_blocks, input_blocks_ldr, p_job_params.options);
}
- int num_real_blocks = ((w - x_start) + 3) / 4;
+ unsigned int num_real_blocks = ((w - x_start) + 3) / 4;
if (num_real_blocks > cvtt::NumParallelBlocks) {
num_real_blocks = cvtt::NumParallelBlocks;
}
@@ -131,7 +131,7 @@ static void _digest_row_task(const CVTTCompressionJobParams &p_job_params, const
static void _digest_job_queue(void *p_job_queue) {
CVTTCompressionJobQueue *job_queue = static_cast<CVTTCompressionJobQueue *>(p_job_queue);
- for (int next_task = atomic_increment(&job_queue->current_task); next_task <= job_queue->num_tasks; next_task = atomic_increment(&job_queue->current_task)) {
+ for (uint32_t next_task = atomic_increment(&job_queue->current_task); next_task <= job_queue->num_tasks; next_task = atomic_increment(&job_queue->current_task)) {
_digest_row_task(job_queue->job_params, job_queue->job_tasks[next_task - 1]);
}
}
@@ -228,8 +228,6 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::CompressS
uint8_t *out_bytes = &wb[dst_ofs];
for (int y_start = 0; y_start < h; y_start += 4) {
- int y_end = y_start + 4;
-
CVTTCompressionRowTask row_task;
row_task.width = w;
row_task.height = h;
@@ -308,7 +306,6 @@ void image_decompress_cvtt(Image *p_image) {
int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps());
int mm_count = p_image->get_mipmap_count();
data.resize(target_size);
- int shift = Image::get_format_pixel_rshift(target_format);
PoolVector<uint8_t>::Write wb = data.write();
@@ -335,7 +332,7 @@ void image_decompress_cvtt(Image *p_image) {
uint8_t input_blocks[16 * cvtt::NumParallelBlocks];
memset(input_blocks, 0, sizeof(input_blocks));
- int num_real_blocks = ((w - x_start) + 3) / 4;
+ unsigned int num_real_blocks = ((w - x_start) + 3) / 4;
if (num_real_blocks > cvtt::NumParallelBlocks) {
num_real_blocks = cvtt::NumParallelBlocks;
}
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 0a1061f92e..7b5fd854ff 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -207,13 +207,13 @@ void NetworkedMultiplayerENet::poll() {
_pop_current_packet();
ENetEvent event;
- /* Wait up to 1000 milliseconds for an 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;
- int ret = enet_host_service(host, &event, 1);
+ int ret = enet_host_service(host, &event, 0);
if (ret < 0) {
// Error, do something?
@@ -293,7 +293,7 @@ void NetworkedMultiplayerENet::poll() {
encode_uint32(*id, &packet->data[4]);
enet_peer_send(E->get(), SYSCH_CONFIG, packet);
}
- } else if (!server) {
+ } else {
emit_signal("server_disconnected");
close_connection();
return;
diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp
index a534aec11b..57f5b68c61 100644
--- a/modules/etc/image_etc.cpp
+++ b/modules/etc/image_etc.cpp
@@ -47,13 +47,14 @@ static Image::Format _get_etc2_mode(Image::DetectChannels format) {
case Image::DETECTED_RGB:
return Image::FORMAT_ETC2_RGB8;
- default:
+ case Image::DETECTED_RGBA:
return Image::FORMAT_ETC2_RGBA8;
- // TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551
+ // TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551
+ default:
+ // TODO: Kept for compatibility, but should be investigated whether it's correct or if it should error out
+ return Image::FORMAT_ETC2_RGBA8;
}
-
- ERR_FAIL_COND_V(true, Image::FORMAT_MAX);
}
static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format) {
@@ -81,9 +82,10 @@ static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format)
case Image::FORMAT_ETC2_RGB8A1:
return Etc::Image::Format::RGB8A1;
- }
- ERR_FAIL_COND_V(true, Etc::Image::Format::UNKNOWN);
+ default:
+ ERR_FAIL_V(Etc::Image::Format::UNKNOWN);
+ }
}
static void _decompress_etc1(Image *p_img) {
@@ -174,7 +176,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
PoolVector<uint8_t>::Read r = img->get_data().read();
- int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps());
+ unsigned int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps());
int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0);
PoolVector<uint8_t> dst_data;
diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp
index 48c0fc8aef..62e87c3651 100644
--- a/modules/gdnative/register_types.cpp
+++ b/modules/gdnative/register_types.cpp
@@ -29,19 +29,19 @@
/*************************************************************************/
#include "register_types.h"
+
#include "gdnative/gdnative.h"
#include "gdnative.h"
-#include "core/io/resource_loader.h"
-#include "core/io/resource_saver.h"
-
#include "arvr/register_types.h"
#include "nativescript/register_types.h"
#include "net/register_types.h"
#include "pluginscript/register_types.h"
#include "core/engine.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -148,7 +148,7 @@ protected:
};
struct LibrarySymbol {
- char *name;
+ const char *name;
bool is_required;
};
@@ -239,7 +239,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty
String additional_code = "extern void register_dynamic_symbol(char *name, void *address);\n"
"extern void add_ios_init_callback(void (*cb)());\n";
String linker_flags = "";
- for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
+ for (unsigned int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
String full_name = lib->get_symbol_prefix() + expected_symbols[i].name;
String code = declare_pattern.replace("$name", full_name);
code = code.replace("$weak", expected_symbols[i].is_required ? "" : " __attribute__((weak))");
@@ -255,7 +255,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty
additional_code += String("void $prefixinit() {\n").replace("$prefix", lib->get_symbol_prefix());
String register_pattern = " if (&$name) register_dynamic_symbol((char *)\"$name\", (void *)$name);\n";
- for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
+ for (unsigned int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
String full_name = lib->get_symbol_prefix() + expected_symbols[i].name;
additional_code += register_pattern.replace("$name", full_name);
}
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index b0d5422afe..48c1760662 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -1981,6 +1981,7 @@ String GDScriptWarning::get_message() const {
CHECK_SYMBOLS(2);
return "The '" + symbols[0] + "' keyword is deprecated and will be removed in a future release, please replace its uses by '" + symbols[1] + "'.";
} break;
+ case WARNING_MAX: break; // Can't happen, but silences warning
}
ERR_EXPLAIN("Invalid GDScript warning code: " + get_name_from_code(code));
ERR_FAIL_V(String());
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index d795500265..4a74b0712a 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -147,7 +147,7 @@ public:
const Map<StringName, Variant> &get_constants() const { return constants; }
const Set<StringName> &get_members() const { return members; }
const GDScriptDataType &get_member_type(const StringName &p_member) const {
- ERR_FAIL_COND_V(!member_indices.has(p_member), GDScriptDataType());
+ CRASH_COND(!member_indices.has(p_member));
return member_indices[p_member].data_type;
}
const Map<StringName, GDScriptFunction *> &get_member_functions() const { return member_functions; }
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index a9b641de50..55bc3d2359 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -33,12 +33,9 @@
#include "core/engine.h"
#include "core/global_constants.h"
#include "core/os/file_access.h"
-#include "editor/editor_settings.h"
#include "gdscript_compiler.h"
#ifdef TOOLS_ENABLED
-#include "core/engine.h"
-#include "core/reference.h"
#include "editor/editor_file_system.h"
#include "editor/editor_settings.h"
#endif
@@ -1113,6 +1110,7 @@ static bool _guess_expression_type(const GDScriptCompletionContext &p_context, c
} break;
}
} break;
+ default: {}
}
// It may have found a null, but that's never useful
@@ -3357,6 +3355,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
return OK;
}
} break;
+ default: {}
}
return ERR_CANT_RESOLVE;
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index abd08d13ff..b935861652 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -789,7 +789,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#ifdef DEBUG_ENABLED
GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(type->operator Object *());
GD_ERR_BREAK(!nc);
- if (!src->get_type() != Variant::OBJECT && !src->get_type() != Variant::NIL) {
+ if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) {
err_text = "Trying to assign value of type '" + Variant::get_type_name(src->get_type()) +
"' to a variable of type '" + nc->get_name() + "'.";
OPCODE_BREAK;
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index ea1287374b..5facfe7869 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -5079,7 +5079,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class) {
if (found) continue;
if (p->constant_expressions.has(base)) {
- if (!p->constant_expressions[base].expression->type == Node::TYPE_CONSTANT) {
+ if (p->constant_expressions[base].expression->type != Node::TYPE_CONSTANT) {
_set_error("Could not resolve constant '" + base + "'.", p_class->line);
return;
}
@@ -5219,6 +5219,8 @@ String GDScriptParser::DataType::to_string() const {
}
return class_type->name.operator String();
} break;
+ case UNRESOLVED: {
+ } break;
}
return "Unresolved";
@@ -5791,7 +5793,10 @@ bool GDScriptParser::_is_type_compatible(const DataType &p_container, const Data
expr_native = base->base_type.native_type;
expr_script = base->base_type.script_type;
}
- }
+ } break;
+ case DataType::BUILTIN: // Already handled above
+ case DataType::UNRESOLVED: // Not allowed, see above
+ break;
}
switch (p_container.kind) {
@@ -5834,7 +5839,10 @@ bool GDScriptParser::_is_type_compatible(const DataType &p_container, const Data
expr_class = expr_class->base_type.class_type;
}
return false;
- }
+ } break;
+ case DataType::BUILTIN: // Already handled above
+ case DataType::UNRESOLVED: // Not allowed, see above
+ break;
}
return false;
@@ -6228,6 +6236,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case Variant::COLOR: {
error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::STRING;
} break;
+ default: {}
}
}
if (error) {
@@ -6345,6 +6354,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
}
}
} break;
+ default: {}
}
p_node->set_datatype(_resolve_type(node_type, p_node->line));
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index cd68072499..c7813a2144 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -88,6 +88,8 @@ public:
case CLASS: {
return class_type == other.class_type;
} break;
+ case UNRESOLVED: {
+ } break;
}
return false;
}
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index a480c4183e..a8fdf8cf1f 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -29,37 +29,19 @@
/*************************************************************************/
#include "grid_map.h"
-#include "core/message_queue.h"
-#include "scene/3d/light.h"
-#include "scene/resources/surface_tool.h"
-#include "servers/visual_server.h"
#include "core/io/marshalls.h"
-#include "core/os/os.h"
+#include "core/message_queue.h"
+#include "scene/3d/light.h"
#include "scene/resources/mesh_library.h"
+#include "scene/resources/surface_tool.h"
#include "scene/scene_string_names.h"
+#include "servers/visual_server.h"
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
- /* } else if (name=="cells") {
- PoolVector<int> cells = p_value;
- int amount=cells.size();
- PoolVector<int>::Read r = cells.read();
- ERR_FAIL_COND_V(amount&1,false); // not even
- cell_map.clear();
- for(int i=0;i<amount/3;i++) {
-
-
- IndexKey ik;
- ik.key=decode_uint64(&r[i*3]);
- Cell cell;
- cell.cell=uint32_t(r[i*+1]);
- cell_map[ik]=cell;
-
- }
- _recreate_octant_data();*/
if (name == "data") {
Dictionary d = p_value;
@@ -80,7 +62,9 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
cell_map[ik] = cell;
}
}
+
_recreate_octant_data();
+
} else if (name == "baked_meshes") {
clear_baked_meshes();
@@ -103,8 +87,9 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
_recreate_octant_data();
- } else
+ } else {
return false;
+ }
return true;
}
@@ -1081,8 +1066,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
}
}
- int ofs = 0;
-
for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool> > >::Element *E = surface_map.front(); E; E = E->next()) {
Ref<ArrayMesh> mesh;
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index 5fdb6a5196..fae88042af 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -597,29 +597,31 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (mb->get_button_index() == BUTTON_LEFT) {
if (input_action == INPUT_DUPLICATE) {
-
//paste
_duplicate_paste();
input_action = INPUT_NONE;
_update_duplicate_indicator();
} else if (mb->get_shift()) {
input_action = INPUT_SELECT;
- } else if (mb->get_command())
+ } else if (mb->get_command()) {
input_action = INPUT_COPY;
- else {
+ } else {
input_action = INPUT_PAINT;
set_items.clear();
}
- } else if (mb->get_button_index() == BUTTON_RIGHT)
+ } else if (mb->get_button_index() == BUTTON_RIGHT) {
if (input_action == INPUT_DUPLICATE) {
-
input_action = INPUT_NONE;
_update_duplicate_indicator();
} else if (mb->get_shift()) {
input_action = INPUT_ERASE;
set_items.clear();
- } else
+ } else {
return false;
+ }
+ } else {
+ return false;
+ }
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
} else {
diff --git a/modules/mbedtls/stream_peer_mbed_tls.cpp b/modules/mbedtls/stream_peer_mbed_tls.cpp
index e0cd67a810..5c81f32e9e 100755
--- a/modules/mbedtls/stream_peer_mbed_tls.cpp
+++ b/modules/mbedtls/stream_peer_mbed_tls.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "stream_peer_mbed_tls.h"
+
#include "core/io/stream_peer_tcp.h"
#include "core/os/file_access.h"
-#include "mbedtls/platform_util.h"
+
+#include <mbedtls/platform_util.h>
static void my_debug(void *ctx, int level,
const char *file, int line,
@@ -283,7 +285,7 @@ void StreamPeerMbedTLS::poll() {
}
Ref<StreamPeerTCP> tcp = base;
- if (tcp.is_valid() && tcp->get_status() != STATUS_CONNECTED) {
+ if (tcp.is_valid() && tcp->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
disconnect_from_stream();
return;
}
@@ -310,7 +312,7 @@ void StreamPeerMbedTLS::disconnect_from_stream() {
return;
Ref<StreamPeerTCP> tcp = base;
- if (tcp.is_valid() && tcp->get_status() == STATUS_CONNECTED) {
+ if (tcp.is_valid() && tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
// We are still connected on the socket, try to send close notity.
mbedtls_ssl_close_notify(&ssl);
}
diff --git a/modules/mbedtls/stream_peer_mbed_tls.h b/modules/mbedtls/stream_peer_mbed_tls.h
index 0cf893eacf..abf87b79cc 100755
--- a/modules/mbedtls/stream_peer_mbed_tls.h
+++ b/modules/mbedtls/stream_peer_mbed_tls.h
@@ -33,12 +33,12 @@
#include "core/io/stream_peer_ssl.h"
-#include "mbedtls/config.h"
-#include "mbedtls/ctr_drbg.h"
-#include "mbedtls/debug.h"
-#include "mbedtls/entropy.h"
-#include "mbedtls/net.h"
-#include "mbedtls/ssl.h"
+#include <mbedtls/config.h>
+#include <mbedtls/ctr_drbg.h>
+#include <mbedtls/debug.h>
+#include <mbedtls/entropy.h>
+#include <mbedtls/net.h>
+#include <mbedtls/ssl.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp
index e2c630565f..2cabc7bd59 100644
--- a/modules/mobile_vr/mobile_vr_interface.cpp
+++ b/modules/mobile_vr/mobile_vr_interface.cpp
@@ -297,6 +297,7 @@ bool MobileVRInterface::initialize() {
mag_current_min = Vector3(0, 0, 0);
mag_current_max = Vector3(0, 0, 0);
+#if !defined(SERVER_ENABLED)
// build our shader
if (lens_shader == NULL) {
///@TODO need to switch between GLES2 and GLES3 version, Reduz suggested moving this into our drivers and making this a core shader
@@ -337,6 +338,7 @@ bool MobileVRInterface::initialize() {
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
}
+#endif
// reset our orientation
orientation = Basis();
@@ -360,6 +362,7 @@ void MobileVRInterface::uninitialize() {
arvr_server->clear_primary_interface_if(this);
}
+#if !defined(SERVER_ENABLED)
// cleanup our shader and buffers
if (lens_shader != NULL) {
glDeleteVertexArrays(1, &half_screen_array);
@@ -368,6 +371,7 @@ void MobileVRInterface::uninitialize() {
delete lens_shader;
lens_shader = NULL;
}
+#endif
initialized = false;
};
@@ -470,6 +474,7 @@ void MobileVRInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_t
// get our render target
RID eye_texture = VSG::storage->render_target_get_texture(p_render_target);
uint32_t texid = VS::get_singleton()->texture_get_texid(eye_texture);
+#if !defined(SERVER_ENABLED)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texid);
@@ -484,6 +489,7 @@ void MobileVRInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_t
glBindVertexArray(half_screen_array);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindVertexArray(0);
+#endif
};
void MobileVRInterface::process() {
diff --git a/modules/mobile_vr/mobile_vr_interface.h b/modules/mobile_vr/mobile_vr_interface.h
index cee0cca90e..63cad4c738 100644
--- a/modules/mobile_vr/mobile_vr_interface.h
+++ b/modules/mobile_vr/mobile_vr_interface.h
@@ -34,7 +34,9 @@
#include "servers/arvr/arvr_interface.h"
#include "servers/arvr/arvr_positional_tracker.h"
+#if !defined(SERVER_ENABLED)
#include "shaders/lens_distorted.glsl.gen.h"
+#endif
/**
@author Bastiaan Olij <mux213@gmail.com>
@@ -58,9 +60,13 @@ private:
float eye_height;
uint64_t last_ticks;
+#if !defined(SERVER_ENABLED)
LensDistortedShaderGLES3 *lens_shader;
GLuint half_screen_quad;
GLuint half_screen_array;
+#else
+ void *lens_shader;
+#endif
real_t intraocular_dist;
real_t display_width;
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index c013c232d4..91fd482235 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -1174,7 +1174,7 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
GDMonoProperty *property = script->script_class->get_property(p_name);
if (property) {
- property->set_value(mono_object, GDMonoMarshal::variant_to_mono_object(p_value));
+ property->set_value(mono_object, GDMonoMarshal::variant_to_mono_object(p_value, property->get_type()));
return true;
}
diff --git a/modules/mono/glue/Managed/Files/Array.cs b/modules/mono/glue/Managed/Files/Array.cs
index c80cb7cc83..d5a35d7ae0 100644
--- a/modules/mono/glue/Managed/Files/Array.cs
+++ b/modules/mono/glue/Managed/Files/Array.cs
@@ -128,7 +128,7 @@ namespace Godot.Collections
for (int i = 0; i < count; i++)
{
- yield return godot_icall_Array_At(GetPtr(), i);
+ yield return this[i];
}
}
@@ -167,6 +167,9 @@ namespace Godot.Collections
internal extern static object godot_icall_Array_At(IntPtr ptr, int index);
[MethodImpl(MethodImplOptions.InternalCall)]
+ internal extern static object godot_icall_Array_At_Generic(IntPtr ptr, int index, int elemTypeEncoding, IntPtr elemTypeClass);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static void godot_icall_Array_SetAt(IntPtr ptr, int index, object value);
[MethodImpl(MethodImplOptions.InternalCall)]
@@ -195,12 +198,23 @@ namespace Godot.Collections
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern static void godot_icall_Array_RemoveAt(IntPtr ptr, int index);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ internal extern static void godot_icall_Array_Generic_GetElementTypeInfo(Type elemType, out int elemTypeEncoding, out IntPtr elemTypeClass);
}
public class Array<T> : IList<T>, ICollection<T>, IEnumerable<T>
{
Array objectArray;
+ internal static int elemTypeEncoding;
+ internal static IntPtr elemTypeClass;
+
+ static Array()
+ {
+ Array.godot_icall_Array_Generic_GetElementTypeInfo(typeof(T), out elemTypeEncoding, out elemTypeClass);
+ }
+
public Array()
{
objectArray = new Array();
@@ -230,7 +244,7 @@ namespace Godot.Collections
{
get
{
- return (T)objectArray[index];
+ return (T)Array.godot_icall_Array_At_Generic(GetPtr(), index, elemTypeEncoding, elemTypeClass);
}
set
{
@@ -287,7 +301,7 @@ namespace Godot.Collections
for (int i = 0; i < count; i++)
{
- array[arrayIndex] = (T)objectArray[i];
+ array[arrayIndex] = (T)this[i];
arrayIndex++;
}
}
@@ -298,7 +312,7 @@ namespace Godot.Collections
for (int i = 0; i < count; i++)
{
- yield return (T)objectArray[i];
+ yield return (T)this[i];
}
}
diff --git a/modules/mono/glue/Managed/Files/Dictionary.cs b/modules/mono/glue/Managed/Files/Dictionary.cs
index 523e48c31a..7695f03cd6 100644
--- a/modules/mono/glue/Managed/Files/Dictionary.cs
+++ b/modules/mono/glue/Managed/Files/Dictionary.cs
@@ -204,6 +204,9 @@ namespace Godot.Collections
internal extern static object godot_icall_Dictionary_GetValue(IntPtr ptr, object key);
[MethodImpl(MethodImplOptions.InternalCall)]
+ internal extern static object godot_icall_Dictionary_GetValue_Generic(IntPtr ptr, object key, int valTypeEncoding, IntPtr valTypeClass);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
internal extern static void godot_icall_Dictionary_SetValue(IntPtr ptr, object key, object value);
[MethodImpl(MethodImplOptions.InternalCall)]
@@ -235,6 +238,12 @@ namespace Godot.Collections
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern static bool godot_icall_Dictionary_TryGetValue(IntPtr ptr, object key, out object value);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ internal extern static bool godot_icall_Dictionary_TryGetValue_Generic(IntPtr ptr, object key, out object value, int valTypeEncoding, IntPtr valTypeClass);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ internal extern static void godot_icall_Dictionary_Generic_GetValueTypeInfo(Type valueType, out int valTypeEncoding, out IntPtr valTypeClass);
}
public class Dictionary<TKey, TValue> :
@@ -244,6 +253,14 @@ namespace Godot.Collections
{
Dictionary objectDict;
+ internal static int valTypeEncoding;
+ internal static IntPtr valTypeClass;
+
+ static Dictionary()
+ {
+ Dictionary.godot_icall_Dictionary_Generic_GetValueTypeInfo(typeof(TValue), out valTypeEncoding, out valTypeClass);
+ }
+
public Dictionary()
{
objectDict = new Dictionary();
@@ -273,7 +290,7 @@ namespace Godot.Collections
{
get
{
- return (TValue)objectDict[key];
+ return (TValue)Dictionary.godot_icall_Dictionary_GetValue_Generic(objectDict.GetPtr(), key, valTypeEncoding, valTypeClass);
}
set
{
@@ -382,7 +399,7 @@ namespace Godot.Collections
public bool TryGetValue(TKey key, out TValue value)
{
object retValue;
- bool found = objectDict.TryGetValue(key, out retValue);
+ bool found = Dictionary.godot_icall_Dictionary_TryGetValue_Generic(GetPtr(), key, out retValue, valTypeEncoding, valTypeClass);
value = found ? (TValue)retValue : default(TValue);
return found;
}
diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp
index d9dba1c60d..059e2ff6de 100644
--- a/modules/mono/glue/collections_glue.cpp
+++ b/modules/mono/glue/collections_glue.cpp
@@ -53,6 +53,14 @@ MonoObject *godot_icall_Array_At(Array *ptr, int index) {
return GDMonoMarshal::variant_to_mono_object(ptr->operator[](index));
}
+MonoObject *godot_icall_Array_At_Generic(Array *ptr, int index, uint32_t type_encoding, GDMonoClass *type_class) {
+ if (index < 0 || index > ptr->size()) {
+ GDMonoUtils::set_pending_exception(mono_get_exception_index_out_of_range());
+ return NULL;
+ }
+ return GDMonoMarshal::variant_to_mono_object(ptr->operator[](index), ManagedType(type_encoding, type_class));
+}
+
void godot_icall_Array_SetAt(Array *ptr, int index, MonoObject *value) {
if (index < 0 || index > ptr->size()) {
GDMonoUtils::set_pending_exception(mono_get_exception_index_out_of_range());
@@ -122,6 +130,14 @@ void godot_icall_Array_RemoveAt(Array *ptr, int index) {
ptr->remove(index);
}
+void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class) {
+ MonoType *elem_type = mono_reflection_type_get_type(refltype);
+
+ *type_encoding = mono_type_get_type(elem_type);
+ MonoClass *type_class_raw = mono_class_from_mono_type(elem_type);
+ *type_class = GDMono::get_singleton()->get_class(type_class_raw);
+}
+
Dictionary *godot_icall_Dictionary_Ctor() {
return memnew(Dictionary);
}
@@ -144,6 +160,20 @@ MonoObject *godot_icall_Dictionary_GetValue(Dictionary *ptr, MonoObject *key) {
return GDMonoMarshal::variant_to_mono_object(ret);
}
+MonoObject *godot_icall_Dictionary_GetValue_Generic(Dictionary *ptr, MonoObject *key, uint32_t type_encoding, GDMonoClass *type_class) {
+ Variant *ret = ptr->getptr(GDMonoMarshal::mono_object_to_variant(key));
+ if (ret == NULL) {
+ MonoObject *exc = mono_object_new(mono_domain_get(), CACHED_CLASS(KeyNotFoundException)->get_mono_ptr());
+#ifdef DEBUG_ENABLED
+ CRASH_COND(!exc);
+#endif
+ GDMonoUtils::runtime_object_init(exc);
+ GDMonoUtils::set_pending_exception((MonoException *)exc);
+ return NULL;
+ }
+ return GDMonoMarshal::variant_to_mono_object(ret, ManagedType(type_encoding, type_class));
+}
+
void godot_icall_Dictionary_SetValue(Dictionary *ptr, MonoObject *key, MonoObject *value) {
ptr->operator[](GDMonoMarshal::mono_object_to_variant(key)) = GDMonoMarshal::mono_object_to_variant(value);
}
@@ -211,10 +241,29 @@ bool godot_icall_Dictionary_TryGetValue(Dictionary *ptr, MonoObject *key, MonoOb
return true;
}
+bool godot_icall_Dictionary_TryGetValue_Generic(Dictionary *ptr, MonoObject *key, MonoObject **value, uint32_t type_encoding, GDMonoClass *type_class) {
+ Variant *ret = ptr->getptr(GDMonoMarshal::mono_object_to_variant(key));
+ if (ret == NULL) {
+ *value = NULL;
+ return false;
+ }
+ *value = GDMonoMarshal::variant_to_mono_object(ret, ManagedType(type_encoding, type_class));
+ return true;
+}
+
+void godot_icall_Dictionary_Generic_GetValueTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class) {
+ MonoType *value_type = mono_reflection_type_get_type(refltype);
+
+ *type_encoding = mono_type_get_type(value_type);
+ MonoClass *type_class_raw = mono_class_from_mono_type(value_type);
+ *type_class = GDMono::get_singleton()->get_class(type_class_raw);
+}
+
void godot_register_collections_icalls() {
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Ctor", (void *)godot_icall_Array_Ctor);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Dtor", (void *)godot_icall_Array_Dtor);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_At", (void *)godot_icall_Array_At);
+ mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_At_Generic", (void *)godot_icall_Array_At_Generic);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_SetAt", (void *)godot_icall_Array_SetAt);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Count", (void *)godot_icall_Array_Count);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Add", (void *)godot_icall_Array_Add);
@@ -225,10 +274,12 @@ void godot_register_collections_icalls() {
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Insert", (void *)godot_icall_Array_Insert);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", (void *)godot_icall_Array_Remove);
mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_RemoveAt", (void *)godot_icall_Array_RemoveAt);
+ mono_add_internal_call("Godot.Collections.Array::godot_icall_Array_Generic_GetElementTypeInfo", (void *)godot_icall_Array_Generic_GetElementTypeInfo);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Ctor", (void *)godot_icall_Dictionary_Ctor);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Dtor", (void *)godot_icall_Dictionary_Dtor);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_GetValue", (void *)godot_icall_Dictionary_GetValue);
+ mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_GetValue_Generic", (void *)godot_icall_Dictionary_GetValue_Generic);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_SetValue", (void *)godot_icall_Dictionary_SetValue);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Keys", (void *)godot_icall_Dictionary_Keys);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Values", (void *)godot_icall_Dictionary_Values);
@@ -240,6 +291,8 @@ void godot_register_collections_icalls() {
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_RemoveKey", (void *)godot_icall_Dictionary_RemoveKey);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Remove", (void *)godot_icall_Dictionary_Remove);
mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_TryGetValue", (void *)godot_icall_Dictionary_TryGetValue);
+ mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_TryGetValue_Generic", (void *)godot_icall_Dictionary_TryGetValue_Generic);
+ mono_add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Generic_GetValueTypeInfo", (void *)godot_icall_Dictionary_Generic_GetValueTypeInfo);
}
#endif // MONO_GLUE_ENABLED
diff --git a/modules/mono/glue/collections_glue.h b/modules/mono/glue/collections_glue.h
index fa8e4c28aa..b9b1338510 100644
--- a/modules/mono/glue/collections_glue.h
+++ b/modules/mono/glue/collections_glue.h
@@ -45,6 +45,8 @@ void godot_icall_Array_Dtor(Array *ptr);
MonoObject *godot_icall_Array_At(Array *ptr, int index);
+MonoObject *godot_icall_Array_At_Generic(Array *ptr, int index, uint32_t type_encoding, GDMonoClass *type_class);
+
void godot_icall_Array_SetAt(Array *ptr, int index, MonoObject *value);
int godot_icall_Array_Count(Array *ptr);
@@ -65,6 +67,8 @@ bool godot_icall_Array_Remove(Array *ptr, MonoObject *item);
void godot_icall_Array_RemoveAt(Array *ptr, int index);
+void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class);
+
// Dictionary
Dictionary *godot_icall_Dictionary_Ctor();
@@ -73,6 +77,8 @@ void godot_icall_Dictionary_Dtor(Dictionary *ptr);
MonoObject *godot_icall_Dictionary_GetValue(Dictionary *ptr, MonoObject *key);
+MonoObject *godot_icall_Dictionary_GetValue_Generic(Dictionary *ptr, MonoObject *key, uint32_t type_encoding, GDMonoClass *type_class);
+
void godot_icall_Dictionary_SetValue(Dictionary *ptr, MonoObject *key, MonoObject *value);
Array *godot_icall_Dictionary_Keys(Dictionary *ptr);
@@ -95,6 +101,10 @@ bool godot_icall_Dictionary_Remove(Dictionary *ptr, MonoObject *key, MonoObject
bool godot_icall_Dictionary_TryGetValue(Dictionary *ptr, MonoObject *key, MonoObject **value);
+bool godot_icall_Dictionary_TryGetValue_Generic(Dictionary *ptr, MonoObject *key, MonoObject **value, uint32_t type_encoding, GDMonoClass *type_class);
+
+void godot_icall_Dictionary_Generic_GetValueTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class);
+
// Register internal calls
void godot_register_collections_icalls();
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index 2fed6064b7..9311aa3930 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -259,14 +259,15 @@ void GDMono::initialize() {
// The following assemblies are not required at initialization
#ifdef MONO_GLUE_ENABLED
if (_load_api_assemblies()) {
- if (!core_api_assembly_out_of_sync && !editor_api_assembly_out_of_sync && GDMonoUtils::mono_cache.godot_api_cache_updated) {
- // Everything is fine with the api assemblies, load the project assembly
- _load_project_assembly();
- } else {
+ // Everything is fine with the api assemblies, load the project assembly
+ _load_project_assembly();
+ } else {
+ if ((core_api_assembly && (core_api_assembly_out_of_sync || !GDMonoUtils::mono_cache.godot_api_cache_updated)) ||
+ (editor_api_assembly && editor_api_assembly_out_of_sync)) {
#ifdef TOOLS_ENABLED
// The assembly was successfully loaded, but the full api could not be cached.
- // This is most likely an outdated assembly loaded because of an invalid version in the metadata,
- // so we invalidate the version in the metadata and unload the script domain.
+ // This is most likely an outdated assembly loaded because of an invalid version in the
+ // metadata, so we invalidate the version in the metadata and unload the script domain.
if (core_api_assembly_out_of_sync) {
ERR_PRINT("The loaded Core API assembly is out of sync");
@@ -290,12 +291,12 @@ void GDMono::initialize() {
#else
ERR_PRINT("The loaded API assembly is invalid");
CRASH_NOW();
-#endif
+#endif // TOOLS_ENABLED
}
}
#else
print_verbose("Mono: Glue disabled, ignoring script assemblies.");
-#endif
+#endif // MONO_GLUE_ENABLED
print_verbose("Mono: INITIALIZED");
}
@@ -448,8 +449,10 @@ bool GDMono::_load_core_api_assembly() {
return true;
#ifdef TOOLS_ENABLED
- if (metadata_is_api_assembly_invalidated(APIAssembly::API_CORE))
+ if (metadata_is_api_assembly_invalidated(APIAssembly::API_CORE)) {
+ print_verbose("Mono: Skipping loading of Core API assembly because it was invalidated");
return false;
+ }
#endif
bool success = load_assembly(API_ASSEMBLY_NAME, &core_api_assembly);
@@ -460,8 +463,12 @@ bool GDMono::_load_core_api_assembly() {
core_api_assembly_out_of_sync = GodotSharpBindings::get_core_api_hash() != api_assembly_ver.godot_api_hash ||
GodotSharpBindings::get_bindings_version() != api_assembly_ver.bindings_version ||
CS_GLUE_VERSION != api_assembly_ver.cs_glue_version;
-#endif
+ if (!core_api_assembly_out_of_sync) {
+ GDMonoUtils::update_godot_api_cache();
+ }
+#else
GDMonoUtils::update_godot_api_cache();
+#endif
}
return success;
@@ -474,8 +481,10 @@ bool GDMono::_load_editor_api_assembly() {
return true;
#ifdef TOOLS_ENABLED
- if (metadata_is_api_assembly_invalidated(APIAssembly::API_EDITOR))
+ if (metadata_is_api_assembly_invalidated(APIAssembly::API_EDITOR)) {
+ print_verbose("Mono: Skipping loading of Editor API assembly because it was invalidated");
return false;
+ }
#endif
bool success = load_assembly(EDITOR_API_ASSEMBLY_NAME, &editor_api_assembly);
@@ -533,16 +542,22 @@ bool GDMono::_load_api_assemblies() {
if (OS::get_singleton()->is_stdout_verbose())
print_error("Mono: Failed to load Core API assembly");
return false;
- } else {
+ }
+
+ if (core_api_assembly_out_of_sync || !GDMonoUtils::mono_cache.godot_api_cache_updated)
+ return false;
+
#ifdef TOOLS_ENABLED
- if (!_load_editor_api_assembly()) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_error("Mono: Failed to load Editor API assembly");
- return false;
- }
-#endif
+ if (!_load_editor_api_assembly()) {
+ if (OS::get_singleton()->is_stdout_verbose())
+ print_error("Mono: Failed to load Editor API assembly");
+ return false;
}
+ if (editor_api_assembly_out_of_sync)
+ return false;
+#endif
+
return true;
}
@@ -708,43 +723,42 @@ Error GDMono::reload_scripts_domain() {
#ifdef MONO_GLUE_ENABLED
if (!_load_api_assemblies()) {
- return ERR_CANT_OPEN;
- }
+ if ((core_api_assembly && (core_api_assembly_out_of_sync || !GDMonoUtils::mono_cache.godot_api_cache_updated)) ||
+ (editor_api_assembly && editor_api_assembly_out_of_sync)) {
+ // The assembly was successfully loaded, but the full api could not be cached.
+ // This is most likely an outdated assembly loaded because of an invalid version in the
+ // metadata, so we invalidate the version in the metadata and unload the script domain.
- if (!core_api_assembly_out_of_sync && !editor_api_assembly_out_of_sync && GDMonoUtils::mono_cache.godot_api_cache_updated) {
- // Everything is fine with the api assemblies, load the project assembly
- _load_project_assembly();
- } else {
- // The assembly was successfully loaded, but the full api could not be cached.
- // This is most likely an outdated assembly loaded because of an invalid version in the metadata,
- // so we invalidate the version in the metadata and unload the script domain.
-
- if (core_api_assembly_out_of_sync) {
- ERR_PRINT("The loaded Core API assembly is out of sync");
- metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
- } else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) {
- ERR_PRINT("The loaded Core API assembly is in sync, but the cache update failed");
- metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
- }
+ if (core_api_assembly_out_of_sync) {
+ ERR_PRINT("The loaded Core API assembly is out of sync");
+ metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
+ } else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) {
+ ERR_PRINT("The loaded Core API assembly is in sync, but the cache update failed");
+ metadata_set_api_assembly_invalidated(APIAssembly::API_CORE, true);
+ }
- if (editor_api_assembly_out_of_sync) {
- ERR_PRINT("The loaded Editor API assembly is out of sync");
- metadata_set_api_assembly_invalidated(APIAssembly::API_EDITOR, true);
- }
+ if (editor_api_assembly_out_of_sync) {
+ ERR_PRINT("The loaded Editor API assembly is out of sync");
+ metadata_set_api_assembly_invalidated(APIAssembly::API_EDITOR, true);
+ }
- Error err = _unload_scripts_domain();
- if (err != OK) {
- WARN_PRINT("Mono: Failed to unload scripts domain");
- }
+ Error err = _unload_scripts_domain();
+ if (err != OK) {
+ WARN_PRINT("Mono: Failed to unload scripts domain");
+ }
- return ERR_CANT_RESOLVE;
+ return ERR_CANT_RESOLVE;
+ } else {
+ return ERR_CANT_OPEN;
+ }
}
- if (!_load_project_assembly())
+ if (!_load_project_assembly()) {
return ERR_CANT_OPEN;
+ }
#else
print_verbose("Mono: Glue disabled, ignoring script assemblies.");
-#endif
+#endif // MONO_GLUE_ENABLED
return OK;
}
diff --git a/modules/mono/mono_gd/gd_mono_header.h b/modules/mono/mono_gd/gd_mono_header.h
index 2fe05006f1..4f2efc7b92 100644
--- a/modules/mono/mono_gd/gd_mono_header.h
+++ b/modules/mono/mono_gd/gd_mono_header.h
@@ -44,9 +44,14 @@ struct ManagedType {
int type_encoding;
GDMonoClass *type_class;
- ManagedType() {
- type_encoding = 0;
- type_class = NULL;
+ ManagedType() :
+ type_encoding(0),
+ type_class(NULL) {
+ }
+
+ ManagedType(int p_type_encoding, GDMonoClass *p_type_class) :
+ type_encoding(p_type_encoding),
+ type_class(p_type_class) {
}
};
diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h
index 1ad0a4a6ea..cc0ab5fa05 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.h
+++ b/modules/mono/mono_gd/gd_mono_marshal.h
@@ -97,10 +97,14 @@ _FORCE_INLINE_ MonoString *mono_string_from_godot(const String &p_string) {
MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_type);
MonoObject *variant_to_mono_object(const Variant *p_var);
-_FORCE_INLINE_ MonoObject *variant_to_mono_object(Variant p_var) {
+_FORCE_INLINE_ MonoObject *variant_to_mono_object(const Variant &p_var) {
return variant_to_mono_object(&p_var);
}
+_FORCE_INLINE_ MonoObject *variant_to_mono_object(const Variant &p_var, const ManagedType &p_type) {
+ return variant_to_mono_object(&p_var, p_type);
+}
+
Variant mono_object_to_variant(MonoObject *p_obj);
// Array
diff --git a/modules/opensimplex/simplex_noise.cpp b/modules/opensimplex/simplex_noise.cpp
index e489b7f6f0..c99fd7b123 100644
--- a/modules/opensimplex/simplex_noise.cpp
+++ b/modules/opensimplex/simplex_noise.cpp
@@ -196,7 +196,7 @@ float SimplexNoise::get_noise_2d(float x, float y) {
float max = 1.0;
float sum = _get_octave_noise_2d(0, x, y);
- unsigned int i = 0;
+ int i = 0;
while (++i < octaves) {
x *= lacunarity;
y *= lacunarity;
@@ -218,7 +218,7 @@ float SimplexNoise::get_noise_3d(float x, float y, float z) {
float max = 1.0;
float sum = _get_octave_noise_3d(0, x, y, z);
- unsigned int i = 0;
+ int i = 0;
while (++i < octaves) {
x *= lacunarity;
y *= lacunarity;
@@ -242,7 +242,7 @@ float SimplexNoise::get_noise_4d(float x, float y, float z, float w) {
float max = 1.0;
float sum = _get_octave_noise_4d(0, x, y, z, w);
- unsigned int i = 0;
+ int i = 0;
while (++i < octaves) {
x *= lacunarity;
y *= lacunarity;
diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp
index 44052d473f..d72d74cf79 100644
--- a/modules/theora/video_stream_theora.cpp
+++ b/modules/theora/video_stream_theora.cpp
@@ -332,8 +332,8 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
int w;
int h;
- w = (ti.pic_x + ti.frame_width + 1 & ~1) - (ti.pic_x & ~1);
- h = (ti.pic_y + ti.frame_height + 1 & ~1) - (ti.pic_y & ~1);
+ w = ((ti.pic_x + ti.frame_width + 1) & ~1) - (ti.pic_x & ~1);
+ h = ((ti.pic_y + ti.frame_height + 1) & ~1) - (ti.pic_y & ~1);
size.x = w;
size.y = h;
@@ -439,7 +439,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
}
}
- int tr = vorbis_synthesis_read(&vd, ret - to_read);
+ vorbis_synthesis_read(&vd, ret - to_read);
audio_frames_wrote += ret - to_read;
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 1027c74f34..79f71535ad 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -2518,8 +2518,6 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
}
ofs /= EDSCALE;
- bool seq_connect = false;
-
Set<int> vn;
switch (p_option) {
@@ -2552,7 +2550,6 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
}
} break;
case CREATE_ACTION: {
- seq_connect = true;
VisualScriptNode::TypeGuess tg = _guess_output_type(port_action_node, port_action_output, vn);
PropertyInfo property_info = script->get_node(edited_func, port_action_node)->get_output_value_port_info(port_action_output);
if (tg.type == Variant::OBJECT) {
@@ -2603,7 +2600,6 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua
if (port >= value_count) {
port = 0;
}
- int count = vnode_old->get_output_value_port_count() + vnode_old->get_output_sequence_port_count();
undo_redo->add_do_method(script.ptr(), "data_connect", edited_func, port_action_node, port, new_id, 0);
undo_redo->add_undo_method(script.ptr(), "data_disconnect", edited_func, port_action_node, port, new_id, 0);
undo_redo->commit_action();
@@ -2657,7 +2653,6 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
Ref<VisualScriptNode> vnode;
- seq_connect = false;
if (p_category == String("method")) {
Ref<VisualScriptFunctionCall> n;
@@ -2683,38 +2678,32 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
Ref<VisualScriptCondition> n;
n.instance();
vnode = n;
- seq_connect = true;
}
if (p_text == "VisualScriptSwitch") {
Ref<VisualScriptSwitch> n;
n.instance();
vnode = n;
- seq_connect = true;
} else if (p_text == "VisualScriptSequence") {
Ref<VisualScriptSequence> n;
n.instance();
vnode = n;
- seq_connect = true;
} else if (p_text == "VisualScriptIterator") {
Ref<VisualScriptIterator> n;
n.instance();
vnode = n;
- seq_connect = true;
} else if (p_text == "VisualScriptWhile") {
Ref<VisualScriptWhile> n;
n.instance();
vnode = n;
- seq_connect = true;
} else if (p_text == "VisualScriptReturn") {
Ref<VisualScriptReturn> n;
n.instance();
vnode = n;
- seq_connect = true;
}
}
@@ -2826,7 +2815,6 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
}
void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id) {
- int seq_count = vnode_old->get_output_sequence_port_count();
VisualScriptOperator *vnode_operator = Object::cast_to<VisualScriptOperator>(vnode_new.ptr());
if (vnode_operator != NULL && vnode_operator->has_input_sequence_port() == false) {
return;
@@ -2841,7 +2829,7 @@ void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<Visual
if (vnode_new->has_input_sequence_port() == false) {
return;
}
- VisualScriptFunction *vnode_function = Object::cast_to<VisualScriptFunction>(vnode_old.ptr());
+
undo_redo->create_action(TTR("Connect Node Sequence"));
int pass_port = -vnode_old->get_output_sequence_port_count() + 1;
int return_port = port_action_output - 1;
@@ -3367,11 +3355,6 @@ void VisualScriptEditor::_member_option(int p_option) {
undo_redo->add_undo_method(script.ptr(), "data_connect", name, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port);
}
- /*
- for(int i=0;i<script->function_get_argument_count(name);i++) {
- undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i));
- }
- */
undo_redo->add_do_method(this, "_update_members");
undo_redo->add_undo_method(this, "_update_members");
undo_redo->add_do_method(this, "_update_graph");
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h
index b0bf971630..fb90e346a4 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/visual_script_editor.h
@@ -37,6 +37,7 @@
#include "scene/gui/graph_edit.h"
#include "visual_script.h"
#include "visual_script_property_selector.h"
+
class VisualScriptEditorSignalEdit;
class VisualScriptEditorVariableEdit;
@@ -159,8 +160,6 @@ class VisualScriptEditor : public ScriptEditorBase {
MemberType member_type;
String member_name;
- bool seq_connect = false;
-
PortAction port_action;
int port_action_node;
int port_action_output;
diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp
index 9942d5baa6..e2e5cc77f5 100644
--- a/modules/visual_script/visual_script_property_selector.cpp
+++ b/modules/visual_script/visual_script_property_selector.cpp
@@ -190,15 +190,14 @@ void VisualScriptPropertySelector::_update_search() {
if (type_filter.size() && type_filter.find(E->get().type) == -1)
continue;
+ // capitalize() also converts underscore to space, we'll match again both possible styles
String get_text_raw = String(vformat(TTR("Get %s"), E->get().name));
String get_text = get_text_raw.capitalize();
-
String set_text_raw = String(vformat(TTR("Set %s"), E->get().name));
String set_text = set_text_raw.capitalize();
String input = search_box->get_text().capitalize();
- if (input == String() ||
- get_text_raw.findn(input) != -1 ||
- get_text.findn(input) != -1) {
+
+ if (input == String() || get_text_raw.findn(input) != -1 || get_text.findn(input) != -1) {
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, get_text);
item->set_metadata(0, E->get().name);
@@ -211,9 +210,7 @@ void VisualScriptPropertySelector::_update_search() {
item->set_metadata(2, connecting);
}
- if (input == String() ||
- set_text_raw.findn(input) != -1 &&
- set_text.findn(input) != -1) {
+ if (input == String() || set_text_raw.findn(input) != -1 || set_text.findn(input) != -1) {
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, set_text);
item->set_metadata(0, E->get().name);
@@ -389,8 +386,8 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt
}
Vector<String> path = E->get().split("/");
bool is_filter = false;
- for (Set<String>::Element *E = filter.front(); E; E = E->next()) {
- if (path.size() >= 2 && path[1].findn(E->get()) != -1) {
+ for (Set<String>::Element *F = filter.front(); F; F = F->next()) {
+ if (path.size() >= 2 && path[1].findn(F->get()) != -1) {
is_filter = true;
break;
}
@@ -721,6 +718,7 @@ VisualScriptPropertySelector::VisualScriptPropertySelector() {
search_options->set_hide_root(true);
search_options->set_hide_folding(true);
virtuals_only = false;
+ seq_connect = false;
help_bit = memnew(EditorHelpBit);
vbc->add_margin_child(TTR("Description:"), help_bit);
help_bit->connect("request_hide", this, "_closed");
diff --git a/modules/visual_script/visual_script_property_selector.h b/modules/visual_script/visual_script_property_selector.h
index 917ef9ae6d..f974ee3355 100644
--- a/modules/visual_script/visual_script_property_selector.h
+++ b/modules/visual_script/visual_script_property_selector.h
@@ -63,8 +63,7 @@ class VisualScriptPropertySelector : public ConfirmationDialog {
ObjectID script;
Object *instance;
bool virtuals_only;
-
- bool seq_connect = false;
+ bool seq_connect;
void _item_selected();
diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub
index 2daf8c282f..711000bd9f 100644
--- a/modules/webm/libvpx/SCsub
+++ b/modules/webm/libvpx/SCsub
@@ -349,7 +349,7 @@ if webm_multithread:
env_libvpx.add_source_files(env.modules_sources, libvpx_sources_mt)
if webm_cpu_x86:
- is_clang_or_gcc = ('gcc' in env["CC"]) or ('clang' in env["CC"]) or ("OSXCROSS_ROOT" in os.environ)
+ is_clang_or_gcc = ('gcc' in os.path.basename(env["CC"])) or ('clang' in os.path.basename(env["CC"])) or ("OSXCROSS_ROOT" in os.environ)
env_libvpx_mmx = env_libvpx.Clone()
if cpu_bits == '32' and is_clang_or_gcc:
diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml
index 9241492623..b3ea535495 100644
--- a/modules/websocket/doc_classes/WebSocketClient.xml
+++ b/modules/websocket/doc_classes/WebSocketClient.xml
@@ -31,8 +31,12 @@
<method name="disconnect_from_host">
<return type="void">
</return>
+ <argument index="0" name="code" type="int" default="1000">
+ </argument>
+ <argument index="1" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Disconnect from the server if currently connected.
+ Disconnect this client from the connected host. See [method WebSocketPeer.close] for more info.
</description>
</method>
</methods>
@@ -43,8 +47,10 @@
</members>
<signals>
<signal name="connection_closed">
+ <argument index="0" name="was_clean_close" type="bool">
+ </argument>
<description>
- Emitted when the connection to the server is closed.
+ Emitted when the connection to the server is closed. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
</description>
</signal>
<signal name="connection_error">
@@ -64,6 +70,15 @@
Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
</description>
</signal>
+ <signal name="server_close_request">
+ <argument index="0" name="code" type="int">
+ </argument>
+ <argument index="1" name="reason" type="String">
+ </argument>
+ <description>
+ Emitted when the server requests a clean close. You should keep polling until you get a [signal connection_closed] signal to achieve the clean close. See [method WebSocketPeer.close] for more details.
+ </description>
+ </signal>
</signals>
<constants>
</constants>
diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml
index 85a08e0c0b..cc59706916 100644
--- a/modules/websocket/doc_classes/WebSocketPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketPeer.xml
@@ -15,8 +15,14 @@
<method name="close">
<return type="void">
</return>
+ <argument index="0" name="code" type="int" default="1000">
+ </argument>
+ <argument index="1" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Close this WebSocket connection, actively disconnecting the peer.
+ Close this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC6455 section 7.4 for a list of valid status codes). [reason] is the human readable reason for closing the connection (can be any UTF8 string, must be less than 123 bytes).
+ Note: To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received.
+ Note: HTML5 export might not support all status codes. Please refer to browsers-specific documentation for more details.
</description>
</method>
<method name="get_connected_host" qualifiers="const">
diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml
index a1061e446b..ba66fdd89b 100644
--- a/modules/websocket/doc_classes/WebSocketServer.xml
+++ b/modules/websocket/doc_classes/WebSocketServer.xml
@@ -18,8 +18,12 @@
</return>
<argument index="0" name="id" type="int">
</argument>
+ <argument index="1" name="code" type="int" default="1000">
+ </argument>
+ <argument index="2" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Disconnects the given peer.
+ Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more info.
</description>
</method>
<method name="get_peer_address" qualifiers="const">
@@ -68,7 +72,7 @@
<description>
Start listening on the given port.
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
- You can use this server as a network peer for [MultiplayerAPI] by passing true as "gd_mp_api". Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
+ You can use this server as a network peer for [MultiplayerAPI] by passing [code]true[/code] as [code]gd_mp_api[/code]. Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
</description>
</method>
<method name="stop">
@@ -80,6 +84,17 @@
</method>
</methods>
<signals>
+ <signal name="client_close_request">
+ <argument index="0" name="id" type="int">
+ </argument>
+ <argument index="1" name="code" type="int">
+ </argument>
+ <argument index="2" name="reason" type="String">
+ </argument>
+ <description>
+ Emitted when a client requests a clean close. You should keep polling until you get a [signal client_disconnected] signal with the same [code]id[/code] to achieve the clean close. See [method WebSocketPeer.close] for more details.
+ </description>
+ </signal>
<signal name="client_connected">
<argument index="0" name="id" type="int">
</argument>
@@ -92,8 +107,10 @@
<signal name="client_disconnected">
<argument index="0" name="id" type="int">
</argument>
+ <argument index="1" name="was_clean_close" type="bool">
+ </argument>
<description>
- Emitted when a client disconnects.
+ Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
</description>
</signal>
<signal name="data_received">
diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp
index 836b564de8..8255ed7116 100644
--- a/modules/websocket/emws_client.cpp
+++ b/modules/websocket/emws_client.cpp
@@ -55,8 +55,9 @@ EMSCRIPTEN_KEEPALIVE void _esws_on_error(void *obj) {
EMSCRIPTEN_KEEPALIVE void _esws_on_close(void *obj, int code, char *reason, int was_clean) {
EMWSClient *client = static_cast<EMWSClient *>(obj);
+ client->_on_close_request(code, String(reason));
client->_is_connecting = false;
- client->_on_disconnect();
+ client->_on_disconnect(was_clean != 0);
}
}
@@ -145,7 +146,7 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
if (!Module.IDHandler.has($0))
return; // Godot Object is gone!
var was_clean = 0;
- if (event.was_clean)
+ if (event.wasClean)
was_clean = 1;
ccall("_esws_on_close",
"void",
@@ -182,9 +183,9 @@ NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() c
return CONNECTION_DISCONNECTED;
};
-void EMWSClient::disconnect_from_host() {
+void EMWSClient::disconnect_from_host(int p_code, String p_reason) {
- _peer->close();
+ _peer->close(p_code, p_reason);
};
IP_Address EMWSClient::get_connected_host() const {
diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h
index 6c2fa23b53..b20633baff 100644
--- a/modules/websocket/emws_client.h
+++ b/modules/websocket/emws_client.h
@@ -48,7 +48,7 @@ public:
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
- void disconnect_from_host();
+ void disconnect_from_host(int p_code = 1000, String p_reason = "");
IP_Address get_connected_host() const;
uint16_t get_connected_port() const;
virtual ConnectionStatus get_connection_status() const;
diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp
index e0b987b4d7..68f41165eb 100644
--- a/modules/websocket/emws_peer.cpp
+++ b/modules/websocket/emws_peer.cpp
@@ -130,15 +130,17 @@ bool EMWSPeer::is_connected_to_host() const {
return peer_sock != -1;
};
-void EMWSPeer::close() {
+void EMWSPeer::close(int p_code, String p_reason) {
if (peer_sock != -1) {
/* clang-format off */
EM_ASM({
var sock = Module.IDHandler.get($0);
- sock.close();
+ var code = $1;
+ var reason = UTF8ToString($2);
+ sock.close(code, reason);
Module.IDHandler.remove($0);
- }, peer_sock);
+ }, peer_sock, p_code, p_reason.utf8().get_data());
/* clang-format on */
}
peer_sock = -1;
diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h
index e06f725265..a4b2c8f50b 100644
--- a/modules/websocket/emws_peer.h
+++ b/modules/websocket/emws_peer.h
@@ -63,7 +63,7 @@ public:
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const { return PACKET_BUFFER_SIZE; };
- virtual void close();
+ virtual void close(int p_code = 1000, String p_reason = "");
virtual bool is_connected_to_host() const;
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp
index 3eb93e4152..ad4a758c0f 100644
--- a/modules/websocket/emws_server.cpp
+++ b/modules/websocket/emws_server.cpp
@@ -68,7 +68,7 @@ int EMWSServer::get_peer_port(int p_peer_id) const {
return 0;
}
-void EMWSServer::disconnect_peer(int p_peer_id) {
+void EMWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
}
EMWSServer::EMWSServer() {
diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h
index 9ec4ce72c8..74b689a29b 100644
--- a/modules/websocket/emws_server.h
+++ b/modules/websocket/emws_server.h
@@ -48,7 +48,7 @@ public:
Ref<WebSocketPeer> get_peer(int p_id) const;
IP_Address get_peer_address(int p_peer_id) const;
int get_peer_port(int p_peer_id) const;
- void disconnect_peer(int p_peer_id);
+ void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "");
virtual void poll();
virtual PoolVector<String> get_protocols() const;
diff --git a/modules/websocket/lws_client.cpp b/modules/websocket/lws_client.cpp
index 09f6422058..cd814760e6 100644
--- a/modules/websocket/lws_client.cpp
+++ b/modules/websocket/lws_client.cpp
@@ -129,6 +129,7 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
peer->set_wsi(wsi);
peer_data->peer_id = 0;
peer_data->force_close = false;
+ peer_data->clean_close = false;
_on_connect(lws_get_protocol(wsi)->name);
break;
@@ -137,10 +138,18 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
destroy_context();
return -1; // We should close the connection (would probably happen anyway)
+ case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: {
+ int code;
+ String reason = peer->get_close_reason(in, len, code);
+ peer_data->clean_close = true;
+ _on_close_request(code, reason);
+ return 0;
+ }
+
case LWS_CALLBACK_CLIENT_CLOSED:
peer->close();
destroy_context();
- _on_disconnect();
+ _on_disconnect(peer_data->clean_close);
return 0; // We can end here
case LWS_CALLBACK_CLIENT_RECEIVE:
@@ -150,8 +159,10 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
break;
case LWS_CALLBACK_CLIENT_WRITEABLE:
- if (peer_data->force_close)
+ if (peer_data->force_close) {
+ peer->send_close_status(wsi);
return -1;
+ }
peer->write_wsi();
break;
@@ -179,13 +190,12 @@ NetworkedMultiplayerPeer::ConnectionStatus LWSClient::get_connection_status() co
return CONNECTION_CONNECTING;
}
-void LWSClient::disconnect_from_host() {
+void LWSClient::disconnect_from_host(int p_code, String p_reason) {
if (context == NULL)
return;
- _peer->close();
- destroy_context();
+ _peer->close(p_code, p_reason);
};
IP_Address LWSClient::get_connected_host() const {
@@ -208,6 +218,7 @@ LWSClient::~LWSClient() {
invalidate_lws_ref(); // We do not want any more callback
disconnect_from_host();
+ destroy_context();
_peer = Ref<LWSPeer>();
};
diff --git a/modules/websocket/lws_client.h b/modules/websocket/lws_client.h
index 8850683cb5..1bbc19f352 100644
--- a/modules/websocket/lws_client.h
+++ b/modules/websocket/lws_client.h
@@ -46,7 +46,7 @@ class LWSClient : public WebSocketClient {
public:
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
- void disconnect_from_host();
+ void disconnect_from_host(int p_code = 1000, String p_reason = "");
IP_Address get_connected_host() const;
uint16_t get_connected_port() const;
virtual ConnectionStatus get_connection_status() const;
diff --git a/modules/websocket/lws_peer.cpp b/modules/websocket/lws_peer.cpp
index 0989357258..b5c130b308 100644
--- a/modules/websocket/lws_peer.cpp
+++ b/modules/websocket/lws_peer.cpp
@@ -30,6 +30,7 @@
#ifndef JAVASCRIPT_ENABLED
#include "lws_peer.h"
+
#include "core/io/ip.h"
// Needed for socket_helpers on Android at least. UNIXes has it, just include if not windows
@@ -38,7 +39,7 @@
#include <sys/socket.h>
#endif
-#include "drivers/unix/socket_helpers.h"
+#include "drivers/unix/net_socket_posix.h"
void LWSPeer::set_wsi(struct lws *p_wsi) {
ERR_FAIL_COND(wsi != NULL);
@@ -60,7 +61,6 @@ Error LWSPeer::read_wsi(void *in, size_t len) {
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
- PeerData *peer_data = (PeerData *)(lws_wsi_user(wsi));
uint32_t size = in_size;
uint8_t is_string = lws_frame_is_binary(wsi) ? 0 : 1;
@@ -88,7 +88,6 @@ Error LWSPeer::write_wsi() {
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
- PeerData *peer_data = (PeerData *)(lws_wsi_user(wsi));
PoolVector<uint8_t> tmp;
int left = rbw.data_left();
uint32_t to_write = 0;
@@ -119,7 +118,6 @@ Error LWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
- PeerData *peer_data = (PeerData *)lws_wsi_user(wsi);
rbw.write((uint8_t *)&p_buffer_size, 4);
rbw.write(p_buffer, MIN(p_buffer_size, rbw.space_left()));
out_count++;
@@ -132,8 +130,6 @@ Error LWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
- PeerData *peer_data = (PeerData *)lws_wsi_user(wsi);
-
if (in_count == 0)
return ERR_UNAVAILABLE;
@@ -178,11 +174,49 @@ bool LWSPeer::is_connected_to_host() const {
return wsi != NULL;
};
-void LWSPeer::close() {
+String LWSPeer::get_close_reason(void *in, size_t len, int &r_code) {
+ String s;
+ r_code = 0;
+ if (len < 2) // From docs this should not happen
+ return s;
+
+ const uint8_t *b = (const uint8_t *)in;
+ r_code = b[0] << 8 | b[1];
+
+ if (len > 2) {
+ const char *utf8 = (const char *)&b[2];
+ s.parse_utf8(utf8, len - 2);
+ }
+ return s;
+}
+
+void LWSPeer::send_close_status(struct lws *p_wsi) {
+ if (close_code == -1)
+ return;
+
+ int len = close_reason.size();
+ ERR_FAIL_COND(len > 123); // Maximum allowed reason size in bytes
+
+ lws_close_status code = (lws_close_status)close_code;
+ unsigned char *reason = len > 0 ? (unsigned char *)close_reason.utf8().ptrw() : NULL;
+
+ lws_close_reason(p_wsi, code, reason, len);
+
+ close_code = -1;
+ close_reason = "";
+}
+
+void LWSPeer::close(int p_code, String p_reason) {
if (wsi != NULL) {
+ close_code = p_code;
+ close_reason = p_reason;
PeerData *data = ((PeerData *)lws_wsi_user(wsi));
data->force_close = true;
- lws_callback_on_writable(wsi); // notify that we want to disconnect
+ data->clean_close = true;
+ lws_callback_on_writable(wsi); // Notify that we want to disconnect
+ } else {
+ close_code = -1;
+ close_reason = "";
}
wsi = NULL;
rbw.resize(0);
@@ -198,7 +232,7 @@ IP_Address LWSPeer::get_connected_host() const {
ERR_FAIL_COND_V(!is_connected_to_host(), IP_Address());
IP_Address ip;
- int port = 0;
+ uint16_t port = 0;
struct sockaddr_storage addr;
socklen_t len = sizeof(addr);
@@ -209,7 +243,7 @@ IP_Address LWSPeer::get_connected_host() const {
int ret = getpeername(fd, (struct sockaddr *)&addr, &len);
ERR_FAIL_COND_V(ret != 0, IP_Address());
- _set_ip_addr_port(ip, port, &addr);
+ NetSocketPosix::_set_ip_port(&addr, ip, port);
return ip;
};
@@ -219,7 +253,7 @@ uint16_t LWSPeer::get_connected_port() const {
ERR_FAIL_COND_V(!is_connected_to_host(), 0);
IP_Address ip;
- int port = 0;
+ uint16_t port = 0;
struct sockaddr_storage addr;
socklen_t len = sizeof(addr);
@@ -230,7 +264,7 @@ uint16_t LWSPeer::get_connected_port() const {
int ret = getpeername(fd, (struct sockaddr *)&addr, &len);
ERR_FAIL_COND_V(ret != 0, 0);
- _set_ip_addr_port(ip, port, &addr);
+ NetSocketPosix::_set_ip_port(&addr, ip, port);
return port;
};
diff --git a/modules/websocket/lws_peer.h b/modules/websocket/lws_peer.h
index d7d46e3076..571445db01 100644
--- a/modules/websocket/lws_peer.h
+++ b/modules/websocket/lws_peer.h
@@ -53,10 +53,14 @@ private:
WriteMode write_mode;
bool _was_string;
+ int close_code;
+ String close_reason;
+
public:
struct PeerData {
uint32_t peer_id;
bool force_close;
+ bool clean_close;
};
RingBuffer<uint8_t> rbw;
@@ -71,7 +75,7 @@ public:
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const { return PACKET_BUFFER_SIZE; };
- virtual void close();
+ virtual void close(int p_code = 1000, String p_reason = "");
virtual bool is_connected_to_host() const;
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
@@ -83,6 +87,8 @@ public:
void set_wsi(struct lws *wsi);
Error read_wsi(void *in, size_t len);
Error write_wsi();
+ void send_close_status(struct lws *wsi);
+ String get_close_reason(void *in, size_t len, int &r_code);
LWSPeer();
~LWSPeer();
diff --git a/modules/websocket/lws_server.cpp b/modules/websocket/lws_server.cpp
index 4a614f6933..58fa043346 100644
--- a/modules/websocket/lws_server.cpp
+++ b/modules/websocket/lws_server.cpp
@@ -90,20 +90,36 @@ int LWSServer::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
peer_data->peer_id = id;
peer_data->force_close = false;
-
+ peer_data->clean_close = false;
_on_connect(id, lws_get_protocol(wsi)->name);
break;
}
+ case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: {
+ if (peer_data == NULL)
+ return 0;
+
+ int32_t id = peer_data->peer_id;
+ if (_peer_map.has(id)) {
+ int code;
+ Ref<LWSPeer> peer = _peer_map[id];
+ String reason = peer->get_close_reason(in, len, code);
+ peer_data->clean_close = true;
+ _on_close_request(id, code, reason);
+ }
+ return 0;
+ }
+
case LWS_CALLBACK_CLOSED: {
if (peer_data == NULL)
return 0;
int32_t id = peer_data->peer_id;
+ bool clean = peer_data->clean_close;
if (_peer_map.has(id)) {
_peer_map[id]->close();
_peer_map.erase(id);
}
- _on_disconnect(id);
+ _on_disconnect(id, clean);
return 0; // we can end here
}
@@ -118,10 +134,15 @@ int LWSServer::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
}
case LWS_CALLBACK_SERVER_WRITEABLE: {
- if (peer_data->force_close)
+ int id = peer_data->peer_id;
+ if (peer_data->force_close) {
+ if (_peer_map.has(id)) {
+ Ref<LWSPeer> peer = _peer_map[id];
+ peer->send_close_status(wsi);
+ }
return -1;
+ }
- int id = peer_data->peer_id;
if (_peer_map.has(id))
static_cast<Ref<LWSPeer> >(_peer_map[id])->write_wsi();
break;
@@ -164,10 +185,10 @@ int LWSServer::get_peer_port(int p_peer_id) const {
return _peer_map[p_peer_id]->get_connected_port();
}
-void LWSServer::disconnect_peer(int p_peer_id) {
+void LWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
ERR_FAIL_COND(!has_peer(p_peer_id));
- get_peer(p_peer_id)->close();
+ get_peer(p_peer_id)->close(p_code, p_reason);
}
LWSServer::LWSServer() {
diff --git a/modules/websocket/lws_server.h b/modules/websocket/lws_server.h
index 9e3fb9b775..346773ebc4 100644
--- a/modules/websocket/lws_server.h
+++ b/modules/websocket/lws_server.h
@@ -54,7 +54,7 @@ public:
Ref<WebSocketPeer> get_peer(int p_id) const;
IP_Address get_peer_address(int p_peer_id) const;
int get_peer_port(int p_peer_id) const;
- void disconnect_peer(int p_peer_id);
+ void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "");
virtual void poll() { _lws_poll(); }
LWSServer();
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp
index 7701163085..f9b94dc519 100644
--- a/modules/websocket/websocket_client.cpp
+++ b/modules/websocket/websocket_client.cpp
@@ -107,12 +107,17 @@ void WebSocketClient::_on_connect(String p_protocol) {
}
}
-void WebSocketClient::_on_disconnect() {
+void WebSocketClient::_on_close_request(int p_code, String p_reason) {
+
+ emit_signal("server_close_request", p_code, p_reason);
+}
+
+void WebSocketClient::_on_disconnect(bool p_was_clean) {
if (_is_multiplayer) {
emit_signal("connection_failed");
} else {
- emit_signal("connection_closed");
+ emit_signal("connection_closed", p_was_clean);
}
}
@@ -127,7 +132,7 @@ void WebSocketClient::_on_error() {
void WebSocketClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_url", "url", "protocols", "gd_mp_api"), &WebSocketClient::connect_to_url, DEFVAL(PoolVector<String>()), DEFVAL(false));
- ClassDB::bind_method(D_METHOD("disconnect_from_host"), &WebSocketClient::disconnect_from_host);
+ ClassDB::bind_method(D_METHOD("disconnect_from_host", "code", "reason"), &WebSocketClient::disconnect_from_host, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("set_verify_ssl_enabled", "enabled"), &WebSocketClient::set_verify_ssl_enabled);
ClassDB::bind_method(D_METHOD("is_verify_ssl_enabled"), &WebSocketClient::is_verify_ssl_enabled);
@@ -135,6 +140,7 @@ void WebSocketClient::_bind_methods() {
ADD_SIGNAL(MethodInfo("data_received"));
ADD_SIGNAL(MethodInfo("connection_established", PropertyInfo(Variant::STRING, "protocol")));
- ADD_SIGNAL(MethodInfo("connection_closed"));
+ ADD_SIGNAL(MethodInfo("server_close_request", PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason")));
+ ADD_SIGNAL(MethodInfo("connection_closed", PropertyInfo(Variant::BOOL, "was_clean_close")));
ADD_SIGNAL(MethodInfo("connection_error"));
}
diff --git a/modules/websocket/websocket_client.h b/modules/websocket/websocket_client.h
index 6165f37d40..948f128e9f 100644
--- a/modules/websocket/websocket_client.h
+++ b/modules/websocket/websocket_client.h
@@ -53,7 +53,7 @@ public:
virtual void poll() = 0;
virtual Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>()) = 0;
- virtual void disconnect_from_host() = 0;
+ virtual void disconnect_from_host(int p_code = 1000, String p_reason = "") = 0;
virtual IP_Address get_connected_host() const = 0;
virtual uint16_t get_connected_port() const = 0;
@@ -62,7 +62,8 @@ public:
void _on_peer_packet();
void _on_connect(String p_protocol);
- void _on_disconnect();
+ void _on_close_request(int p_code, String p_reason);
+ void _on_disconnect(bool p_was_clean);
void _on_error();
WebSocketClient();
diff --git a/modules/websocket/websocket_peer.cpp b/modules/websocket/websocket_peer.cpp
index 61f783e377..3ecb32ce19 100644
--- a/modules/websocket/websocket_peer.cpp
+++ b/modules/websocket/websocket_peer.cpp
@@ -42,7 +42,7 @@ void WebSocketPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_write_mode", "mode"), &WebSocketPeer::set_write_mode);
ClassDB::bind_method(D_METHOD("is_connected_to_host"), &WebSocketPeer::is_connected_to_host);
ClassDB::bind_method(D_METHOD("was_string_packet"), &WebSocketPeer::was_string_packet);
- ClassDB::bind_method(D_METHOD("close"), &WebSocketPeer::close);
+ ClassDB::bind_method(D_METHOD("close", "code", "reason"), &WebSocketPeer::close, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_connected_host"), &WebSocketPeer::get_connected_host);
ClassDB::bind_method(D_METHOD("get_connected_port"), &WebSocketPeer::get_connected_port);
diff --git a/modules/websocket/websocket_peer.h b/modules/websocket/websocket_peer.h
index ad451e9cc7..5918fda3c2 100644
--- a/modules/websocket/websocket_peer.h
+++ b/modules/websocket/websocket_peer.h
@@ -58,7 +58,7 @@ public:
virtual WriteMode get_write_mode() const = 0;
virtual void set_write_mode(WriteMode p_mode) = 0;
- virtual void close() = 0;
+ virtual void close(int p_code = 1000, String p_reason = "") = 0;
virtual bool is_connected_to_host() const = 0;
virtual IP_Address get_connected_host() const = 0;
diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp
index 53dd7b51b7..c631ed70d5 100644
--- a/modules/websocket/websocket_server.cpp
+++ b/modules/websocket/websocket_server.cpp
@@ -46,9 +46,10 @@ void WebSocketServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_peer", "id"), &WebSocketServer::has_peer);
ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &WebSocketServer::get_peer_address);
ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketServer::get_peer_port);
- ClassDB::bind_method(D_METHOD("disconnect_peer", "id"), &WebSocketServer::disconnect_peer);
+ ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "code", "reason"), &WebSocketServer::disconnect_peer, DEFVAL(1000), DEFVAL(""));
- ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("client_close_request", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason")));
+ ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::BOOL, "was_clean_close")));
ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol")));
ADD_SIGNAL(MethodInfo("data_received", PropertyInfo(Variant::INT, "id")));
}
@@ -85,13 +86,18 @@ void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) {
}
}
-void WebSocketServer::_on_disconnect(int32_t p_peer_id) {
+void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool p_was_clean) {
if (_is_multiplayer) {
// Send delete to clients
_send_del(p_peer_id);
emit_signal("peer_disconnected", p_peer_id);
} else {
- emit_signal("client_disconnected", p_peer_id);
+ emit_signal("client_disconnected", p_peer_id, p_was_clean);
}
}
+
+void WebSocketServer::_on_close_request(int32_t p_peer_id, int p_code, String p_reason) {
+
+ emit_signal("client_close_request", p_peer_id, p_code, p_reason);
+}
diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h
index 64935f8a58..156f25897c 100644
--- a/modules/websocket/websocket_server.h
+++ b/modules/websocket/websocket_server.h
@@ -54,11 +54,12 @@ public:
virtual IP_Address get_peer_address(int p_peer_id) const = 0;
virtual int get_peer_port(int p_peer_id) const = 0;
- virtual void disconnect_peer(int p_peer_id) = 0;
+ virtual void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "") = 0;
void _on_peer_packet(int32_t p_peer_id);
void _on_connect(int32_t p_peer_id, String p_protocol);
- void _on_disconnect(int32_t p_peer_id);
+ void _on_disconnect(int32_t p_peer_id, bool p_was_clean);
+ void _on_close_request(int32_t p_peer_id, int p_code, String p_reason);
WebSocketServer();
~WebSocketServer();