Use const reference instead of copy for location structures

This commit is contained in:
Matt 2020-02-13 10:25:42 +01:00
parent e53d76ae2e
commit 758a7e432f
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
26 changed files with 65 additions and 66 deletions

View File

@ -134,7 +134,7 @@ private:
return result;
}
money32 ClearSceneryFromTile(CoordsXY tilePos, bool executing) const
money32 ClearSceneryFromTile(const CoordsXY& tilePos, bool executing) const
{
// Pass down all flags.
TileElement* tileElement = nullptr;

View File

@ -43,13 +43,13 @@ private:
public:
LandBuyRightsAction() = default;
LandBuyRightsAction(MapRange range, LandBuyRightSetting setting)
LandBuyRightsAction(const MapRange& range, LandBuyRightSetting setting)
: _range(range)
, _setting(static_cast<uint8_t>(setting))
{
}
LandBuyRightsAction(CoordsXY coord, LandBuyRightSetting setting)
LandBuyRightsAction(const CoordsXY& coord, LandBuyRightSetting setting)
: _range(coord.x, coord.y, coord.x, coord.y)
, _setting(static_cast<uint8_t>(setting))
{

View File

@ -36,7 +36,7 @@ public:
LandLowerAction()
{
}
LandLowerAction(CoordsXY coords, MapRange range, uint8_t selectionType)
LandLowerAction(const CoordsXY& coords, MapRange range, uint8_t selectionType)
: _coords(coords)
, _range(range)
, _selectionType(selectionType)

View File

@ -37,7 +37,7 @@ public:
LandRaiseAction()
{
}
LandRaiseAction(CoordsXY coords, MapRange range, uint8_t selectionType)
LandRaiseAction(const CoordsXY& coords, MapRange range, uint8_t selectionType)
: _coords(coords)
, _range(range)
, _selectionType(selectionType)

View File

@ -35,7 +35,7 @@ public:
LandSetHeightAction()
{
}
LandSetHeightAction(CoordsXY coords, uint8_t height, uint8_t style)
LandSetHeightAction(const CoordsXY& coords, uint8_t height, uint8_t style)
: _coords(coords)
, _height(height)
, _style(style)

View File

@ -45,14 +45,14 @@ private:
public:
LandSetRightsAction() = default;
LandSetRightsAction(MapRange range, LandSetRightSetting setting, uint8_t ownership = 0)
LandSetRightsAction(const MapRange& range, LandSetRightSetting setting, uint8_t ownership = 0)
: _range(range)
, _setting(static_cast<uint8_t>(setting))
, _ownership(ownership)
{
}
LandSetRightsAction(CoordsXY coord, LandSetRightSetting setting, uint8_t ownership = 0)
LandSetRightsAction(const CoordsXY& coord, LandSetRightSetting setting, uint8_t ownership = 0)
: _range(coord.x, coord.y, coord.x, coord.y)
, _setting(static_cast<uint8_t>(setting))
, _ownership(ownership)

View File

@ -41,7 +41,7 @@ public:
LandSmoothAction()
{
}
LandSmoothAction(CoordsXY coords, MapRange range, uint8_t selectionType, bool isLowering)
LandSmoothAction(const CoordsXY& coords, MapRange range, uint8_t selectionType, bool isLowering)
: _coords(coords)
, _range(range)
, _selectionType(selectionType)
@ -105,8 +105,8 @@ private:
}
money32 SmoothLandRowByEdge(
bool isExecuting, CoordsXY loc, int32_t expectedLandHeight1, int32_t expectedLandHeight2, int32_t stepX, int32_t stepY,
int32_t direction1, int32_t direction2, int32_t checkDirection1, int32_t checkDirection2) const
bool isExecuting, const CoordsXY& loc, int32_t expectedLandHeight1, int32_t expectedLandHeight2, int32_t stepX,
int32_t stepY, int32_t direction1, int32_t direction2, int32_t checkDirection1, int32_t checkDirection2) const
{
uint8_t shouldContinue = 0xF;
int32_t landChangePerTile = _isLowering ? 2 : -2;
@ -249,7 +249,7 @@ private:
}
money32 SmoothLandRowByCorner(
bool isExecuting, CoordsXY loc, int32_t expectedLandHeight, int32_t stepX, int32_t stepY, int32_t direction,
bool isExecuting, const CoordsXY& loc, int32_t expectedLandHeight, int32_t stepX, int32_t stepY, int32_t direction,
int32_t checkDirection) const
{
bool shouldContinue = true;

View File

@ -30,7 +30,7 @@ private:
public:
RideEntranceExitPlaceAction() = default;
RideEntranceExitPlaceAction(CoordsXY loc, Direction direction, ride_id_t rideIndex, uint8_t stationNum, bool isExit)
RideEntranceExitPlaceAction(const CoordsXY& loc, Direction direction, ride_id_t rideIndex, uint8_t stationNum, bool isExit)
: _loc(loc)
, _direction(direction)
, _rideIndex(rideIndex)

View File

@ -25,7 +25,7 @@ private:
public:
RideEntranceExitRemoveAction() = default;
RideEntranceExitRemoveAction(CoordsXY loc, ride_id_t rideIndex, uint8_t stationNum, bool isExit)
RideEntranceExitRemoveAction(const CoordsXY& loc, ride_id_t rideIndex, uint8_t stationNum, bool isExit)
: _loc(loc)
, _rideIndex(rideIndex)
, _stationNum(stationNum)

View File

@ -25,7 +25,7 @@ public:
StaffSetPatrolAreaAction()
{
}
StaffSetPatrolAreaAction(uint16_t spriteId, CoordsXY loc)
StaffSetPatrolAreaAction(uint16_t spriteId, const CoordsXY& loc)
: _spriteId(spriteId)
, _loc(loc)
{

View File

@ -25,7 +25,7 @@ public:
WaterSetHeightAction()
{
}
WaterSetHeightAction(CoordsXY coords, uint8_t height)
WaterSetHeightAction(const CoordsXY& coords, uint8_t height)
: _coords(coords)
, _height(height)
{

View File

@ -103,10 +103,8 @@ void viewport_init_all()
* out_x : ax
* out_y : bx
*/
std::optional<ScreenCoordsXY> centre_2d_coordinates(CoordsXYZ loc, rct_viewport* viewport)
std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, rct_viewport* viewport)
{
auto screenCoord = translate_3d_to_2d_with_z(get_current_rotation(), loc);
// If the start location was invalid
// propagate the invalid location to the output.
// This fixes a bug that caused the game to enter an infinite loop.
@ -115,6 +113,7 @@ std::optional<ScreenCoordsXY> centre_2d_coordinates(CoordsXYZ loc, rct_viewport*
return std::nullopt;
}
auto screenCoord = translate_3d_to_2d_with_z(get_current_rotation(), loc);
screenCoord.x -= viewport->view_width / 2;
screenCoord.y -= viewport->view_height / 2;
return { screenCoord };

View File

@ -130,7 +130,7 @@ extern paint_entry* gNextFreePaintStruct;
extern uint8_t gCurrentRotation;
void viewport_init_all();
std::optional<ScreenCoordsXY> centre_2d_coordinates(CoordsXYZ loc, rct_viewport* viewport);
std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, rct_viewport* viewport);
void viewport_create(
rct_window* w, int32_t x, int32_t y, int32_t width, int32_t height, int32_t zoom, int32_t centre_x, int32_t centre_y,
int32_t centre_z, char flags, uint16_t sprite);
@ -177,7 +177,7 @@ int32_t viewport_interaction_right_over(ScreenCoordsXY screenCoords);
int32_t viewport_interaction_right_click(ScreenCoordsXY screenCoords);
CoordsXY sub_68A15E(ScreenCoordsXY screenCoords);
void sub_68B2B7(paint_session* session, CoordsXY mapCoords);
void sub_68B2B7(paint_session* session, const CoordsXY& mapCoords);
void viewport_invalidate(rct_viewport* viewport, int32_t left, int32_t top, int32_t right, int32_t bottom);

View File

@ -67,7 +67,7 @@ void tile_element_paint_setup(paint_session* session, int32_t x, int32_t y)
*
* rct2: 0x0068B2B7
*/
void sub_68B2B7(paint_session* session, CoordsXY mapCoords)
void sub_68B2B7(paint_session* session, const CoordsXY& mapCoords)
{
if (mapCoords.x < gMapSizeUnits && mapCoords.y < gMapSizeUnits && mapCoords.x >= 32 && mapCoords.y >= 32)
{

View File

@ -832,7 +832,7 @@ public:
void UpdateStaff(uint32_t stepsToTake);
void Tick128UpdateStaff();
bool IsMechanic() const;
bool IsPatrolAreaSet(CoordsXY coords) const;
bool IsPatrolAreaSet(const CoordsXY& coords) const;
private:
void UpdatePatrolling();

View File

@ -395,7 +395,7 @@ static bool staff_is_patrol_area_set(int32_t staffIndex, int32_t x, int32_t y)
return gStaffPatrolAreas[peepOffset + offset] & (((uint32_t)1) << bitIndex);
}
bool Staff::IsPatrolAreaSet(CoordsXY coords) const
bool Staff::IsPatrolAreaSet(const CoordsXY& coords) const
{
return staff_is_patrol_area_set(staff_id, coords.x, coords.y);
}

View File

@ -202,7 +202,7 @@ enum
// clang-format on
bool track_paint_util_has_fence(
enum edge_t edge, CoordsXY position, const TileElement* tileElement, Ride* ride, uint8_t rotation)
enum edge_t edge, const CoordsXY& position, const TileElement* tileElement, Ride* ride, uint8_t rotation)
{
TileCoordsXY offset;
switch (edge)
@ -285,7 +285,7 @@ void track_paint_util_paint_fences(
}
/* Supports are only placed every 2 tiles for flat pieces*/
bool track_paint_util_should_paint_supports(CoordsXY position)
bool track_paint_util_should_paint_supports(const CoordsXY& position)
{
if ((position.x & (1 << 5)) == (position.y & (1 << 5)))
return true;

View File

@ -279,7 +279,7 @@ extern const uint8_t mapLeftEighthTurnToOrthogonal[5];
extern const size_t mini_golf_peep_animation_lengths[];
bool track_paint_util_has_fence(
enum edge_t edge, CoordsXY position, const TileElement* tileElement, Ride* ride, uint8_t rotation);
enum edge_t edge, const CoordsXY& position, const TileElement* tileElement, Ride* ride, uint8_t rotation);
void track_paint_util_paint_floor(
paint_session* session, uint8_t edges, uint32_t colourFlags, uint16_t height, const uint32_t floorSprites[4]);
void track_paint_util_paint_fences(
@ -303,7 +303,7 @@ void track_paint_util_draw_station_3(
void track_paint_util_draw_station_inverted(
paint_session* session, ride_id_t rideIndex, uint8_t direction, int32_t height, const TileElement* tileElement,
uint8_t stationVariant);
bool track_paint_util_should_paint_supports(CoordsXY position);
bool track_paint_util_should_paint_supports(const CoordsXY& position);
void track_paint_util_draw_pier(
paint_session* session, Ride* ride, const StationObject* stationObject, CoordsXY position, uint8_t direction,
int32_t height, const TileElement* tileElement, uint8_t rotation);

View File

@ -2244,7 +2244,7 @@ void PathElement::SetEdgesAndCorners(uint8_t newEdgesAndCorners)
edges = newEdgesAndCorners;
}
bool PathElement::IsLevelCrossing(CoordsXY coords) const
bool PathElement::IsLevelCrossing(const CoordsXY& coords) const
{
auto trackElement = map_get_track_element_at({ coords, GetBaseZ() });
if (trackElement == nullptr)

View File

@ -94,14 +94,14 @@ struct CoordsXY
{
}
CoordsXY& operator+=(const CoordsXY rhs)
CoordsXY& operator+=(const CoordsXY& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
CoordsXY& operator-=(const CoordsXY rhs)
CoordsXY& operator-=(const CoordsXY& rhs)
{
x -= rhs.x;
y -= rhs.y;
@ -189,7 +189,7 @@ struct CoordsXYRangedZ : public CoordsXY
{
}
constexpr CoordsXYRangedZ(CoordsXY _c, int32_t _baseZ, int32_t _clearanceZ)
constexpr CoordsXYRangedZ(const CoordsXY& _c, int32_t _baseZ, int32_t _clearanceZ)
: CoordsXY(_c)
, baseZ(_baseZ)
, clearanceZ(_clearanceZ)
@ -209,7 +209,7 @@ struct TileCoordsXY
{
}
explicit TileCoordsXY(CoordsXY c)
explicit TileCoordsXY(const CoordsXY& c)
: x(c.x / 32)
, y(c.y / 32)
{
@ -220,14 +220,14 @@ struct TileCoordsXY
return { x + rhs.x, y + rhs.y };
}
TileCoordsXY& operator+=(const TileCoordsXY rhs)
TileCoordsXY& operator+=(const TileCoordsXY& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
TileCoordsXY& operator-=(const TileCoordsXY rhs)
TileCoordsXY& operator-=(const TileCoordsXY& rhs)
{
x -= rhs.x;
y -= rhs.y;
@ -298,7 +298,7 @@ struct CoordsXYZ : public CoordsXY
{
}
constexpr CoordsXYZ(CoordsXY c, int32_t _z)
constexpr CoordsXYZ(const CoordsXY& c, int32_t _z)
: CoordsXY(c)
, z(_z)
{
@ -341,32 +341,32 @@ struct TileCoordsXYZ : public TileCoordsXY
{
}
TileCoordsXYZ(TileCoordsXY c, int32_t z_)
TileCoordsXYZ(const TileCoordsXY& c, int32_t z_)
: TileCoordsXY(c.x, c.y)
, z(z_)
{
}
TileCoordsXYZ(CoordsXY c, int32_t z_)
TileCoordsXYZ(const CoordsXY& c, int32_t z_)
: TileCoordsXY(c)
, z(z_)
{
}
explicit TileCoordsXYZ(CoordsXYZ c)
explicit TileCoordsXYZ(const CoordsXYZ& c)
: TileCoordsXY(c)
, z(c.z / 8)
{
}
TileCoordsXYZ& operator+=(const TileCoordsXY rhs)
TileCoordsXYZ& operator+=(const TileCoordsXY& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
TileCoordsXYZ& operator-=(const TileCoordsXY rhs)
TileCoordsXYZ& operator-=(const TileCoordsXY& rhs)
{
x -= rhs.x;
y -= rhs.y;
@ -451,13 +451,13 @@ struct CoordsXYZD : public CoordsXYZ
{
}
constexpr CoordsXYZD(CoordsXY _c, int32_t _z, Direction _d)
constexpr CoordsXYZD(const CoordsXY& _c, int32_t _z, Direction _d)
: CoordsXYZ(_c, _z)
, direction(_d)
{
}
constexpr CoordsXYZD(CoordsXYZ _c, Direction _d)
constexpr CoordsXYZD(const CoordsXYZ& _c, Direction _d)
: CoordsXYZ(_c)
, direction(_d)
{
@ -485,25 +485,25 @@ struct TileCoordsXYZD : public TileCoordsXYZ
{
}
TileCoordsXYZD(TileCoordsXY t_, int32_t z_, Direction d_)
TileCoordsXYZD(const TileCoordsXY& t_, int32_t z_, Direction d_)
: TileCoordsXYZ(t_, z_)
, direction(d_)
{
}
TileCoordsXYZD(CoordsXY c_, int32_t z_, Direction d_)
TileCoordsXYZD(const CoordsXY& c_, int32_t z_, Direction d_)
: TileCoordsXYZ(c_, z_)
, direction(d_)
{
}
TileCoordsXYZD(CoordsXYZ c_, Direction d_)
TileCoordsXYZD(const CoordsXYZ& c_, Direction d_)
: TileCoordsXYZ(c_)
, direction(d_)
{
}
TileCoordsXYZD(CoordsXYZD c_)
TileCoordsXYZD(const CoordsXYZD& c_)
: TileCoordsXYZ(c_)
, direction(c_.direction)
{

View File

@ -1881,7 +1881,7 @@ EntranceElement* map_get_ride_exit_element_at(const CoordsXYZ& exitCoords, bool
return nullptr;
}
SmallSceneryElement* map_get_small_scenery_element_at(CoordsXYZ sceneryCoords, int32_t type, uint8_t quadrant)
SmallSceneryElement* map_get_small_scenery_element_at(const CoordsXYZ& sceneryCoords, int32_t type, uint8_t quadrant)
{
auto sceneryTileCoords = TileCoordsXYZ{ sceneryCoords };
TileElement* tileElement = map_get_first_element_at(sceneryCoords);
@ -2092,7 +2092,7 @@ int32_t map_get_tile_quadrant(const CoordsXY& mapPos)
*
* rct2: 0x00693BFF
*/
bool map_surface_is_blocked(CoordsXY mapCoords)
bool map_surface_is_blocked(const CoordsXY& mapCoords)
{
if (!map_is_location_valid(mapCoords))
return true;
@ -2230,7 +2230,7 @@ TileElement* map_get_track_element_at_of_type_seq(const CoordsXYZ& trackPos, int
return nullptr;
}
TrackElement* map_get_track_element_at_of_type(CoordsXYZD location, int32_t trackType)
TrackElement* map_get_track_element_at_of_type(const CoordsXYZD& location, int32_t trackType)
{
auto tileElement = map_get_first_element_at(location);
if (tileElement != nullptr)
@ -2253,7 +2253,7 @@ TrackElement* map_get_track_element_at_of_type(CoordsXYZD location, int32_t trac
return nullptr;
}
TrackElement* map_get_track_element_at_of_type_seq(CoordsXYZD location, int32_t trackType, int32_t sequence)
TrackElement* map_get_track_element_at_of_type_seq(const CoordsXYZD& location, int32_t trackType, int32_t sequence)
{
auto tileElement = map_get_first_element_at(location);
if (tileElement != nullptr)
@ -2364,7 +2364,7 @@ TileElement* map_get_track_element_at_with_direction_from_ride(const CoordsXYZD&
return nullptr;
};
WallElement* map_get_wall_element_at(CoordsXYZD wallCoords)
WallElement* map_get_wall_element_at(const CoordsXYZD& wallCoords)
{
auto tileWallCoords = TileCoordsXYZ(wallCoords);
TileElement* tileElement = map_get_first_element_at(wallCoords);

View File

@ -157,8 +157,8 @@ int32_t map_height_from_slope(const CoordsXY& coords, int32_t slope, bool isSlop
BannerElement* map_get_banner_element_at(const CoordsXYZ& bannerPos, uint8_t direction);
SurfaceElement* map_get_surface_element_at(const CoordsXY& coords);
PathElement* map_get_path_element_at(const TileCoordsXYZ& loc);
WallElement* map_get_wall_element_at(CoordsXYZD wallCoords);
SmallSceneryElement* map_get_small_scenery_element_at(CoordsXYZ sceneryCoords, int32_t type, uint8_t quadrant);
WallElement* map_get_wall_element_at(const CoordsXYZD& wallCoords);
SmallSceneryElement* map_get_small_scenery_element_at(const CoordsXYZ& sceneryCoords, int32_t type, uint8_t quadrant);
EntranceElement* map_get_park_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost);
EntranceElement* map_get_ride_entrance_element_at(const CoordsXYZ& entranceCoords, bool ghost);
EntranceElement* map_get_ride_exit_element_at(const CoordsXYZ& exitCoords, bool ghost);
@ -176,7 +176,7 @@ bool map_can_build_at(const CoordsXYZ& loc);
bool map_is_location_owned(const CoordsXYZ& loc);
bool map_is_location_in_park(const CoordsXY& coords);
bool map_is_location_owned_or_has_rights(const CoordsXY& loc);
bool map_surface_is_blocked(CoordsXY mapCoords);
bool map_surface_is_blocked(const CoordsXY& mapCoords);
void tile_element_remove(TileElement* tileElement);
void map_remove_all_rides();
void map_invalidate_map_selection_tiles();
@ -244,8 +244,8 @@ ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos)
TrackElement* map_get_track_element_at(const CoordsXYZ& trackPos);
TileElement* map_get_track_element_at_of_type(const CoordsXYZ& trackPos, int32_t trackType);
TileElement* map_get_track_element_at_of_type_seq(const CoordsXYZ& trackPos, int32_t trackType, int32_t sequence);
TrackElement* map_get_track_element_at_of_type(CoordsXYZD location, int32_t trackType);
TrackElement* map_get_track_element_at_of_type_seq(CoordsXYZD location, int32_t trackType, int32_t sequence);
TrackElement* map_get_track_element_at_of_type(const CoordsXYZD& location, int32_t trackType);
TrackElement* map_get_track_element_at_of_type_seq(const CoordsXYZD& location, int32_t trackType, int32_t sequence);
TileElement* map_get_track_element_at_of_type_from_ride(const CoordsXYZ& trackPos, int32_t trackType, ride_id_t rideIndex);
TileElement* map_get_track_element_at_from_ride(const CoordsXYZ& trackPos, ride_id_t rideIndex);
TileElement* map_get_track_element_at_with_direction_from_ride(const CoordsXYZD& trackPos, ride_id_t rideIndex);

View File

@ -102,7 +102,7 @@ void park_set_open(bool open)
*
* rct2: 0x00664D05
*/
void update_park_fences(const CoordsXY coords)
void update_park_fences(const CoordsXY& coords)
{
if (map_is_edge(coords))
return;
@ -173,7 +173,7 @@ void update_park_fences(const CoordsXY coords)
}
}
void update_park_fences_around_tile(const CoordsXY coords)
void update_park_fences_around_tile(const CoordsXY& coords)
{
update_park_fences(coords);
update_park_fences({ coords.x + 32, coords.y });

View File

@ -114,8 +114,8 @@ int32_t get_forced_park_rating();
int32_t park_is_open();
int32_t park_calculate_size();
void update_park_fences(CoordsXY coords);
void update_park_fences_around_tile(CoordsXY coords);
void update_park_fences(const CoordsXY& coords);
void update_park_fences_around_tile(const CoordsXY& coords);
uint8_t calculate_guest_initial_happiness(uint8_t percentage);

View File

@ -72,7 +72,7 @@ void SurfaceElement::SetGrassLength(uint8_t newLength)
GrassLength = newLength;
}
void SurfaceElement::SetGrassLengthAndInvalidate(uint8_t length, CoordsXY coords)
void SurfaceElement::SetGrassLengthAndInvalidate(uint8_t length, const CoordsXY& coords)
{
uint8_t oldLength = GrassLength & 0x7;
uint8_t newLength = length & 0x7;
@ -100,7 +100,7 @@ void SurfaceElement::SetGrassLengthAndInvalidate(uint8_t length, CoordsXY coords
*
* rct2: 0x006647A1
*/
void SurfaceElement::UpdateGrassLength(CoordsXY coords)
void SurfaceElement::UpdateGrassLength(const CoordsXY& coords)
{
// Check if tile is grass
if (!CanGrassGrow())

View File

@ -162,8 +162,8 @@ public:
bool CanGrassGrow() const;
uint8_t GetGrassLength() const;
void SetGrassLength(uint8_t newLength);
void SetGrassLengthAndInvalidate(uint8_t newLength, CoordsXY coords);
void UpdateGrassLength(CoordsXY coords);
void SetGrassLengthAndInvalidate(uint8_t newLength, const CoordsXY& coords);
void UpdateGrassLength(const CoordsXY& coords);
uint8_t GetOwnership() const;
void SetOwnership(uint8_t newOwnership);
@ -255,7 +255,7 @@ public:
bool ShouldDrawPathOverSupports();
void SetShouldDrawPathOverSupports(bool on);
bool IsLevelCrossing(CoordsXY coords) const;
bool IsLevelCrossing(const CoordsXY& coords) const;
};
assert_struct_size(PathElement, 16);