From 57d2877e67965e780d68fc16d71e384741ab7ead Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 4 Jul 2020 07:53:10 +0100 Subject: [PATCH] Provide accesor function for get entity list count --- src/openrct2-ui/windows/EditorBottomToolbar.cpp | 8 +++----- src/openrct2/actions/StaffHireNewAction.hpp | 2 +- src/openrct2/peep/Peep.cpp | 2 +- src/openrct2/ride/Ride.cpp | 4 ++-- src/openrct2/world/Sprite.cpp | 13 +++++++++---- src/openrct2/world/Sprite.h | 1 + 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 2918e80e00..9dc1d04dce 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -310,8 +310,7 @@ static void window_editor_bottom_toolbar_mouseup([[maybe_unused]] rct_window* w, if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON) { if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) - || (gSpriteListCount[static_cast(EntityListId::Free)] == MAX_SPRITES - && !(gParkFlags & PARK_FLAGS_SPRITES_INITIALISED))) + || (GetEntityListCount(EntityListId::Free) == MAX_SPRITES && !(gParkFlags & PARK_FLAGS_SPRITES_INITIALISED))) { previous_button_mouseup_events[gS6Info.editor_step](); } @@ -371,8 +370,7 @@ void window_editor_bottom_toolbar_invalidate(rct_window* w) } else if (!(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)) { - if (gSpriteListCount[static_cast(EntityListId::Free)] != MAX_SPRITES - || gParkFlags & PARK_FLAGS_SPRITES_INITIALISED) + if (GetEntityListCount(EntityListId::Free) != MAX_SPRITES || gParkFlags & PARK_FLAGS_SPRITES_INITIALISED) { hide_previous_step_button(); } @@ -397,7 +395,7 @@ void window_editor_bottom_toolbar_paint(rct_window* w, rct_drawpixelinfo* dpi) { drawPreviousButton = true; } - else if (gSpriteListCount[static_cast(EntityListId::Free)] != MAX_SPRITES) + else if (GetEntityListCount(EntityListId::Free) != MAX_SPRITES) { drawNextButton = true; } diff --git a/src/openrct2/actions/StaffHireNewAction.hpp b/src/openrct2/actions/StaffHireNewAction.hpp index c89f9c131b..58836bce1c 100644 --- a/src/openrct2/actions/StaffHireNewAction.hpp +++ b/src/openrct2/actions/StaffHireNewAction.hpp @@ -105,7 +105,7 @@ private: return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); } - if (gSpriteListCount[static_cast(EntityListId::Free)] < 400) + if (GetEntityListCount(EntityListId::Free) < 400) { return MakeResult(GA_ERROR::NO_FREE_ELEMENTS, STR_TOO_MANY_PEOPLE_IN_GAME); } diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index cc220d2ddb..c2926885f3 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1587,7 +1587,7 @@ void Peep::InsertNewThought(PeepThoughtType thoughtType, uint8_t thoughtArgument */ Peep* Peep::Generate(const CoordsXYZ& coords) { - if (gSpriteListCount[static_cast(EntityListId::Free)] < 400) + if (GetEntityListCount(EntityListId::Free) < 400) return nullptr; Peep* peep = &create_sprite(SPRITE_IDENTIFIER_PEEP)->peep; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index d949919eef..dc25caca15 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4299,8 +4299,8 @@ static void ride_set_start_finish_points(ride_id_t rideIndex, CoordsXYE* startEl */ static int32_t count_free_misc_sprite_slots() { - int32_t miscSpriteCount = gSpriteListCount[static_cast(EntityListId::Misc)]; - int32_t remainingSpriteCount = gSpriteListCount[static_cast(EntityListId::Free)]; + int32_t miscSpriteCount = GetEntityListCount(EntityListId::Misc); + int32_t remainingSpriteCount = GetEntityListCount(EntityListId::Free); return std::max(0, miscSpriteCount + remainingSpriteCount - 300); } diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 00d0af04ad..18513ead2e 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -78,6 +78,11 @@ template<> bool SpriteBase::Is() const return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_EXPLOSION_CLOUD; } +uint16_t GetEntityListCount(EntityListId list) +{ + return gSpriteListCount[static_cast(list)]; +} + std::string rct_sprite_checksum::ToString() const { std::string result; @@ -380,7 +385,7 @@ static constexpr uint16_t MAX_MISC_SPRITES = 300; rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, EntityListId linkedListIndex) { - if (gSpriteListCount[static_cast(EntityListId::Free)] == 0) + if (GetEntityListCount(EntityListId::Free) == 0) { // No free sprites. return nullptr; @@ -391,8 +396,8 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, EntityListId linke // Misc sprites are commonly used for effects, if there are less than MAX_MISC_SPRITES // free it will fail to keep slots for more relevant sprites. // Also there can't be more than MAX_MISC_SPRITES sprites in this list. - uint16_t miscSlotsRemaining = MAX_MISC_SPRITES - gSpriteListCount[static_cast(EntityListId::Misc)]; - if (miscSlotsRemaining >= gSpriteListCount[static_cast(EntityListId::Free)]) + uint16_t miscSlotsRemaining = MAX_MISC_SPRITES - GetEntityListCount(EntityListId::Misc); + if (miscSlotsRemaining >= GetEntityListCount(EntityListId::Free)) { return nullptr; } @@ -800,7 +805,7 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type) if (!litter_can_be_at(offsetLitterPos)) return; - if (gSpriteListCount[static_cast(EntityListId::Litter)] >= 500) + if (GetEntityListCount(EntityListId::Litter) >= 500) { Litter* newestLitter = nullptr; uint32_t newestLitterCreationTick = 0; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 89aed45d91..fd89ddecbb 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -202,6 +202,7 @@ template T* GetEntity(size_t sprite_idx) } SpriteBase* GetEntity(size_t sprite_idx); +uint16_t GetEntityListCount(EntityListId list); extern uint16_t gSpriteListHead[static_cast(EntityListId::Count)]; extern uint16_t gSpriteListCount[static_cast(EntityListId::Count)];