mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Improve performance of exclusive preview engine test.
Check group statistics to test if a company has built an exclusive preview engine. This improves performance by avoiding iterating the vehicle pool.pull/14270/head
parent
9f190aa534
commit
f9d0877f36
|
@ -1085,22 +1085,13 @@ static void NewVehicleAvailable(Engine *e)
|
|||
* prevent that company from getting future intro periods for a while. */
|
||||
if (e->flags.Test(EngineFlag::ExclusivePreview)) {
|
||||
for (Company *c : Company::Iterate()) {
|
||||
uint block_preview = c->block_preview;
|
||||
|
||||
if (!e->company_avail.Test(c->index)) continue;
|
||||
|
||||
/* We assume the user did NOT build it.. prove me wrong ;) */
|
||||
c->block_preview = 20;
|
||||
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
|
||||
(v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) {
|
||||
if (v->owner == c->index && v->engine_type == index) {
|
||||
/* The user did prove me wrong, so restore old value */
|
||||
c->block_preview = block_preview;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Check the company's 'ALL_GROUP' group statistics. This only includes countable vehicles, which is fine
|
||||
* as those are the only engines that can be given exclusive previews. */
|
||||
if (GetGroupNumEngines(c->index, ALL_GROUP, e->index) == 0) {
|
||||
/* The company did not build this engine during preview. */
|
||||
c->block_preview = 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue