1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 15:24:30 +01:00

Apply review suggestions

This commit is contained in:
ζeh Matt
2023-02-22 00:31:11 +02:00
parent ef8d08c5e5
commit d6be08a410

View File

@@ -98,8 +98,8 @@ static constexpr const int32_t RideInspectionInterval[] = {
// Ride storage for all the rides in the park, rides with RideId::Null are considered free.
static std::array<Ride, OpenRCT2::Limits::MaxRidesInPark> _rides{};
// This is not the real size of rides in use, rather the highest slot used + 1.
static size_t _maxRideSize = 0;
// This is the highest used index + 1 of the _rides array.
static size_t _endOfUsedRange = 0;
// A special instance of Ride that is used to draw previews such as the track designs.
static Ride _previewRide{};
@@ -131,7 +131,7 @@ RideManager GetRideManager()
size_t RideManager::size() const
{
size_t count = 0;
for (size_t i = 0; i < _maxRideSize; i++)
for (size_t i = 0; i < _endOfUsedRange; i++)
{
if (!_rides[i].id.IsNull())
{
@@ -143,17 +143,17 @@ size_t RideManager::size() const
RideManager::Iterator RideManager::begin()
{
return RideManager::Iterator(*this, 0u, _maxRideSize);
return RideManager::Iterator(*this, 0u, _endOfUsedRange);
}
RideManager::Iterator RideManager::end()
{
return RideManager::Iterator(*this, _maxRideSize, _maxRideSize);
return RideManager::Iterator(*this, _endOfUsedRange, _endOfUsedRange);
}
RideManager::Iterator RideManager::get(RideId rideId)
{
return RideManager::Iterator(*this, rideId.ToUnderlying(), _maxRideSize);
return RideManager::Iterator(*this, rideId.ToUnderlying(), _endOfUsedRange);
}
RideId GetNextFreeRideId()
@@ -171,7 +171,7 @@ RideId GetNextFreeRideId()
Ride* RideAllocateAtIndex(RideId index)
{
const auto idx = index.ToUnderlying();
_maxRideSize = std::max<size_t>(idx + 1, _maxRideSize);
_endOfUsedRange = std::max<size_t>(idx + 1, _endOfUsedRange);
auto result = &_rides[idx];
assert(result->id == RideId::GetNull());
@@ -185,6 +185,14 @@ Ride& RideGetTemporaryForPreview()
return _previewRide;
}
static void RideReset(Ride& ride)
{
ride.id = RideId::GetNull();
ride.type = RIDE_TYPE_NULL;
ride.custom_name = {};
ride.measurement = {};
}
void RideDelete(RideId id)
{
const auto idx = id.ToUnderlying();
@@ -193,15 +201,12 @@ void RideDelete(RideId id)
assert(_rides[idx].type != RIDE_TYPE_NULL);
auto& ride = _rides[idx];
ride.id = RideId::GetNull();
ride.type = RIDE_TYPE_NULL;
ride.custom_name = {};
ride.measurement = {};
RideReset(ride);
// Shrink maximum ride size.
while (_maxRideSize > 0 && _rides[_maxRideSize - 1].id.IsNull())
while (_endOfUsedRange > 0 && _rides[_endOfUsedRange - 1].id.IsNull())
{
_maxRideSize--;
_endOfUsedRange--;
}
}
@@ -936,12 +941,8 @@ bool Ride::SupportsStatus(RideStatus s) const
*/
void RideInitAll()
{
std::for_each(std::begin(_rides), std::end(_rides), [](auto& ride) {
ride.id = RideId::GetNull();
ride.type = RIDE_TYPE_NULL;
ride.custom_name = {};
});
_maxRideSize = 0;
std::for_each(std::begin(_rides), std::end(_rides), RideReset);
_endOfUsedRange = 0;
}
/**