summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/autoreplace.cpp5
-rw-r--r--src/cargopacket.cpp8
-rw-r--r--src/cargopacket.h2
-rw-r--r--src/company_cmd.cpp1
-rw-r--r--src/core/pool_func.cpp7
-rw-r--r--src/core/pool_func.hpp5
-rw-r--r--src/core/pool_type.hpp24
-rw-r--r--src/depot.cpp5
-rw-r--r--src/depot_func.h1
-rw-r--r--src/group.h1
-rw-r--r--src/group_cmd.cpp5
-rw-r--r--src/industry_cmd.cpp2
-rw-r--r--src/misc.cpp24
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_admin.h2
-rw-r--r--src/network/network_base.h2
-rw-r--r--src/network/network_server.h2
-rw-r--r--src/newgrf_spritegroup.h2
-rw-r--r--src/object_cmd.cpp1
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/order_backup.cpp5
-rw-r--r--src/order_cmd.cpp6
-rw-r--r--src/roadstop.cpp6
-rw-r--r--src/signs.cpp10
-rw-r--r--src/station.cpp6
-rw-r--r--src/subsidy.cpp8
-rw-r--r--src/town_cmd.cpp5
-rw-r--r--src/vehicle.cpp3
28 files changed, 37 insertions, 117 deletions
diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp
index 18a5c4e3b..464aa354a 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 012ae78f5..55c62cd02 100644
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -18,14 +18,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.
*/
CargoPacket::CargoPacket()
diff --git a/src/cargopacket.h b/src/cargopacket.h
index 063896476..0f2e46177 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<CargoPacket, CargoPacketID, 1024, 0xFFF000, true, false> CargoPacketPool;
+typedef Pool<CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false> CargoPacketPool;
/** The actual pool with cargo packets. */
extern CargoPacketPool _cargopacket_pool;
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index b2f42d538..b5764d732 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 7b65b96a4..999dbe3d9 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 299aee86c..0d9c23165 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 <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, bool Tcache, bool Tzero> \
- type Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero>
+ template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type, bool Tcache, bool Tzero> \
+ type Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero>
/**
* 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 9f4f8d99c..e5e58238c 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<struct PoolBase *, 4> 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 <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
+template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
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 <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero> *Tpool>
+ template <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero> *Tpool>
struct PoolItem {
Tindex index; ///< Index of this pool item
diff --git a/src/depot.cpp b/src/depot.cpp
index b666ca879..e09179b69 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 46c754b48..c11901025 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 46a12d9e2..335b4c768 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 cfa6a3fb5..3cd6f6757 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 9a47a43c5..84b9ef931 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 40fd7e0d8..09ace072d 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 04268dbf6..308a493b0 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 d9f64c73e..874aaf787 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<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS> NetworkAdminSocketPool;
+typedef Pool<ServerNetworkAdminSocketHandler, AdminIndex, 2, MAX_ADMINS, PT_NADMIN> 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 219afe927..86a444cb1 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<NetworkClientInfo, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientInfoPool;
+typedef Pool<NetworkClientInfo, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT> 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 1ea273ffa..5fda5b257 100644
--- a/src/network/network_server.h
+++ b/src/network/network_server.h
@@ -20,7 +20,7 @@
class ServerNetworkGameSocketHandler;
typedef ServerNetworkGameSocketHandler NetworkClientSocket;
-typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientSocketPool;
+typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT> 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 232382cba..da4d5e5df 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<SpriteGroup, SpriteGroupID, 1024, 1 << 30> SpriteGroupPool;
+typedef Pool<SpriteGroup, SpriteGroupID, 1024, 1 << 30, PT_DATA> 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 6603ed1bc..2f8dcda03 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 a39ef57e8..415f822cc 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 9632fa3e1..00645c852 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 d327aa252..f8a553024 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 921125f08..74d8aa749 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 536644bf9..06ea3664c 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 8933015f8..0cfcf027c 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 b53c73758..d4e701298 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 3ca3e3ddb..25f59d174 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 573610c6d..e3ffbbc91 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();