diff --git a/src/pc/network/packets/packet_reliable.c b/src/pc/network/packets/packet_reliable.c index e74550d8..2f8cd91a 100644 --- a/src/pc/network/packets/packet_reliable.c +++ b/src/pc/network/packets/packet_reliable.c @@ -3,8 +3,8 @@ #include "pc/utils/misc.h" #include "pc/debuglog.h" -#define RELIABLE_RESEND_RATE 0.33f -#define MAX_RESEND_ATTEMPTS 10 +#define RELIABLE_RESEND_RATE 0.07f +#define MAX_RESEND_ATTEMPTS 15 struct PacketLinkedList { struct Packet p; @@ -117,7 +117,7 @@ void network_remember_reliable(struct Packet* p) { tail = node; } -static float network_adjust_max_elapsed(enum PacketType packetType, float maxElapsed) { +static float adjust_max_elapsed(enum PacketType packetType, float maxElapsed) { switch (packetType) { case PACKET_DOWNLOAD_REQUEST: case PACKET_DOWNLOAD: @@ -126,18 +126,26 @@ static float network_adjust_max_elapsed(enum PacketType packetType, float maxEla case PACKET_MOD_LIST_ENTRY: case PACKET_MOD_LIST_FILE: case PACKET_MOD_LIST_DONE: - return 0.2f + maxElapsed * 2.0f; + return MIN(0.2f + maxElapsed * 2.0f, 5); default: - return maxElapsed; + return MIN(maxElapsed, 5); } } +static float get_max_elapsed_time(int sendAttempts) { + f32 scalar = (sendAttempts / MAX_RESEND_ATTEMPTS); + scalar *= scalar; + f32 aScalar = 1.0 - scalar; + f32 interp = sendAttempts * aScalar + (sendAttempts * sendAttempts) * scalar; + return interp * RELIABLE_RESEND_RATE; +} + void network_update_reliable(void) { struct PacketLinkedList* node = head; while (node != NULL) { float elapsed = (clock_elapsed() - node->lastSend); - float maxElapsed = (node->sendAttempts * node->sendAttempts * RELIABLE_RESEND_RATE) / ((float)MAX_RESEND_ATTEMPTS); - maxElapsed = network_adjust_max_elapsed(node->p.packetType, maxElapsed); + float maxElapsed = get_max_elapsed_time(node->sendAttempts); + maxElapsed = adjust_max_elapsed(node->p.packetType, maxElapsed); if (elapsed > maxElapsed) { if (node->p.packetType == PACKET_JOIN_REQUEST && gNetworkPlayerServer != NULL) { node->p.localIndex = gNetworkPlayerServer->localIndex;