forked from rosebudai/OpenRCT2-Web
Refactor: more use of the Direction type and helpers (#27237)
Advance adoption of the 'Direction' type for cardinal directions: * Split `Direction` and its helpers out to their own header (`Direction.h`) * Replace loops that iterate all four directions with range-based loops * Replace some math with calls to helper functions. I also introduced a new `DirectionRotate()` function, a generalisation of `DirectionNext()`/`DirectionPrev()`. * Replace `uint8_t`/`int32_t` with `Direction` in some function signatures and field types, if the thing being passed/stored is supposed to be a cardinal direction In the process I also fixed two defects in the code: * The bitmask used to select the direction from a TD6EntranceElement was too wide - it was grabbing the low 4 bits, but only needs the low 2. * `CoordsXYZD.toTileCentre()` was taking the tile corner and adding a `CoordsXYZD` value to it, to add half-tile offsets to X and Y. So, it's more correct to add a `CoordsXY` value instead, and skip the unnecessary Z and D dimensions.
This commit is contained in:
1 parent
d28122de93
commit
41b1cd01bc
35 files changed
+163
-146
No files matched your search
@@ -3467,7 +3467,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
PathElement* pathsByDir[kNumOrthogonalDirections];
|
||||
|
||||
bool keepOrientation = false;
|
||||
for (int8_t i = 0; i < kNumOrthogonalDirections; i++)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
const auto testLoc = CoordsXYZ{ *mapCoords + CoordsDirectionDelta[i], z };
|
||||
if (!MapIsLocationOwned(testLoc))
|
||||
@@ -3509,7 +3509,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
if (!keepOrientation)
|
||||
{
|
||||
for (int8_t i = 0; i < kNumOrthogonalDirections; i++)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
if (pathsByDir[i] != nullptr)
|
||||
{
|
||||
|
||||
@@ -94,12 +94,12 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3];
|
||||
entranceLoc += CoordsDirectionDelta[DirectionPrev(_loc.direction)];
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2;
|
||||
entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2;
|
||||
}
|
||||
|
||||
if (auto res2 = MapCanConstructAt({ entranceLoc, zLow, zHigh }, { 0b1111, 0 }); res2.error != Status::ok)
|
||||
@@ -143,13 +143,13 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
if (index == ParkEntranceSequence::left)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].x;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction - 1) & 0x3].y;
|
||||
entranceLoc.x += CoordsDirectionDelta[DirectionPrev(_loc.direction)].x;
|
||||
entranceLoc.y += CoordsDirectionDelta[DirectionPrev(_loc.direction)].y;
|
||||
}
|
||||
else if (index == ParkEntranceSequence::right)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2;
|
||||
entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2;
|
||||
}
|
||||
|
||||
if (!flags.has(CommandFlag::ghost))
|
||||
@@ -208,12 +208,12 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3];
|
||||
entranceLoc += CoordsDirectionDelta[DirectionPrev(_loc.direction)];
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2;
|
||||
entranceLoc.x += CoordsDirectionDelta[DirectionNext(_loc.direction)].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[DirectionNext(_loc.direction)].y * 2;
|
||||
}
|
||||
if (!MapCheckCapacityAndReorganise(entranceLoc, numTiles))
|
||||
{
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRCT2::GameActions
|
||||
return Result(Status::invalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone);
|
||||
}
|
||||
|
||||
auto direction = (park.entrances[entranceIndex].direction - 1) & 3;
|
||||
auto direction = DirectionPrev(park.entrances[entranceIndex].direction);
|
||||
|
||||
// Centre (sign)
|
||||
ParkEntranceRemoveSegment(_loc);
|
||||
|
||||
@@ -279,11 +279,7 @@ namespace OpenRCT2::GameActions
|
||||
{
|
||||
auto rand = ScenarioRandMax(static_cast<uint32_t>(park.entrances.size()));
|
||||
const auto& entrance = park.entrances[rand];
|
||||
auto dir = entrance.direction;
|
||||
newLocation = entrance;
|
||||
// TODO: Replace with CoordsDirectionDelta
|
||||
newLocation.x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0);
|
||||
newLocation.y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0);
|
||||
newLocation = entrance + CoordsDirectionDelta[entrance.direction] + CoordsXY{ 16, 16 };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -513,7 +513,7 @@ namespace OpenRCT2::GameActions
|
||||
continue;
|
||||
if (elementType == TileElementType::wall)
|
||||
{
|
||||
int32_t direction = tileElement->getDirection();
|
||||
Direction direction = tileElement->getDirection();
|
||||
if (_edge == direction)
|
||||
{
|
||||
auto res = Result(Status::noClearance, STR_CANT_BUILD_THIS_HERE, kStringIdNone);
|
||||
|
||||
@@ -513,7 +513,7 @@ namespace OpenRCT2::GameActions
|
||||
uint8_t intersectingDirections = ted.sequenceData.sequences[blockIndex].allowedWallEdges;
|
||||
intersectingDirections ^= 0x0F;
|
||||
intersectingDirections = rol4(intersectingDirections, _origin.direction);
|
||||
for (int32_t i = 0; i < kNumOrthogonalDirections; i++)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
if (intersectingDirections & (1 << i))
|
||||
{
|
||||
|
||||
@@ -4908,7 +4908,7 @@ namespace OpenRCT2
|
||||
uint8_t hedges[4]{ 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
uint8_t openCount = 0;
|
||||
uint8_t mazeReverseLastEdge = DirectionReverse(mazeLastEdge);
|
||||
for (uint8_t i = 0; i < kNumOrthogonalDirections; ++i)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
if (!(mazeEntry & (1 << kMazeCurrentDirectionToOpenHedge[var37 / 4][i])) && i != mazeReverseLastEdge)
|
||||
{
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRCT2
|
||||
{
|
||||
case Pattern::cyclicSquares:
|
||||
// 0, 1, 2, 3
|
||||
for (int32_t i = 0; i < kNumOrthogonalDirections; i++)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
create(
|
||||
newType, { newLoc + _fountainDirectionsPositive[i], newZ }, _fountainDirections[i],
|
||||
|
||||
@@ -316,9 +316,9 @@ void VirtualFloorPaint(PaintSession& session)
|
||||
|
||||
// Try the four tiles next to us for the same parameters as above,
|
||||
// if our parameters differ we set an edge towards that tile
|
||||
for (uint8_t i = 0; i < kNumOrthogonalDirections; i++)
|
||||
for (Direction i : kAllDirections)
|
||||
{
|
||||
uint8_t effectiveRotation = (kNumOrthogonalDirections + i - direction) % kNumOrthogonalDirections;
|
||||
Direction effectiveRotation = (kNumOrthogonalDirections + i - direction) % kNumOrthogonalDirections;
|
||||
CoordsXY theirLocation = session.MapPosition + scenery_half_tile_offsets[effectiveRotation];
|
||||
|
||||
bool theyAreOccupied;
|
||||
|
||||
@@ -39,7 +39,7 @@ void PaintUtilSetVerticalTunnel(PaintSession& session, uint16_t height)
|
||||
session.VerticalTunnelHeight = height / 16;
|
||||
}
|
||||
|
||||
void PaintUtilPushTunnelRotated(PaintSession& session, uint8_t direction, uint16_t height, TunnelType type)
|
||||
void PaintUtilPushTunnelRotated(PaintSession& session, Direction direction, uint16_t height, TunnelType type)
|
||||
{
|
||||
if (direction & 1)
|
||||
{
|
||||
|
||||
@@ -83,7 +83,7 @@ TunnelType GetTunnelType(TunnelGroup tunnelGroup, TunnelSubType tunnelSubType);
|
||||
void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, TunnelType type);
|
||||
void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, TunnelType type);
|
||||
void PaintUtilSetVerticalTunnel(PaintSession& session, uint16_t height);
|
||||
void PaintUtilPushTunnelRotated(PaintSession& session, uint8_t direction, uint16_t height, TunnelType type);
|
||||
void PaintUtilPushTunnelRotated(PaintSession& session, Direction direction, uint16_t height, TunnelType type);
|
||||
|
||||
inline void PaintUtilPushTunnelLeft(
|
||||
PaintSession& session, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType)
|
||||
@@ -98,7 +98,7 @@ inline void PaintUtilPushTunnelRight(
|
||||
}
|
||||
|
||||
inline void PaintUtilPushTunnelRotated(
|
||||
PaintSession& session, uint8_t direction, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType)
|
||||
PaintSession& session, Direction direction, uint16_t height, TunnelGroup tunnelGroup, TunnelSubType tunnelSubType)
|
||||
{
|
||||
PaintUtilPushTunnelRotated(session, direction, height, GetTunnelType(tunnelGroup, tunnelSubType));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRCT2
|
||||
{
|
||||
const size_t directionOffset = sequenceCount * spriteCount;
|
||||
uint64_t spriteMap = 0;
|
||||
for (size_t direction = 0; direction < kNumOrthogonalDirections; direction++)
|
||||
for (Direction direction : kAllDirections)
|
||||
{
|
||||
for (size_t sequence = 0; sequence < sequenceCount; sequence++)
|
||||
{
|
||||
|
||||
@@ -324,7 +324,7 @@ namespace OpenRCT2::RCT2
|
||||
|
||||
constexpr Direction GetDirection() const
|
||||
{
|
||||
return (direction & 0b00001111);
|
||||
return direction & 0b00000011;
|
||||
}
|
||||
|
||||
constexpr bool IsExit() const
|
||||
|
||||
@@ -2162,7 +2162,7 @@ void TrackDesignDrawPreview(TrackDesign& td, TrackDesignPreviewBuffer& pixels, b
|
||||
drawingEngine->BeginDraw();
|
||||
|
||||
const ScreenCoordsXY offset = { size_x / 2, size_y / 2 };
|
||||
for (Direction direction = 0; direction < kNumOrthogonalDirections; direction++)
|
||||
for (Direction direction : kAllDirections)
|
||||
{
|
||||
view.viewPos = Translate3DTo2DWithZ(direction, centre) - offset;
|
||||
view.rotation = direction;
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace OpenRCT2
|
||||
int32_t y = input->y;
|
||||
int32_t OriginZ = inputElement->getBaseZ();
|
||||
|
||||
uint8_t rotation = inputElement->getDirection();
|
||||
Direction rotation = inputElement->getDirection();
|
||||
|
||||
CoordsXY coords = { x, y };
|
||||
CoordsXY trackCoordOffset = { trackCoordinate.x, trackCoordinate.y };
|
||||
|
||||
@@ -165,7 +165,7 @@ static bool ride_station_can_depart_synchronised(const Ride& ride, StationIndex
|
||||
* is found we allow for space between that and the next.
|
||||
*/
|
||||
|
||||
int32_t direction = tileElement->getDirectionWithOffset(1);
|
||||
Direction direction = tileElement->getDirectionWithOffset(1);
|
||||
constexpr uint8_t maxCheckDistance = kRideAdjacencyCheckDistance;
|
||||
uint8_t spaceBetween = maxCheckDistance;
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace OpenRCT2::Editor
|
||||
|
||||
for (const auto& parkEntrance : gameState.park.entrances)
|
||||
{
|
||||
int32_t direction = DirectionReverse(parkEntrance.direction);
|
||||
Direction direction = DirectionReverse(parkEntrance.direction);
|
||||
|
||||
switch (FootpathIsConnectedToMapEdge(parkEntrance, direction, 0))
|
||||
{
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace OpenRCT2::Scripting
|
||||
JSValue result = JS_NewArray(ctx);
|
||||
int32_t resultIndex = 0;
|
||||
|
||||
for (int32_t direction = 0; direction < 4; direction++)
|
||||
for (Direction direction : kAllDirections)
|
||||
{
|
||||
if (!(edges & (1 << direction)))
|
||||
continue;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2026 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
constexpr auto kNumOrthogonalDirections = 4;
|
||||
|
||||
/**
|
||||
* Cardinal directions are represented by the Direction type. It has four
|
||||
* possible values:
|
||||
* 0 is X-decreasing (West)
|
||||
* 1 is Y-increasing (North)
|
||||
* 2 is X-increasing (East)
|
||||
* 3 is Y-decreasing (South)
|
||||
* Direction is not used to model up/down, or diagonal directions.
|
||||
*/
|
||||
using Direction = uint8_t;
|
||||
|
||||
const Direction kInvalidDirection = 0xFF;
|
||||
|
||||
/**
|
||||
* Array of all valid cardinal directions, to make it easy to write range-based for loops like:
|
||||
* for (Direction d : kAllDirections)
|
||||
*/
|
||||
constexpr Direction kAllDirections[] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a direction, return the direction that points the other way,
|
||||
* on the same axis.
|
||||
*/
|
||||
inline constexpr Direction DirectionReverse(Direction dir)
|
||||
{
|
||||
return dir ^ 2;
|
||||
}
|
||||
|
||||
inline constexpr bool DirectionValid(Direction dir)
|
||||
{
|
||||
return dir < kNumOrthogonalDirections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate a direction by the given number of 90-degree increments. Positive values
|
||||
* rotate clockwise, negative values rotate counterclockwise.
|
||||
*/
|
||||
inline constexpr Direction DirectionRotate(Direction dir, int rotations)
|
||||
{
|
||||
return (dir + rotations) & 0x03;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a direction, return the next clockwise cardinal direction, wrapping around if necessary.
|
||||
*/
|
||||
inline constexpr Direction DirectionNext(Direction dir)
|
||||
{
|
||||
return DirectionRotate(dir, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a direction, return the next counter-clockwise cardinal direction, wrapping around if necessary.
|
||||
*/
|
||||
inline constexpr Direction DirectionPrev(Direction dir)
|
||||
{
|
||||
return DirectionRotate(dir, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Flips the X axis so 1 and 3 are swapped 0 and 2 will stay the same.
|
||||
*/
|
||||
inline constexpr Direction DirectionFlipXAxis(Direction direction)
|
||||
{
|
||||
return (direction * 3) % 4;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ money64 OpenRCT2::RideEntranceExitPlaceGhost(
|
||||
*/
|
||||
void MazeEntranceHedgeReplacement(const CoordsXYE& entrance)
|
||||
{
|
||||
int32_t direction = entrance.element->getDirection();
|
||||
Direction direction = entrance.element->getDirection();
|
||||
auto hedgePos = entrance + CoordsDirectionDelta[direction];
|
||||
int32_t z = entrance.element->getBaseZ();
|
||||
RideId rideIndex = entrance.element->asEntrance()->getRideIndex();
|
||||
@@ -160,7 +160,7 @@ void MazeEntranceHedgeReplacement(const CoordsXYE& entrance)
|
||||
*/
|
||||
void MazeEntranceHedgeRemoval(const CoordsXYE& entrance)
|
||||
{
|
||||
int32_t direction = entrance.element->getDirection();
|
||||
Direction direction = entrance.element->getDirection();
|
||||
auto hedgePos = entrance + CoordsDirectionDelta[direction];
|
||||
int32_t z = entrance.element->getBaseZ();
|
||||
RideId rideIndex = entrance.element->asEntrance()->getRideIndex();
|
||||
|
||||
@@ -219,9 +219,9 @@ namespace OpenRCT2
|
||||
|
||||
std::get<0>(tileElements) = { initialTileElement, footpathPos };
|
||||
int32_t z = initialTileElement->getBaseZ();
|
||||
for (int32_t initialDirection = 0; initialDirection < kNumOrthogonalDirections; initialDirection++)
|
||||
for (Direction initialDirection : kAllDirections)
|
||||
{
|
||||
int32_t direction = initialDirection;
|
||||
Direction direction = initialDirection;
|
||||
auto currentPos = footpathPos + CoordsDirectionDelta[direction];
|
||||
|
||||
std::get<1>(tileElements) = {
|
||||
@@ -1552,7 +1552,7 @@ namespace OpenRCT2
|
||||
if (tileElement->asPath()->isQueue())
|
||||
{
|
||||
FootpathQueueChainPush(tileElement->asPath()->getRideIndex());
|
||||
for (int32_t direction = 0; direction < kNumOrthogonalDirections; direction++)
|
||||
for (Direction direction : kAllDirections)
|
||||
{
|
||||
if (tileElement->asPath()->getEdges() & (1 << direction))
|
||||
{
|
||||
@@ -1764,7 +1764,7 @@ namespace OpenRCT2
|
||||
|
||||
FootpathUpdateQueueEntranceBanner(footpathPos, tileElement);
|
||||
|
||||
for (uint8_t direction = 0; direction < kNumOrthogonalDirections; direction++)
|
||||
for (Direction direction : kAllDirections)
|
||||
{
|
||||
int32_t z1 = tileElement->baseHeight;
|
||||
if (tileElement->getType() == TileElementType::path)
|
||||
@@ -1890,7 +1890,7 @@ namespace OpenRCT2
|
||||
return ride->getRideTypeDescriptor().flags.has(RtdFlag::supportsLevelCrossings);
|
||||
}
|
||||
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& pathElement, int32_t currentZ, int32_t currentDirection)
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& pathElement, int32_t currentZ, Direction currentDirection)
|
||||
{
|
||||
if (pathElement.isSloped())
|
||||
{
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace OpenRCT2
|
||||
void FootpathQueueChainReset();
|
||||
void FootpathQueueChainPush(RideId rideIndex);
|
||||
int32_t FootpathQueueCountConnections(const CoordsXY& position, const PathElement& pathElement);
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& tileElement, int32_t currentZ, int32_t currentDirection);
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& tileElement, int32_t currentZ, Direction currentDirection);
|
||||
|
||||
FootpathPlacementResult FootpathGetOnTerrainPlacement(const TileCoordsXY& location);
|
||||
FootpathPlacementResult FootpathGetOnTerrainPlacement(const SurfaceElement& surfaceElement);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../core/CoordsRange.hpp"
|
||||
#include "../core/Numerics.hpp"
|
||||
#include "../world/Direction.hpp"
|
||||
#include "../world/MapLimits.h"
|
||||
|
||||
#include <cstdint>
|
||||
@@ -18,8 +19,6 @@
|
||||
constexpr int16_t kLocationNull = -32768;
|
||||
constexpr int32_t kCoordsNull = 0xFFFF8000;
|
||||
|
||||
constexpr auto kNumOrthogonalDirections = 4;
|
||||
|
||||
/**
|
||||
* Tile coordinates use 1 x/y increment per tile and 1 z increment per step.
|
||||
* Regular ('big', 'sprite') coordinates use 32 x/y increments per tile and 8 z increments per step.
|
||||
@@ -453,89 +452,6 @@ struct TileCoordsXYRangedZ : public TileCoordsXY
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Cardinal directions are represented by the Direction type. It has four
|
||||
* possible values:
|
||||
* 0 is X-decreasing
|
||||
* 1 is Y-increasing
|
||||
* 2 is X-increasing
|
||||
* 3 is Y-decreasing
|
||||
* Direction is not used to model up/down, or diagonal directions.
|
||||
*/
|
||||
using Direction = uint8_t;
|
||||
|
||||
const Direction kInvalidDirection = 0xFF;
|
||||
|
||||
/**
|
||||
* Array of all valid cardinal directions, to make it easy to write range-based for loops like:
|
||||
* for (Direction d : kAllDirections)
|
||||
*/
|
||||
constexpr Direction kAllDirections[] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a direction, return the direction that points the other way,
|
||||
* on the same axis.
|
||||
*/
|
||||
inline constexpr Direction DirectionReverse(Direction dir)
|
||||
{
|
||||
return dir ^ 2;
|
||||
}
|
||||
|
||||
inline constexpr bool DirectionValid(Direction dir)
|
||||
{
|
||||
return dir < kNumOrthogonalDirections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a direction, return the next cardinal direction, wrapping around if necessary.
|
||||
* (TODO: Figure out if this is CW or CCW)
|
||||
*/
|
||||
inline constexpr Direction DirectionNext(Direction dir)
|
||||
{
|
||||
return (dir + 1) & 0x03;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a direction, return the previous cardinal direction, wrapping around if necessary.
|
||||
* (TODO: Figure out if this is CW or CCW)
|
||||
*/
|
||||
inline constexpr Direction DirectionPrev(Direction dir)
|
||||
{
|
||||
return (dir - 1) & 0x03;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two positions, return the cardinal direction which is closest to the direction from 'from' to 'to'.
|
||||
*/
|
||||
inline constexpr Direction DirectionFromTo(const CoordsXY& from, const CoordsXY& to)
|
||||
{
|
||||
int16_t x_diff = to.x - from.x;
|
||||
int16_t y_diff = to.y - from.y;
|
||||
|
||||
int16_t abs_x = x_diff < 0 ? -x_diff : x_diff;
|
||||
int16_t abs_y = y_diff < 0 ? -y_diff : y_diff;
|
||||
|
||||
if (abs_x <= abs_y)
|
||||
{
|
||||
return y_diff < 0 ? 3 : 1;
|
||||
}
|
||||
|
||||
return x_diff < 0 ? 0 : 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flips the X axis so 1 and 3 are swapped 0 and 2 will stay the same.
|
||||
*/
|
||||
inline constexpr Direction DirectionFlipXAxis(Direction direction)
|
||||
{
|
||||
return (direction * 3) % 4;
|
||||
}
|
||||
|
||||
struct CoordsXYZD : public CoordsXYZ
|
||||
{
|
||||
Direction direction{};
|
||||
@@ -605,7 +521,7 @@ struct CoordsXYZD : public CoordsXYZ
|
||||
|
||||
constexpr CoordsXYZD toTileCentre() const
|
||||
{
|
||||
return toTileStart() + CoordsXYZD{ kCoordsXYHalfTile, kCoordsXYHalfTile, 0, 0 };
|
||||
return toTileStart() + CoordsXY{ kCoordsXYHalfTile, kCoordsXYHalfTile };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -668,6 +584,25 @@ struct TileCoordsXYZD : public TileCoordsXYZ
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Given two positions, return the cardinal direction which is closest to the direction from 'from' to 'to'.
|
||||
*/
|
||||
inline constexpr Direction DirectionFromTo(const CoordsXY& from, const CoordsXY& to)
|
||||
{
|
||||
int16_t x_diff = to.x - from.x;
|
||||
int16_t y_diff = to.y - from.y;
|
||||
|
||||
int16_t abs_x = x_diff < 0 ? -x_diff : x_diff;
|
||||
int16_t abs_y = y_diff < 0 ? -y_diff : y_diff;
|
||||
|
||||
if (abs_x <= abs_y)
|
||||
{
|
||||
return y_diff < 0 ? 3 : 1;
|
||||
}
|
||||
|
||||
return x_diff < 0 ? 0 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a rectangular range of the map using regular coordinates (32 per tile).
|
||||
*/
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace OpenRCT2
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, uint8_t position)
|
||||
BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, Direction position)
|
||||
{
|
||||
const auto bannerTilePos = TileCoordsXYZ{ bannerPos };
|
||||
for (auto* element : TileElementsView<BannerElement>(bannerPos))
|
||||
@@ -688,7 +688,7 @@ namespace OpenRCT2
|
||||
* Checks if the tile at coordinate at height counts as connected.
|
||||
* @return 1 if connected, 0 otherwise
|
||||
*/
|
||||
bool MapCoordIsConnected(const TileCoordsXYZ& loc, uint8_t faceDirection)
|
||||
bool MapCoordIsConnected(const TileCoordsXYZ& loc, Direction faceDirection)
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(loc);
|
||||
|
||||
@@ -700,7 +700,7 @@ namespace OpenRCT2
|
||||
if (tileElement->getType() != TileElementType::path)
|
||||
continue;
|
||||
|
||||
uint8_t slopeDirection = tileElement->asPath()->getSlopeDirection();
|
||||
Direction slopeDirection = tileElement->asPath()->getSlopeDirection();
|
||||
|
||||
if (tileElement->asPath()->isSloped())
|
||||
{
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRCT2
|
||||
TileElement* MapGetFirstTileElementWithBaseHeightBetween(const TileCoordsXYRangedZ& loc, TileElementType type);
|
||||
void MapSetTileElement(const TileCoordsXY& tilePos, TileElement* elements);
|
||||
int32_t MapHeightFromSlope(const CoordsXY& coords, int32_t slopeDirection, bool isSloped);
|
||||
BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, uint8_t position);
|
||||
BannerElement* MapGetBannerElementAt(const CoordsXYZ& bannerPos, Direction position);
|
||||
SurfaceElement* MapGetSurfaceElementAt(const TileCoordsXY& coords);
|
||||
SurfaceElement* MapGetSurfaceElementAt(const CoordsXY& coords);
|
||||
PathElement* MapGetPathElementAt(const TileCoordsXYZ& loc);
|
||||
@@ -86,7 +86,7 @@ namespace OpenRCT2
|
||||
EntranceElement* MapGetRideExitElementAt(const CoordsXYZ& exitCoords, bool ghost);
|
||||
uint8_t MapGetHighestLandHeight(const MapRange& range);
|
||||
uint8_t MapGetLowestLandHeight(const MapRange& range);
|
||||
bool MapCoordIsConnected(const TileCoordsXYZ& loc, uint8_t faceDirection);
|
||||
bool MapCoordIsConnected(const TileCoordsXYZ& loc, Direction faceDirection);
|
||||
void MapUpdatePathWideFlags();
|
||||
bool MapIsLocationValid(const CoordsXY& coords);
|
||||
bool MapIsEdge(const CoordsXY& coords);
|
||||
|
||||
@@ -166,7 +166,7 @@ static std::optional<UpdateType> UpdateSmallSceneryAnimation(
|
||||
// Don't apply anything to peeps when the scenery is a ghost.
|
||||
if (!scenery.isGhost() && !(getGameState().currentTicks & 0x3FF))
|
||||
{
|
||||
const int32_t direction = scenery.getDirection();
|
||||
const Direction direction = scenery.getDirection();
|
||||
auto quad = EntityTileList<Peep>(CoordsXY{ loc.x, loc.y } - CoordsDirectionDelta[direction]);
|
||||
for (auto peep : quad)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Location.hpp"
|
||||
|
||||
// Rotate both of the values amount
|
||||
const QuarterTile QuarterTile::Rotate(uint8_t amount) const
|
||||
const QuarterTile QuarterTile::Rotate(Direction amount) const
|
||||
{
|
||||
switch (amount)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
using Direction = uint8_t;
|
||||
struct TileCornersZ;
|
||||
|
||||
class QuarterTile
|
||||
@@ -30,7 +31,7 @@ public:
|
||||
}
|
||||
|
||||
// Rotate both of the values amount. Returns new RValue QuarterTile
|
||||
const QuarterTile Rotate(uint8_t amount) const;
|
||||
const QuarterTile Rotate(Direction amount) const;
|
||||
uint8_t GetBaseQuarterOccupied() const;
|
||||
uint8_t GetZQuarterOccupied() const;
|
||||
TileCornersZ GetQuarterHeights(int32_t height) const;
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace OpenRCT2::TileInspector
|
||||
case TileElementType::path:
|
||||
if (tileElement->asPath()->isSloped())
|
||||
{
|
||||
newRotation = (tileElement->asPath()->getSlopeDirection() + 1) & kTileElementDirectionMask;
|
||||
newRotation = DirectionNext(tileElement->asPath()->getSlopeDirection());
|
||||
tileElement->asPath()->setSlopeDirection(newRotation);
|
||||
}
|
||||
pathEdges = tileElement->asPath()->getEdges();
|
||||
|
||||
@@ -121,7 +121,7 @@ uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge)
|
||||
*
|
||||
* rct2: 0x006E59DC
|
||||
*/
|
||||
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction)
|
||||
bool WallInTheWay(const CoordsXYRangedZ& fencePos, Direction direction)
|
||||
{
|
||||
TileElement* tileElement = MapGetFirstElementAt(fencePos);
|
||||
if (tileElement == nullptr)
|
||||
|
||||
@@ -31,4 +31,4 @@ void WallRemoveIntersectingWalls(const CoordsXYRangedZ& wallPos, Direction direc
|
||||
|
||||
uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge);
|
||||
|
||||
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction);
|
||||
bool WallInTheWay(const CoordsXYRangedZ& fencePos, Direction direction);
|
||||
@@ -31,12 +31,12 @@ namespace OpenRCT2
|
||||
index = newIndex;
|
||||
}
|
||||
|
||||
uint8_t BannerElement::getPosition() const
|
||||
Direction BannerElement::getPosition() const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
void BannerElement::setPosition(uint8_t newPosition)
|
||||
void BannerElement::setPosition(Direction newPosition)
|
||||
{
|
||||
position = newPosition;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRCT2
|
||||
|
||||
private:
|
||||
BannerIndex index; // 5
|
||||
uint8_t position; // 7
|
||||
Direction position; // 7
|
||||
uint8_t allowedEdges; // 8
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-private-field"
|
||||
@@ -36,8 +36,8 @@ namespace OpenRCT2
|
||||
BannerIndex getIndex() const;
|
||||
void setIndex(BannerIndex newIndex);
|
||||
|
||||
uint8_t getPosition() const;
|
||||
void setPosition(uint8_t newPosition);
|
||||
Direction getPosition() const;
|
||||
void setPosition(Direction newPosition);
|
||||
|
||||
uint8_t getAllowedEdges() const;
|
||||
void setAllowedEdges(uint8_t newEdges);
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRCT2
|
||||
uint8_t additions; // 9 (0 means no addition)
|
||||
uint8_t edgesAndCorners; // 10 (edges in lower 4 bits, corners in upper 4)
|
||||
FootpathElementFlags flags2; // 11
|
||||
uint8_t slopeDirection; // 12
|
||||
Direction slopeDirection; // 12
|
||||
union
|
||||
{
|
||||
uint8_t additionStatus; // 13, only used for litter bins
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRCT2
|
||||
|
||||
Direction TileElementBase::getDirectionWithOffset(uint8_t offset) const
|
||||
{
|
||||
return ((this->type & kTileElementDirectionMask) + offset) & kTileElementDirectionMask;
|
||||
return DirectionRotate(getDirection(), offset);
|
||||
}
|
||||
|
||||
bool TileElementBase::isLastForTile() const
|
||||
|
||||
Reference in new issue
Block a user