Add fast path to vehicle var 0x42 if only upper byte is required
This commit is contained in:
@@ -589,6 +589,19 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
|||||||
return v->grf_cache.position_same_id_length;
|
return v->grf_cache.position_same_id_length;
|
||||||
|
|
||||||
case 0x42: { // Consist cargo information
|
case 0x42: { // Consist cargo information
|
||||||
|
if ((extra->mask & 0x00FFFFFF) == 0) {
|
||||||
|
if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD)) {
|
||||||
|
byte user_def_data = 0;
|
||||||
|
if (v->type == VEH_TRAIN) {
|
||||||
|
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||||
|
user_def_data |= Train::From(u)->tcache.user_def_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SB(v->grf_cache.consist_cargo_information, 24, 8, user_def_data);
|
||||||
|
SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD);
|
||||||
|
}
|
||||||
|
return (v->grf_cache.consist_cargo_information & 0xFF000000);
|
||||||
|
}
|
||||||
if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
|
if (!HasBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION)) {
|
||||||
const Vehicle *u;
|
const Vehicle *u;
|
||||||
byte cargo_classes = 0;
|
byte cargo_classes = 0;
|
||||||
@@ -642,6 +655,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
|||||||
* which will need different translations */
|
* which will need different translations */
|
||||||
v->grf_cache.consist_cargo_information = cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
|
v->grf_cache.consist_cargo_information = cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
|
||||||
SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION);
|
SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION);
|
||||||
|
SetBit(v->grf_cache.cache_valid, NCVV_CONSIST_CARGO_INFORMATION_UD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
|
/* The cargo translation is specific to the accessing GRF, and thus cannot be cached. */
|
||||||
@@ -1569,7 +1583,10 @@ void FillNewGRFVehicleCache(const Vehicle *v)
|
|||||||
{ 0x43, NCVV_COMPANY_INFORMATION },
|
{ 0x43, NCVV_COMPANY_INFORMATION },
|
||||||
{ 0x4D, NCVV_POSITION_IN_VEHICLE },
|
{ 0x4D, NCVV_POSITION_IN_VEHICLE },
|
||||||
};
|
};
|
||||||
static_assert(NCVV_END == lengthof(cache_entries));
|
static const int partial_cache_entries[] = {
|
||||||
|
NCVV_CONSIST_CARGO_INFORMATION_UD,
|
||||||
|
};
|
||||||
|
static_assert(NCVV_END == lengthof(cache_entries) + lengthof(partial_cache_entries));
|
||||||
|
|
||||||
/* Resolve all the variables, so their caches are set. */
|
/* Resolve all the variables, so their caches are set. */
|
||||||
for (size_t i = 0; i < lengthof(cache_entries); i++) {
|
for (size_t i = 0; i < lengthof(cache_entries); i++) {
|
||||||
|
@@ -73,6 +73,7 @@ enum NewGRFCacheValidValues {
|
|||||||
NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid.
|
NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid.
|
||||||
NCVV_COMPANY_INFORMATION = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid.
|
NCVV_COMPANY_INFORMATION = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid.
|
||||||
NCVV_POSITION_IN_VEHICLE = 4, ///< This bit will be set if the NewGRF var 4D currently stored is valid.
|
NCVV_POSITION_IN_VEHICLE = 4, ///< This bit will be set if the NewGRF var 4D currently stored is valid.
|
||||||
|
NCVV_CONSIST_CARGO_INFORMATION_UD = 5, ///< This bit will be set if the uppermost byte of NewGRF var 42 currently stored is valid.
|
||||||
NCVV_END, ///< End of the bits.
|
NCVV_END, ///< End of the bits.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user