Change: Use bitmap for free unit ID generation. (#12165)
This improves performance of finding the next free unit number for a vehicle. Based loosely on pool's used slot bitmap.
This commit is contained in:
@@ -755,7 +755,7 @@ public:
|
||||
* and that shall not be resetted for the new vehicle.
|
||||
* @param src The old vehicle
|
||||
*/
|
||||
inline void CopyVehicleConfigAndStatistics(const Vehicle *src)
|
||||
inline void CopyVehicleConfigAndStatistics(Vehicle *src)
|
||||
{
|
||||
this->CopyConsistPropertiesFrom(src);
|
||||
|
||||
@@ -766,6 +766,8 @@ public:
|
||||
|
||||
this->profit_this_year = src->profit_this_year;
|
||||
this->profit_last_year = src->profit_last_year;
|
||||
|
||||
src->unitnumber = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1270,19 +1272,6 @@ struct SpecializedVehicle : public Vehicle {
|
||||
static Pool::IterateWrapper<T> Iterate(size_t from = 0) { return Pool::IterateWrapper<T>(from); }
|
||||
};
|
||||
|
||||
/** Generates sequence of free UnitID numbers */
|
||||
struct FreeUnitIDGenerator {
|
||||
bool *cache; ///< array of occupied unit id numbers
|
||||
UnitID maxid; ///< maximum ID at the moment of constructor call
|
||||
UnitID curid; ///< last ID returned; 0 if none
|
||||
|
||||
FreeUnitIDGenerator(VehicleType type, CompanyID owner);
|
||||
UnitID NextID();
|
||||
|
||||
/** Releases allocated memory */
|
||||
~FreeUnitIDGenerator() { free(this->cache); }
|
||||
};
|
||||
|
||||
/** Sentinel for an invalid coordinate. */
|
||||
static const int32_t INVALID_COORD = 0x7fffffff;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user