mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-03 04:43:12 +00:00
(svn r10772) -Codechange: also make use of the generic clean and destroy pool callback functions for vehicle.
This commit is contained in:
parent
48df8b374c
commit
9741094464
@ -78,27 +78,8 @@ const uint32 _send_to_depot_proc_table[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum {
|
|
||||||
BLOCKS_FOR_SPECIAL_VEHICLES = 2, ///< Blocks needed for special vehicles
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called if a new block is added to the vehicle-pool
|
|
||||||
*/
|
|
||||||
static void VehiclePoolNewBlock(uint start_item)
|
|
||||||
{
|
|
||||||
Vehicle *v;
|
|
||||||
|
|
||||||
/* 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 + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) {
|
|
||||||
v->index = start_item++;
|
|
||||||
v = new (v) InvalidVehicle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the vehicle-pool */
|
/* Initialize the vehicle-pool */
|
||||||
DEFINE_OLD_POOL(Vehicle, Vehicle, VehiclePoolNewBlock, NULL)
|
DEFINE_OLD_POOL_GENERIC(Vehicle, Vehicle)
|
||||||
|
|
||||||
void VehicleServiceInDepot(Vehicle *v)
|
void VehicleServiceInDepot(Vehicle *v)
|
||||||
{
|
{
|
||||||
@ -473,16 +454,8 @@ void ResetVehiclePosHash()
|
|||||||
|
|
||||||
void InitializeVehicles()
|
void InitializeVehicles()
|
||||||
{
|
{
|
||||||
uint i;
|
_Vehicle_pool.CleanPool();
|
||||||
|
_Vehicle_pool.AddBlockToPool();
|
||||||
/* 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);
|
|
||||||
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) {
|
|
||||||
AddBlockToPool(&_Vehicle_pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
ResetVehiclePosHash();
|
ResetVehiclePosHash();
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
|
|||||||
* Get a string 'representation' of the vehicle type.
|
* Get a string 'representation' of the vehicle type.
|
||||||
* @return the string representation.
|
* @return the string representation.
|
||||||
*/
|
*/
|
||||||
virtual const char* GetTypeString() const = 0;
|
virtual const char* GetTypeString() const { return "base vehicle"; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the vehicles to be redrawn and updates cached variables
|
* Marks the vehicles to be redrawn and updates cached variables
|
||||||
@ -417,7 +417,7 @@ struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
|
|||||||
/**
|
/**
|
||||||
* Calls the tick handler of the vehicle
|
* Calls the tick handler of the vehicle
|
||||||
*/
|
*/
|
||||||
virtual void Tick() = 0;
|
virtual void Tick() {};
|
||||||
|
|
||||||
bool IsValid() const { return this->type != VEH_INVALID; }
|
bool IsValid() const { return this->type != VEH_INVALID; }
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user