mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-21 13:39:09 +00:00
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
@@ -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; }
|
||||
|
||||
|
@@ -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 */
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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,
|
||||
|
||||
|
Reference in New Issue
Block a user