summaryrefslogtreecommitdiff
path: root/src/network/network_base.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-23 20:52:27 +0000
committerrubidium <rubidium@openttd.org>2008-12-23 20:52:27 +0000
commitafddfcb2b1a37358459158ce83a64535f13cd05e (patch)
tree5fc12b987e4ccf94d7c727fd7c3eccc1826b870a /src/network/network_base.h
parent94dd23aaf86cb1c22ce78d8555261d045de0ee60 (diff)
downloadopenttd-afddfcb2b1a37358459158ce83a64535f13cd05e.tar.xz
(svn r14730) -Codechange: remove the need for networkclientsockets and networkclientinfo structs to be in a contiguous piece of memory and put them in a pool.
-Note: 255 should really be enough for now... making it any more means network protocol bumps.
Diffstat (limited to 'src/network/network_base.h')
-rw-r--r--src/network/network_base.h18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/network/network_base.h b/src/network/network_base.h
index e8171a027..be3ada0c8 100644
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -8,8 +8,11 @@
#ifdef ENABLE_NETWORK
#include "network_type.h"
+#include "../oldpool.h"
-struct NetworkClientInfo {
+DECLARE_OLD_POOL(NetworkClientInfo, NetworkClientInfo, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK);
+
+struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_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
@@ -18,21 +21,18 @@ struct NetworkClientInfo {
Date join_date; ///< Gamedate the client has joined
char unique_id[NETWORK_UNIQUE_ID_LENGTH]; ///< Every play sends an unique id so we can indentify him
+ 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; }
};
-static NetworkClientInfo *GetNetworkClientInfo(int ci)
-{
- extern NetworkClientInfo _network_client_info[MAX_CLIENT_SLOTS];
- return &_network_client_info[ci];
-}
-
static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
{
- return (uint)index < MAX_CLIENT_SLOTS && GetNetworkClientInfo(index)->IsValid();
+ return (uint)index < GetNetworkClientInfoPoolSize() && GetNetworkClientInfo(index)->IsValid();
}
-#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (ci = GetNetworkClientInfo(start); ci != GetNetworkClientInfo(MAX_CLIENT_SLOTS); ci++) if (ci->IsValid())
+#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (d = GetNetworkClientInfo(start); d != NULL; d = (d->index + 1U < GetNetworkClientInfoPoolSize()) ? GetNetworkClientInfo(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
#endif /* ENABLE_NETWORK */