mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r6983) Use the pool macros for the Station pool
This commit is contained in:
parent
470a054c06
commit
f51d2a3311
@ -635,7 +635,7 @@ static bool LoadOldStation(LoadgameState *ls, int num)
|
|||||||
{
|
{
|
||||||
Station *st;
|
Station *st;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_station_pool, num))
|
if (!AddBlockIfNeeded(&_Station_pool, num))
|
||||||
error("Stations: failed loading savegame: too many stations");
|
error("Stations: failed loading savegame: too many stations");
|
||||||
|
|
||||||
st = GetStation(num);
|
st = GetStation(num);
|
||||||
|
@ -256,7 +256,7 @@ static void UnInitializeDynamicVariables(void)
|
|||||||
/* Dynamic stuff needs to be free'd somewhere... */
|
/* Dynamic stuff needs to be free'd somewhere... */
|
||||||
CleanPool(&_town_pool);
|
CleanPool(&_town_pool);
|
||||||
CleanPool(&_Industry_pool);
|
CleanPool(&_Industry_pool);
|
||||||
CleanPool(&_station_pool);
|
CleanPool(&_Station_pool);
|
||||||
CleanPool(&_Vehicle_pool);
|
CleanPool(&_Vehicle_pool);
|
||||||
CleanPool(&_Sign_pool);
|
CleanPool(&_Sign_pool);
|
||||||
CleanPool(&_Order_pool);
|
CleanPool(&_Order_pool);
|
||||||
|
@ -1253,7 +1253,7 @@ static void *IntToReference(uint index, SLRefType rt)
|
|||||||
return GetVehicle(index);
|
return GetVehicle(index);
|
||||||
}
|
}
|
||||||
case REF_STATION: {
|
case REF_STATION: {
|
||||||
if (!AddBlockIfNeeded(&_station_pool, index))
|
if (!AddBlockIfNeeded(&_Station_pool, index))
|
||||||
error("Stations: failed loading savegame: too many stations");
|
error("Stations: failed loading savegame: too many stations");
|
||||||
return GetStation(index);
|
return GetStation(index);
|
||||||
}
|
}
|
||||||
|
20
station.h
20
station.h
@ -142,23 +142,7 @@ void UpdateAllStationVirtCoord(void);
|
|||||||
void RebuildStationLists(void);
|
void RebuildStationLists(void);
|
||||||
void ResortStationLists(void);
|
void ResortStationLists(void);
|
||||||
|
|
||||||
extern MemoryPool _station_pool;
|
DECLARE_POOL(Station, Station, 6, 1000)
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline StationID GetStationArraySize(void)
|
static inline StationID GetStationArraySize(void)
|
||||||
{
|
{
|
||||||
@ -191,7 +175,7 @@ static inline void DeleteStation(Station *st)
|
|||||||
st->xy = 0;
|
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)
|
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,10 +34,6 @@
|
|||||||
#include "date.h"
|
#include "date.h"
|
||||||
|
|
||||||
enum {
|
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) */
|
/* Max roadstops: 64000 (32 * 2000) */
|
||||||
ROADSTOP_POOL_BLOCK_SIZE_BITS = 5, /* In bits, so (1 << 5) == 32 */
|
ROADSTOP_POOL_BLOCK_SIZE_BITS = 5, /* In bits, so (1 << 5) == 32 */
|
||||||
ROADSTOP_POOL_MAX_BLOCKS = 2000,
|
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.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* 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)
|
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++;
|
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 */
|
DEFINE_POOL(Station, Station, StationPoolNewBlock, StationPoolCleanBlock)
|
||||||
MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, &StationPoolCleanBlock, 0, 0, NULL };
|
|
||||||
MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL };
|
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.
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
||||||
* TODO - This is just a temporary stage, this will be removed. */
|
* 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)) {
|
if (!IsValidStation(st)) {
|
||||||
StationID index = st->index;
|
StationID index = st->index;
|
||||||
|
|
||||||
@ -294,7 +289,7 @@ static Station *AllocateStation(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we can add a block to the pool */
|
/* 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;
|
_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -2880,8 +2875,8 @@ static int32 ClearTile_Station(TileIndex tile, byte flags)
|
|||||||
void InitializeStations(void)
|
void InitializeStations(void)
|
||||||
{
|
{
|
||||||
/* Clean the station pool and create 1 block in it */
|
/* Clean the station pool and create 1 block in it */
|
||||||
CleanPool(&_station_pool);
|
CleanPool(&_Station_pool);
|
||||||
AddBlockToPool(&_station_pool);
|
AddBlockToPool(&_Station_pool);
|
||||||
|
|
||||||
/* Clean the roadstop pool and create 1 block in it */
|
/* Clean the roadstop pool and create 1 block in it */
|
||||||
CleanPool(&_roadstop_pool);
|
CleanPool(&_roadstop_pool);
|
||||||
@ -3061,7 +3056,7 @@ static void Load_STNS(void)
|
|||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Station *st;
|
Station *st;
|
||||||
|
|
||||||
if (!AddBlockIfNeeded(&_station_pool, index))
|
if (!AddBlockIfNeeded(&_Station_pool, index))
|
||||||
error("Stations: failed loading savegame: too many stations");
|
error("Stations: failed loading savegame: too many stations");
|
||||||
|
|
||||||
st = GetStation(index);
|
st = GetStation(index);
|
||||||
|
Loading…
Reference in New Issue
Block a user