diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/enet/networked_multiplayer_enet.cpp | 11 | ||||
-rw-r--r-- | modules/gdscript/doc_classes/@GDScript.xml | 20 |
2 files changed, 30 insertions, 1 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index a787cd3b80..2f6ed5efc0 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -440,6 +440,8 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { 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); peers_disconnected = true; } } @@ -455,6 +457,7 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { enet_host_destroy(host); active = false; incoming_packets.clear(); + peer_map.clear(); unique_id = 1; // Server is 1 connection_status = CONNECTION_DISCONNECTED; } @@ -471,10 +474,13 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { // enet_peer_disconnect_now doesn't generate ENET_EVENT_TYPE_DISCONNECT, // notify everyone else, send disconnect signal & remove from peer_map like in poll() + int *id = NULL; for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == p_peer) + if (E->key() == p_peer) { + id = (int *)(E->get()->data); continue; + } ENetPacket *packet = enet_packet_create(NULL, 8, ENET_PACKET_FLAG_RELIABLE); encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]); @@ -482,6 +488,9 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { enet_peer_send(E->get(), SYSCH_CONFIG, packet); } + if (id) + memdelete(id); + emit_signal("peer_disconnected", p_peer); peer_map.erase(p_peer); } else { diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 840971dcf8..10eb719235 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -1363,6 +1363,26 @@ Stops the function execution and returns the current suspended state to the calling function. From the caller, call [method GDScriptFunctionState.resume] on the state to resume execution. This invalidates the state. Within the resumed function, [code]yield()[/code] returns whatever was passed to the [code]resume()[/code] function call. If passed an object and a signal, the execution is resumed when the object emits the given signal. In this case, [code]yield()[/code] returns the argument passed to [code]emit_signal()[/code] if the signal takes only one argument, or an array containing all the arguments passed to [code]emit_signal()[/code] if the signal takes multiple arguments. + You can also use [code]yield[/code] to wait for a function to finish: + [codeblock] + func _ready -> void: + yield(do_something(), "completed") + yield(do_something_else(), "completed") + print("All functions are done!") + + func do_something(): + print("Something is done!") + + func do_something_else(): + print("Something else is done!") + + # prints: + # Something is done! + # Something else is done! + # All functions are done! + [/codeblock] + When yielding on a function, the [code]completed[/code] signal will be emitted automatically when the function returns. It can, therefore, be used as the [code]signal[/code] parameter of the [code]yield[/code] method to resume. + If you are planning on calling the same function within a loop, you should consider using [code]yield(get_tree(), "idle_frame")[/code] also. </description> </method> </methods> |