# HG changeset patch # User rubidium # Date 2012-01-04 22:08:43 # Node ID ba984148392cb2f10c862080e21332f36fac3a74 # Parent 3baccba5d58739469bdede7737d9e5942cde7eda (svn r23751) -Codechange: rename NetworkUDPGameLoop to a more descriptive name, and move the UDP specific bits to network_udp diff --git a/src/network/network.cpp b/src/network/network.cpp --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -827,20 +827,18 @@ static void NetworkSend() } } -/* We have to do some UDP checking */ -void NetworkUDPGameLoop() +/** + * We have to do some (simple) background stuff that runs normally, + * even when we are not in multiplayer. For example stuff needed + * for finding servers or downloading content. + */ +void NetworkBackgroundLoop() { _network_content_client.SendReceive(); TCPConnecter::CheckCallbacks(); NetworkHTTPSocketHandler::HTTPReceive(); - if (_network_udp_server) { - _udp_server_socket->ReceivePackets(); - _udp_master_socket->ReceivePackets(); - } else { - _udp_client_socket->ReceivePackets(); - if (_network_udp_broadcast > 0) _network_udp_broadcast--; - } + NetworkBackgroundUDPLoop(); } /* The main loop called from ttd.c diff --git a/src/network/network_func.h b/src/network/network_func.h --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -40,7 +40,7 @@ const char *NetworkChangeCompanyPassword void NetworkReboot(); void NetworkDisconnect(bool blocking = false, bool close_admins = true); void NetworkGameLoop(); -void NetworkUDPGameLoop(); +void NetworkBackgroundLoop(); void ParseConnectionString(const char **company, const char **port, char *connection_string); void NetworkStartDebugLog(NetworkAddress address); void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -675,4 +675,16 @@ void NetworkUDPClose() DEBUG(net, 1, "[udp] closed listeners"); } +/** Receive the UDP packets. */ +void NetworkBackgroundUDPLoop() +{ + if (_network_udp_server) { + _udp_server_socket->ReceivePackets(); + _udp_master_socket->ReceivePackets(); + } else { + _udp_client_socket->ReceivePackets(); + if (_network_udp_broadcast > 0) _network_udp_broadcast--; + } +} + #endif /* ENABLE_NETWORK */ diff --git a/src/network/network_udp.h b/src/network/network_udp.h --- a/src/network/network_udp.h +++ b/src/network/network_udp.h @@ -23,6 +23,7 @@ void NetworkUDPQueryServer(NetworkAddres void NetworkUDPAdvertise(); void NetworkUDPRemoveAdvertise(bool blocking); void NetworkUDPClose(); +void NetworkBackgroundUDPLoop(); #endif /* ENABLE_NETWORK */ diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1348,7 +1348,7 @@ void GameLoop() if (_game_mode == GM_BOOTSTRAP) { #ifdef ENABLE_NETWORK /* Check for UDP stuff */ - if (_network_available) NetworkUDPGameLoop(); + if (_network_available) NetworkBackgroundLoop(); #endif InputLoop(); return; @@ -1378,7 +1378,7 @@ void GameLoop() #ifdef ENABLE_NETWORK /* Check for UDP stuff */ - if (_network_available) NetworkUDPGameLoop(); + if (_network_available) NetworkBackgroundLoop(); if (_networking && !HasModalProgress()) { /* Multiplayer */