From d47f5d380f995528afa23b5e20c188c2aa2b2acb Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 11 Jan 2023 17:57:40 +0100 Subject: [PATCH] Pass CarEntry as a ref in a few functions --- src/openrct2/object/RideObject.cpp | 54 +++++++++++++++--------------- src/openrct2/object/RideObject.h | 4 +-- src/openrct2/ride/Ride.cpp | 14 ++++---- src/openrct2/ride/RideEntry.h | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index decf8159db..c97f45bf7c 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -211,59 +211,59 @@ void RideObject::Load() int32_t currentCarImagesOffset = _legacyType.images_offset + RCT2::ObjectLimits::MaxRideTypesPerRideEntry; for (int32_t i = 0; i < RCT2::ObjectLimits::MaxCarTypesPerRideEntry; i++) { - CarEntry* carEntry = &_legacyType.Cars[i]; - if (carEntry->GroupEnabled(SpriteGroupType::SlopeFlat)) + CarEntry& carEntry = _legacyType.Cars[i]; + if (carEntry.GroupEnabled(SpriteGroupType::SlopeFlat)) { // RCT2 calculates num_vertical_frames and num_horizontal_frames and overwrites these properties on the car // entry. Immediately afterwards, the two were multiplied in order to calculate base_num_frames and were never used // again. This has been changed to use the calculation results directly - num_vertical_frames and // num_horizontal_frames are no longer set on the car entry. // 0x6DE946 - carEntry->base_num_frames = CalculateNumVerticalFrames(carEntry) * CalculateNumHorizontalFrames(carEntry); + carEntry.base_num_frames = CalculateNumVerticalFrames(carEntry) * CalculateNumHorizontalFrames(carEntry); uint32_t baseImageId = currentCarImagesOffset; uint32_t imageIndex = baseImageId; - carEntry->base_image_id = baseImageId; + carEntry.base_image_id = baseImageId; for (uint8_t spriteGroup = 0; spriteGroup < EnumValue(SpriteGroupType::Count); spriteGroup++) { - if (carEntry->SpriteGroups[spriteGroup].Enabled()) + if (carEntry.SpriteGroups[spriteGroup].Enabled()) { - carEntry->SpriteGroups[spriteGroup].imageId = imageIndex; - const auto spriteCount = carEntry->base_num_frames - * carEntry->NumRotationSprites(static_cast(spriteGroup)) + carEntry.SpriteGroups[spriteGroup].imageId = imageIndex; + const auto spriteCount = carEntry.base_num_frames + * carEntry.NumRotationSprites(static_cast(spriteGroup)) * SpriteGroupMultiplier[spriteGroup]; imageIndex += spriteCount; } } - carEntry->NumCarImages = imageIndex - currentCarImagesOffset; + carEntry.NumCarImages = imageIndex - currentCarImagesOffset; // Move the offset over this car’s images. Including peeps - currentCarImagesOffset = imageIndex + carEntry->no_seating_rows * carEntry->NumCarImages; + currentCarImagesOffset = imageIndex + carEntry.no_seating_rows * carEntry.NumCarImages; // 0x6DEB0D - if (!(carEntry->flags & CAR_ENTRY_FLAG_RECALCULATE_SPRITE_BOUNDS)) + if (!(carEntry.flags & CAR_ENTRY_FLAG_RECALCULATE_SPRITE_BOUNDS)) { int32_t num_images = currentCarImagesOffset - baseImageId; - if (carEntry->flags & CAR_ENTRY_FLAG_SPRITE_BOUNDS_INCLUDE_INVERTED_SET) + if (carEntry.flags & CAR_ENTRY_FLAG_SPRITE_BOUNDS_INCLUDE_INVERTED_SET) { num_images *= 2; } if (!gOpenRCT2NoGraphics) { - set_vehicle_type_image_max_sizes(carEntry, num_images); + CarEntrySetImageMaxSizes(carEntry, num_images); } } if (!_peepLoadingPositions[i].empty()) { - carEntry->peep_loading_positions = std::move(_peepLoadingPositions[i]); + carEntry.peep_loading_positions = std::move(_peepLoadingPositions[i]); } if (!_peepLoadingWaypoints[i].empty()) { - carEntry->peep_loading_waypoints = std::move(_peepLoadingWaypoints[i]); + carEntry.peep_loading_waypoints = std::move(_peepLoadingWaypoints[i]); } } } @@ -369,22 +369,22 @@ void RideObject::ReadLegacyCar([[maybe_unused]] IReadObjectContext* context, ISt ReadLegacySpriteGroups(car, spriteGroups); } -uint8_t RideObject::CalculateNumVerticalFrames(const CarEntry* carEntry) +uint8_t RideObject::CalculateNumVerticalFrames(const CarEntry& carEntry) { // 0x6DE90B uint8_t numVerticalFrames; - if (carEntry->flags & CAR_ENTRY_FLAG_OVERRIDE_NUM_VERTICAL_FRAMES) + if (carEntry.flags & CAR_ENTRY_FLAG_OVERRIDE_NUM_VERTICAL_FRAMES) { - numVerticalFrames = carEntry->num_vertical_frames_override; + numVerticalFrames = carEntry.num_vertical_frames_override; } else { - if (!(carEntry->flags & CAR_ENTRY_FLAG_SPINNING_ADDITIONAL_FRAMES)) + if (!(carEntry.flags & CAR_ENTRY_FLAG_SPINNING_ADDITIONAL_FRAMES)) { - if (carEntry->flags & CAR_ENTRY_FLAG_VEHICLE_ANIMATION - && carEntry->animation != CAR_ENTRY_ANIMATION_OBSERVATION_TOWER) + if (carEntry.flags & CAR_ENTRY_FLAG_VEHICLE_ANIMATION + && carEntry.animation != CAR_ENTRY_ANIMATION_OBSERVATION_TOWER) { - if (!(carEntry->flags & CAR_ENTRY_FLAG_DODGEM_INUSE_LIGHTS)) + if (!(carEntry.flags & CAR_ENTRY_FLAG_DODGEM_INUSE_LIGHTS)) { numVerticalFrames = 4; } @@ -407,14 +407,14 @@ uint8_t RideObject::CalculateNumVerticalFrames(const CarEntry* carEntry) return numVerticalFrames; } -uint8_t RideObject::CalculateNumHorizontalFrames(const CarEntry* carEntry) +uint8_t RideObject::CalculateNumHorizontalFrames(const CarEntry& carEntry) { uint8_t numHorizontalFrames; - if (carEntry->flags & CAR_ENTRY_FLAG_SWINGING) + if (carEntry.flags & CAR_ENTRY_FLAG_SWINGING) { - if (!(carEntry->flags & CAR_ENTRY_FLAG_SUSPENDED_SWING) && !(carEntry->flags & CAR_ENTRY_FLAG_SLIDE_SWING)) + if (!(carEntry.flags & CAR_ENTRY_FLAG_SUSPENDED_SWING) && !(carEntry.flags & CAR_ENTRY_FLAG_SLIDE_SWING)) { - if (carEntry->flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) + if (carEntry.flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) { numHorizontalFrames = 3; } @@ -423,7 +423,7 @@ uint8_t RideObject::CalculateNumHorizontalFrames(const CarEntry* carEntry) numHorizontalFrames = 5; } } - else if (!(carEntry->flags & CAR_ENTRY_FLAG_SUSPENDED_SWING) || !(carEntry->flags & CAR_ENTRY_FLAG_SLIDE_SWING)) + else if (!(carEntry.flags & CAR_ENTRY_FLAG_SUSPENDED_SWING) || !(carEntry.flags & CAR_ENTRY_FLAG_SLIDE_SWING)) { numHorizontalFrames = 7; } diff --git a/src/openrct2/object/RideObject.h b/src/openrct2/object/RideObject.h index f5e78e66c8..fed6398065 100644 --- a/src/openrct2/object/RideObject.h +++ b/src/openrct2/object/RideObject.h @@ -55,8 +55,8 @@ private: vehicle_colour_preset_list ReadJsonCarColours(json_t& jCarColours); std::vector ReadJsonColourConfiguration(json_t& jColourConfig); - static uint8_t CalculateNumVerticalFrames(const CarEntry* carEntry); - static uint8_t CalculateNumHorizontalFrames(const CarEntry* carEntry); + static uint8_t CalculateNumVerticalFrames(const CarEntry& carEntry); + static uint8_t CalculateNumHorizontalFrames(const CarEntry& carEntry); static bool IsRideTypeShopOrFacility(ride_type_t rideType); static uint8_t ParseRideCategory(const std::string& s); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 0ea798cede..0708ce1d11 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4489,7 +4489,7 @@ bool ride_has_any_track_elements(const Ride& ride) * * rct2: 0x006847BA */ -void set_vehicle_type_image_max_sizes(CarEntry* vehicle_type, int32_t num_images) +void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages) { uint8_t bitmap[200][200] = { 0 }; @@ -4503,9 +4503,9 @@ void set_vehicle_type_image_max_sizes(CarEntry* vehicle_type, int32_t num_images /*.zoom_level = */ ZoomLevel{ 0 }, }; - for (int32_t i = 0; i < num_images; ++i) + for (int32_t i = 0; i < numImages; ++i) { - gfx_draw_sprite_software(&dpi, ImageId(vehicle_type->base_image_id + i), { 0, 0 }); + gfx_draw_sprite_software(&dpi, ImageId(carEntry.base_image_id + i), { 0, 0 }); } int32_t al = -1; for (int32_t i = 99; i != 0; --i) @@ -4574,14 +4574,14 @@ void set_vehicle_type_image_max_sizes(CarEntry* vehicle_type, int32_t num_images // Moved from object paint - if (vehicle_type->flags & CAR_ENTRY_FLAG_SPRITE_BOUNDS_INCLUDE_INVERTED_SET) + if (carEntry.flags & CAR_ENTRY_FLAG_SPRITE_BOUNDS_INCLUDE_INVERTED_SET) { bl += 16; } - vehicle_type->sprite_width = al; - vehicle_type->sprite_height_negative = bl; - vehicle_type->sprite_height_positive = bh; + carEntry.sprite_width = al; + carEntry.sprite_height_negative = bl; + carEntry.sprite_height_positive = bh; } /** diff --git a/src/openrct2/ride/RideEntry.h b/src/openrct2/ride/RideEntry.h index 7caa62706a..ea9f48f799 100644 --- a/src/openrct2/ride/RideEntry.h +++ b/src/openrct2/ride/RideEntry.h @@ -100,5 +100,5 @@ struct rct_ride_entry } }; -void set_vehicle_type_image_max_sizes(CarEntry* vehicle_type, int32_t num_images); +void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages); RideNaming get_ride_naming(const ride_type_t rideType, const rct_ride_entry& rideEntry);