VarAction2: Fix calculated result groups being incorrectly pruned

This commit is contained in:
Jonathan G Rennison
2022-05-30 17:24:26 +01:00
parent d6015194c1
commit 994dc683a2
3 changed files with 11 additions and 2 deletions

View File

@@ -5526,7 +5526,7 @@ static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 grou
while (result != nullptr) { while (result != nullptr) {
if (result->type == SGT_DETERMINISTIC) { if (result->type == SGT_DETERMINISTIC) {
const DeterministicSpriteGroup *sg = static_cast<const DeterministicSpriteGroup *>(result); const DeterministicSpriteGroup *sg = static_cast<const DeterministicSpriteGroup *>(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 */ /* 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; uint32 value = (sg->adjusts.size() == 1) ? EvaluateDeterministicSpriteGroupAdjust(sg->size, sg->adjusts[0], nullptr, 0, UINT_MAX) : 0;
result = sg->default_group; result = sg->default_group;

View File

@@ -286,7 +286,7 @@ void DeterministicSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) co
} }
auto check_1A_range = [&]() -> bool { 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 */ /* 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; uint32 value = (this->adjusts.size() == 1) ? EvaluateDeterministicSpriteGroupAdjust(this->size, this->adjusts[0], nullptr, 0, UINT_MAX) : 0;
for (const auto &range : this->ranges) { 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 void CallbackResultSpriteGroup::AnalyseCallbacks(AnalyseCallbackOperation &op) const
{ {
if (op.mode == ACOM_FIND_CB_RESULT) op.cb_result_found = true; if (op.mode == ACOM_FIND_CB_RESULT) op.cb_result_found = true;

View File

@@ -316,6 +316,7 @@ struct DeterministicSpriteGroup : SpriteGroup {
const SpriteGroup *error_group; // was first range, before sorting ranges const SpriteGroup *error_group; // was first range, before sorting ranges
void AnalyseCallbacks(AnalyseCallbackOperation &op) const override; void AnalyseCallbacks(AnalyseCallbackOperation &op) const override;
bool GroupMayBeBypassed() const;
protected: protected:
const SpriteGroup *Resolve(ResolverObject &object) const override; const SpriteGroup *Resolve(ResolverObject &object) const override;