NewGRF: Elide unmasked vehicle callbacks where possible
This includes: * CBID_VEHICLE_32DAY_CALLBACK * CBID_VEHICLE_REFIT_COST * CBID_VEHICLE_MODIFY_PROPERTY This is on a per-property basis The main benefit of this is to avoid callbacks not handled by the vehicle's current sprite group from using the full graphics chain as the "default" branch in the callback switch. In the case where the graphics chain is long/expensive, a lot of work had to be done before a callback failure result was eventually returned.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "../newgrf_house.h"
|
||||
#include "../newgrf_engine.h"
|
||||
#include "../newgrf_roadtype.h"
|
||||
#include "../newgrf_cargo.h"
|
||||
#include "../date_func.h"
|
||||
#include "../timetable.h"
|
||||
#include "../ship.h"
|
||||
@@ -272,6 +273,39 @@ class NIHVehicle : public NIHelper {
|
||||
print(buffer);
|
||||
const Engine *e = Engine::GetIfValid(v->engine_type);
|
||||
if (e != nullptr) {
|
||||
seprintf(buffer, lastof(buffer), " Callbacks: 0x%X, CB36 Properties: 0x" OTTD_PRINTFHEX64,
|
||||
e->callbacks_used, e->cb36_properties_used);
|
||||
print(buffer);
|
||||
uint64 cb36_properties = e->cb36_properties_used;
|
||||
if (!e->sprite_group_cb36_properties_used.empty()) {
|
||||
const SpriteGroup *root_spritegroup = nullptr;
|
||||
if (v->IsGroundVehicle()) root_spritegroup = GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->GetGroundVehicleCache()->first_engine);
|
||||
if (root_spritegroup == nullptr) {
|
||||
CargoID cargo = v->cargo_type;
|
||||
assert(cargo < lengthof(e->grf_prop.spritegroup));
|
||||
root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[CT_DEFAULT];
|
||||
}
|
||||
auto iter = e->sprite_group_cb36_properties_used.find(root_spritegroup);
|
||||
if (iter != e->sprite_group_cb36_properties_used.end()) {
|
||||
cb36_properties = iter->second;
|
||||
seprintf(buffer, lastof(buffer), " Current sprite group: CB36 Properties: 0x" OTTD_PRINTFHEX64, iter->second);
|
||||
print(buffer);
|
||||
}
|
||||
}
|
||||
if (cb36_properties != UINT64_MAX) {
|
||||
uint64 props = cb36_properties;
|
||||
while (props) {
|
||||
PropertyID prop = (PropertyID)FindFirstBit64(props);
|
||||
props = KillFirstBit(props);
|
||||
uint16 res = GetVehicleProperty(v, prop, CALLBACK_FAILED);
|
||||
if (res == CALLBACK_FAILED) {
|
||||
seprintf(buffer, lastof(buffer), " CB36: 0x%X --> FAILED", prop);
|
||||
} else {
|
||||
seprintf(buffer, lastof(buffer), " CB36: 0x%X --> 0x%X", prop, res);
|
||||
}
|
||||
print(buffer);
|
||||
}
|
||||
}
|
||||
YearMonthDay ymd;
|
||||
ConvertDateToYMD(e->intro_date, &ymd);
|
||||
seprintf(buffer, lastof(buffer), " Intro: %4i-%02i-%02i, Age: %u, Base life: %u, Durations: %u %u %u (sum: %u)",
|
||||
|
Reference in New Issue
Block a user