Codechange: Use EnumBitSet for pool types

This commit is contained in:
Rubidium 2025-02-01 13:30:03 +01:00 committed by rubidium42
parent c4c5028862
commit 89d0a688a9
9 changed files with 20 additions and 19 deletions

View File

@ -24,7 +24,7 @@ typedef uint32_t CargoPacketID;
struct CargoPacket;
/** Type of the pool for cargo packets for a little over 16 million packets. */
typedef Pool<CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false> CargoPacketPool;
using CargoPacketPool = Pool<CargoPacket, CargoPacketID, 1024, 0xFFF000, PoolType::Normal, true, false>;
/** The actual pool with cargo packets. */
extern CargoPacketPool _cargopacket_pool;

View File

@ -27,9 +27,9 @@
* Clean all pools of given type.
* @param pt pool types to clean.
*/
/* static */ void PoolBase::Clean(PoolType pt)
/* static */ void PoolBase::Clean(PoolTypes pt)
{
for (PoolBase *pool : *PoolBase::GetPools()) {
if (pool->type & pt) pool->CleanPool();
if (pt.Test(pool->type)) pool->CleanPool();
}
}

View File

@ -13,15 +13,14 @@
#include "enum_type.hpp"
/** Various types of a pool. */
enum PoolType : uint8_t {
PT_NONE = 0x00, ///< No pool is selected.
PT_NORMAL = 0x01, ///< Normal pool containing game objects.
PT_NCLIENT = 0x02, ///< Network client pools.
PT_NADMIN = 0x04, ///< Network admin pool.
PT_DATA = 0x08, ///< NewGRF or other data, that is not reset together with normal pools.
PT_ALL = 0x0F, ///< All pool types.
enum class PoolType : uint8_t {
Normal, ///< Normal pool containing game objects.
NetworkClient, ///< Network client pools.
NetworkAdmin, ///< Network admin pool.
Data, ///< NewGRF or other data, that is not reset together with normal pools.
};
DECLARE_ENUM_AS_BIT_SET(PoolType)
using PoolTypes = EnumBitSet<PoolType, uint8_t>;
static constexpr PoolTypes PT_ALL = {PoolType::Normal, PoolType::NetworkClient, PoolType::NetworkAdmin, PoolType::Data};
typedef std::vector<struct PoolBase *> PoolVector; ///< Vector of pointers to PoolBase
@ -39,7 +38,7 @@ struct PoolBase {
return pools;
}
static void Clean(PoolType);
static void Clean(PoolTypes);
/**
* Constructor registers this object in the pool vector.
@ -76,7 +75,7 @@ private:
* @tparam Tzero Whether to zero the memory
* @warning when Tcache is enabled *all* instances of this pool's item must be of the same size.
*/
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PoolType::Normal, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
private:
/** Some helper functions to get the maximum value of the provided index. */

View File

@ -121,7 +121,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
}
LinkGraphSchedule::Clear();
PoolBase::Clean(PT_NORMAL);
PoolBase::Clean(PoolType::Normal);
RebuildStationKdtree();
RebuildTownKdtree();

View File

@ -582,7 +582,9 @@ NetworkAddress ParseConnectionString(const std::string &connection_string, uint1
*/
static void InitializeNetworkPools(bool close_admins = true)
{
PoolBase::Clean(PT_NCLIENT | (close_admins ? PT_NADMIN : PT_NONE));
PoolTypes to_clean{PoolType::NetworkClient};
if (close_admins) to_clean.Set(PoolType::NetworkAdmin);
PoolBase::Clean(to_clean);
}
/**

View File

@ -18,7 +18,7 @@ extern AdminID _redirect_console_to_admin;
class ServerNetworkAdminSocketHandler;
/** Pool with all admin connections. */
typedef Pool<ServerNetworkAdminSocketHandler, AdminID, 2, 16, PT_NADMIN> NetworkAdminSocketPool;
using NetworkAdminSocketPool = Pool<ServerNetworkAdminSocketHandler, AdminID, 2, 16, PoolType::NetworkAdmin>;
extern NetworkAdminSocketPool _networkadminsocket_pool;
/** Class for handling the server side of the game connection. */

View File

@ -17,7 +17,7 @@
#include "../timer/timer_game_economy.h"
/** Type for the pool with client information. */
using NetworkClientInfoPool = Pool<NetworkClientInfo, ClientPoolID, 8, MAX_CLIENT_SLOTS, PT_NCLIENT>;
using NetworkClientInfoPool = Pool<NetworkClientInfo, ClientPoolID, 8, MAX_CLIENT_SLOTS, PoolType::NetworkClient>;
extern NetworkClientInfoPool _networkclientinfo_pool;
/** Container for all information known about a client. */

View File

@ -17,7 +17,7 @@ class ServerNetworkGameSocketHandler;
/** Make the code look slightly nicer/simpler. */
typedef ServerNetworkGameSocketHandler NetworkClientSocket;
/** Pool with all client sockets. */
using NetworkClientSocketPool = Pool<NetworkClientSocket, ClientPoolID, 8, MAX_CLIENT_SLOTS, PT_NCLIENT>;
using NetworkClientSocketPool = Pool<NetworkClientSocket, ClientPoolID, 8, MAX_CLIENT_SLOTS, PoolType::NetworkClient>;
extern NetworkClientSocketPool _networkclientsocket_pool;
/** Class for handling the server side of the game connection. */

View File

@ -50,7 +50,7 @@ struct ResolverObject;
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite.
* Adding an 'extra' margin would be assuming 64 sprite groups per real
* sprite. 64 = 2^6, so 2^30 should be enough (for now) */
typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1U << 30, PT_DATA> SpriteGroupPool;
using SpriteGroupPool = Pool<SpriteGroup, SpriteGroupID, 1024, 1U << 30, PoolType::Data>;
extern SpriteGroupPool _spritegroup_pool;
/* Common wrapper for all the different sprite group types */