From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- modules/enet/networked_multiplayer_enet.cpp | 60 ----------------------------- modules/enet/networked_multiplayer_enet.h | 2 - modules/enet/register_types.cpp | 2 - 3 files changed, 64 deletions(-) (limited to 'modules/enet') diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 444ffae713..0ff747c6d8 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -34,21 +34,17 @@ #include "core/os/os.h" void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) { - transfer_mode = p_mode; } NetworkedMultiplayerPeer::TransferMode NetworkedMultiplayerENet::get_transfer_mode() const { - return transfer_mode; } void NetworkedMultiplayerENet::set_target_peer(int p_peer) { - target_peer = p_peer; } int NetworkedMultiplayerENet::get_packet_peer() const { - ERR_FAIL_COND_V_MSG(!active, 1, "The multiplayer instance isn't currently active."); ERR_FAIL_COND_V(incoming_packets.size() == 0, 1); @@ -56,7 +52,6 @@ int NetworkedMultiplayerENet::get_packet_peer() const { } int NetworkedMultiplayerENet::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); @@ -64,7 +59,6 @@ int NetworkedMultiplayerENet::get_packet_channel() const { } int NetworkedMultiplayerENet::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); @@ -72,7 +66,6 @@ int NetworkedMultiplayerENet::get_last_packet_channel() const { } Error NetworkedMultiplayerENet::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 port number must be set 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)."); @@ -121,7 +114,6 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int return OK; } Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_client_port) { - 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 server port number must be set between 0 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_client_port < 0 || p_client_port > 65535, ERR_INVALID_PARAMETER, "The client port number must be set between 0 and 65535 (inclusive)."); @@ -213,7 +205,6 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por } void NetworkedMultiplayerENet::poll() { - ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -221,7 +212,6 @@ void NetworkedMultiplayerENet::poll() { 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; @@ -272,7 +262,6 @@ void NetworkedMultiplayerENet::poll() { // Someone connected, notify all the peers available for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *new_id) continue; // Send existing peers to new peer @@ -287,13 +276,11 @@ void NetworkedMultiplayerENet::poll() { enet_peer_send(E->get(), SYSCH_CONFIG, packet); } } else { - emit_signal("connection_succeeded"); } } break; case ENET_EVENT_TYPE_DISCONNECT: { - // Reset the peer's client information. int *id = (int *)event.peer->data; @@ -307,16 +294,13 @@ void NetworkedMultiplayerENet::poll() { } if (!server) { - // Client just disconnected from server. emit_signal("server_disconnected"); close_connection(); return; } else if (server_relay) { - // Server just received a client disconnect and is in relay mode, notify everyone else. for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *id) continue; @@ -332,7 +316,6 @@ void NetworkedMultiplayerENet::poll() { memdelete(id); } break; case ENET_EVENT_TYPE_RECEIVE: { - if (event.channelID == SYSCH_CONFIG) { // Some config message ERR_CONTINUE(event.packet->dataLength < 8); @@ -345,13 +328,11 @@ void NetworkedMultiplayerENet::poll() { switch (msg) { case SYSMSG_ADD_PEER: { - peer_map[id] = nullptr; emit_signal("peer_connected", id); } break; case SYSMSG_REMOVE_PEER: { - peer_map.erase(id); emit_signal("peer_disconnected", id); } break; @@ -359,7 +340,6 @@ void NetworkedMultiplayerENet::poll() { enet_packet_destroy(event.packet); } else if (event.channelID < channel_count) { - Packet packet; packet.packet = event.packet; @@ -391,7 +371,6 @@ void NetworkedMultiplayerENet::poll() { incoming_packets.push_back(packet); // And make copies for sending for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (uint32_t(E->key()) == source) // Do not resend to self continue; @@ -405,7 +384,6 @@ void NetworkedMultiplayerENet::poll() { // And make copies for sending for (Map::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; @@ -428,7 +406,6 @@ void NetworkedMultiplayerENet::poll() { enet_peer_send(peer_map[target], event.channelID, packet.packet); } } else { - incoming_packets.push_back(packet); } @@ -452,7 +429,6 @@ bool NetworkedMultiplayerENet::is_server() const { } void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { - ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -484,7 +460,6 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { } void NetworkedMultiplayerENet::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)); @@ -497,7 +472,6 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { // notify everyone else, send disconnect signal & remove from peer_map like in poll() if (server_relay) { for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == p_peer) { continue; } @@ -520,12 +494,10 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { } int NetworkedMultiplayerENet::get_available_packet_count() const { - return incoming_packets.size(); } Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available."); _pop_current_packet(); @@ -540,7 +512,6 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff } Error NetworkedMultiplayerENet::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(connection_status != CONNECTION_CONNECTED, ERR_UNCONFIGURED, "The multiplayer instance isn't currently connected to any server or client."); @@ -571,7 +542,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer Map::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)); } @@ -582,7 +552,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer copymem(&packet->data[8], p_buffer, p_buffer_size); if (server) { - if (target_peer == 0) { enet_host_broadcast(host, channel, packet); } else if (target_peer < 0) { @@ -592,7 +561,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer int exclude = -target_peer; for (Map::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() == exclude) // Exclude packet continue; @@ -606,7 +574,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer enet_peer_send(E->get(), channel, packet); } } else { - ERR_FAIL_COND_V(!peer_map.has(1), ERR_BUG); enet_peer_send(peer_map[1], channel, packet); // Send to server for broadcast } @@ -617,12 +584,10 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer } int NetworkedMultiplayerENet::get_max_packet_size() const { - return 1 << 24; // Anything is good } void NetworkedMultiplayerENet::_pop_current_packet() { - if (current_packet.packet) { enet_packet_destroy(current_packet.packet); current_packet.packet = nullptr; @@ -632,16 +597,13 @@ void NetworkedMultiplayerENet::_pop_current_packet() { } NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerENet::get_connection_status() const { - return connection_status; } uint32_t NetworkedMultiplayerENet::_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( @@ -660,33 +622,27 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { } int NetworkedMultiplayerENet::get_unique_id() const { - ERR_FAIL_COND_V_MSG(!active, 0, "The multiplayer instance isn't currently active."); return unique_id; } void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; } bool NetworkedMultiplayerENet::is_refusing_new_connections() const { - return refuse_connections; } void NetworkedMultiplayerENet::set_compression_mode(CompressionMode p_mode) { - compression_mode = p_mode; } NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::get_compression_mode() const { - return compression_mode; } size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); if (size_t(enet->src_compressor_mem.size()) < inLimit) { @@ -739,20 +695,16 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * } size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(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: { @@ -766,11 +718,8 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 } void NetworkedMultiplayerENet::_setup_compressor() { - switch (compression_mode) { - case COMPRESS_NONE: { - enet_host_compress(host, nullptr); } break; case COMPRESS_RANGE_CODER: { @@ -779,19 +728,16 @@ void NetworkedMultiplayerENet::_setup_compressor() { case COMPRESS_FASTLZ: case COMPRESS_ZLIB: case COMPRESS_ZSTD: { - enet_host_compress(host, &enet_compressor); } break; } } void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) { - // Nothing to do } IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { - ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IP_Address(), 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, IP_Address(), "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, IP_Address(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -807,7 +753,6 @@ IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { } int NetworkedMultiplayerENet::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)); @@ -819,7 +764,6 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { } void NetworkedMultiplayerENet::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; @@ -830,7 +774,6 @@ int NetworkedMultiplayerENet::get_transfer_channel() const { } void NetworkedMultiplayerENet::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; @@ -859,7 +802,6 @@ bool NetworkedMultiplayerENet::is_server_relay_enabled() const { } void NetworkedMultiplayerENet::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_server", "port", "max_clients", "in_bandwidth", "out_bandwidth"), &NetworkedMultiplayerENet::create_server, DEFVAL(32), DEFVAL(0), DEFVAL(0)); ClassDB::bind_method(D_METHOD("create_client", "address", "port", "in_bandwidth", "out_bandwidth", "client_port"), &NetworkedMultiplayerENet::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &NetworkedMultiplayerENet::close_connection, DEFVAL(100)); @@ -903,7 +845,6 @@ void NetworkedMultiplayerENet::_bind_methods() { } NetworkedMultiplayerENet::NetworkedMultiplayerENet() { - active = false; server = false; refuse_connections = false; @@ -929,7 +870,6 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { } NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { - if (active) { close_connection(); } diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index ff436ce2c0..b2ed951327 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/networked_multiplayer_enet.h @@ -38,7 +38,6 @@ #include class NetworkedMultiplayerENet : public NetworkedMultiplayerPeer { - GDCLASS(NetworkedMultiplayerENet, NetworkedMultiplayerPeer); public: @@ -86,7 +85,6 @@ private: Map peer_map; struct Packet { - ENetPacket *packet; int from; int channel; diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index 27f27196d6..e5e9628c26 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -35,7 +35,6 @@ static bool enet_ok = false; void register_enet_types() { - if (enet_initialize() != 0) { ERR_PRINT("ENet initialization failure"); } else { @@ -46,7 +45,6 @@ void register_enet_types() { } void unregister_enet_types() { - if (enet_ok) enet_deinitialize(); } -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- modules/enet/networked_multiplayer_enet.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/enet') diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 0ff747c6d8..a53c2a2364 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -36,6 +36,7 @@ void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) { transfer_mode = p_mode; } + NetworkedMultiplayerPeer::TransferMode NetworkedMultiplayerENet::get_transfer_mode() const { return transfer_mode; } @@ -113,6 +114,7 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int connection_status = CONNECTION_CONNECTED; return OK; } + Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_client_port) { 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 server port number must be set between 0 and 65535 (inclusive)."); -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- modules/enet/networked_multiplayer_enet.cpp | 38 +++++++++++++++++++---------- modules/enet/register_types.cpp | 3 ++- 2 files changed, 27 insertions(+), 14 deletions(-) (limited to 'modules/enet') diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index a53c2a2364..4e7698b67c 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -214,8 +214,9 @@ void NetworkedMultiplayerENet::poll() { 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 + if (!host || !active) { // Might have been disconnected while emitting a notification return; + } int ret = enet_host_service(host, &event, 0); @@ -259,13 +260,15 @@ void NetworkedMultiplayerENet::poll() { if (server) { // Do not notify other peers when server_relay is disabled. - if (!server_relay) + if (!server_relay) { break; + } // Someone connected, notify all the peers available for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *new_id) + 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]); @@ -303,8 +306,9 @@ void NetworkedMultiplayerENet::poll() { } else if (server_relay) { // Server just received a client disconnect and is in relay mode, notify everyone else. for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *id) + if (E->key() == *id) { continue; + } ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE); encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]); @@ -373,8 +377,9 @@ void NetworkedMultiplayerENet::poll() { incoming_packets.push_back(packet); // And make copies for sending for (Map::Element *E = peer_map.front(); E; E = E->next()) { - if (uint32_t(E->key()) == source) // Do not resend to self + 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); @@ -386,8 +391,9 @@ void NetworkedMultiplayerENet::poll() { // And make copies for sending for (Map::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 + 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); @@ -485,8 +491,9 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { } } - if (id) + if (id) { memdelete(id); + } emit_signal("peer_disconnected", p_peer); peer_map.erase(p_peer); @@ -522,10 +529,11 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer switch (transfer_mode) { case TRANSFER_MODE_UNRELIABLE: { - if (always_ordered) + if (always_ordered) { packet_flags = 0; - else + } else { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; + } channel = SYSCH_UNRELIABLE; } break; case TRANSFER_MODE_UNRELIABLE_ORDERED: { @@ -538,8 +546,9 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer } break; } - if (transfer_channel > SYSCH_CONFIG) + if (transfer_channel > SYSCH_CONFIG) { channel = transfer_channel; + } Map::Element *E = nullptr; @@ -563,8 +572,9 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer int exclude = -target_peer; for (Map::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() == exclude) // Exclude packet + if (F->key() == exclude) { // Exclude packet continue; + } ENetPacket *packet2 = enet_packet_create(packet->data, packet->dataLength, packet_flags); @@ -685,11 +695,13 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * } int ret = Compression::compress(enet->dst_compressor_mem.ptrw(), enet->src_compressor_mem.ptr(), ofs, mode); - if (ret < 0) + if (ret < 0) { return 0; + } - if (ret > int(outLimit)) + if (ret > int(outLimit)) { return 0; // Do not bother + } copymem(outData, enet->dst_compressor_mem.ptr(), ret); diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index e5e9628c26..18051f756a 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -45,6 +45,7 @@ void register_enet_types() { } void unregister_enet_types() { - if (enet_ok) + if (enet_ok) { enet_deinitialize(); + } } -- cgit v1.2.3