From 21e88a8a335e030d3b629a40251acbbd3adee5d2 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Sun, 13 Nov 2022 15:04:49 +0100 Subject: [PATCH] Remove code duplication in character bitmap init --- src/openrct2/drawing/ScrollingText.cpp | 43 +++++++++----------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index 6056fd3108..66fd82c1ff 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -47,7 +47,7 @@ static void scrolling_text_set_bitmap_for_sprite( static void scrolling_text_set_bitmap_for_ttf( std::string_view text, int32_t scroll, uint8_t* bitmap, const int16_t* scrollPositionOffsets, colour_t colour); -void scrolling_text_initialise_bitmaps() +static void ScrollingTextInitialiseCharacterBitmaps(uint32_t glyphStart, uint16_t offset, uint16_t count, bool isAntiAliased) { uint8_t drawingSurface[64]; rct_drawpixelinfo dpi; @@ -55,11 +55,10 @@ void scrolling_text_initialise_bitmaps() dpi.width = 8; dpi.height = 8; - for (int32_t i = 0; i < FONT_SPRITE_GLYPH_COUNT; i++) + for (int32_t i = 0; i < count; i++) { std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00); - gfx_draw_sprite_software( - &dpi, ImageId(SPR_CHAR_START + (EnumValue(FontStyle::Tiny) * FONT_SPRITE_GLYPH_COUNT) + i), { -1, 0 }); + gfx_draw_sprite_software(&dpi, ImageId(glyphStart + (EnumValue(FontStyle::Tiny) * count) + i), { -1, 0 }); for (int32_t x = 0; x < 8; x++) { @@ -68,37 +67,18 @@ void scrolling_text_initialise_bitmaps() { val >>= 1; uint8_t pixel = dpi.bits[x + y * 8]; - if (pixel == 1 || (gTinyFontAntiAliased && pixel == 2)) + if (pixel == 1 || (isAntiAliased && pixel == 2)) { val |= 0x80; } } - _characterBitmaps[i][x] = val; - } - } - - for (int32_t i = 0; i < SPR_G2_GLYPH_COUNT; i++) - { - std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00); - gfx_draw_sprite_software( - &dpi, ImageId(SPR_G2_CHAR_BEGIN + (EnumValue(FontStyle::Tiny) * SPR_G2_GLYPH_COUNT) + i), { -1, 0 }); - - for (int32_t x = 0; x < 8; x++) - { - uint8_t val = 0; - for (int32_t y = 0; y < 8; y++) - { - val >>= 1; - uint8_t pixel = dpi.bits[x + y * 8]; - if (pixel == 1 || (gTinyFontAntiAliased && pixel == 2)) - { - val |= 0x80; - } - } - _characterBitmaps[FONT_SPRITE_GLYPH_COUNT + i][x] = val; + _characterBitmaps[offset + i][x] = val; } } +}; +static void ScrollingTextInitialiseScrollingText() +{ for (int32_t i = 0; i < OpenRCT2::MaxScrollingTextEntries; i++) { const int32_t imageId = SPR_SCROLLING_TEXT_START + i; @@ -122,6 +102,13 @@ void scrolling_text_initialise_bitmaps() } } +void scrolling_text_initialise_bitmaps() +{ + ScrollingTextInitialiseCharacterBitmaps(SPR_CHAR_START, 0, FONT_SPRITE_GLYPH_COUNT, gTinyFontAntiAliased); + ScrollingTextInitialiseCharacterBitmaps(SPR_G2_CHAR_BEGIN, FONT_SPRITE_GLYPH_COUNT, SPR_G2_GLYPH_COUNT, false); + ScrollingTextInitialiseScrollingText(); +} + static uint8_t* font_sprite_get_codepoint_bitmap(int32_t codepoint) { auto offset = font_sprite_get_codepoint_offset(codepoint);