1
0
Fork 0

Codechange: Use range-for when loading NewGRF deterministic sprite groups. (#12605)

pull/12606/head
Peter Nelson 2024-05-01 19:59:46 +01:00 committed by GitHub
parent 532ce1a907
commit 7147fe9e7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 12 deletions

View File

@ -5279,10 +5279,10 @@ static void NewSpriteGroup(ByteReader *buf)
std::vector<DeterministicSpriteGroupRange> ranges; std::vector<DeterministicSpriteGroupRange> ranges;
ranges.resize(buf->ReadByte()); ranges.resize(buf->ReadByte());
for (uint i = 0; i < ranges.size(); i++) { for (auto &range : ranges) {
ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord()); range.group = GetGroupFromGroupID(setid, type, buf->ReadWord());
ranges[i].low = buf->ReadVarSize(varsize); range.low = buf->ReadVarSize(varsize);
ranges[i].high = buf->ReadVarSize(varsize); range.high = buf->ReadVarSize(varsize);
} }
group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord()); group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
@ -5292,20 +5292,19 @@ static void NewSpriteGroup(ByteReader *buf)
/* Sort ranges ascending. When ranges overlap, this may required clamping or splitting them */ /* Sort ranges ascending. When ranges overlap, this may required clamping or splitting them */
std::vector<uint32_t> bounds; std::vector<uint32_t> bounds;
for (uint i = 0; i < ranges.size(); i++) { for (const auto &range : ranges) {
bounds.push_back(ranges[i].low); bounds.push_back(range.low);
if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1); if (range.high != UINT32_MAX) bounds.push_back(range.high + 1);
} }
std::sort(bounds.begin(), bounds.end()); std::sort(bounds.begin(), bounds.end());
bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end()); bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
std::vector<const SpriteGroup *> target; std::vector<const SpriteGroup *> target;
for (uint j = 0; j < bounds.size(); ++j) { for (const auto &bound : bounds) {
uint32_t v = bounds[j];
const SpriteGroup *t = group->default_group; const SpriteGroup *t = group->default_group;
for (uint i = 0; i < ranges.size(); i++) { for (const auto &range : ranges) {
if (ranges[i].low <= v && v <= ranges[i].high) { if (range.low <= bound && bound <= range.high) {
t = ranges[i].group; t = range.group;
break; break;
} }
} }