mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Make GRF temporary engine data a vector. (#10685)
This replaces manual C-style realloc/memset/free.pull/10396/merge
parent
b56be83937
commit
27b4b5d0a0
|
@ -347,7 +347,7 @@ struct GRFTempEngineData {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static GRFTempEngineData *_gted; ///< Temporary engine data used during NewGRF loading
|
static std::vector<GRFTempEngineData> _gted; ///< Temporary engine data used during NewGRF loading
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the GRF ID of the owner of a vehicle if it has been reserved.
|
* Contains the GRF ID of the owner of a vehicle if it has been reserved.
|
||||||
|
@ -667,11 +667,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern
|
||||||
|
|
||||||
if (engine_pool_size != Engine::GetPoolSize()) {
|
if (engine_pool_size != Engine::GetPoolSize()) {
|
||||||
/* Resize temporary engine data ... */
|
/* Resize temporary engine data ... */
|
||||||
_gted = ReallocT(_gted, Engine::GetPoolSize());
|
_gted.resize(Engine::GetPoolSize());
|
||||||
|
|
||||||
/* and blank the new block. */
|
|
||||||
size_t len = (Engine::GetPoolSize() - engine_pool_size) * sizeof(*_gted);
|
|
||||||
memset(_gted + engine_pool_size, 0, len);
|
|
||||||
}
|
}
|
||||||
if (type == VEH_TRAIN) {
|
if (type == VEH_TRAIN) {
|
||||||
_gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label;
|
_gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label;
|
||||||
|
@ -8753,7 +8749,7 @@ void ResetNewGRFData()
|
||||||
ResetRoadTypes();
|
ResetRoadTypes();
|
||||||
|
|
||||||
/* Allocate temporary refit/cargo class data */
|
/* Allocate temporary refit/cargo class data */
|
||||||
_gted = CallocT<GRFTempEngineData>(Engine::GetPoolSize());
|
_gted.resize(Engine::GetPoolSize());
|
||||||
|
|
||||||
/* Fill rail type label temporary data for default trains */
|
/* Fill rail type label temporary data for default trains */
|
||||||
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
|
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
|
||||||
|
@ -9928,7 +9924,7 @@ static void AfterLoadGRFs()
|
||||||
FinalisePriceBaseMultipliers();
|
FinalisePriceBaseMultipliers();
|
||||||
|
|
||||||
/* Deallocate temporary loading data */
|
/* Deallocate temporary loading data */
|
||||||
free(_gted);
|
_gted.clear();
|
||||||
_grm_sprites.clear();
|
_grm_sprites.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue