Reduce direct usage of LOCATION_NULL (#10480)

* Reduce direct usage of Location_Null

Ideally we want to refactor these out to use std::optional as much as possible but for now move to using the standard interfaces.

* Remove incorrect AND with LOCATION_NULL

In the original this was a simple comparison to check for negative. Unsure how it ended up as an AND with the negative bit.
This commit is contained in:
Duncan 2019-12-31 08:01:17 +00:00 committed by Michael Steenbeek
parent 97b1c888b3
commit d486ac4d3b
11 changed files with 21 additions and 21 deletions

View File

@ -670,7 +670,7 @@ CoordsXY sub_68A15E(ScreenCoordsXY screenCoords)
if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE) if (interactionType == VIEWPORT_INTERACTION_ITEM_NONE)
{ {
initialPos.x = LOCATION_NULL; initialPos.setNull();
return initialPos; return initialPos;
} }

View File

@ -1194,13 +1194,13 @@ static CoordsXYZD place_park_entrance_get_map_position(ScreenCoordsXY screenCoor
CoordsXYZD parkEntranceMapPosition{ 0, 0, 0, INVALID_DIRECTION }; CoordsXYZD parkEntranceMapPosition{ 0, 0, 0, INVALID_DIRECTION };
const CoordsXY mapCoords = sub_68A15E(screenCoords); const CoordsXY mapCoords = sub_68A15E(screenCoords);
parkEntranceMapPosition = { mapCoords.x, mapCoords.y, 0, INVALID_DIRECTION }; parkEntranceMapPosition = { mapCoords.x, mapCoords.y, 0, INVALID_DIRECTION };
if (parkEntranceMapPosition.x == LOCATION_NULL) if (parkEntranceMapPosition.isNull())
return parkEntranceMapPosition; return parkEntranceMapPosition;
auto surfaceElement = map_get_surface_element_at(mapCoords); auto surfaceElement = map_get_surface_element_at(mapCoords);
if (surfaceElement == nullptr) if (surfaceElement == nullptr)
{ {
parkEntranceMapPosition.x = LOCATION_NULL; parkEntranceMapPosition.setNull();
return parkEntranceMapPosition; return parkEntranceMapPosition;
} }
@ -1235,7 +1235,7 @@ static void window_map_place_park_entrance_tool_update(ScreenCoordsXY screenCoor
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT;
CoordsXYZD parkEntrancePosition = place_park_entrance_get_map_position(screenCoords); CoordsXYZD parkEntrancePosition = place_park_entrance_get_map_position(screenCoords);
if (parkEntrancePosition.x == LOCATION_NULL) if (parkEntrancePosition.isNull())
{ {
park_entrance_remove_ghost(); park_entrance_remove_ghost();
return; return;
@ -1309,7 +1309,7 @@ static void window_map_place_park_entrance_tool_down(ScreenCoordsXY screenCoords
park_entrance_remove_ghost(); park_entrance_remove_ghost();
CoordsXYZD parkEntrancePosition = place_park_entrance_get_map_position(screenCoords); CoordsXYZD parkEntrancePosition = place_park_entrance_get_map_position(screenCoords);
if (parkEntrancePosition.x != LOCATION_NULL) if (!parkEntrancePosition.isNull())
{ {
auto gameAction = PlaceParkEntranceAction(parkEntrancePosition); auto gameAction = PlaceParkEntranceAction(parkEntrancePosition);
auto result = GameActions::Execute(&gameAction); auto result = GameActions::Execute(&gameAction);

View File

@ -363,7 +363,7 @@ static void window_maze_construction_entrance_tooldown(ScreenCoordsXY screenCoor
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
CoordsXYZD entranceOrExitCoords = ride_get_entrance_or_exit_position_from_screen_position(screenCoords); CoordsXYZD entranceOrExitCoords = ride_get_entrance_or_exit_position_from_screen_position(screenCoords);
if (entranceOrExitCoords.x == LOCATION_NULL) if (entranceOrExitCoords.isNull())
return; return;
if (gRideEntranceExitPlaceDirection == 0xFF) if (gRideEntranceExitPlaceDirection == 0xFF)

View File

@ -2174,7 +2174,7 @@ static std::optional<CoordsXY> ride_get_place_position_from_screen_position(Scre
if (!_trackPlaceCtrlState) if (!_trackPlaceCtrlState)
{ {
mapCoords = sub_68A15E(screenCoords); mapCoords = sub_68A15E(screenCoords);
if (mapCoords.x == LOCATION_NULL) if (mapCoords.isNull())
return std::nullopt; return std::nullopt;
_trackPlaceZ = 0; _trackPlaceZ = 0;
@ -3578,7 +3578,7 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords)
break; break;
_currentTrackBegin.z -= 8; _currentTrackBegin.z -= 8;
if (_currentTrackBegin.z & LOCATION_NULL) if (_currentTrackBegin.z < 0)
break; break;
if (bx >= 0) if (bx >= 0)
@ -3605,7 +3605,7 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords)
break; break;
_currentTrackBegin.z -= 8; _currentTrackBegin.z -= 8;
if (_currentTrackBegin.z & LOCATION_NULL) if (_currentTrackBegin.z < 0)
break; break;
if (bx >= 0) if (bx >= 0)

View File

@ -344,7 +344,7 @@ static void window_staff_list_tooldown(rct_window* w, rct_widgetindex widgetInde
TileElement* tileElement; TileElement* tileElement;
CoordsXY footpathCoords; CoordsXY footpathCoords;
footpath_get_coordinates_from_pos(screenCoords, &footpathCoords.x, &footpathCoords.y, &direction, &tileElement); footpath_get_coordinates_from_pos(screenCoords, &footpathCoords.x, &footpathCoords.y, &direction, &tileElement);
if (footpathCoords.x == LOCATION_NULL) if (footpathCoords.isNull())
return; return;
bool isPatrolAreaSet = staff_is_patrol_area_set(200 + selectedPeepType, footpathCoords.x, footpathCoords.y); bool isPatrolAreaSet = staff_is_patrol_area_set(200 + selectedPeepType, footpathCoords.x, footpathCoords.y);

View File

@ -273,7 +273,7 @@ static void window_track_place_toolupdate(rct_window* w, rct_widgetindex widgetI
// Get the tool map position // Get the tool map position
CoordsXY mapCoords = sub_68A15E(screenCoords); CoordsXY mapCoords = sub_68A15E(screenCoords);
if (mapCoords.x == LOCATION_NULL) if (mapCoords.isNull())
{ {
window_track_place_clear_provisional(); window_track_place_clear_provisional();
return; return;
@ -343,7 +343,7 @@ static void window_track_place_tooldown(rct_window* w, rct_widgetindex widgetInd
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
const CoordsXY mapCoords = sub_68A15E(screenCoords); const CoordsXY mapCoords = sub_68A15E(screenCoords);
if (mapCoords.x == LOCATION_NULL) if (mapCoords.isNull())
return; return;
// Try increasing Z until a feasible placement is found // Try increasing Z until a feasible placement is found

View File

@ -768,7 +768,7 @@ namespace OpenRCT2
} }
// Focus camera on event. // Focus camera on event.
if (isPositionValid && result->Position.x != LOCATION_NULL) if (isPositionValid && !result->Position.isNull())
{ {
auto* mainWindow = window_get_main(); auto* mainWindow = window_get_main();
if (mainWindow != nullptr) if (mainWindow != nullptr)

View File

@ -431,7 +431,7 @@ namespace GameActions
network_add_player_money_spent(playerIndex, result->Cost); network_add_player_money_spent(playerIndex, result->Cost);
} }
if (result->Position.x != LOCATION_NULL) if (!result->Position.isNull())
{ {
network_set_player_last_action_coord(playerId, result->Position); network_set_player_last_action_coord(playerId, result->Position);
} }

View File

@ -110,7 +110,7 @@ std::optional<ScreenCoordsXY> centre_2d_coordinates(CoordsXYZ loc, rct_viewport*
// If the start location was invalid // If the start location was invalid
// propagate the invalid location to the output. // propagate the invalid location to the output.
// This fixes a bug that caused the game to enter an infinite loop. // This fixes a bug that caused the game to enter an infinite loop.
if (loc.x == LOCATION_NULL) if (loc.isNull())
{ {
return std::nullopt; return std::nullopt;
} }

View File

@ -6184,7 +6184,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
ride = get_ride(gRideEntranceExitPlaceRideIndex); ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride == nullptr) if (ride == nullptr)
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.setNull();
return entranceExitCoords; return entranceExitCoords;
} }
@ -6193,7 +6193,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight); auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight);
if (!coords) if (!coords)
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.setNull();
return entranceExitCoords; return entranceExitCoords;
} }
@ -6204,14 +6204,14 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
if (ride->type == RIDE_TYPE_NULL) if (ride->type == RIDE_TYPE_NULL)
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.setNull();
return entranceExitCoords; return entranceExitCoords;
} }
auto stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start; auto stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start;
if (stationStart.isNull()) if (stationStart.isNull())
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.setNull();
return entranceExitCoords; return entranceExitCoords;
} }
@ -6280,7 +6280,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
tileElement = ride_get_station_start_track_element(ride, gRideEntranceExitPlaceStationIndex); tileElement = ride_get_station_start_track_element(ride, gRideEntranceExitPlaceStationIndex);
if (tileElement == nullptr) if (tileElement == nullptr)
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.setNull();
return entranceExitCoords; return entranceExitCoords;
} }
entranceExitCoords.direction = tileElement->GetDirection(); entranceExitCoords.direction = tileElement->GetDirection();

View File

@ -77,7 +77,7 @@ void rct_money_effect::CreateAt(money32 value, int32_t x, int32_t y, int32_t z,
*/ */
void rct_money_effect::Create(money32 value, CoordsXYZ loc) void rct_money_effect::Create(money32 value, CoordsXYZ loc)
{ {
if (loc.x == LOCATION_NULL) if (loc.isNull())
{ {
// If game actions return no valid location of the action we can not use the screen // If game actions return no valid location of the action we can not use the screen
// coordinates as every client will have different ones. // coordinates as every client will have different ones.