diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 77a5140e2b..f03fe35712 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5526,7 +5526,7 @@ static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 grou while (result != nullptr) { if (result->type == SGT_DETERMINISTIC) { const DeterministicSpriteGroup *sg = static_cast(result); - if (sg->adjusts.size() == 0 || (sg->adjusts.size() == 1 && sg->adjusts[0].variable == 0x1A && (sg->adjusts[0].operation == DSGA_OP_ADD || sg->adjusts[0].operation == DSGA_OP_RST))) { + if (sg->GroupMayBeBypassed()) { /* Deterministic sprite group can be trivially resolved, skip it */ uint32 value = (sg->adjusts.size() == 1) ? EvaluateDeterministicSpriteGroupAdjust(sg->size, sg->adjusts[0], nullptr, 0, UINT_MAX) : 0; result = sg->default_group; diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 7549548771..63b91a2764 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -286,7 +286,7 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co } auto check_1A_range = [&]() -> bool { - if (this->adjusts.size() == 0 || (this->adjusts.size() == 1 && this->adjusts[0].variable == 0x1A && (this->adjusts[0].operation == DSGA_OP_ADD || this->adjusts[0].operation == DSGA_OP_RST))) { + if (this->GroupMayBeBypassed()) { /* Not clear why some GRFs do this, perhaps a way of commenting out a branch */ uint32 value = (this->adjusts.size() == 1) ? EvaluateDeterministicSpriteGroupAdjust(this->size, this->adjusts[0], nullptr, 0, UINT_MAX) : 0; for (const auto &range : this->ranges) { @@ -442,6 +442,14 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co } } +bool DeterministicSpriteGroup::GroupMayBeBypassed() const +{ + if (this->calculated_result) return false; + if (this->adjusts.size() == 0) return true; + if ((this->adjusts.size() == 1 && this->adjusts[0].variable == 0x1A && (this->adjusts[0].operation == DSGA_OP_ADD || this->adjusts[0].operation == DSGA_OP_RST))) return true; + return false; +} + void CallbackResultSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) const { if (op.mode == ACOM_FIND_CB_RESULT) op.cb_result_found = true; diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 78b2e25adb..22ae6aad58 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -316,6 +316,7 @@ struct DeterministicSpriteGroup : SpriteGroup { const SpriteGroup *error_group; // was first range, before sorting ranges void AnalyseCallbacks(AnalyseCallbackOperation &op) const override; + bool GroupMayBeBypassed() const; protected: const SpriteGroup *Resolve(ResolverObject &object) const override;