mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01: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:
parent
918fbe3ec1
commit
d51d0f3a5a
@ -378,6 +378,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
|
|||||||
// Smoothen and invert the above
|
// Smoothen and invert the above
|
||||||
fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1;
|
fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1;
|
||||||
// Amplify according to the intensity of the impact
|
// Amplify according to the intensity of the impact
|
||||||
|
if (player->camera_impact > 0.0f)
|
||||||
fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5;
|
fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5;
|
||||||
|
|
||||||
fall_bobbing *= m_cache_fall_bobbing_amount;
|
fall_bobbing *= m_cache_fall_bobbing_amount;
|
||||||
|
@ -334,13 +334,13 @@ public:
|
|||||||
// disconnect client when CSM failed.
|
// disconnect client when CSM failed.
|
||||||
const std::string &accessDeniedReason() const { return m_access_denied_reason; }
|
const std::string &accessDeniedReason() const { return m_access_denied_reason; }
|
||||||
|
|
||||||
const bool itemdefReceived() const
|
bool itemdefReceived() const
|
||||||
{ return m_itemdef_received; }
|
{ return m_itemdef_received; }
|
||||||
const bool nodedefReceived() const
|
bool nodedefReceived() const
|
||||||
{ return m_nodedef_received; }
|
{ return m_nodedef_received; }
|
||||||
const bool mediaReceived() const
|
bool mediaReceived() const
|
||||||
{ return !m_media_downloader; }
|
{ return !m_media_downloader; }
|
||||||
const bool activeObjectsReceived() const
|
bool activeObjectsReceived() const
|
||||||
{ return m_activeobjects_received; }
|
{ return m_activeobjects_received; }
|
||||||
|
|
||||||
u16 getProtoVersion()
|
u16 getProtoVersion()
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
void showTranslatedStatusText(const char *str);
|
void showTranslatedStatusText(const char *str);
|
||||||
inline void clearStatusText() { m_statustext.clear(); }
|
inline void clearStatusText() { m_statustext.clear(); }
|
||||||
|
|
||||||
const bool isChatVisible()
|
bool isChatVisible()
|
||||||
{
|
{
|
||||||
return m_flags.show_chat && m_recent_chat_count != 0 && m_profiler_current_page == 0;
|
return m_flags.show_chat && m_recent_chat_count != 0 && m_profiler_current_page == 0;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ public:
|
|||||||
return m_selected_item;
|
return m_selected_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u16 getSelectedAmount() const
|
u16 getSelectedAmount() const
|
||||||
{
|
{
|
||||||
return m_selected_amount;
|
return m_selected_amount;
|
||||||
}
|
}
|
||||||
|
@ -995,7 +995,7 @@ const InventoryList *Inventory::getList(const std::string &name) const
|
|||||||
return m_lists[i];
|
return m_lists[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const s32 Inventory::getListIndex(const std::string &name) const
|
s32 Inventory::getListIndex(const std::string &name) const
|
||||||
{
|
{
|
||||||
for(u32 i=0; i<m_lists.size(); i++)
|
for(u32 i=0; i<m_lists.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -336,7 +336,7 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
// -1 if not found
|
// -1 if not found
|
||||||
const s32 getListIndex(const std::string &name) const;
|
s32 getListIndex(const std::string &name) const;
|
||||||
|
|
||||||
std::vector<InventoryList*> m_lists;
|
std::vector<InventoryList*> m_lists;
|
||||||
IItemDefManager *m_itemdef;
|
IItemDefManager *m_itemdef;
|
||||||
|
@ -578,7 +578,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful)
|
|||||||
// ugly cast but this one is required in order to tell compiler we
|
// ugly cast but this one is required in order to tell compiler we
|
||||||
// know about difference of two unsigned may be negative in general
|
// know about difference of two unsigned may be negative in general
|
||||||
// but we already made sure it won't happen in this case
|
// 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;
|
successful = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -588,7 +588,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful)
|
|||||||
// know about difference of two unsigned may be negative in general
|
// know about difference of two unsigned may be negative in general
|
||||||
// but we already made sure it won't happen in this case
|
// but we already made sure it won't happen in this case
|
||||||
if ((next_outgoing_seqnum + (u16)(SEQNUM_MAX - lowest_unacked_seqnumber)) >
|
if ((next_outgoing_seqnum + (u16)(SEQNUM_MAX - lowest_unacked_seqnumber)) >
|
||||||
window_size) {
|
m_window_size) {
|
||||||
successful = false;
|
successful = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -666,7 +666,7 @@ void Channel::UpdateTimers(float dtime)
|
|||||||
//packet_too_late = current_packet_too_late;
|
//packet_too_late = current_packet_too_late;
|
||||||
packets_successful = current_packet_successful;
|
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;
|
reasonable_amount_of_data_transmitted = true;
|
||||||
}
|
}
|
||||||
current_packet_loss = 0;
|
current_packet_loss = 0;
|
||||||
@ -681,37 +681,25 @@ void Channel::UpdateTimers(float dtime)
|
|||||||
if (packets_successful > 0) {
|
if (packets_successful > 0) {
|
||||||
successful_to_lost_ratio = packet_loss/packets_successful;
|
successful_to_lost_ratio = packet_loss/packets_successful;
|
||||||
} else if (packet_loss > 0) {
|
} else if (packet_loss > 0) {
|
||||||
window_size = std::max(
|
setWindowSize(m_window_size - 10);
|
||||||
(window_size - 10),
|
|
||||||
MIN_RELIABLE_WINDOW_SIZE);
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
if ((successful_to_lost_ratio < 0.01f) &&
|
if (successful_to_lost_ratio < 0.01f) {
|
||||||
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
|
|
||||||
/* don't even think about increasing if we didn't even
|
/* don't even think about increasing if we didn't even
|
||||||
* use major parts of our window */
|
* use major parts of our window */
|
||||||
if (reasonable_amount_of_data_transmitted)
|
if (reasonable_amount_of_data_transmitted)
|
||||||
window_size = std::min(
|
setWindowSize(m_window_size + 100);
|
||||||
(window_size + 100),
|
} else if (successful_to_lost_ratio < 0.05f) {
|
||||||
MAX_RELIABLE_WINDOW_SIZE);
|
|
||||||
} else if ((successful_to_lost_ratio < 0.05f) &&
|
|
||||||
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
|
|
||||||
/* don't even think about increasing if we didn't even
|
/* don't even think about increasing if we didn't even
|
||||||
* use major parts of our window */
|
* use major parts of our window */
|
||||||
if (reasonable_amount_of_data_transmitted)
|
if (reasonable_amount_of_data_transmitted)
|
||||||
window_size = std::min(
|
setWindowSize(m_window_size + 50);
|
||||||
(window_size + 50),
|
|
||||||
MAX_RELIABLE_WINDOW_SIZE);
|
|
||||||
} else if (successful_to_lost_ratio > 0.15f) {
|
} else if (successful_to_lost_ratio > 0.15f) {
|
||||||
window_size = std::max(
|
setWindowSize(m_window_size - 100);
|
||||||
(window_size - 100),
|
|
||||||
MIN_RELIABLE_WINDOW_SIZE);
|
|
||||||
} else if (successful_to_lost_ratio > 0.1f) {
|
} else if (successful_to_lost_ratio > 0.1f) {
|
||||||
window_size = std::max(
|
setWindowSize(m_window_size - 50);
|
||||||
(window_size - 50),
|
|
||||||
MIN_RELIABLE_WINDOW_SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,34 +420,38 @@ public:
|
|||||||
|
|
||||||
void UpdateTimers(float dtime);
|
void UpdateTimers(float dtime);
|
||||||
|
|
||||||
const float getCurrentDownloadRateKB()
|
float getCurrentDownloadRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return cur_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return cur_kbps; };
|
||||||
const float getMaxDownloadRateKB()
|
float getMaxDownloadRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return max_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return max_kbps; };
|
||||||
|
|
||||||
const float getCurrentLossRateKB()
|
float getCurrentLossRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; };
|
{ MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; };
|
||||||
const float getMaxLossRateKB()
|
float getMaxLossRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; };
|
{ MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; };
|
||||||
|
|
||||||
const float getCurrentIncomingRateKB()
|
float getCurrentIncomingRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; };
|
||||||
const float getMaxIncomingRateKB()
|
float getMaxIncomingRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; };
|
||||||
|
|
||||||
const float getAvgDownloadRateKB()
|
float getAvgDownloadRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return avg_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return avg_kbps; };
|
||||||
const float getAvgLossRateKB()
|
float getAvgLossRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; };
|
{ MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; };
|
||||||
const float getAvgIncomingRateKB()
|
float getAvgIncomingRateKB()
|
||||||
{ MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; };
|
{ MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; };
|
||||||
|
|
||||||
const unsigned int getWindowSize() const { return window_size; };
|
u16 getWindowSize() const { return m_window_size; };
|
||||||
|
|
||||||
|
void setWindowSize(long size)
|
||||||
|
{
|
||||||
|
m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
void setWindowSize(unsigned int size) { window_size = size; };
|
|
||||||
private:
|
private:
|
||||||
std::mutex m_internal_mutex;
|
std::mutex m_internal_mutex;
|
||||||
int window_size = MIN_RELIABLE_WINDOW_SIZE;
|
u16 m_window_size = MIN_RELIABLE_WINDOW_SIZE;
|
||||||
|
|
||||||
u16 next_incoming_seqnum = SEQNUM_INITIAL;
|
u16 next_incoming_seqnum = SEQNUM_INITIAL;
|
||||||
|
|
||||||
@ -765,7 +769,7 @@ public:
|
|||||||
Address GetPeerAddress(session_t peer_id);
|
Address GetPeerAddress(session_t peer_id);
|
||||||
float getPeerStat(session_t peer_id, rtt_stat_type type);
|
float getPeerStat(session_t peer_id, rtt_stat_type type);
|
||||||
float getLocalStat(rate_stat_type type);
|
float getLocalStat(rate_stat_type type);
|
||||||
const u32 GetProtocolID() const { return m_protocol_id; };
|
u32 GetProtocolID() const { return m_protocol_id; };
|
||||||
const std::string getDesc();
|
const std::string getDesc();
|
||||||
void DisconnectPeer(session_t peer_id);
|
void DisconnectPeer(session_t peer_id);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
u32 getSize() const { return m_datasize; }
|
u32 getSize() const { return m_datasize; }
|
||||||
session_t getPeerId() const { return m_peer_id; }
|
session_t getPeerId() const { return m_peer_id; }
|
||||||
u16 getCommand() { return m_command; }
|
u16 getCommand() { return m_command; }
|
||||||
const u32 getRemainingBytes() const { return m_datasize - m_read_offset; }
|
u32 getRemainingBytes() const { return m_datasize - m_read_offset; }
|
||||||
const char *getRemainingString() { return getString(m_read_offset); }
|
const char *getRemainingString() { return getString(m_read_offset); }
|
||||||
|
|
||||||
// Returns a c-string without copying.
|
// Returns a c-string without copying.
|
||||||
|
@ -84,7 +84,7 @@ RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const RemotePlayerChatResult RemotePlayer::canSendChatMessage()
|
RemotePlayerChatResult RemotePlayer::canSendChatMessage()
|
||||||
{
|
{
|
||||||
// Rate limit messages
|
// Rate limit messages
|
||||||
u32 now = time(NULL);
|
u32 now = time(NULL);
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
PlayerSAO *getPlayerSAO() { return m_sao; }
|
PlayerSAO *getPlayerSAO() { return m_sao; }
|
||||||
void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
|
void setPlayerSAO(PlayerSAO *sao) { m_sao = sao; }
|
||||||
|
|
||||||
const RemotePlayerChatResult canSendChatMessage();
|
RemotePlayerChatResult canSendChatMessage();
|
||||||
|
|
||||||
void setHotbarItemcount(s32 hotbar_itemcount)
|
void setHotbarItemcount(s32 hotbar_itemcount)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user