From 756cc6cf651aa5650f055c70f31f7e07391be8c6 Mon Sep 17 00:00:00 2001 From: smatz Date: Sat, 19 Feb 2011 23:05:47 +0000 Subject: [PATCH] (svn r22116) -Codechange: use PoolBase::Clean() at more places --- src/autoreplace.cpp | 5 ----- src/cargopacket.cpp | 8 -------- src/cargopacket.h | 2 +- src/company_cmd.cpp | 1 - src/core/pool_func.cpp | 7 ++++--- src/core/pool_func.hpp | 5 +++-- src/core/pool_type.hpp | 24 ++++++++++++++++++++---- src/depot.cpp | 5 ----- src/depot_func.h | 1 - src/group.h | 1 - src/group_cmd.cpp | 5 ----- src/industry_cmd.cpp | 2 -- src/misc.cpp | 24 +++--------------------- src/network/network.cpp | 4 +--- src/network/network_admin.h | 2 +- src/network/network_base.h | 2 +- src/network/network_server.h | 2 +- src/newgrf_spritegroup.h | 2 +- src/object_cmd.cpp | 1 - src/openttd.cpp | 2 +- src/order_backup.cpp | 5 ----- src/order_cmd.cpp | 6 ------ src/roadstop.cpp | 6 ------ src/signs.cpp | 10 ---------- src/station.cpp | 6 ------ src/subsidy.cpp | 8 -------- src/town_cmd.cpp | 5 ----- src/vehicle.cpp | 3 --- 28 files changed, 37 insertions(+), 117 deletions(-) diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp index 18a5c4e3bc..464aa354a1 100644 --- a/src/autoreplace.cpp +++ b/src/autoreplace.cpp @@ -134,8 +134,3 @@ CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, Group return CMD_ERROR; } - -void InitializeEngineRenews() -{ - _enginerenew_pool.CleanPool(); -} diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 012ae78f50..55c62cd02e 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -17,14 +17,6 @@ CargoPacketPool _cargopacket_pool("CargoPacket"); INSTANTIATE_POOL_METHODS(CargoPacket) -/** - * Initialize, i.e. clean, the pool with cargo packets. - */ -void InitializeCargoPackets() -{ - _cargopacket_pool.CleanPool(); -} - /** * Create a new packet for savegame loading. */ diff --git a/src/cargopacket.h b/src/cargopacket.h index 063896476a..0f2e461770 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -24,7 +24,7 @@ typedef uint32 CargoPacketID; struct CargoPacket; /** Type of the pool for cargo packets for a little over 16 million packets. */ -typedef Pool CargoPacketPool; +typedef Pool CargoPacketPool; /** The actual pool with cargo packets. */ extern CargoPacketPool _cargopacket_pool; diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index b2f42d5384..b5764d7326 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -601,7 +601,6 @@ static void MaybeStartNewCompany() /** Initialize the pool of companies. */ void InitializeCompanies() { - _company_pool.CleanPool(); _cur_company_tick_index = 0; } diff --git a/src/core/pool_func.cpp b/src/core/pool_func.cpp index 7b65b96a4b..999dbe3d95 100644 --- a/src/core/pool_func.cpp +++ b/src/core/pool_func.cpp @@ -24,14 +24,15 @@ PoolBase::~PoolBase() } /** - * Clean all pools - calls Pool::CleanPool() + * Clean all pools of given type. + * @param pt pool types to clean. */ -/* static */ void PoolBase::CleanAll() +/* static */ void PoolBase::Clean(PoolType pt) { PoolVector *pools = PoolBase::GetPools(); PoolBase **end = pools->End(); for (PoolBase **ppool = pools->Begin(); ppool != end; ppool++) { PoolBase *pool = *ppool; - pool->CleanPool(); + if (pool->type & pt) pool->CleanPool(); } } diff --git a/src/core/pool_func.hpp b/src/core/pool_func.hpp index 299aee86ce..0d9c231653 100644 --- a/src/core/pool_func.hpp +++ b/src/core/pool_func.hpp @@ -17,14 +17,15 @@ #include "pool_type.hpp" #define DEFINE_POOL_METHOD(type) \ - template \ - type Pool + template \ + type Pool /** * Create a clean pool. * @param name The name for the pool. */ DEFINE_POOL_METHOD(inline)::Pool(const char *name) : + PoolBase(Tpool_type), name(name), size(0), first_free(0), diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp index 9f4f8d99c8..e5e58238c7 100644 --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -13,11 +13,25 @@ #define POOL_TYPE_HPP #include "smallvec_type.hpp" +#include "enum_type.hpp" + +/** Various types of a pool. */ +enum PoolType { + 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. +}; +DECLARE_ENUM_AS_BIT_SET(PoolType) typedef SmallVector PoolVector; ///< Vector of pointers to PoolBase /** Base class for base of all pools. */ struct PoolBase { + const PoolType type; ///< Type of this pool. + /** * Function used to access the vector of all pools. * @return pointer to vector of all pools @@ -28,12 +42,13 @@ struct PoolBase { return pools; } - static void CleanAll(); + static void Clean(PoolType); /** * Contructor registers this object in the pool vector. + * @param pt type of this pool. */ - PoolBase() + PoolBase(PoolType pt) : type(pt) { *PoolBase::GetPools()->Append() = this; } @@ -52,11 +67,12 @@ struct PoolBase { * @tparam Tindex Type of the index for this pool * @tparam Tgrowth_step Size of growths; if the pool is full increase the size by this amount * @tparam Tmax_size Maximum size of the pool + * @tparam Tpool_type Type of this pool * @tparam Tcache Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory * @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 +template struct Pool : PoolBase { static const size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside @@ -116,7 +132,7 @@ struct Pool : PoolBase { * Base class for all PoolItems * @tparam Tpool The pool this item is going to be part of */ - template *Tpool> + template *Tpool> struct PoolItem { Tindex index; ///< Index of this pool item diff --git a/src/depot.cpp b/src/depot.cpp index b666ca8799..e09179b690 100644 --- a/src/depot.cpp +++ b/src/depot.cpp @@ -52,8 +52,3 @@ Depot::~Depot() } DeleteWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack()); } - -void InitializeDepots() -{ - _depot_pool.CleanPool(); -} diff --git a/src/depot_func.h b/src/depot_func.h index 46c754b48d..c11901025b 100644 --- a/src/depot_func.h +++ b/src/depot_func.h @@ -18,7 +18,6 @@ #include "slope_type.h" void ShowDepotWindow(TileIndex tile, VehicleType type); -void InitializeDepots(); void DeleteDepotHighlightOfVehicle(const Vehicle *v); diff --git a/src/group.h b/src/group.h index 46a12d9e28..335b4c7685 100644 --- a/src/group.h +++ b/src/group.h @@ -82,7 +82,6 @@ static inline void DecreaseGroupNumVehicle(GroupID id_g) } -void InitializeGroup(); void SetTrainGroupID(Train *v, GroupID grp); void UpdateTrainGroupID(Train *v); void RemoveVehicleFromGroup(const Vehicle *v); diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index cfa6a3fb52..3cd6f67577 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -67,11 +67,6 @@ Group::~Group() free(this->num_engines); } -void InitializeGroup() -{ - _group_pool.CleanPool(); -} - /** * Create a new vehicle group. diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 9a47a43c56..84b9ef9317 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2638,8 +2638,6 @@ void IndustryMonthlyLoop() void InitializeIndustries() { - _industry_pool.CleanPool(); - Industry::ResetIndustryCounts(); _industry_sound_tile = 0; diff --git a/src/misc.cpp b/src/misc.cpp index 40fd7e0d85..09ace072d1 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -25,6 +25,7 @@ #include "tilehighlight_func.h" #include "network/network_func.h" #include "window_func.h" +#include "core/pool_type.hpp" extern TileIndex _cur_tileloop_tile; @@ -33,10 +34,6 @@ extern void MakeNewgameSettingsLive(); void InitializeSound(); void InitializeMusic(); void InitializeVehicles(); -void InitializeDepots(); -void InitializeEngineRenews(); -void InitializeOrders(); -void InitializeOrderBackups(); void InitializeClearLand(); void InitializeRailGui(); void InitializeRoadGui(); @@ -45,13 +42,7 @@ void InitializeDockGui(); void InitializeObjectGui(); void InitializeIndustries(); void InitializeObjects(); -void InitializeTowns(); -void InitializeSubsidies(); void InitializeTrees(); -void InitializeSigns(); -void InitializeStations(); -void InitializeRoadStops(); -void InitializeCargoPackets(); void InitializeCompanies(); void InitializeCheats(); void InitializeNPF(); @@ -77,15 +68,12 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin InitializeOldNames(); } + PoolBase::Clean(PT_NORMAL); + InitializeSound(); InitializeMusic(); - InitializeEngineRenews(); InitializeVehicles(); - InitializeDepots(); - InitializeOrders(); - InitializeOrderBackups(); - InitializeGroup(); InitNewsItemStructs(); InitializeLandscape(); @@ -96,13 +84,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin InitializeDockGui(); InitializeObjectGui(); InitializeAIGui(); - InitializeTowns(); - InitializeSubsidies(); InitializeTrees(); - InitializeSigns(); - InitializeStations(); - InitializeRoadStops(); - InitializeCargoPackets(); InitializeIndustries(); InitializeObjects(); InitializeBuildingCounts(); diff --git a/src/network/network.cpp b/src/network/network.cpp index 04268dbf6e..308a493b04 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -493,9 +493,7 @@ void ParseConnectionString(const char **company, const char **port, char *connec */ static void InitializeNetworkPools(bool close_admins = true) { - _networkclientsocket_pool.CleanPool(); - _networkclientinfo_pool.CleanPool(); - if (close_admins) _networkadminsocket_pool.CleanPool(); + PoolBase::Clean(PT_NCLIENT | (close_admins ? PT_NADMIN : PT_NONE)); } /** diff --git a/src/network/network_admin.h b/src/network/network_admin.h index d9f64c73e7..874aaf787b 100644 --- a/src/network/network_admin.h +++ b/src/network/network_admin.h @@ -21,7 +21,7 @@ extern AdminIndex _redirect_console_to_admin; class ServerNetworkAdminSocketHandler; -typedef Pool NetworkAdminSocketPool; +typedef Pool NetworkAdminSocketPool; extern NetworkAdminSocketPool _networkadminsocket_pool; /** Class for handling the server side of the game connection. */ diff --git a/src/network/network_base.h b/src/network/network_base.h index 219afe9270..86a444cb1d 100644 --- a/src/network/network_base.h +++ b/src/network/network_base.h @@ -19,7 +19,7 @@ #include "../core/pool_type.hpp" #include "../company_type.h" -typedef Pool NetworkClientInfoPool; +typedef Pool NetworkClientInfoPool; extern NetworkClientInfoPool _networkclientinfo_pool; struct NetworkClientInfo : NetworkClientInfoPool::PoolItem<&_networkclientinfo_pool> { diff --git a/src/network/network_server.h b/src/network/network_server.h index 1ea273ffa8..5fda5b2571 100644 --- a/src/network/network_server.h +++ b/src/network/network_server.h @@ -20,7 +20,7 @@ class ServerNetworkGameSocketHandler; typedef ServerNetworkGameSocketHandler NetworkClientSocket; -typedef Pool NetworkClientSocketPool; +typedef Pool NetworkClientSocketPool; extern NetworkClientSocketPool _networkclientsocket_pool; /** Class for handling the server side of the game connection. */ diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 232382cba7..da4d5e5df8 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -52,7 +52,7 @@ typedef uint32 SpriteGroupID; /* 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 SpriteGroupPool; +typedef Pool SpriteGroupPool; extern SpriteGroupPool _spritegroup_pool; /* Common wrapper for all the different sprite group types */ diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 6603ed1bcd..2f8dcda038 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -55,7 +55,6 @@ uint16 Object::counts[NUM_OBJECTS]; /** Initialize/reset the objects. */ void InitializeObjects() { - _object_pool.CleanPool(); Object::ResetTypeCounts(); } diff --git a/src/openttd.cpp b/src/openttd.cpp index a39ef57e89..415f822cca 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -270,7 +270,7 @@ static void ShutdownGame() free(_config_file); #endif - PoolBase::CleanAll(); + PoolBase::Clean(PT_ALL); ResetNewGRFData(); diff --git a/src/order_backup.cpp b/src/order_backup.cpp index 9632fa3e19..00645c8527 100644 --- a/src/order_backup.cpp +++ b/src/order_backup.cpp @@ -254,8 +254,3 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1, } } } - -void InitializeOrderBackups() -{ - _order_backup_pool.CleanPool(); -} diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index d327aa2529..f8a5530246 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -2009,9 +2009,3 @@ bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const /* Finally do stop when there is no non-stop flag set for this type of station. */ !(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS)); } - -void InitializeOrders() -{ - _order_pool.CleanPool(); - _orderlist_pool.CleanPool(); -} diff --git a/src/roadstop.cpp b/src/roadstop.cpp index 921125f084..74d8aa749e 100644 --- a/src/roadstop.cpp +++ b/src/roadstop.cpp @@ -387,9 +387,3 @@ void RoadStop::Entry::CheckIntegrity(const RoadStop *rs) const temp.Rebuild(rs, rs->east == this); if (temp.length != this->length || temp.occupied != this->occupied) NOT_REACHED(); } - - -void InitializeRoadStops() -{ - _roadstop_pool.CleanPool(); -} diff --git a/src/signs.cpp b/src/signs.cpp index 536644bf9c..06ea3664c0 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -59,13 +59,3 @@ void UpdateAllSignVirtCoords() si->UpdateVirtCoord(); } } - -/** - * - * Initialize the signs - * - */ -void InitializeSigns() -{ - _sign_pool.CleanPool(); -} diff --git a/src/station.cpp b/src/station.cpp index 8933015f89..0cfcf027c0 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -514,9 +514,3 @@ StationRect& StationRect::operator = (const Rect &src) this->bottom = src.bottom; return *this; } - - -void InitializeStations() -{ - _station_pool.CleanPool(); -} diff --git a/src/subsidy.cpp b/src/subsidy.cpp index b53c737587..d4e701298b 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -62,14 +62,6 @@ void Subsidy::AwardTo(CompanyID company) InvalidateWindowData(WC_SUBSIDIES_LIST, 0); } -/** - * Initializes subsidies, files don't have to include subsidy_base,h this way - */ -void InitializeSubsidies() -{ - _subsidy_pool.CleanPool(); -} - Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode) { NewsReferenceType reftype1 = NR_NONE; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 3ca3e3ddb9..25f59d1740 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -3028,11 +3028,6 @@ void TownsYearlyLoop() } } -void InitializeTowns() -{ - _town_pool.CleanPool(); -} - static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) { if (AutoslopeEnabled()) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 573610c6da..e3ffbbc91e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -586,9 +586,6 @@ static AutoreplaceMap _vehicles_to_autoreplace; void InitializeVehicles() { - _vehicle_pool.CleanPool(); - _cargo_payment_pool.CleanPool(); - _age_cargo_skip_counter = 1; _vehicles_to_autoreplace.Reset();