summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-10-28 10:55:59 +0000
committertron <tron@openttd.org>2006-10-28 10:55:59 +0000
commitfd9e71999b6ac9e55b2a88f3221ab0e660934953 (patch)
tree8b0e233f3a0470fc60d6453aee27da317a3f2692
parentbb6818aa5c39f373395dc32bd37ce3e4d914e516 (diff)
downloadopenttd-fd9e71999b6ac9e55b2a88f3221ab0e660934953.tar.xz
(svn r6975) Use the pool macros for the Vehicle pool
-rw-r--r--date.c2
-rw-r--r--oldloader.c2
-rw-r--r--openttd.c2
-rw-r--r--saveload.c4
-rw-r--r--vehicle.c30
-rw-r--r--vehicle.h20
6 files changed, 20 insertions, 40 deletions
diff --git a/date.c b/date.c
index c9b02d013..8401baa31 100644
--- a/date.c
+++ b/date.c
@@ -196,7 +196,7 @@ static const Month _autosave_months[] = {
*/
static void RunVehicleDayProc(uint daytick)
{
- uint total = _vehicle_pool.total_items;
+ uint total = GetVehiclePoolSize();
uint i;
for (i = daytick; i < total; i += DAY_TICKS) {
diff --git a/oldloader.c b/oldloader.c
index 52d2d1258..8675b9b9d 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -1196,7 +1196,7 @@ static bool LoadOldVehicle(LoadgameState *ls, int num)
_current_vehicle_id = num * _old_vehicle_multiplier + i;
- if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id))
+ if (!AddBlockIfNeeded(&_Vehicle_pool, _current_vehicle_id))
error("Vehicles: failed loading savegame: too many vehicles");
v = GetVehicle(_current_vehicle_id);
diff --git a/openttd.c b/openttd.c
index cd28d9697..89b755cae 100644
--- a/openttd.c
+++ b/openttd.c
@@ -257,7 +257,7 @@ static void UnInitializeDynamicVariables(void)
CleanPool(&_town_pool);
CleanPool(&_industry_pool);
CleanPool(&_station_pool);
- CleanPool(&_vehicle_pool);
+ CleanPool(&_Vehicle_pool);
CleanPool(&_sign_pool);
CleanPool(&_order_pool);
diff --git a/saveload.c b/saveload.c
index 2f837e886..a1bea9dd4 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1253,7 +1253,7 @@ static void *IntToReference(uint index, SLRefType rt)
return GetOrder(index);
}
case REF_VEHICLE: {
- if (!AddBlockIfNeeded(&_vehicle_pool, index))
+ if (!AddBlockIfNeeded(&_Vehicle_pool, index))
error("Vehicles: failed loading savegame: too many vehicles");
return GetVehicle(index);
}
@@ -1286,7 +1286,7 @@ static void *IntToReference(uint index, SLRefType rt)
if (index == INVALID_VEHICLE)
return NULL;
- if (!AddBlockIfNeeded(&_vehicle_pool, index))
+ if (!AddBlockIfNeeded(&_Vehicle_pool, index))
error("Vehicles: failed loading savegame: too many vehicles");
return GetVehicle(index);
}
diff --git a/vehicle.c b/vehicle.c
index 85430e8c9..353c4b293 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -79,10 +79,6 @@ const uint32 _send_to_depot_proc_table[] = {
enum {
- /* Max vehicles: 64000 (512 * 125) */
- VEHICLES_POOL_BLOCK_SIZE_BITS = 9, /* In bits, so (1 << 9) == 512 */
- VEHICLES_POOL_MAX_BLOCKS = 125,
-
BLOCKS_FOR_SPECIAL_VEHICLES = 2, ///< Blocks needed for special vehicles
};
@@ -95,11 +91,11 @@ static void VehiclePoolNewBlock(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 (v = GetVehicle(start_item); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) v->index = start_item++;
+ for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) v->index = start_item++;
}
/* Initialize the vehicle-pool */
-MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, NULL, 0, 0, NULL };
+DEFINE_POOL(Vehicle, Vehicle, VehiclePoolNewBlock, NULL)
void VehicleServiceInDepot(Vehicle *v)
{
@@ -297,9 +293,9 @@ Vehicle *ForceAllocateSpecialVehicle(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 (v = GetVehicle(0); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
+ for (v = GetVehicle(0); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
/* No more room for the special vehicles, return NULL */
- if (v->index >= (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES)
+ if (v->index >= (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES)
return NULL;
if (!IsValidVehicle(v)) return InitializeVehicle(v);
@@ -314,26 +310,26 @@ Vehicle *ForceAllocateSpecialVehicle(void)
* *skip_vehicles is an offset to where in the array we should begin looking
* this is to avoid looping though the same vehicles more than once after we learned that they are not free
* this feature is used by AllocateVehicles() since it need to allocate more than one and when
- * another block is added to _vehicle_pool, since we only do that when we know it's already full
+ * another block is added to _Vehicle_pool, since we only do that when we know it's already full
*/
static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles)
{
/* See note by ForceAllocateSpecialVehicle() why we skip the
* first blocks */
Vehicle *v;
- const int offset = (1 << VEHICLES_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES;
+ const int offset = (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES;
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* TODO - This is just a temporary stage, this will be removed. */
- if (*skip_vehicles < (_vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself
- for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
+ if (*skip_vehicles < (_Vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself
+ for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
(*skip_vehicles)++;
if (!IsValidVehicle(v)) return InitializeVehicle(v);
}
}
/* Check if we can add a block to the pool */
- if (AddBlockToPool(&_vehicle_pool))
+ if (AddBlockToPool(&_Vehicle_pool))
return AllocateSingleVehicle(skip_vehicles);
return NULL;
@@ -451,10 +447,10 @@ void InitializeVehicles(void)
/* Clean the vehicle pool, and reserve enough blocks
* for the special vehicles, plus one for all the other
* vehicles (which is increased on-the-fly) */
- CleanPool(&_vehicle_pool);
- AddBlockToPool(&_vehicle_pool);
+ CleanPool(&_Vehicle_pool);
+ AddBlockToPool(&_Vehicle_pool);
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++)
- AddBlockToPool(&_vehicle_pool);
+ AddBlockToPool(&_Vehicle_pool);
for (i = 0; i < lengthof(_vehicle_position_hash); i++) {
_vehicle_position_hash[i] = INVALID_VEHICLE;
@@ -3177,7 +3173,7 @@ static void Load_VEHS(void)
while ((index = SlIterateArray()) != -1) {
Vehicle *v;
- if (!AddBlockIfNeeded(&_vehicle_pool, index))
+ if (!AddBlockIfNeeded(&_Vehicle_pool, index))
error("Vehicles: failed loading savegame: too many vehicles");
v = GetVehicle(index);
diff --git a/vehicle.h b/vehicle.h
index fc6645ff1..ef57eaee2 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -359,23 +359,7 @@ Direction GetDirectionTowards(const Vehicle* v, int x, int y);
#define BEGIN_ENUM_WAGONS(v) do {
#define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL);
-extern MemoryPool _vehicle_pool;
-
-/**
- * Get the pointer to the vehicle with index 'index'
- */
-static inline Vehicle *GetVehicle(VehicleID index)
-{
- return (Vehicle*)GetItemFromPool(&_vehicle_pool, index);
-}
-
-/**
- * Get the current size of the VehiclePool
- */
-static inline uint16 GetVehiclePoolSize(void)
-{
- return _vehicle_pool.total_items;
-}
+DECLARE_POOL(Vehicle, Vehicle, 9, 125)
static inline VehicleID GetVehicleArraySize(void)
{
@@ -403,7 +387,7 @@ static inline void DeleteVehicle(Vehicle *v)
v->type = 0;
}
-#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
+#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) if (IsValidVehicle(v))
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
/**