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:
@@ -49,6 +49,19 @@ struct CompanyInfrastructure {
|
||||
uint32_t GetTramTotal() const;
|
||||
};
|
||||
|
||||
class FreeUnitIDGenerator {
|
||||
public:
|
||||
UnitID NextID() const;
|
||||
UnitID UseID(UnitID index);
|
||||
void ReleaseID(UnitID index);
|
||||
|
||||
private:
|
||||
using BitmapStorage = size_t;
|
||||
static constexpr size_t BITMAP_SIZE = std::numeric_limits<BitmapStorage>::digits;
|
||||
|
||||
std::vector<BitmapStorage> used_bitmap;
|
||||
};
|
||||
|
||||
typedef Pool<Company, CompanyID, 1, MAX_COMPANIES> CompanyPool;
|
||||
extern CompanyPool _company_pool;
|
||||
|
||||
@@ -129,6 +142,8 @@ struct Company : CompanyProperties, CompanyPool::PoolItem<&_company_pool> {
|
||||
|
||||
CompanyInfrastructure infrastructure; ///< NOSAVE: Counts of company owned infrastructure.
|
||||
|
||||
FreeUnitIDGenerator freeunits[VEH_COMPANY_END];
|
||||
|
||||
Money GetMaxLoan() const;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user