summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-01-08 10:16:18 +0000
committerGitHub <noreply@github.com>2021-01-08 11:16:18 +0100
commit9b800a96ed32720ff60b74e498a0e0a6351004f9 (patch)
tree3f287d339e15c4902ee415556475fd9b2918d33c /src/network
parentc1fddb9a6ae5c3af6865461a7295788a341011a2 (diff)
downloadopenttd-9b800a96ed32720ff60b74e498a0e0a6351004f9.tar.xz
Codechange: Remove min/max functions in favour of STL variants (#8502)
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp_http.cpp8
-rw-r--r--src/network/network_admin.cpp4
-rw-r--r--src/network/network_chat_gui.cpp6
-rw-r--r--src/network/network_client.cpp6
-rw-r--r--src/network/network_content.cpp4
-rw-r--r--src/network/network_content_gui.cpp6
-rw-r--r--src/network/network_gui.cpp26
-rw-r--r--src/network/network_server.cpp4
-rw-r--r--src/network/network_udp.cpp2
9 files changed, 33 insertions, 33 deletions
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp
index b2a6b0c04..be5a2c39a 100644
--- a/src/network/core/tcp_http.cpp
+++ b/src/network/core/tcp_http.cpp
@@ -250,8 +250,8 @@ int NetworkHTTPSocketHandler::Receive()
/* Wait till we read the end-of-header identifier */
if (this->recv_length == 0) {
- int read = this->recv_pos + res;
- int end = min(read, lengthof(this->recv_buffer) - 1);
+ ssize_t read = this->recv_pos + res;
+ ssize_t end = std::min<ssize_t>(read, lengthof(this->recv_buffer) - 1);
/* Do a 'safe' search for the end of the header. */
char prev = this->recv_buffer[end];
@@ -272,7 +272,7 @@ int NetworkHTTPSocketHandler::Receive()
this->recv_length = ret;
end_of_header += strlen(END_OF_HEADER);
- int len = min(read - (end_of_header - this->recv_buffer), res);
+ int len = std::min(read - (end_of_header - this->recv_buffer), res);
if (len != 0) {
this->callback->OnReceiveData(end_of_header, len);
this->recv_length -= len;
@@ -281,7 +281,7 @@ int NetworkHTTPSocketHandler::Receive()
this->recv_pos = 0;
}
} else {
- res = min(this->recv_length, res);
+ res = std::min<ssize_t>(this->recv_length, res);
/* Receive whatever we're expecting. */
this->callback->OnReceiveData(this->recv_buffer, res);
this->recv_length -= res;
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 007722ec6..20bd25f8f 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -413,13 +413,13 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
p->Send_uint64(company->money);
p->Send_uint64(company->current_loan);
p->Send_uint64(income);
- p->Send_uint16(min(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>()));
+ p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>())));
/* Send stats for the last 2 quarters. */
for (uint i = 0; i < 2; i++) {
p->Send_uint64(company->old_economy[i].company_value);
p->Send_uint16(company->old_economy[i].performance_history);
- p->Send_uint16(min(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>()));
+ p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>())));
}
this->SendPacket(p);
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index e0f3bf57c..83824e126 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -154,7 +154,7 @@ void NetworkUndrawChatMessage()
int width = _chatmsg_box.width;
int height = _chatmsg_box.height;
if (y < 0) {
- height = max(height + y, min(_chatmsg_box.height, _screen.height));
+ height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
y = 0;
}
if (x + width >= _screen.width) {
@@ -214,7 +214,7 @@ void NetworkDrawChatMessage()
int width = _chatmsg_box.width;
int height = _chatmsg_box.height;
if (y < 0) {
- height = max(height + y, min(_chatmsg_box.height, _screen.height));
+ height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height));
y = 0;
}
if (x + width >= _screen.width) {
@@ -235,7 +235,7 @@ void NetworkDrawChatMessage()
string_height += GetStringLineCount(STR_JUST_RAW_STRING, width - 1) * FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING;
}
- string_height = min(string_height, MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
+ string_height = std::min<uint>(string_height, MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING));
int top = _screen.height - _chatmsg_box.y - string_height - 2;
int bottom = _screen.height - _chatmsg_box.y - 2;
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 343f71eb7..7a7ec9f21 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -68,7 +68,7 @@ struct PacketReader : LoadFilter {
assert(this->read_bytes == 0);
size_t in_packet = p->size - p->pos;
- size_t to_write = min((size_t)(this->bufe - this->buf), in_packet);
+ size_t to_write = std::min<size_t>(this->bufe - this->buf, in_packet);
const byte *pbuf = p->buffer + p->pos;
this->written_bytes += in_packet;
@@ -93,7 +93,7 @@ struct PacketReader : LoadFilter {
size_t Read(byte *rbuf, size_t size) override
{
/* Limit the amount to read to whatever we still have. */
- size_t ret_size = size = min(this->written_bytes - this->read_bytes, size);
+ size_t ret_size = size = std::min(this->written_bytes - this->read_bytes, size);
this->read_bytes += ret_size;
const byte *rbufe = rbuf + ret_size;
@@ -103,7 +103,7 @@ struct PacketReader : LoadFilter {
this->bufe = this->buf + CHUNK;
}
- size_t to_write = min(this->bufe - this->buf, rbufe - rbuf);
+ size_t to_write = std::min(this->bufe - this->buf, rbufe - rbuf);
memcpy(rbuf, this->buf, to_write);
rbuf += to_write;
this->buf += to_write;
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 46e371e6f..1c19a2b52 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -221,7 +221,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con
* A packet begins with the packet size and a byte for the type.
* Then this packet adds a uint16 for the count in this packet.
* The rest of the packet can be used for the IDs. */
- uint p_count = min(count, (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16)) / sizeof(uint32));
+ uint p_count = std::min<uint>(count, (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16)) / sizeof(uint32));
Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_ID);
p->Send_uint16(p_count);
@@ -363,7 +363,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
* A packet begins with the packet size and a byte for the type.
* Then this packet adds a uint16 for the count in this packet.
* The rest of the packet can be used for the IDs. */
- uint p_count = min(count, (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16)) / sizeof(uint32));
+ uint p_count = std::min<uint>(count, (SEND_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16)) / sizeof(uint32));
Packet *p = new Packet(PACKET_CONTENT_CLIENT_CONTENT);
p->Send_uint16(p_count);
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index dd87a4948..06e57a2ac 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -575,7 +575,7 @@ public:
}
case WID_NCL_MATRIX:
- resize->height = max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
+ resize->height = std::max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
size->height = 10 * resize->height;
break;
}
@@ -626,7 +626,7 @@ public:
const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(WID_NCL_NAME);
const NWidgetBase *nwi_type = this->GetWidget<NWidgetBase>(WID_NCL_TYPE);
- int line_height = max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL);
+ int line_height = std::max(this->checkbox_size.height, (uint)FONT_HEIGHT_NORMAL);
/* Fill the matrix with the information */
int sprite_y_offset = WD_MATRIX_TOP + (line_height - this->checkbox_size.height) / 2 - 1;
@@ -877,7 +877,7 @@ public:
break;
case WKC_PAGEDOWN:
/* scroll down a page */
- this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.size() - 1);
+ this->list_pos = std::min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 13e6fbe8f..a2c2cac19 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -123,7 +123,7 @@ public:
/* First initialise some variables... */
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
- this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
+ this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
}
/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
@@ -498,12 +498,12 @@ public:
{
switch (widget) {
case WID_NG_MATRIX:
- resize->height = WD_MATRIX_TOP + max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
+ resize->height = WD_MATRIX_TOP + std::max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
size->height = 12 * resize->height;
break;
case WID_NG_LASTJOINED:
- size->height = WD_MATRIX_TOP + max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
+ size->height = WD_MATRIX_TOP + std::max(GetSpriteSize(SPR_BLOT).height, (uint)FONT_HEIGHT_NORMAL) + WD_MATRIX_BOTTOM;
break;
case WID_NG_LASTJOINED_SPACER:
@@ -545,7 +545,7 @@ public:
case WID_NG_MATRIX: {
uint16 y = r.top;
- const int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.size());
+ const int max = std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.size());
for (int i = this->vscroll->GetPosition(); i < max; ++i) {
const NetworkGameList *ngl = this->servers[i];
@@ -812,7 +812,7 @@ public:
case WKC_PAGEDOWN:
/* scroll down a page */
if (this->list_pos == SLP_INVALID) return ES_HANDLED;
- this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.size() - 1);
+ this->list_pos = std::min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
@@ -904,7 +904,7 @@ GUIGameServerList::FilterFunction * const NetworkGameWindow::filter_funcs[] = {
static NWidgetBase *MakeResizableHeader(int *biggest_index)
{
- *biggest_index = max<int>(*biggest_index, WID_NG_INFO);
+ *biggest_index = std::max<int>(*biggest_index, WID_NG_INFO);
return new NWidgetServerListHeader();
}
@@ -1861,13 +1861,13 @@ struct NetworkClientListWindow : Window {
{
if (widget != WID_CL_PANEL) return;
- this->server_client_width = max(GetStringBoundingBox(STR_NETWORK_SERVER).width, GetStringBoundingBox(STR_NETWORK_CLIENT).width) + WD_FRAMERECT_RIGHT;
+ this->server_client_width = std::max(GetStringBoundingBox(STR_NETWORK_SERVER).width, GetStringBoundingBox(STR_NETWORK_CLIENT).width) + WD_FRAMERECT_RIGHT;
this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
- this->line_height = max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
+ this->line_height = std::max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
uint width = 100; // Default width
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
- width = max(width, GetStringBoundingBox(ci->client_name).width);
+ width = std::max(width, GetStringBoundingBox(ci->client_name).width);
}
size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->icon_size.width + WD_FRAMERECT_LEFT + width + WD_FRAMERECT_RIGHT;
@@ -2028,18 +2028,18 @@ struct NetworkJoinStatusWindow : Window {
/* Account for the statuses */
uint width = 0;
for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
- width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i).width);
+ width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i).width);
}
/* For the number of waiting (other) players */
SetDParamMaxValue(0, MAX_CLIENTS);
- width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING).width);
+ width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING).width);
/* Account for downloading ~ 10 MiB */
SetDParamMaxDigits(0, 8);
SetDParamMaxDigits(1, 8);
- width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1).width);
- width = max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_2).width);
+ width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1).width);
+ width = std::max(width, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_2).width);
/* Give a bit more clearing for the widest strings than strictly needed */
size->width = width + WD_FRAMERECT_LEFT + WD_FRAMERECT_BOTTOM + 10;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 067ffd09d..6ae8e7cdc 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -174,7 +174,7 @@ struct PacketWriter : SaveFilter {
byte *bufe = buf + size;
while (buf != bufe) {
- size_t to_write = min(SEND_MTU - this->current->size, bufe - buf);
+ size_t to_write = std::min<size_t>(SEND_MTU - this->current->size, bufe - buf);
memcpy(this->current->buffer + this->current->size, buf, to_write);
this->current->size += (PacketSize)to_write;
buf += to_write;
@@ -1807,7 +1807,7 @@ void NetworkServer_Tick(bool send_frame)
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
/* We allow a number of bytes per frame, but only to the burst amount
* to be available for packet receiving at any particular time. */
- cs->receive_limit = min(cs->receive_limit + _settings_client.network.bytes_per_frame,
+ cs->receive_limit = std::min<int>(cs->receive_limit + _settings_client.network.bytes_per_frame,
_settings_client.network.bytes_per_frame_burst);
/* Check if the speed of the client is what we can expect from a client */
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 0fd20b5f4..771f51fbe 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -263,7 +263,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, Networ
* the current list and do not send the other data.
* The name could be an empty string, if so take the filename. */
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
- min(strlen(f->GetName()) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
+ std::min(strlen(f->GetName()) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
break;
}