From 7dfe0b02a6db54aa8511383e6cb28e29ed6b2533 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 1 Jan 2021 03:06:53 +0200 Subject: [PATCH] Add ScrollingText.h --- src/openrct2/drawing/Drawing.Sprite.cpp | 3 ++- src/openrct2/drawing/ScrollingText.cpp | 15 +++++++-------- src/openrct2/drawing/ScrollingText.h | 8 ++++++++ src/openrct2/libopenrct2.vcxproj | 1 + src/openrct2/sprites.h | 5 +++-- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 src/openrct2/drawing/ScrollingText.h diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index 5b8d237a3f..470aa9d451 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -18,6 +18,7 @@ #include "../ui/UiContext.h" #include "../util/Util.h" #include "Drawing.h" +#include "ScrollingText.h" #include #include @@ -180,7 +181,7 @@ void mask_scalar( static rct_gx _g1 = {}; static rct_gx _g2 = {}; static rct_gx _csg = {}; -static rct_g1_element _scrollingText[256]{}; +static rct_g1_element _scrollingText[MaxScrollingTextEntries]{}; static bool _csgLoaded = false; static rct_g1_element _g1Temp = {}; diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index aefb6af56a..6cec34bf7f 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -1,4 +1,4 @@ -/***************************************************************************** +/***************************************************************************** * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md @@ -7,6 +7,8 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "ScrollingText.h" + #include "../config/Config.h" #include "../core/String.hpp" #include "../interface/Colour.h" @@ -34,9 +36,7 @@ struct rct_draw_scroll_text uint8_t bitmap[64 * 40]; }; -constexpr int32_t MAX_SCROLLING_TEXT_ENTRIES = SPR_SCROLLING_TEXT_END - SPR_SCROLLING_TEXT_START; - -static rct_draw_scroll_text _drawScrollTextList[MAX_SCROLLING_TEXT_ENTRIES]; +static rct_draw_scroll_text _drawScrollTextList[OpenRCT2::MaxScrollingTextEntries]; static uint8_t _characterBitmaps[FONT_SPRITE_GLYPH_COUNT + SPR_G2_GLYPH_COUNT][8]; static uint32_t _drawSCrollNextIndex = 0; static std::mutex _scrollingTextMutex; @@ -97,7 +97,7 @@ void scrolling_text_initialise_bitmaps() } } - for (int32_t i = 0; i < MAX_SCROLLING_TEXT_ENTRIES; i++) + for (int32_t i = 0; i < OpenRCT2::MaxScrollingTextEntries; i++) { const int32_t imageIdReference = SPR_SCROLLING_TEXT_LEGACY_START; const int32_t imageId = SPR_SCROLLING_TEXT_START + i; @@ -137,7 +137,7 @@ static int32_t scrolling_text_get_matching_or_oldest( { uint32_t oldestId = 0xFFFFFFFF; int32_t scrollIndex = -1; - for (int32_t i = 0; i < MAX_SCROLLING_TEXT_ENTRIES; i++) + for (int32_t i = 0; i < std::size(_drawScrollTextList); i++) { rct_draw_scroll_text* scrollText = &_drawScrollTextList[i]; if (oldestId >= scrollText->id) @@ -1438,9 +1438,8 @@ static constexpr const int16_t* _scrollPositions[MAX_SCROLLING_TEXT_MODES] = { void scrolling_text_invalidate() { - for (int32_t i = 0; i < MAX_SCROLLING_TEXT_ENTRIES; i++) + for (auto& scrollText : _drawScrollTextList) { - rct_draw_scroll_text& scrollText = _drawScrollTextList[i]; scrollText.string_id = 0; std::memset(scrollText.string_args, 0, sizeof(scrollText.string_args)); } diff --git a/src/openrct2/drawing/ScrollingText.h b/src/openrct2/drawing/ScrollingText.h new file mode 100644 index 0000000000..ec3f10100c --- /dev/null +++ b/src/openrct2/drawing/ScrollingText.h @@ -0,0 +1,8 @@ +#pragma once + +namespace OpenRCT2 +{ + static auto constexpr MaxScrollingTextLegacyEntries = 32; + static auto constexpr MaxScrollingTextEntries = 256; + +} // namespace OpenRCT2 diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 43d1df1f5f..a8139fdcb0 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -190,6 +190,7 @@ + diff --git a/src/openrct2/sprites.h b/src/openrct2/sprites.h index 70453bab3b..b8fea28f33 100644 --- a/src/openrct2/sprites.h +++ b/src/openrct2/sprites.h @@ -10,6 +10,7 @@ #ifndef _SPRITES_H_ #define _SPRITES_H_ +#include "drawing/ScrollingText.h" #include "rct1/RCT1.h" enum @@ -20,7 +21,7 @@ enum SPR_TEMP = 0x7FFFE, SPR_SCROLLING_TEXT_LEGACY_START = 1542, - SPR_SCROLLING_TEXT_LEGACY_END = SPR_SCROLLING_TEXT_LEGACY_START + 32, + SPR_SCROLLING_TEXT_LEGACY_END = SPR_SCROLLING_TEXT_LEGACY_START + OpenRCT2::MaxScrollingTextLegacyEntries, SPR_SCROLLING_TEXT_DEFAULT = 1574, SPR_EDGE_ROCK_BASE = 1579, @@ -1038,7 +1039,7 @@ enum SPR_CSG_END = SPR_CSG_BEGIN + RCT1_NUM_LL_CSG_ENTRIES, SPR_SCROLLING_TEXT_START = SPR_CSG_END, - SPR_SCROLLING_TEXT_END = SPR_SCROLLING_TEXT_START + 256, + SPR_SCROLLING_TEXT_END = SPR_SCROLLING_TEXT_START + OpenRCT2::MaxScrollingTextEntries, SPR_IMAGE_LIST_BEGIN = SPR_SCROLLING_TEXT_END, SPR_IMAGE_LIST_END = 0x7FFFE