diff options
author | smatz <smatz@openttd.org> | 2009-05-22 15:13:50 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-22 15:13:50 +0000 |
commit | 62a7948af0ca9eb3b190a54918201e1075edcbbc (patch) | |
tree | 27a79b7850682cd43cac2462c3410ed8b567c4b2 /src/network | |
parent | 04723b240ebc7384954f73590be517ad2a47ce04 (diff) | |
download | openttd-62a7948af0ca9eb3b190a54918201e1075edcbbc.tar.xz |
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/tcp_game.cpp | 8 | ||||
-rw-r--r-- | src/network/core/tcp_game.h | 8 | ||||
-rw-r--r-- | src/network/network.cpp | 14 | ||||
-rw-r--r-- | src/network/network_base.h | 9 | ||||
-rw-r--r-- | src/network/network_chat_gui.cpp | 13 | ||||
-rw-r--r-- | src/network/network_type.h | 9 |
6 files changed, 27 insertions, 34 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp index d34ace4bf..b4bb52190 100644 --- a/src/network/core/tcp_game.cpp +++ b/src/network/core/tcp_game.cpp @@ -13,16 +13,16 @@ #include "../network_internal.h" #include "packet.h" #include "tcp_game.h" +#include "../../core/pool_func.hpp" #include "table/strings.h" -#include "../../oldpool_func.h" /** Make very sure the preconditions given in network_type.h are actually followed */ -assert_compile(MAX_CLIENT_SLOTS == (MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK) << NCI_BITS_PER_POOL_BLOCK); assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS); +assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS); -typedef ClientIndex NetworkClientSocketID; -DEFINE_OLD_POOL_GENERIC(NetworkClientSocket, NetworkClientSocket); +NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket"); +INSTANTIATE_POOL_METHODS(NetworkClientSocket) NetworkClientSocket::NetworkClientSocket(ClientID client_id) { diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index bfc82f17f..d01a3d9a8 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -12,6 +12,7 @@ #include "os_abstraction.h" #include "tcp.h" #include "packet.h" +#include "../../core/pool.hpp" /** * Enum with all types of UDP packets. @@ -76,12 +77,12 @@ enum ClientStatus { STATUS_ACTIVE, ///< The client is active within in the game }; - class NetworkClientSocket; -DECLARE_OLD_POOL(NetworkClientSocket, NetworkClientSocket, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK); +typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientSocketPool; +extern NetworkClientSocketPool _networkclientsocket_pool; /** Base socket handler for all TCP sockets */ -class NetworkClientSocket : public PoolItem<NetworkClientSocket, ClientIndex, &_NetworkClientSocket_pool>, public NetworkTCPSocketHandler { +class NetworkClientSocket : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkTCPSocketHandler { /* TODO: rewrite into a proper class */ private: NetworkClientInfo *info; ///< Client info related to this socket @@ -100,7 +101,6 @@ public: NetworkClientSocket(ClientID client_id = INVALID_CLIENT_ID); ~NetworkClientSocket(); - inline bool IsValid() const { return this->IsConnected(); } inline void SetInfo(NetworkClientInfo *info) { assert(info != NULL && this->info == NULL); this->info = info; } inline NetworkClientInfo *GetInfo() const { return this->info; } diff --git a/src/network/network.cpp b/src/network/network.cpp index 4d407e2b0..266ce506d 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -32,16 +32,18 @@ #include "../landscape_type.h" #include "../rev.h" #include "../core/alloc_func.hpp" +#include "../core/pool_func.hpp" #ifdef DEBUG_DUMP_COMMANDS #include "../fileio_func.h" #endif /* DEBUG_DUMP_COMMANDS */ #include "table/strings.h" -#include "../oldpool_func.h" DECLARE_POSTFIX_INCREMENT(ClientID); -typedef ClientIndex NetworkClientInfoID; -DEFINE_OLD_POOL_GENERIC(NetworkClientInfo, NetworkClientInfo); +assert_compile(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE); + +NetworkClientInfoPool _networkclientinfo_pool("NetworkClientInfo"); +INSTANTIATE_POOL_METHODS(NetworkClientInfo) bool _networking; ///< are we in networking mode? bool _network_server; ///< network-server is active @@ -557,10 +559,8 @@ static bool NetworkListen() /** Resets both pools used for network clients */ static void InitializeNetworkPools() { - _NetworkClientSocket_pool.CleanPool(); - _NetworkClientSocket_pool.AddBlockToPool(); - _NetworkClientInfo_pool.CleanPool(); - _NetworkClientInfo_pool.AddBlockToPool(); + _networkclientsocket_pool.CleanPool(); + _networkclientinfo_pool.CleanPool(); } /* Close all current connections */ diff --git a/src/network/network_base.h b/src/network/network_base.h index 700541b49..2714217cd 100644 --- a/src/network/network_base.h +++ b/src/network/network_base.h @@ -8,11 +8,12 @@ #ifdef ENABLE_NETWORK #include "network_type.h" -#include "../oldpool.h" +#include "../core/pool.hpp" -DECLARE_OLD_POOL(NetworkClientInfo, NetworkClientInfo, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK); +typedef Pool<NetworkClientInfo, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientInfoPool; +extern NetworkClientInfoPool _networkclientinfo_pool; -struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkClientInfo_pool> { +struct NetworkClientInfo : NetworkClientInfoPool::PoolItem<&_networkclientinfo_pool> { ClientID client_id; ///< Client identifier (same as ClientState->client_id) char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the client byte client_lang; ///< The language of the client @@ -23,8 +24,6 @@ struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkCli NetworkClientInfo(ClientID client_id = INVALID_CLIENT_ID) : client_id(client_id) {} ~NetworkClientInfo() { client_id = INVALID_CLIENT_ID; } - - inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; } }; #define FOR_ALL_CLIENT_INFOS_FROM(var, start) FOR_ALL_ITEMS_FROM(NetworkClientInfo, clientinfo_index, var, start) diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 9f896c185..4284f15d7 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -303,14 +303,11 @@ struct NetworkChatWindow : public QueryStringBaseWindow { /* First, try clients */ if (*item < MAX_CLIENT_SLOTS) { - if (*item < NetworkClientInfo::GetPoolSize()) { - /* Skip inactive clients */ - NetworkClientInfo *ci; - FOR_ALL_CLIENT_INFOS_FROM(ci, *item) break; - if (ci != NULL) { - *item = ci->index; - return ci->client_name; - } + /* Skip inactive clients */ + NetworkClientInfo *ci; + FOR_ALL_CLIENT_INFOS_FROM(ci, *item) { + *item = ci->index; + return ci->client_name; } *item = MAX_CLIENT_SLOTS; } diff --git a/src/network/network_type.h b/src/network/network_type.h index 7e27d398c..4bdb64429 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -16,13 +16,10 @@ enum { /** How many clients can we have */ MAX_CLIENTS = 255, - /** The number of bits per pool client block */ - NCI_BITS_PER_POOL_BLOCK = 3, // => 8 items per block /** - * The number of slots; must be a multiple of (1 << NCI_BITS_PER_POOL_BLOCK) - * and be at least 1 more than MAX_CLIENTS. It must furthermore be less than - * or equal to 256 as client indices (sent over the network) are 8 bits. - * It needs 1 more for the dedicated server. + * The number of slots; must be at least 1 more than MAX_CLIENTS. It must + * furthermore be less than or equal to 256 as client indices (sent over + * the network) are 8 bits. It needs 1 more for the dedicated server. */ MAX_CLIENT_SLOTS = 256, |