Exclude non-default style only GRFs when determining default style lookahead

This commit is contained in:
Jonathan G Rennison 2024-09-19 00:20:14 +01:00
parent 64b047bee1
commit 63758e412c
5 changed files with 16 additions and 2 deletions

View File

@ -3447,6 +3447,7 @@ DEF_CONSOLE_CMD(ConDumpSignalStyles)
IConsolePrintF(CC_DEFAULT, " r = realistic braking only");
IConsolePrintF(CC_DEFAULT, " b = both sides");
IConsolePrintF(CC_DEFAULT, " Extra aspects: %u", _extra_aspects);
IConsolePrintF(CC_DEFAULT, " Default style extra aspects: %u", _default_signal_style_lookahead_extra_aspects);
btree::btree_map<uint32_t, const GRFFile *> grfs;
for (uint8_t i = 0; i < _num_new_signal_styles; i++) {

View File

@ -20,6 +20,7 @@
std::vector<const GRFFile *> _new_signals_grfs;
std::array<NewSignalStyle, MAX_NEW_SIGNAL_STYLES> _new_signal_styles;
uint8_t _default_signal_style_lookahead_extra_aspects = 0;
std::array<NewSignalStyleMapping, MAX_NEW_SIGNAL_STYLES> _new_signal_style_mapping;
uint8_t _num_new_signal_styles = 0;
uint16_t _enabled_new_signal_styles_mask = 0;

View File

@ -50,6 +50,8 @@ struct NewSignalStyle {
PalSpriteID signals[SIGTYPE_END][2][2];
};
extern std::array<NewSignalStyle, MAX_NEW_SIGNAL_STYLES> _new_signal_styles;
extern uint8_t _default_signal_style_lookahead_extra_aspects;
struct NewSignalStyleMapping {
uint32_t grfid = 0;
uint8_t grf_local_id = 0;

View File

@ -1122,7 +1122,11 @@ int AdvanceTrainReservationLookaheadEnd(const Train *v, int lookahead_end_positi
uint8_t known_signals_ahead = 1;
bool allow_skip_no_aspect_inc = false;
if (v->IsInDepot()) {
known_signals_ahead = _extra_aspects + 1;
if (_default_signal_style_lookahead_extra_aspects == 0xFF) {
/* Default signal style (depot) has unlimited lookahead */
return v->lookahead->reservation_end_position + 1;
}
known_signals_ahead = _default_signal_style_lookahead_extra_aspects + 1;
allow_skip_no_aspect_inc = true;
}
for (const TrainReservationLookAheadItem &item : v->lookahead->items) {
@ -1143,7 +1147,7 @@ int AdvanceTrainReservationLookaheadEnd(const Train *v, int lookahead_end_positi
if (item.start <= threshold) {
/* Signal is within visual range */
uint8_t style = item.data_aux >> 8;
uint8_t max_aspect = (style == 0) ? _extra_aspects : _new_signal_styles[style - 1].lookahead_extra_aspects;
uint8_t max_aspect = (style == 0) ? _default_signal_style_lookahead_extra_aspects : _new_signal_styles[style - 1].lookahead_extra_aspects;
if (max_aspect == 0xFF) {
/* This signal has unlimited lookahead */
return v->lookahead->reservation_end_position + 1;

View File

@ -1884,6 +1884,7 @@ static bool DetermineExtraAspectsVariable()
{
bool changed = false;
uint8_t new_extra_aspects = 0;
uint8_t default_style_aspects = 0;
_signal_style_masks = {};
@ -1893,9 +1894,13 @@ static bool DetermineExtraAspectsVariable()
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
const RailTypeInfo *rti = GetRailTypeInfo(r);
new_extra_aspects = std::max<uint8_t>(new_extra_aspects, rti->signal_extra_aspects);
default_style_aspects = std::max<uint8_t>(default_style_aspects, rti->signal_extra_aspects);
}
for (const GRFFile *grf : _new_signals_grfs) {
new_extra_aspects = std::max<uint8_t>(new_extra_aspects, grf->new_signal_extra_aspects);
if (HasBit(grf->new_signal_style_mask, 0)) {
default_style_aspects = std::max<uint8_t>(default_style_aspects, grf->new_signal_extra_aspects);
}
}
}
@ -1943,6 +1948,7 @@ static bool DetermineExtraAspectsVariable()
}
_extra_aspects = new_extra_aspects;
_default_signal_style_lookahead_extra_aspects = (default_style_aspects > 0) ? default_style_aspects : 255;
SimpleChecksum64 checksum;
checksum.Update(SimpleHash32(_extra_aspects));