Codechange: Replace pointer to Sprite array with reference to SpriteCollection. (#11580)

Add `SpriteLoader::SpriteCollection` type which is an array of `SpriteLoad::Sprite`.

This removes the ambiguity of what `SpriteLoader::Sprite *` is pointing to,
and cleans up mismatches using both dereference -> and array access [] for the
same object.
This commit is contained in:
Peter Nelson
2023-12-20 20:38:21 +00:00
committed by GitHub
parent 7466c3c39e
commit b85ecf9ac2
25 changed files with 90 additions and 82 deletions

View File

@@ -235,7 +235,8 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
SpriteLoader::Sprite sprite;
SpriteLoader::SpriteCollection spritecollection;
SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
sprite.type = SpriteType::Font;
sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
@@ -266,7 +267,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa)
}
GlyphEntry new_glyph;
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
new_glyph.width = slot->advance.x >> 6;
this->SetGlyphPtr(key, &new_glyph);

View File

@@ -136,7 +136,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
};
#undef CPSET
#undef CP___
static const SpriteLoader::Sprite builtin_questionmark = {
static const SpriteLoader::SpriteCollection builtin_questionmark = {{ {
10, // height
8, // width
0, // x_offs
@@ -144,9 +144,9 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key)
SpriteType::Font,
SCC_PAL,
builtin_questionmark_data
};
} }};
Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, SimpleSpriteAlloc);
Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(builtin_questionmark, SimpleSpriteAlloc);
assert(spr != nullptr);
GlyphEntry new_glyph;
new_glyph.sprite = spr;