From 63702fcc6fadff27d0451313372bf6ca5effd2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:31:44 +0200 Subject: [PATCH 01/10] Implement identifier comparison overloads --- src/openrct2/core/Identifier.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/openrct2/core/Identifier.hpp b/src/openrct2/core/Identifier.hpp index 22fe9b0981..a08156e498 100644 --- a/src/openrct2/core/Identifier.hpp +++ b/src/openrct2/core/Identifier.hpp @@ -63,4 +63,14 @@ public: { return _handle != other; } + + constexpr bool operator==(const TIdentifier& other) const noexcept + { + return _handle == other._handle; + } + + constexpr bool operator!=(const TIdentifier& other) const noexcept + { + return _handle != other._handle; + } }; From f704358cb30f4c0ea75592737e9747bb556f9499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:34:53 +0200 Subject: [PATCH 02/10] Add TIdentifier specialization for OrcaStream --- src/openrct2/core/OrcaStream.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openrct2/core/OrcaStream.hpp b/src/openrct2/core/OrcaStream.hpp index fbc330ae51..a2fe8edaf8 100644 --- a/src/openrct2/core/OrcaStream.hpp +++ b/src/openrct2/core/OrcaStream.hpp @@ -12,6 +12,7 @@ #include "../world/Location.hpp" #include "Crypt.h" #include "FileStream.h" +#include "Identifier.hpp" #include "MemoryStream.h" #include @@ -312,6 +313,21 @@ namespace OpenRCT2 } } + template void ReadWrite(TIdentifier& value) + { + if (_mode == Mode::READING) + { + T temp{}; + ReadWrite(temp); + value = TIdentifier::FromUnderlying(temp); + } + else + { + const auto temp = value.ToUnderlying(); + ReadWrite(temp); + } + } + void ReadWrite(bool& value) { uint8_t value8 = value ? 1 : 0; From ee53f1db660b95d1fb1446a6a086f39067d2346f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:35:21 +0200 Subject: [PATCH 03/10] Use TIdentifier for BannerIndex --- src/openrct2/Identifiers.h | 3 +++ src/openrct2/world/Banner.h | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openrct2/Identifiers.h b/src/openrct2/Identifiers.h index d4e2f1c557..076b26b2e2 100644 --- a/src/openrct2/Identifiers.h +++ b/src/openrct2/Identifiers.h @@ -15,3 +15,6 @@ #include using ParkEntranceIndex = TIdentifier::max(), struct ParkEntranceIndexTag>; + +using BannerIndex = TIdentifier::max(), struct BannerIndexTag>; +constexpr BannerIndex BANNER_INDEX_NULL = BannerIndex::GetNull(); diff --git a/src/openrct2/world/Banner.h b/src/openrct2/world/Banner.h index e4ad35c2ec..81cef113c3 100644 --- a/src/openrct2/world/Banner.h +++ b/src/openrct2/world/Banner.h @@ -9,6 +9,7 @@ #pragma once +#include "../Identifiers.h" #include "../common.h" #include "../ride/RideTypes.h" #include "Location.hpp" @@ -19,11 +20,8 @@ class Formatter; struct TileElement; struct WallElement; -using BannerIndex = uint16_t; - constexpr ObjectEntryIndex BANNER_NULL = OBJECT_ENTRY_INDEX_NULL; constexpr size_t MAX_BANNERS = 8192; -constexpr BannerIndex BANNER_INDEX_NULL = static_cast(-1); constexpr uint8_t SCROLLING_MODE_NONE = 255; From cf27c4a0249a72f5d0d1a88174e14426c771ae04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:37:56 +0200 Subject: [PATCH 04/10] Implement TIdentifier specialization for Intent --- src/openrct2/windows/Intent.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 77c5ecbb03..962479ea52 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -10,6 +10,7 @@ #pragma once #include "../common.h" +#include "../core/Identifier.hpp" #include "../interface/Window.h" #include @@ -54,6 +55,12 @@ public: Intent* putExtra(uint32_t key, int32_t value); Intent* putExtra(uint32_t key, std::string value); Intent* putExtra(uint32_t key, close_callback value); + + template Intent* putExtra(uint32_t key, const TIdentifier& value) + { + const auto val = value.ToUnderlying(); + return putExtra(key, static_cast(val)); + } }; enum From 3563d89e5893fd55a6c072babcf75f1eb01bbf37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:41:48 +0200 Subject: [PATCH 05/10] Add TIdentifier specialization to GameAction visitor --- src/openrct2/actions/GameAction.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index 4a017bb1f5..7e5e89eb0a 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -12,6 +12,7 @@ #include "../Game.h" #include "../common.h" #include "../core/DataSerialiser.h" +#include "../core/Identifier.hpp" #include "../localisation/StringIds.h" #include "GameActionResult.h" @@ -86,6 +87,13 @@ public: param = static_cast(value); } + template void Visit(std::string_view name, TIdentifier& param) + { + auto value = param.ToUnderlying(); + Visit(name, value); + param = TIdentifier::FromUnderlying(value); + } + template void Visit(std::string_view name, NetworkObjectId_t& param) { Visit(name, param.id); From 63a2e9d716b48235bdb71c6392462ee2b9f18504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:58:07 +0200 Subject: [PATCH 06/10] Refactor uses of old BannerIndex --- .../interface/ViewportInteraction.cpp | 6 ++-- src/openrct2-ui/windows/Banner.cpp | 25 +++++++------ src/openrct2-ui/windows/Sign.cpp | 20 ++++++----- src/openrct2-ui/windows/TileInspector.cpp | 4 +-- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- src/openrct2/ParkFile.cpp | 8 ++--- src/openrct2/core/DataSerialiserTraits.h | 21 +++++++++++ src/openrct2/core/OrcaStream.hpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 4 +-- src/openrct2/rct2/S6Importer.cpp | 28 +++++++-------- .../bindings/world/ScTileElement.cpp | 9 ++--- src/openrct2/world/Banner.cpp | 36 ++++++++++--------- src/openrct2/world/TileElement.cpp | 2 +- 13 files changed, 100 insertions(+), 67 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 24b644e0eb..4819564d60 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -582,7 +582,7 @@ bool ViewportInteractionRightClick(const ScreenCoordsXY& screenCoords) ViewportInteractionRemoveLargeScenery(info.Element, info.Loc); break; case ViewportInteractionItem::Banner: - context_open_detail_window(WD_BANNER, info.Element->AsBanner()->GetIndex()); + context_open_detail_window(WD_BANNER, info.Element->AsBanner()->GetIndex().ToUnderlying()); break; } @@ -669,7 +669,7 @@ static void ViewportInteractionRemoveParkWall(TileElement* tileElement, const Co auto* wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry->scrolling_mode != SCROLLING_MODE_NONE) { - context_open_detail_window(WD_SIGN_SMALL, tileElement->AsWall()->GetBannerIndex()); + context_open_detail_window(WD_SIGN_SMALL, tileElement->AsWall()->GetBannerIndex().ToUnderlying()); } else { @@ -690,7 +690,7 @@ static void ViewportInteractionRemoveLargeScenery(TileElement* tileElement, cons if (sceneryEntry->scrolling_mode != SCROLLING_MODE_NONE) { auto bannerIndex = tileElement->AsLargeScenery()->GetBannerIndex(); - context_open_detail_window(WD_SIGN, bannerIndex); + context_open_detail_window(WD_SIGN, bannerIndex.ToUnderlying()); } else { diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index bcb64c179e..7482c8be4f 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -88,9 +88,14 @@ private: Invalidate(); } + BannerIndex GetBannerIndex() const + { + return BannerIndex::FromUnderlying(number); + } + BannerElement* GetBannerElement() { - auto* banner = GetBanner(number); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { return nullptr; @@ -109,7 +114,7 @@ private: { continue; } - if (bannerElement->GetIndex() == number) + if (bannerElement->GetIndex() == GetBannerIndex()) { return bannerElement; } @@ -131,7 +136,7 @@ public: void Initialise(rct_windownumber _number) { number = _number; - auto* banner = GetBanner(number); + auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); auto* bannerElement = GetBannerElement(); if (bannerElement == nullptr) @@ -144,7 +149,7 @@ public: void OnMouseDown(rct_widgetindex widgetIndex) override { rct_widget* widget = &widgets[widgetIndex]; - auto* banner = GetBanner(number); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { Close(); @@ -177,7 +182,7 @@ public: void OnMouseUp(rct_widgetindex widgetIndex) override { - auto* banner = GetBanner(number); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { Close(); @@ -207,7 +212,7 @@ public: { textinput_cancel(); auto bannerSetStyle = BannerSetStyleAction( - BannerSetStyleType::NoEntry, number, banner->flags ^ BANNER_FLAG_NO_ENTRY); + BannerSetStyleType::NoEntry, GetBannerIndex(), banner->flags ^ BANNER_FLAG_NO_ENTRY); GameActions::Execute(&bannerSetStyle); break; } @@ -223,7 +228,7 @@ public: if (dropdownIndex == -1) break; - auto bannerSetStyle = BannerSetStyleAction(BannerSetStyleType::PrimaryColour, number, dropdownIndex); + auto bannerSetStyle = BannerSetStyleAction(BannerSetStyleType::PrimaryColour, GetBannerIndex(), dropdownIndex); GameActions::Execute(&bannerSetStyle); break; } @@ -231,7 +236,7 @@ public: { if (dropdownIndex == -1) break; - auto bannerSetStyle = BannerSetStyleAction(BannerSetStyleType::TextColour, number, dropdownIndex + 1); + auto bannerSetStyle = BannerSetStyleAction(BannerSetStyleType::TextColour, GetBannerIndex(), dropdownIndex + 1); GameActions::Execute(&bannerSetStyle); break; } @@ -242,7 +247,7 @@ public: { if (widgetIndex == WIDX_BANNER_TEXT) { - auto bannerSetNameAction = BannerSetNameAction(number, std::string(text)); + auto bannerSetNameAction = BannerSetNameAction(GetBannerIndex(), std::string(text)); GameActions::Execute(&bannerSetNameAction); } } @@ -265,7 +270,7 @@ public: void OnPrepareDraw() override { - auto* banner = GetBanner(number); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { return; diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index d7e8a463c2..1671a0b459 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -61,7 +61,7 @@ private: void ShowTextInput() { - auto* banner = GetBanner(number); + auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); if (banner != nullptr) { auto bannerText = banner->GetText(); @@ -87,14 +87,14 @@ public: { number = windowNumber; _isSmall = isSmall; - auto* banner = GetBanner(number); + auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); if (banner == nullptr) { return false; } auto signViewPosition = banner->position.ToCoordsXY().ToTileCentre(); - auto* tileElement = banner_get_tile_element(number); + auto* tileElement = banner_get_tile_element(BannerIndex::FromUnderlying(number)); if (tileElement == nullptr) return false; @@ -138,7 +138,7 @@ public: void OnMouseUp(rct_widgetindex widgetIndex) override { - auto* banner = GetBanner(number); + auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); if (banner == nullptr) { Close(); @@ -151,7 +151,7 @@ public: break; case WIDX_SIGN_DEMOLISH: { - auto* tileElement = banner_get_tile_element(number); + auto* tileElement = banner_get_tile_element(BannerIndex::FromUnderlying(number)); if (tileElement == nullptr) { Close(); @@ -203,7 +203,8 @@ public: if (dropdownIndex == -1) return; list_information_type = dropdownIndex; - auto signSetStyleAction = SignSetStyleAction(number, dropdownIndex, var_492, !_isSmall); + auto signSetStyleAction = SignSetStyleAction( + BannerIndex::FromUnderlying(number), dropdownIndex, var_492, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -212,7 +213,8 @@ public: if (dropdownIndex == -1) return; var_492 = dropdownIndex; - auto signSetStyleAction = SignSetStyleAction(number, list_information_type, dropdownIndex, !_isSmall); + auto signSetStyleAction = SignSetStyleAction( + BannerIndex::FromUnderlying(number), list_information_type, dropdownIndex, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -227,7 +229,7 @@ public: { if (widgetIndex == WIDX_SIGN_TEXT && !text.empty()) { - auto signSetNameAction = SignSetNameAction(number, std::string(text)); + auto signSetNameAction = SignSetNameAction(BannerIndex::FromUnderlying(number), std::string(text)); GameActions::Execute(&signSetNameAction); } } @@ -288,7 +290,7 @@ public: { RemoveViewport(); - auto banner = GetBanner(number); + auto banner = GetBanner(BannerIndex::FromUnderlying(number)); if (banner == nullptr) { return; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a5c65d7a21..8cd367c082 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -2328,8 +2328,8 @@ static void WindowTileInspectorScrollpaint(rct_window* w, rct_drawpixelinfo* dpi break; case TILE_ELEMENT_TYPE_BANNER: snprintf( - buffer, sizeof(buffer), "%s (%d)", language_get_string(STR_BANNER_WINDOW_TITLE), - tileElement->AsBanner()->GetIndex()); + buffer, sizeof(buffer), "%s (%u)", language_get_string(STR_BANNER_WINDOW_TITLE), + tileElement->AsBanner()->GetIndex().ToUnderlying()); typeName = buffer; break; default: diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 08d2369e4d..32c01e4d84 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -2005,7 +2005,7 @@ static void WindowTopToolbarSceneryToolDown(const ScreenCoordsXY& windowPos, rct { auto data = result->GetData(); OpenRCT2::Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); - context_open_detail_window(WD_BANNER, data.bannerId); + context_open_detail_window(WD_BANNER, data.bannerId.ToUnderlying()); } }); GameActions::Execute(&bannerPlaceAction); diff --git a/src/openrct2/ParkFile.cpp b/src/openrct2/ParkFile.cpp index 3de1d100d8..52f6a2e792 100644 --- a/src/openrct2/ParkFile.cpp +++ b/src/openrct2/ParkFile.cpp @@ -972,9 +972,9 @@ namespace OpenRCT2 cs.Write(static_cast(numBanners)); [[maybe_unused]] size_t numWritten = 0; - for (BannerIndex i = 0; i < MAX_BANNERS; i++) + for (uint16_t i = 0; i < MAX_BANNERS; i++) { - auto banner = GetBanner(i); + auto banner = GetBanner(BannerIndex::FromUnderlying(i)); if (banner != nullptr) { ReadWriteBanner(version, cs, *banner); @@ -990,9 +990,9 @@ namespace OpenRCT2 { std::vector banners; cs.ReadWriteVector(banners, [version, &cs](Banner& banner) { ReadWriteBanner(version, cs, banner); }); - for (size_t i = 0; i < banners.size(); i++) + for (uint16_t i = 0; i < banners.size(); i++) { - auto bannerIndex = static_cast(i); + auto bannerIndex = BannerIndex::FromUnderlying(i); auto banner = GetOrCreateBanner(bannerIndex); if (banner != nullptr) { diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index 8ef60287ba..4df7016803 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -843,3 +843,24 @@ template<> struct DataSerializerTraits_t stream->Write(msg, strlen(msg)); } }; + +template struct DataSerializerTraits_t> +{ + static void encode(OpenRCT2::IStream* stream, const TIdentifier& id) + { + stream->WriteValue(ByteSwapBE(id.ToUnderlying())); + } + + static void decode(OpenRCT2::IStream* stream, TIdentifier& id) + { + auto temp = ByteSwapBE(stream->ReadValue()); + id = TIdentifier::FromUnderlying(temp); + } + + static void log(OpenRCT2::IStream* stream, const TIdentifier& id) + { + char msg[128] = {}; + snprintf(msg, sizeof(msg), "Id(%u)", static_cast(id.ToUnderlying())); + stream->Write(msg, strlen(msg)); + } +}; diff --git a/src/openrct2/core/OrcaStream.hpp b/src/openrct2/core/OrcaStream.hpp index a2fe8edaf8..e5efb77ac9 100644 --- a/src/openrct2/core/OrcaStream.hpp +++ b/src/openrct2/core/OrcaStream.hpp @@ -323,7 +323,7 @@ namespace OpenRCT2 } else { - const auto temp = value.ToUnderlying(); + auto temp = value.ToUnderlying(); ReadWrite(temp); } } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 8527570c5e..9784bf309e 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1863,7 +1863,7 @@ namespace RCT1 if (index < std::size(_s4.banners)) { auto srcBanner = &_s4.banners[index]; - auto dstBanner = GetOrCreateBanner(index); + auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(index)); if (dstBanner == nullptr) { dst2->SetIndex(BANNER_INDEX_NULL); @@ -1871,7 +1871,7 @@ namespace RCT1 else { ImportBanner(dstBanner, srcBanner); - dst2->SetIndex(index); + dst2->SetIndex(BannerIndex::FromUnderlying(index)); } } else diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 750e6e5192..68589ddbc4 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -507,14 +507,14 @@ namespace RCT2 // This scenario breaks pathfinding. Create passages between the worlds. (List is grouped by neighbouring // tiles.) // clang-format off - FixLandOwnershipTilesWithOwnership( - { - { 67, 94 }, { 68, 94 }, { 69, 94 }, - { 58, 24 }, { 58, 25 }, { 58, 26 }, { 58, 27 }, { 58, 28 }, { 58, 29 }, { 58, 30 }, { 58, 31 }, { 58, 32 }, - { 26, 44 }, { 26, 45 }, - { 32, 79 }, { 32, 80 }, { 32, 81 }, - }, - OWNERSHIP_OWNED); + FixLandOwnershipTilesWithOwnership( + { + { 67, 94 }, { 68, 94 }, { 69, 94 }, + { 58, 24 }, { 58, 25 }, { 58, 26 }, { 58, 27 }, { 58, 28 }, { 58, 29 }, { 58, 30 }, { 58, 31 }, { 58, 32 }, + { 26, 44 }, { 26, 45 }, + { 32, 79 }, { 32, 80 }, { 32, 81 }, + }, + OWNERSHIP_OWNED); // clang-format on } else if (String::Equals(gScenarioFileName, "N America - Extreme Hawaiian Island.SC6")) @@ -1357,7 +1357,7 @@ namespace RCT2 if (bannerIndex < std::size(_s6.banners)) { auto srcBanner = &_s6.banners[bannerIndex]; - auto dstBanner = GetOrCreateBanner(bannerIndex); + auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { dst2->SetBannerIndex(BANNER_INDEX_NULL); @@ -1365,7 +1365,7 @@ namespace RCT2 else { ImportBanner(dstBanner, srcBanner); - dst2->SetBannerIndex(src2->GetBannerIndex()); + dst2->SetBannerIndex(BannerIndex::FromUnderlying(src2->GetBannerIndex())); } } } @@ -1390,7 +1390,7 @@ namespace RCT2 if (bannerIndex < std::size(_s6.banners)) { auto srcBanner = &_s6.banners[bannerIndex]; - auto dstBanner = GetOrCreateBanner(bannerIndex); + auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { dst2->SetBannerIndex(BANNER_INDEX_NULL); @@ -1398,7 +1398,7 @@ namespace RCT2 else { ImportBanner(dstBanner, srcBanner); - dst2->SetBannerIndex(src2->GetBannerIndex()); + dst2->SetBannerIndex(BannerIndex::FromUnderlying(src2->GetBannerIndex())); } } } @@ -1416,7 +1416,7 @@ namespace RCT2 if (bannerIndex < std::size(_s6.banners)) { auto srcBanner = &_s6.banners[bannerIndex]; - auto dstBanner = GetOrCreateBanner(bannerIndex); + auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { dst2->SetIndex(BANNER_INDEX_NULL); @@ -1424,7 +1424,7 @@ namespace RCT2 else { ImportBanner(dstBanner, srcBanner); - dst2->SetIndex(bannerIndex); + dst2->SetIndex(BannerIndex::FromUnderlying(bannerIndex)); } } else diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 6e5594454b..6334cca400 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -1013,32 +1013,33 @@ namespace OpenRCT2::Scripting if (idx == BANNER_INDEX_NULL) duk_push_null(ctx); else - duk_push_int(ctx, idx); + duk_push_int(ctx, idx.ToUnderlying()); return DukValue::take_from_stack(ctx); } void ScTileElement::bannerIndex_set(uint16_t value) { ThrowIfGameStateNotMutable(); + switch (_element->GetType()) { case TILE_ELEMENT_TYPE_LARGE_SCENERY: { auto el = _element->AsLargeScenery(); - el->SetBannerIndex(value); + el->SetBannerIndex(BannerIndex::FromUnderlying(value)); Invalidate(); break; } case TILE_ELEMENT_TYPE_WALL: { auto el = _element->AsWall(); - el->SetBannerIndex(value); + el->SetBannerIndex(BannerIndex::FromUnderlying(value)); Invalidate(); break; } case TILE_ELEMENT_TYPE_BANNER: { auto el = _element->AsBanner(); - el->SetIndex(value); + el->SetIndex(BannerIndex::FromUnderlying(value)); Invalidate(); break; } diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index ce9993d6b4..bf9f0c80f1 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -113,19 +113,19 @@ static ride_id_t banner_get_ride_index_at(const CoordsXYZ& bannerCoords) static BannerIndex BannerGetNewIndex() { - for (BannerIndex bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) + for (uint16_t bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) { if (bannerIndex < _banners.size()) { if (_banners[bannerIndex].IsNull()) { - return bannerIndex; + return BannerIndex::FromUnderlying(bannerIndex); } } else { _banners.emplace_back(); - return static_cast(_banners.size() - 1); + return BannerIndex::FromUnderlying(bannerIndex); } } return BANNER_INDEX_NULL; @@ -238,12 +238,13 @@ ride_id_t banner_get_closest_ride_index(const CoordsXYZ& mapPos) void banner_reset_broken_index() { - for (BannerIndex bannerIndex = 0; bannerIndex < _banners.size(); bannerIndex++) + for (uint16_t index = 0; index < _banners.size(); index++) { - auto tileElement = banner_get_tile_element(bannerIndex); + const auto bannerId = BannerIndex::FromUnderlying(index); + auto tileElement = banner_get_tile_element(bannerId); if (tileElement == nullptr) { - auto banner = GetBanner(bannerIndex); + auto banner = GetBanner(bannerId); if (banner != nullptr) { banner->type = BANNER_NULL; @@ -269,10 +270,11 @@ void fix_duplicated_banners() if (bannerIndex == BANNER_INDEX_NULL) continue; - if (activeBanners[bannerIndex]) + const auto index = bannerIndex.ToUnderlying(); + if (activeBanners[index]) { log_info( - "Duplicated banner with index %d found at x = %d, y = %d and z = %d.", bannerIndex, x, y, + "Duplicated banner with index %d found at x = %d, y = %d and z = %d.", index, x, y, bannerElement->base_height); // Banner index is already in use by another banner, so duplicate it @@ -282,7 +284,7 @@ void fix_duplicated_banners() log_error("Failed to create new banner."); continue; } - Guard::Assert(!activeBanners[newBanner->id]); + Guard::Assert(!activeBanners[index]); // Copy over the original banner, but update the location const auto* oldBanner = GetBanner(bannerIndex); @@ -299,7 +301,7 @@ void fix_duplicated_banners() } // Mark banner index as in-use - activeBanners[bannerIndex] = true; + activeBanners[index] = true; } } } @@ -383,9 +385,10 @@ void UnlinkAllBannersForRide(ride_id_t rideId) Banner* GetBanner(BannerIndex id) { - if (id < _banners.size()) + const auto index = id.ToUnderlying(); + if (index < _banners.size()) { - auto banner = &_banners[id]; + auto banner = &_banners[index]; if (banner != nullptr && !banner->IsNull()) { return banner; @@ -396,14 +399,15 @@ Banner* GetBanner(BannerIndex id) Banner* GetOrCreateBanner(BannerIndex id) { - if (id < MAX_BANNERS) + const auto index = id.ToUnderlying(); + if (index < MAX_BANNERS) { - if (id >= _banners.size()) + if (index >= _banners.size()) { - _banners.resize(id + 1); + _banners.resize(index + 1); } // Create the banner - auto& banner = _banners[id]; + auto& banner = _banners[index]; banner.id = id; return &banner; } diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 68eac33494..54a3c39fb5 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -81,7 +81,7 @@ void TileElement::RemoveBannerEntry() auto banner = GetBanner(bannerIndex); if (banner != nullptr) { - window_close_by_number(WC_BANNER, bannerIndex); + window_close_by_number(WC_BANNER, bannerIndex.ToUnderlying()); DeleteBanner(banner->id); } } From 810521bd5b68d06a685f9d88a90b505781b56c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 24 Nov 2021 22:25:36 +0200 Subject: [PATCH 07/10] Remove BANNER_INDEX_NULL --- src/openrct2/Identifiers.h | 1 - src/openrct2/actions/BannerPlaceAction.h | 2 +- src/openrct2/actions/BannerRemoveAction.cpp | 4 ++-- src/openrct2/actions/BannerSetNameAction.h | 2 +- src/openrct2/actions/BannerSetStyleAction.h | 2 +- src/openrct2/actions/LargeSceneryPlaceAction.h | 2 +- src/openrct2/actions/SignSetNameAction.h | 2 +- src/openrct2/actions/SignSetStyleAction.h | 2 +- src/openrct2/actions/WallPlaceAction.cpp | 4 ++-- src/openrct2/actions/WallPlaceAction.h | 2 +- src/openrct2/rct1/S4Importer.cpp | 6 +++--- src/openrct2/rct2/S6Importer.cpp | 12 ++++++------ .../scripting/bindings/world/ScTileElement.cpp | 2 +- src/openrct2/world/Banner.cpp | 4 ++-- src/openrct2/world/Banner.h | 2 +- src/openrct2/world/TileElement.cpp | 6 +++--- src/openrct2/world/TileInspector.cpp | 2 +- 17 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/openrct2/Identifiers.h b/src/openrct2/Identifiers.h index 076b26b2e2..aa008e87d9 100644 --- a/src/openrct2/Identifiers.h +++ b/src/openrct2/Identifiers.h @@ -17,4 +17,3 @@ using ParkEntranceIndex = TIdentifier::max(), struct ParkEntranceIndexTag>; using BannerIndex = TIdentifier::max(), struct BannerIndexTag>; -constexpr BannerIndex BANNER_INDEX_NULL = BannerIndex::GetNull(); diff --git a/src/openrct2/actions/BannerPlaceAction.h b/src/openrct2/actions/BannerPlaceAction.h index 3afc75ea50..54c945e42c 100644 --- a/src/openrct2/actions/BannerPlaceAction.h +++ b/src/openrct2/actions/BannerPlaceAction.h @@ -13,7 +13,7 @@ struct BannerPlaceActionResult { - BannerIndex bannerId = BANNER_INDEX_NULL; + BannerIndex bannerId = BannerIndex::GetNull(); }; class BannerPlaceAction final : public GameActionBase diff --git a/src/openrct2/actions/BannerRemoveAction.cpp b/src/openrct2/actions/BannerRemoveAction.cpp index eff4cc43cb..2495ad3ebd 100644 --- a/src/openrct2/actions/BannerRemoveAction.cpp +++ b/src/openrct2/actions/BannerRemoveAction.cpp @@ -62,7 +62,7 @@ GameActions::Result BannerRemoveAction::Query() const } auto bannerIndex = bannerElement->GetIndex(); - if (bannerIndex == BANNER_INDEX_NULL) + if (bannerIndex == BannerIndex::GetNull()) { log_error("Invalid banner index. index = ", bannerIndex); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_NONE); @@ -101,7 +101,7 @@ GameActions::Result BannerRemoveAction::Execute() const } auto bannerIndex = bannerElement->GetIndex(); - if (bannerIndex == BANNER_INDEX_NULL) + if (bannerIndex == BannerIndex::GetNull()) { log_error("Invalid banner index. index = ", bannerIndex); return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_NONE); diff --git a/src/openrct2/actions/BannerSetNameAction.h b/src/openrct2/actions/BannerSetNameAction.h index 42ea2b99bb..a129753a75 100644 --- a/src/openrct2/actions/BannerSetNameAction.h +++ b/src/openrct2/actions/BannerSetNameAction.h @@ -14,7 +14,7 @@ class BannerSetNameAction final : public GameActionBase { private: - BannerIndex _bannerIndex{ BANNER_INDEX_NULL }; + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; std::string _name; public: diff --git a/src/openrct2/actions/BannerSetStyleAction.h b/src/openrct2/actions/BannerSetStyleAction.h index 0a6beef6a6..06b86031b0 100644 --- a/src/openrct2/actions/BannerSetStyleAction.h +++ b/src/openrct2/actions/BannerSetStyleAction.h @@ -25,7 +25,7 @@ class BannerSetStyleAction final : public GameActionBase diff --git a/src/openrct2/actions/SignSetNameAction.h b/src/openrct2/actions/SignSetNameAction.h index 4d69ceeffe..07019484eb 100644 --- a/src/openrct2/actions/SignSetNameAction.h +++ b/src/openrct2/actions/SignSetNameAction.h @@ -14,7 +14,7 @@ class SignSetNameAction final : public GameActionBase { private: - BannerIndex _bannerIndex{ BANNER_INDEX_NULL }; + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; std::string _name; public: diff --git a/src/openrct2/actions/SignSetStyleAction.h b/src/openrct2/actions/SignSetStyleAction.h index 246ce8d23b..990554c669 100644 --- a/src/openrct2/actions/SignSetStyleAction.h +++ b/src/openrct2/actions/SignSetStyleAction.h @@ -14,7 +14,7 @@ class SignSetStyleAction final : public GameActionBase { private: - BannerIndex _bannerIndex{ BANNER_INDEX_NULL }; + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; uint8_t _mainColour{}; uint8_t _textColour{}; bool _isLarge{}; diff --git a/src/openrct2/actions/WallPlaceAction.cpp b/src/openrct2/actions/WallPlaceAction.cpp index 6fb3b83f3c..1d6053c34b 100644 --- a/src/openrct2/actions/WallPlaceAction.cpp +++ b/src/openrct2/actions/WallPlaceAction.cpp @@ -371,7 +371,7 @@ GameActions::Result WallPlaceAction::Execute() const wallElement->SetAcrossTrack(wallAcrossTrack); wallElement->SetEntryIndex(_wallType); - wallElement->SetBannerIndex(banner != nullptr ? banner->id : BANNER_INDEX_NULL); + wallElement->SetBannerIndex(banner != nullptr ? banner->id : BannerIndex::GetNull()); if (wallEntry->flags & WALL_SCENERY_HAS_TERNARY_COLOUR) { @@ -385,7 +385,7 @@ GameActions::Result WallPlaceAction::Execute() const res.Cost = wallEntry->price; - const auto bannerId = banner != nullptr ? banner->id : BANNER_INDEX_NULL; + const auto bannerId = banner != nullptr ? banner->id : BannerIndex::GetNull(); res.SetData(WallPlaceActionResult{ wallElement->GetBaseZ(), bannerId }); return res; diff --git a/src/openrct2/actions/WallPlaceAction.h b/src/openrct2/actions/WallPlaceAction.h index 094d813b5a..fdca3e5099 100644 --- a/src/openrct2/actions/WallPlaceAction.h +++ b/src/openrct2/actions/WallPlaceAction.h @@ -18,7 +18,7 @@ struct WallPlaceActionResult { int32_t BaseHeight{}; - BannerIndex BannerId = BANNER_INDEX_NULL; + BannerIndex BannerId = BannerIndex::GetNull(); }; class WallPlaceAction final : public GameActionBase diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 9784bf309e..d1ce89997c 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1827,7 +1827,7 @@ namespace RCT1 wallElement->SetPrimaryColour(colourA); wallElement->SetSecondaryColour(colourB); wallElement->SetTertiaryColour(colourC); - wallElement->SetBannerIndex(BANNER_INDEX_NULL); + wallElement->SetBannerIndex(BannerIndex::GetNull()); wallElement->SetAcrossTrack(false); wallElement->SetAnimationIsBackwards(false); wallElement->SetSlope(edgeSlope); @@ -1866,7 +1866,7 @@ namespace RCT1 auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(index)); if (dstBanner == nullptr) { - dst2->SetIndex(BANNER_INDEX_NULL); + dst2->SetIndex(BannerIndex::GetNull()); } else { @@ -1876,7 +1876,7 @@ namespace RCT1 } else { - dst2->SetIndex(BANNER_INDEX_NULL); + dst2->SetIndex(BannerIndex::GetNull()); } return 1; } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 68589ddbc4..43ce2ff7e1 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1349,7 +1349,7 @@ namespace RCT2 dst2->SetAnimationIsBackwards(src2->AnimationIsBackwards()); // Import banner information - dst2->SetBannerIndex(BANNER_INDEX_NULL); + dst2->SetBannerIndex(BannerIndex::GetNull()); auto entry = dst2->GetEntry(); if (entry != nullptr && entry->scrolling_mode != SCROLLING_MODE_NONE) { @@ -1360,7 +1360,7 @@ namespace RCT2 auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { - dst2->SetBannerIndex(BANNER_INDEX_NULL); + dst2->SetBannerIndex(BannerIndex::GetNull()); } else { @@ -1382,7 +1382,7 @@ namespace RCT2 dst2->SetSecondaryColour(src2->GetSecondaryColour()); // Import banner information - dst2->SetBannerIndex(BANNER_INDEX_NULL); + dst2->SetBannerIndex(BannerIndex::GetNull()); auto entry = dst2->GetEntry(); if (entry != nullptr && entry->scrolling_mode != SCROLLING_MODE_NONE) { @@ -1393,7 +1393,7 @@ namespace RCT2 auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { - dst2->SetBannerIndex(BANNER_INDEX_NULL); + dst2->SetBannerIndex(BannerIndex::GetNull()); } else { @@ -1419,7 +1419,7 @@ namespace RCT2 auto dstBanner = GetOrCreateBanner(BannerIndex::FromUnderlying(bannerIndex)); if (dstBanner == nullptr) { - dst2->SetIndex(BANNER_INDEX_NULL); + dst2->SetIndex(BannerIndex::GetNull()); } else { @@ -1429,7 +1429,7 @@ namespace RCT2 } else { - dst2->SetIndex(BANNER_INDEX_NULL); + dst2->SetIndex(BannerIndex::GetNull()); } break; } diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 6334cca400..dece9e203a 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -1010,7 +1010,7 @@ namespace OpenRCT2::Scripting { auto ctx = GetContext()->GetScriptEngine().GetContext(); BannerIndex idx = _element->GetBannerIndex(); - if (idx == BANNER_INDEX_NULL) + if (idx == BannerIndex::GetNull()) duk_push_null(ctx); else duk_push_int(ctx, idx.ToUnderlying()); diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index bf9f0c80f1..6325a30f12 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -128,7 +128,7 @@ static BannerIndex BannerGetNewIndex() return BannerIndex::FromUnderlying(bannerIndex); } } - return BANNER_INDEX_NULL; + return BannerIndex::GetNull(); } /** @@ -267,7 +267,7 @@ void fix_duplicated_banners() for (auto* bannerElement : OpenRCT2::TileElementsView(bannerPos)) { auto bannerIndex = bannerElement->GetIndex(); - if (bannerIndex == BANNER_INDEX_NULL) + if (bannerIndex == BannerIndex::GetNull()) continue; const auto index = bannerIndex.ToUnderlying(); diff --git a/src/openrct2/world/Banner.h b/src/openrct2/world/Banner.h index 81cef113c3..4be4ddb115 100644 --- a/src/openrct2/world/Banner.h +++ b/src/openrct2/world/Banner.h @@ -27,7 +27,7 @@ constexpr uint8_t SCROLLING_MODE_NONE = 255; struct Banner { - BannerIndex id = BANNER_INDEX_NULL; + BannerIndex id = BannerIndex::GetNull(); ObjectEntryIndex type = BANNER_NULL; uint8_t flags{}; std::string text; diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index 54a3c39fb5..df623a19a8 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -37,7 +37,7 @@ BannerIndex TileElement::GetBannerIndex() const { auto* sceneryEntry = AsLargeScenery()->GetEntry(); if (sceneryEntry == nullptr || sceneryEntry->scrolling_mode == SCROLLING_MODE_NONE) - return BANNER_INDEX_NULL; + return BannerIndex::GetNull(); return AsLargeScenery()->GetBannerIndex(); } @@ -45,14 +45,14 @@ BannerIndex TileElement::GetBannerIndex() const { auto* wallEntry = AsWall()->GetEntry(); if (wallEntry == nullptr || wallEntry->scrolling_mode == SCROLLING_MODE_NONE) - return BANNER_INDEX_NULL; + return BannerIndex::GetNull(); return AsWall()->GetBannerIndex(); } case TILE_ELEMENT_TYPE_BANNER: return AsBanner()->GetIndex(); default: - return BANNER_INDEX_NULL; + return BannerIndex::GetNull(); } } diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 17baa1b128..d8788de393 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -328,7 +328,7 @@ namespace OpenRCT2::TileInspector { // Check if the element to be pasted refers to a banner index auto bannerIndex = element.GetBannerIndex(); - if (bannerIndex != BANNER_INDEX_NULL) + if (bannerIndex != BannerIndex::GetNull()) { // The element to be pasted refers to a banner index - make a copy of it auto newBanner = CreateBanner(); From e201c3b7fdac3be6548183f2dc64036f7cb33f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:34:02 +0200 Subject: [PATCH 08/10] Expose UnderlyingType for TIdentifier --- src/openrct2/core/Identifier.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openrct2/core/Identifier.hpp b/src/openrct2/core/Identifier.hpp index a08156e498..e93f8f17ae 100644 --- a/src/openrct2/core/Identifier.hpp +++ b/src/openrct2/core/Identifier.hpp @@ -32,6 +32,8 @@ private: } public: + using UnderlyingType = T; + constexpr TIdentifier() = default; static constexpr TIdentifier GetNull() noexcept From e6187a0af4d687706e2f29a3317edd3f703dc4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:40:59 +0200 Subject: [PATCH 09/10] Use BannerIndex::UnderlyingType for iterations --- src/openrct2/ParkFile.cpp | 4 ++-- src/openrct2/world/Banner.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/ParkFile.cpp b/src/openrct2/ParkFile.cpp index 52f6a2e792..746782dfa1 100644 --- a/src/openrct2/ParkFile.cpp +++ b/src/openrct2/ParkFile.cpp @@ -972,7 +972,7 @@ namespace OpenRCT2 cs.Write(static_cast(numBanners)); [[maybe_unused]] size_t numWritten = 0; - for (uint16_t i = 0; i < MAX_BANNERS; i++) + for (BannerIndex::UnderlyingType i = 0; i < MAX_BANNERS; i++) { auto banner = GetBanner(BannerIndex::FromUnderlying(i)); if (banner != nullptr) @@ -990,7 +990,7 @@ namespace OpenRCT2 { std::vector banners; cs.ReadWriteVector(banners, [version, &cs](Banner& banner) { ReadWriteBanner(version, cs, banner); }); - for (uint16_t i = 0; i < banners.size(); i++) + for (BannerIndex::UnderlyingType i = 0; i < banners.size(); i++) { auto bannerIndex = BannerIndex::FromUnderlying(i); auto banner = GetOrCreateBanner(bannerIndex); diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 6325a30f12..7b40c6ff94 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -113,7 +113,7 @@ static ride_id_t banner_get_ride_index_at(const CoordsXYZ& bannerCoords) static BannerIndex BannerGetNewIndex() { - for (uint16_t bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) + for (BannerIndex::UnderlyingType bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) { if (bannerIndex < _banners.size()) { @@ -238,7 +238,7 @@ ride_id_t banner_get_closest_ride_index(const CoordsXYZ& mapPos) void banner_reset_broken_index() { - for (uint16_t index = 0; index < _banners.size(); index++) + for (BannerIndex::UnderlyingType index = 0; index < _banners.size(); index++) { const auto bannerId = BannerIndex::FromUnderlying(index); auto tileElement = banner_get_tile_element(bannerId); From a1b2996178a6f90952186be91056d4f534c898bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:43:33 +0200 Subject: [PATCH 10/10] Add GetBannerIndex helper in SignWindow --- src/openrct2-ui/windows/Sign.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 1671a0b459..1554c83416 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -59,9 +59,14 @@ class SignWindow final : public Window private: bool _isSmall = false; + BannerIndex GetBannerIndex() const + { + return BannerIndex::FromUnderlying(number); + } + void ShowTextInput() { - auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); + auto* banner = GetBanner(GetBannerIndex()); if (banner != nullptr) { auto bannerText = banner->GetText(); @@ -87,14 +92,14 @@ public: { number = windowNumber; _isSmall = isSmall; - auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { return false; } auto signViewPosition = banner->position.ToCoordsXY().ToTileCentre(); - auto* tileElement = banner_get_tile_element(BannerIndex::FromUnderlying(number)); + auto* tileElement = banner_get_tile_element(GetBannerIndex()); if (tileElement == nullptr) return false; @@ -138,7 +143,7 @@ public: void OnMouseUp(rct_widgetindex widgetIndex) override { - auto* banner = GetBanner(BannerIndex::FromUnderlying(number)); + auto* banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { Close(); @@ -151,7 +156,7 @@ public: break; case WIDX_SIGN_DEMOLISH: { - auto* tileElement = banner_get_tile_element(BannerIndex::FromUnderlying(number)); + auto* tileElement = banner_get_tile_element(GetBannerIndex()); if (tileElement == nullptr) { Close(); @@ -203,8 +208,7 @@ public: if (dropdownIndex == -1) return; list_information_type = dropdownIndex; - auto signSetStyleAction = SignSetStyleAction( - BannerIndex::FromUnderlying(number), dropdownIndex, var_492, !_isSmall); + auto signSetStyleAction = SignSetStyleAction(GetBannerIndex(), dropdownIndex, var_492, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -213,8 +217,7 @@ public: if (dropdownIndex == -1) return; var_492 = dropdownIndex; - auto signSetStyleAction = SignSetStyleAction( - BannerIndex::FromUnderlying(number), list_information_type, dropdownIndex, !_isSmall); + auto signSetStyleAction = SignSetStyleAction(GetBannerIndex(), list_information_type, dropdownIndex, !_isSmall); GameActions::Execute(&signSetStyleAction); break; } @@ -229,7 +232,7 @@ public: { if (widgetIndex == WIDX_SIGN_TEXT && !text.empty()) { - auto signSetNameAction = SignSetNameAction(BannerIndex::FromUnderlying(number), std::string(text)); + auto signSetNameAction = SignSetNameAction(GetBannerIndex(), std::string(text)); GameActions::Execute(&signSetNameAction); } } @@ -290,7 +293,7 @@ public: { RemoveViewport(); - auto banner = GetBanner(BannerIndex::FromUnderlying(number)); + auto banner = GetBanner(GetBannerIndex()); if (banner == nullptr) { return;