1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Use a vector for guest ridden rides (#20506)

* Use a vector for guest ridden rides

* Add casts to reduce warnings

* Add mising clear
This commit is contained in:
Duncan
2023-07-02 20:26:37 +01:00
committed by GitHub
parent 92764c2e32
commit 62914a39fb

View File

@@ -168,6 +168,7 @@ private:
uint16_t _beingWatchedTimer = 0; uint16_t _beingWatchedTimer = 0;
uint16_t _guestAnimationFrame = 0; uint16_t _guestAnimationFrame = 0;
int16_t _pickedPeepX = LOCATION_NULL; // entity->x gets set to 0x8000 on pickup, this is the old value int16_t _pickedPeepX = LOCATION_NULL; // entity->x gets set to 0x8000 on pickup, this is the old value
std::vector<RideId> _riddenRides;
public: public:
void OnOpen() override void OnOpen() override
@@ -181,7 +182,6 @@ public:
min_height = 157; min_height = 157;
max_width = 500; max_width = 500;
max_height = 450; max_height = 450;
no_list_items = 0;
selected_list_item = -1; selected_list_item = -1;
} }
@@ -493,7 +493,7 @@ private:
page = newPage; page = newPage;
frame_no = 0; frame_no = 0;
no_list_items = 0; _riddenRides.clear();
selected_list_item = -1; selected_list_item = -1;
RemoveViewport(); RemoveViewport();
@@ -1237,20 +1237,19 @@ private:
if (!(numTicks & 0x7FF)) if (!(numTicks & 0x7FF))
Invalidate(); Invalidate();
uint8_t currListPosition = 0; const auto oldSize = _riddenRides.size();
_riddenRides.clear();
for (const auto& r : GetRideManager()) for (const auto& r : GetRideManager())
{ {
if (r.IsRide() && guest->HasRidden(r)) if (r.IsRide() && guest->HasRidden(r))
{ {
list_item_positions[currListPosition] = r.id.ToUnderlying(); _riddenRides.push_back(r.id);
currListPosition++;
} }
} }
// If there are new items // If there are new items
if (no_list_items != currListPosition) if (oldSize != _riddenRides.size())
{ {
no_list_items = currListPosition;
Invalidate(); Invalidate();
} }
} }
@@ -1258,7 +1257,7 @@ private:
ScreenSize OnScrollGetSizeRides(int32_t scrollIndex) ScreenSize OnScrollGetSizeRides(int32_t scrollIndex)
{ {
ScreenSize newSize; ScreenSize newSize;
newSize.height = no_list_items * 10; newSize.height = static_cast<int32_t>(_riddenRides.size()) * 10;
if (selected_list_item != -1) if (selected_list_item != -1)
{ {
@@ -1282,18 +1281,18 @@ private:
void OnScrollMouseDownRides(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) void OnScrollMouseDownRides(int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{ {
auto index = screenCoords.y / 10; auto index = screenCoords.y / 10;
if (index >= no_list_items) if (index >= static_cast<int32_t>(_riddenRides.size()))
return; return;
auto intent = Intent(WindowClass::Ride); auto intent = Intent(WindowClass::Ride);
intent.PutExtra(INTENT_EXTRA_RIDE_ID, list_item_positions[index]); intent.PutExtra(INTENT_EXTRA_RIDE_ID, _riddenRides[index]);
ContextOpenIntent(&intent); ContextOpenIntent(&intent);
} }
void OnScrollMouseOverRides(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) void OnScrollMouseOverRides(int32_t scrollIndex, const ScreenCoordsXY& screenCoords)
{ {
auto index = screenCoords.y / 10; auto index = screenCoords.y / 10;
if (index >= no_list_items) if (index >= static_cast<int32_t>(_riddenRides.size()))
return; return;
if (index == selected_list_item) if (index == selected_list_item)
@@ -1353,9 +1352,9 @@ private:
auto colour = ColourMapA[colours[1]].mid_light; auto colour = ColourMapA[colours[1]].mid_light;
GfxFillRect(dpi, { { dpi.x, dpi.y }, { dpi.x + dpi.width - 1, dpi.y + dpi.height - 1 } }, colour); GfxFillRect(dpi, { { dpi.x, dpi.y }, { dpi.x + dpi.width - 1, dpi.y + dpi.height - 1 } }, colour);
for (int32_t listIndex = 0; listIndex < no_list_items; listIndex++) for (int32_t listIndex = 0; listIndex < static_cast<int32_t>(_riddenRides.size()); listIndex++)
{ {
auto y = listIndex * 10; int32_t y = listIndex * 10;
StringId stringId = STR_BLACK_STRING; StringId stringId = STR_BLACK_STRING;
if (listIndex == selected_list_item) if (listIndex == selected_list_item)
{ {
@@ -1363,8 +1362,7 @@ private:
stringId = STR_WINDOW_COLOUR_2_STRINGID; stringId = STR_WINDOW_COLOUR_2_STRINGID;
} }
const auto rId = RideId::FromUnderlying(list_item_positions[listIndex]); auto* r = GetRide(_riddenRides[listIndex]);
auto* r = GetRide(rId);
if (r != nullptr) if (r != nullptr)
{ {
auto ft = Formatter(); auto ft = Formatter();