MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / MultiDoBytesSent

Function MultiDoBytesSent

Descent3/multi.cpp:7501–7551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7499#define MIN(a, b) ((a < b) ? a : b)
7500
7501void MultiDoBytesSent(uint8_t *data) {
7502 int count = 0;
7503 uint32_t server_sent;
7504 float drop_ratio;
7505 SKIP_HEADER(data, &count);
7506 server_sent = MultiGetUint(data, &count);
7507 int dropped = server_sent - NetPlayers[Player_num].total_bytes_rcvd;
7508 if (dropped > 0) {
7509 drop_ratio = (float)NetPlayers[Player_num].total_bytes_rcvd / (float)server_sent;
7510 float loss = 1 - drop_ratio;
7511 int pct_loss = loss * 100;
7512 NetPlayers[Player_num].percent_loss = pct_loss;
7513
7514 if (pct_loss > 15) {
7515 if (Bandwidth_throttle >= 0)
7516 Bandwidth_throttle++;
7517 else
7518 Bandwidth_throttle = 0;
7519 } else if (pct_loss < 5) {
7520 if (Bandwidth_throttle <= 0)
7521 Bandwidth_throttle--;
7522 else
7523 Bandwidth_throttle = 0;
7524 }
7525 if (NetPlayers[Player_num].ping_time >= PING_FALLOFF) {
7526 Bandwidth_throttle--;
7527 Bandwidth_throttle--;
7528 }
7529 // mprintf_at(2,1,0,"Packet Loss: %d%% ",pct_loss);
7530 } else {
7531 // mprintf_at(2,1,0,"Packet Loss: 0%% ");
7532 NetPlayers[Player_num].percent_loss = 0;
7533 Bandwidth_throttle--;
7534 }
7535 if (Bandwidth_throttle >= 3) {
7536 // Time to lower the pps setting!
7537 if (NetPlayers[Player_num].pps > PPS_MIN) {
7538 NetPlayers[Player_num].pps--;
7539 MultiSendPPSSet(NetPlayers[Player_num].pps);
7540 Bandwidth_throttle = 0;
7541 }
7542 } else if (Bandwidth_throttle <= -2) {
7543 // Time to up the pps setting!
7544 if (NetPlayers[Player_num].pps < MIN(nw_ReccomendPPS(), Netgame.packets_per_second)) {
7545 NetPlayers[Player_num].pps++;
7546 MultiSendPPSSet(NetPlayers[Player_num].pps);
7547 Bandwidth_throttle = 0;
7548 }
7549 }
7550 NetPlayers[Player_num].total_bytes_rcvd = 0;
7551}
7552
7553void MultiSendPPSSet(int pps) {
7554 int size = 0;

Callers 1

MultiProcessDataFunction · 0.85

Calls 4

SKIP_HEADERFunction · 0.85
MultiGetUintFunction · 0.85
MultiSendPPSSetFunction · 0.85
nw_ReccomendPPSFunction · 0.85

Tested by

no test coverage detected