summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-01-15 08:32:17 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-01-15 08:38:40 +0100
commitd7cd25ad9c94ee9d0b7e3a8356064f1581be0ff6 (patch)
treef492bc0e47669eab945c6ed50a77d922ddaae213 /modules
parent9ed34d44238d130f5c7d999bb7265e7c0e906567 (diff)
Save 4 bytes in ENet multiplayer protocol.
Avoid sending encoded packet flags (reliable/unreliable/ordered) as that's already been done by ENet itself and we can read them from the incoming packet.
Diffstat (limited to 'modules')
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index e53846e269..196e592086 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -339,11 +339,10 @@ void NetworkedMultiplayerENet::poll() {
uint32_t *id = (uint32_t *)event.peer->data;
- ERR_CONTINUE(event.packet->dataLength < 12)
+ ERR_CONTINUE(event.packet->dataLength < 8)
uint32_t source = decode_uint32(&event.packet->data[0]);
int target = decode_uint32(&event.packet->data[4]);
- uint32_t flags = decode_uint32(&event.packet->data[8]);
packet.from = source;
packet.channel = event.channelID;
@@ -364,7 +363,7 @@ void NetworkedMultiplayerENet::poll() {
if (uint32_t(E->key()) == source) // Do not resend to self
continue;
- ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, flags);
+ ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
enet_peer_send(E->get(), event.channelID, packet2);
}
@@ -378,7 +377,7 @@ void NetworkedMultiplayerENet::poll() {
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, flags);
+ ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
enet_peer_send(E->get(), event.channelID, packet2);
}
@@ -497,8 +496,8 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff
current_packet = incoming_packets.front()->get();
incoming_packets.pop_front();
- *r_buffer = (const uint8_t *)(&current_packet.packet->data[12]);
- r_buffer_size = current_packet.packet->dataLength - 12;
+ *r_buffer = (const uint8_t *)(&current_packet.packet->data[8]);
+ r_buffer_size = current_packet.packet->dataLength - 8;
return OK;
}
@@ -543,11 +542,10 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
}
}
- ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 12, packet_flags);
+ ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 8, packet_flags);
encode_uint32(unique_id, &packet->data[0]); // Source ID
encode_uint32(target_peer, &packet->data[4]); // Dest ID
- encode_uint32(packet_flags, &packet->data[8]); // Dest ID
- copymem(&packet->data[12], p_buffer, p_buffer_size);
+ copymem(&packet->data[8], p_buffer, p_buffer_size);
if (server) {