summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-10-28 11:48:21 +0000
committertron <tron@openttd.org>2006-10-28 11:48:21 +0000
commitf51d2a3311b56f9390c792324430305585644f0d (patch)
tree3ffe678fb18ee1f4bec34159eb8c4eec6d427815
parent470a054c061bbe8d3ec9160a52f79f6314bfa86a (diff)
downloadopenttd-f51d2a3311b56f9390c792324430305585644f0d.tar.xz
(svn r6983) Use the pool macros for the Station pool
-rw-r--r--oldloader.c2
-rw-r--r--openttd.c2
-rw-r--r--saveload.c2
-rw-r--r--station.h20
-rw-r--r--station_cmd.c19
5 files changed, 12 insertions, 33 deletions
diff --git a/oldloader.c b/oldloader.c
index d9faba895..4bc40c2f0 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -635,7 +635,7 @@ static bool LoadOldStation(LoadgameState *ls, int num)
{
Station *st;
- if (!AddBlockIfNeeded(&_station_pool, num))
+ if (!AddBlockIfNeeded(&_Station_pool, num))
error("Stations: failed loading savegame: too many stations");
st = GetStation(num);
diff --git a/openttd.c b/openttd.c
index ca41e23e5..ef9e3a95b 100644
--- a/openttd.c
+++ b/openttd.c
@@ -256,7 +256,7 @@ static void UnInitializeDynamicVariables(void)
/* Dynamic stuff needs to be free'd somewhere... */
CleanPool(&_town_pool);
CleanPool(&_Industry_pool);
- CleanPool(&_station_pool);
+ CleanPool(&_Station_pool);
CleanPool(&_Vehicle_pool);
CleanPool(&_Sign_pool);
CleanPool(&_Order_pool);
diff --git a/saveload.c b/saveload.c
index 0818ebaca..de693d41d 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1253,7 +1253,7 @@ static void *IntToReference(uint index, SLRefType rt)
return GetVehicle(index);
}
case REF_STATION: {
- if (!AddBlockIfNeeded(&_station_pool, index))
+ if (!AddBlockIfNeeded(&_Station_pool, index))
error("Stations: failed loading savegame: too many stations");
return GetStation(index);
}
diff --git a/station.h b/station.h
index 91d18839e..6edb573d5 100644
--- a/station.h
+++ b/station.h
@@ -142,23 +142,7 @@ void UpdateAllStationVirtCoord(void);
void RebuildStationLists(void);
void ResortStationLists(void);
-extern MemoryPool _station_pool;
-
-/**
- * Get the pointer to the station with index 'index'
- */
-static inline Station *GetStation(StationID index)
-{
- return (Station*)GetItemFromPool(&_station_pool, index);
-}
-
-/**
- * Get the current size of the StationPool
- */
-static inline uint16 GetStationPoolSize(void)
-{
- return _station_pool.total_items;
-}
+DECLARE_POOL(Station, Station, 6, 1000)
static inline StationID GetStationArraySize(void)
{
@@ -191,7 +175,7 @@ static inline void DeleteStation(Station *st)
st->xy = 0;
}
-#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st))
+#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (IsValidStation(st))
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
diff --git a/station_cmd.c b/station_cmd.c
index c0a40892a..3afe1bff3 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -34,10 +34,6 @@
#include "date.h"
enum {
- /* Max stations: 64000 (64 * 1000) */
- STATION_POOL_BLOCK_SIZE_BITS = 6, /* In bits, so (1 << 6) == 64 */
- STATION_POOL_MAX_BLOCKS = 1000,
-
/* Max roadstops: 64000 (32 * 2000) */
ROADSTOP_POOL_BLOCK_SIZE_BITS = 5, /* In bits, so (1 << 5) == 32 */
ROADSTOP_POOL_MAX_BLOCKS = 2000,
@@ -52,7 +48,7 @@ static void StationPoolNewBlock(uint start_item)
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* TODO - This is just a temporary stage, this will be removed. */
- for (st = GetStation(start_item); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) st->index = start_item++;
+ for (st = GetStation(start_item); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) st->index = start_item++;
}
static void StationPoolCleanBlock(uint start_item, uint end_item)
@@ -78,8 +74,7 @@ static void RoadStopPoolNewBlock(uint start_item)
for (rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) rs->index = start_item++;
}
-/* Initialize the station-pool and roadstop-pool */
-MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, &StationPoolCleanBlock, 0, 0, NULL };
+DEFINE_POOL(Station, Station, StationPoolNewBlock, StationPoolCleanBlock)
MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL };
@@ -282,7 +277,7 @@ static Station *AllocateStation(void)
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* TODO - This is just a temporary stage, this will be removed. */
- for (st = GetStation(0); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) {
+ for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
if (!IsValidStation(st)) {
StationID index = st->index;
@@ -294,7 +289,7 @@ static Station *AllocateStation(void)
}
/* Check if we can add a block to the pool */
- if (AddBlockToPool(&_station_pool)) return AllocateStation();
+ if (AddBlockToPool(&_Station_pool)) return AllocateStation();
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
return NULL;
@@ -2880,8 +2875,8 @@ static int32 ClearTile_Station(TileIndex tile, byte flags)
void InitializeStations(void)
{
/* Clean the station pool and create 1 block in it */
- CleanPool(&_station_pool);
- AddBlockToPool(&_station_pool);
+ CleanPool(&_Station_pool);
+ AddBlockToPool(&_Station_pool);
/* Clean the roadstop pool and create 1 block in it */
CleanPool(&_roadstop_pool);
@@ -3061,7 +3056,7 @@ static void Load_STNS(void)
while ((index = SlIterateArray()) != -1) {
Station *st;
- if (!AddBlockIfNeeded(&_station_pool, index))
+ if (!AddBlockIfNeeded(&_Station_pool, index))
error("Stations: failed loading savegame: too many stations");
st = GetStation(index);