Merge pull request #16129 from Gymnasiast/refactor/normalised-tile-element-type

Part of #15485: Use normalised tile element type enum for setting type
This commit is contained in:
Michael Steenbeek 2021-12-07 11:50:54 +01:00 committed by GitHub
commit ea099c0d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 34 deletions

View File

@ -2446,7 +2446,7 @@ static void Sub6CbcE2(
map_set_tile_element(southTileCoords, &_tempSideTrackTileElement);
// Set the temporary track element
_tempTrackTileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
_tempTrackTileElement.SetTypeN(TileElementTypeN::Track);
_tempTrackTileElement.SetDirection(trackDirection);
_tempTrackTileElement.AsTrack()->SetHasChain((liftHillAndInvertedState & CONSTRUCTION_LIFT_HILL_SELECTED) != 0);
_tempTrackTileElement.SetOccupiedQuadrants(quarterTile.GetBaseQuarterOccupied());

View File

@ -1778,7 +1778,7 @@ namespace RCT1
clearanceZ += LAND_HEIGHT_STEP;
}
dst->SetType(TILE_ELEMENT_TYPE_WALL);
dst->SetTypeN(TileElementTypeN::Wall);
dst->SetDirection(edge);
dst->SetBaseZ(baseZ);
dst->SetClearanceZ(clearanceZ);

View File

@ -7360,7 +7360,7 @@ void Vehicle::UpdateLandscapeDoor() const
auto coords = CoordsXYZ{ x, y, TrackLocation.z }.ToTileStart();
auto* tileElement = map_get_track_element_at_from_ride(coords, ride);
if (tileElement != nullptr && tileElement->GetType() == static_cast<uint8_t>(TileElementType::Track))
if (tileElement != nullptr && tileElement->GetTypeN() == TileElementTypeN::Track)
{
AnimateLandscapeDoor<false>(tileElement->AsTrack(), next_vehicle_on_train == SPRITE_INDEX_NULL);
}
@ -7434,7 +7434,7 @@ void Vehicle::UpdateLandscapeDoorBackwards() const
auto coords = CoordsXYZ{ TrackLocation, TrackLocation.z };
auto* tileElement = map_get_track_element_at_from_ride(coords, ride);
if (tileElement != nullptr && tileElement->GetType() == static_cast<uint8_t>(TileElementType::Track))
if (tileElement != nullptr && tileElement->GetTypeN() == TileElementTypeN::Track)
{
AnimateLandscapeDoor<true>(tileElement->AsTrack(), next_vehicle_on_train == SPRITE_INDEX_NULL);
}

View File

@ -105,7 +105,7 @@ namespace OpenRCT2::Scripting
auto numToInsert = numElements - currentNumElements;
for (size_t i = 0; i < numToInsert; i++)
{
tile_element_insert(pos, 0, TileElementType::Surface);
tile_element_insert(pos, 0, TileElementTypeN::Surface);
}
// Copy data to element span
@ -150,7 +150,7 @@ namespace OpenRCT2::Scripting
std::vector<TileElement> data(first, first + origNumElements);
auto pos = TileCoordsXYZ(TileCoordsXY(_coords), 0).ToCoordsXYZ();
auto newElement = tile_element_insert(pos, 0, TileElementType::Surface);
auto newElement = tile_element_insert(pos, 0, TileElementTypeN::Surface);
if (newElement == nullptr)
{
auto ctx = GetDukContext();

View File

@ -1234,7 +1234,7 @@ static TileElement* AllocateTileElements(size_t numElementsOnTile, size_t numNew
*
* rct2: 0x0068B1F6
*/
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type)
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementTypeN type)
{
const auto& tileLoc = TileCoordsXYZ(loc);
@ -1278,7 +1278,7 @@ TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants
// Insert new map element
auto* insertedElement = newTileElement;
newTileElement->type = 0;
newTileElement->SetType(static_cast<uint8_t>(type));
newTileElement->SetTypeN(type);
newTileElement->SetBaseZ(loc.z);
newTileElement->Flags = 0;
newTileElement->SetLastForTile(isLastForTile);

View File

@ -189,7 +189,7 @@ void map_remove_all_rides();
void map_invalidate_map_selection_tiles();
void map_invalidate_selection_rect();
bool MapCheckCapacityAndReorganise(const CoordsXY& loc, size_t numElements = 1);
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type);
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementTypeN type);
template<typename T> T* TileElementInsert(const CoordsXYZ& loc, int32_t occupiedQuadrants)
{

View File

@ -48,16 +48,16 @@ enum
TILE_ELEMENT_TYPE_BANNER = (7 << 2),
};
enum class TileElementType : uint8_t
enum class TileElementTypeN : uint8_t
{
Surface = (0 << 2),
Path = (1 << 2),
Track = (2 << 2),
SmallScenery = (3 << 2),
Entrance = (4 << 2),
Wall = (5 << 2),
LargeScenery = (6 << 2),
Banner = (7 << 2),
Surface = 0,
Path = 1,
Track = 2,
SmallScenery = 3,
Entrance = 4,
Wall = 5,
LargeScenery = 6,
Banner = 7,
};
struct TileElement;
@ -81,7 +81,9 @@ struct TileElementBase
void Remove();
uint8_t GetType() const;
void SetType(uint8_t newType);
TileElementTypeN GetTypeN() const;
void SetTypeN(TileElementTypeN newType);
Direction GetDirection() const;
void SetDirection(Direction direction);
@ -111,8 +113,7 @@ struct TileElementBase
if constexpr (std::is_same_v<TType, TileElement>)
return reinterpret_cast<const TileElement*>(this);
else
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<const TType*>(this)
: nullptr;
return GetTypeN() == TType::ElementType ? reinterpret_cast<const TType*>(this) : nullptr;
}
template<typename TType> TType* as()
@ -120,7 +121,7 @@ struct TileElementBase
if constexpr (std::is_same_v<TType, TileElement>)
return reinterpret_cast<TileElement*>(this);
else
return static_cast<TileElementType>(GetType()) == TType::ElementType ? reinterpret_cast<TType*>(this) : nullptr;
return GetTypeN() == TType::ElementType ? reinterpret_cast<TType*>(this) : nullptr;
}
const SurfaceElement* AsSurface() const
@ -210,7 +211,7 @@ assert_struct_size(TileElement, 16);
struct SurfaceElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Surface;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Surface;
private:
uint8_t Slope;
@ -257,7 +258,7 @@ assert_struct_size(SurfaceElement, 16);
struct PathElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Path;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Path;
private:
ObjectEntryIndex SurfaceIndex; // 5
@ -347,7 +348,7 @@ assert_struct_size(PathElement, 16);
struct TrackElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Track;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Track;
private:
track_type_t TrackType;
@ -448,7 +449,7 @@ assert_struct_size(TrackElement, 16);
struct SmallSceneryElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::SmallScenery;
static constexpr TileElementTypeN ElementType = TileElementTypeN::SmallScenery;
private:
ObjectEntryIndex entryIndex; // 5
@ -481,7 +482,7 @@ assert_struct_size(SmallSceneryElement, 16);
struct LargeSceneryElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::LargeScenery;
static constexpr TileElementTypeN ElementType = TileElementTypeN::LargeScenery;
private:
ObjectEntryIndex EntryIndex;
@ -519,7 +520,7 @@ assert_struct_size(LargeSceneryElement, 16);
struct WallElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Wall;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Wall;
private:
ObjectEntryIndex entryIndex; // 05
@ -564,7 +565,7 @@ assert_struct_size(WallElement, 16);
struct EntranceElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Entrance;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Entrance;
private:
uint8_t entranceType; // 5
@ -609,7 +610,7 @@ assert_struct_size(EntranceElement, 16);
struct BannerElement : TileElementBase
{
static constexpr TileElementType ElementType = TileElementType::Banner;
static constexpr TileElementTypeN ElementType = TileElementTypeN::Banner;
private:
BannerIndex index; // 5

View File

@ -15,10 +15,15 @@ uint8_t TileElementBase::GetType() const
return this->type & TILE_ELEMENT_TYPE_MASK;
}
void TileElementBase::SetType(uint8_t newType)
TileElementTypeN TileElementBase::GetTypeN() const
{
return static_cast<TileElementTypeN>((this->type & TILE_ELEMENT_TYPE_MASK) >> 2);
}
void TileElementBase::SetTypeN(TileElementTypeN newType)
{
this->type &= ~TILE_ELEMENT_TYPE_MASK;
this->type |= (newType & TILE_ELEMENT_TYPE_MASK);
this->type |= ((EnumValue(newType) << 2) & TILE_ELEMENT_TYPE_MASK);
}
Direction TileElementBase::GetDirection() const

View File

@ -347,7 +347,7 @@ namespace OpenRCT2::TileInspector
// The occupiedQuadrants will be automatically set when the element is copied over, so it's not necessary to set
// them correctly _here_.
TileElement* const pastedElement = tile_element_insert(
{ loc, element.GetBaseZ() }, 0b0000, TileElementType::Surface);
{ loc, element.GetBaseZ() }, 0b0000, TileElementTypeN::Surface);
bool lastForTile = pastedElement->IsLastForTile();
*pastedElement = element;

View File

@ -437,7 +437,7 @@ private:
for (int direction = 0; direction < 4; direction++)
{
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.SetTypeN(TileElementTypeN::Track);
tileElement.SetLastForTile(true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = 3;