1
0
Fork 0

Codechange: Improve performance of exclusive preview engine test. (#14270)

Check group statistics to test if a company has built an exclusive preview engine.

This improves performance by avoiding iterating the vehicle pool.
pull/13661/head
Peter Nelson 2025-05-21 21:19:38 +01:00 committed by GitHub
parent 9f190aa534
commit 5fe6578f64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 14 deletions

View File

@ -1085,22 +1085,13 @@ static void NewVehicleAvailable(Engine *e)
* prevent that company from getting future intro periods for a while. */ * prevent that company from getting future intro periods for a while. */
if (e->flags.Test(EngineFlag::ExclusivePreview)) { if (e->flags.Test(EngineFlag::ExclusivePreview)) {
for (Company *c : Company::Iterate()) { for (Company *c : Company::Iterate()) {
uint block_preview = c->block_preview;
if (!e->company_avail.Test(c->index)) continue; if (!e->company_avail.Test(c->index)) continue;
/* We assume the user did NOT build it.. prove me wrong ;) */ /* Check the company's 'ALL_GROUP' group statistics. This only includes countable vehicles, which is fine
c->block_preview = 20; * as those are the only engines that can be given exclusive previews. */
if (GetGroupNumEngines(c->index, ALL_GROUP, e->index) == 0) {
for (const Vehicle *v : Vehicle::Iterate()) { /* The company did not build this engine during preview. */
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || c->block_preview = 20;
(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;
}
}
} }
} }
} }