1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Various code improvements

* Camera: Fix division by 0 after view bobbing
* Remove ignored constness
* Connection: Improve window size range limits
This commit is contained in:
SmallJoker 2021-09-27 17:45:44 +02:00 committed by GitHub
parent 918fbe3ec1
commit d51d0f3a5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 40 additions and 47 deletions

View file

@ -578,7 +578,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful)
// ugly cast but this one is required in order to tell compiler we
// know about difference of two unsigned may be negative in general
// but we already made sure it won't happen in this case
if (((u16)(next_outgoing_seqnum - lowest_unacked_seqnumber)) > window_size) {
if (((u16)(next_outgoing_seqnum - lowest_unacked_seqnumber)) > m_window_size) {
successful = false;
return 0;
}
@ -588,7 +588,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful)
// know about difference of two unsigned may be negative in general
// but we already made sure it won't happen in this case
if ((next_outgoing_seqnum + (u16)(SEQNUM_MAX - lowest_unacked_seqnumber)) >
window_size) {
m_window_size) {
successful = false;
return 0;
}
@ -666,7 +666,7 @@ void Channel::UpdateTimers(float dtime)
//packet_too_late = current_packet_too_late;
packets_successful = current_packet_successful;
if (current_bytes_transfered > (unsigned int) (window_size*512/2)) {
if (current_bytes_transfered > (unsigned int) (m_window_size*512/2)) {
reasonable_amount_of_data_transmitted = true;
}
current_packet_loss = 0;
@ -681,37 +681,25 @@ void Channel::UpdateTimers(float dtime)
if (packets_successful > 0) {
successful_to_lost_ratio = packet_loss/packets_successful;
} else if (packet_loss > 0) {
window_size = std::max(
(window_size - 10),
MIN_RELIABLE_WINDOW_SIZE);
setWindowSize(m_window_size - 10);
done = true;
}
if (!done) {
if ((successful_to_lost_ratio < 0.01f) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
if (successful_to_lost_ratio < 0.01f) {
/* don't even think about increasing if we didn't even
* use major parts of our window */
if (reasonable_amount_of_data_transmitted)
window_size = std::min(
(window_size + 100),
MAX_RELIABLE_WINDOW_SIZE);
} else if ((successful_to_lost_ratio < 0.05f) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
setWindowSize(m_window_size + 100);
} else if (successful_to_lost_ratio < 0.05f) {
/* don't even think about increasing if we didn't even
* use major parts of our window */
if (reasonable_amount_of_data_transmitted)
window_size = std::min(
(window_size + 50),
MAX_RELIABLE_WINDOW_SIZE);
setWindowSize(m_window_size + 50);
} else if (successful_to_lost_ratio > 0.15f) {
window_size = std::max(
(window_size - 100),
MIN_RELIABLE_WINDOW_SIZE);
setWindowSize(m_window_size - 100);
} else if (successful_to_lost_ratio > 0.1f) {
window_size = std::max(
(window_size - 50),
MIN_RELIABLE_WINDOW_SIZE);
setWindowSize(m_window_size - 50);
}
}
}