Refactor some accessors to tile element type and flags fields

This commit is contained in:
Gymnasiast 2019-08-24 22:41:01 +02:00
parent f23e3368b1
commit 6e200459d3
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
13 changed files with 74 additions and 50 deletions

View File

@ -2453,7 +2453,8 @@ static void sub_6CBCE2(
_tempTrackTileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
_tempTrackTileElement.SetDirection(trackDirection);
_tempTrackTileElement.AsTrack()->SetHasChain((edx & 0x10000) != 0);
_tempTrackTileElement.flags = quarterTile.GetBaseQuarterOccupied() | TILE_ELEMENT_FLAG_LAST_TILE;
_tempTrackTileElement.flags = quarterTile.GetBaseQuarterOccupied();
_tempTrackTileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
_tempTrackTileElement.base_height = baseZ;
_tempTrackTileElement.clearance_height = clearanceZ;
_tempTrackTileElement.AsTrack()->SetTrackType(trackType);

View File

@ -393,6 +393,10 @@ template<> struct DataSerializerTraits<TileElement>
{
stream->WriteValue(tileElement.pad_04[i]);
}
for (int i = 0; i < 8; ++i)
{
stream->WriteValue(tileElement.pad_08[i]);
}
}
static void decode(IStream* stream, TileElement& tileElement)
{
@ -404,6 +408,10 @@ template<> struct DataSerializerTraits<TileElement>
{
tileElement.pad_04[i] = stream->ReadValue<uint8_t>();
}
for (int i = 0; i < 8; ++i)
{
tileElement.pad_08[i] = stream->ReadValue<uint8_t>();
}
}
static void log(IStream* stream, const TileElement& tileElement)
{

View File

@ -2015,7 +2015,7 @@ private:
void ImportTileElement(TileElement* dst, const RCT12TileElement* src)
{
// Todo: allow for changing defition of OpenRCT2 tile element types - replace with a map
// Todo: allow for changing definition of OpenRCT2 tile element types - replace with a map
uint8_t tileElementType = src->GetType();
dst->ClearAs(tileElementType);
dst->SetDirection(src->GetDirection());
@ -2694,7 +2694,7 @@ private:
for (int32_t y = 0; y < RCT1_MAX_MAP_SIZE; y++)
{
nextFreeTileElement->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
nextFreeTileElement->flags = TILE_ELEMENT_FLAG_LAST_TILE;
nextFreeTileElement->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
nextFreeTileElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
nextFreeTileElement->AsSurface()->SetSurfaceStyle(TERRAIN_GRASS);
nextFreeTileElement->AsSurface()->SetEdgeStyle(TERRAIN_EDGE_ROCK);
@ -2708,7 +2708,7 @@ private:
for (int32_t y = 0; y < 128 * 256; y++)
{
nextFreeTileElement->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
nextFreeTileElement->flags = TILE_ELEMENT_FLAG_LAST_TILE;
nextFreeTileElement->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
nextFreeTileElement->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
nextFreeTileElement->AsSurface()->SetSurfaceStyle(TERRAIN_GRASS);
nextFreeTileElement->AsSurface()->SetEdgeStyle(TERRAIN_EDGE_ROCK);

View File

@ -2411,7 +2411,7 @@ static void track_design_preview_clear_map()
{
TileElement* tile_element = &gTileElements[i];
tile_element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
tile_element->flags = TILE_ELEMENT_FLAG_LAST_TILE;
tile_element->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tile_element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
tile_element->AsSurface()->SetWaterHeight(0);
tile_element->AsSurface()->SetSurfaceStyle(TERRAIN_GRASS);

View File

@ -5169,18 +5169,18 @@ static TileElement* vehicle_check_collision(int16_t x, int16_t y, int16_t z)
return nullptr;
}
uint8_t bl;
uint8_t quadrant;
if ((x & 0x1F) >= 16)
{
bl = 1;
quadrant = 1;
if ((y & 0x1F) < 16)
bl = 2;
quadrant = 2;
}
else
{
bl = 4;
quadrant = 4;
if ((y & 0x1F) >= 16)
bl = 8;
quadrant = 8;
}
do
@ -5191,7 +5191,7 @@ static TileElement* vehicle_check_collision(int16_t x, int16_t y, int16_t z)
if (z / 8 >= tileElement->clearance_height)
continue;
if (tileElement->flags & bl)
if (tileElement->flags & quadrant)
return tileElement;
} while (!(tileElement++)->IsLastForTile());
@ -6769,7 +6769,8 @@ static void vehicle_update_block_brakes_open_previous_section(rct_vehicle* vehic
slowY = slowTrackBeginEnd.end_y;
slowTileElement = *(slowTrackBeginEnd.begin_element);
if (slowX == x && slowY == y && slowTileElement.base_height == tileElement->base_height
&& slowTileElement.type == tileElement->type)
&& slowTileElement.GetType() == tileElement->GetType()
&& slowTileElement.GetDirection() == tileElement->GetDirection())
{
return;
}

View File

@ -310,7 +310,7 @@ void map_init(int32_t size)
{
TileElement* tile_element = &gTileElements[i];
tile_element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
tile_element->flags = TILE_ELEMENT_FLAG_LAST_TILE;
tile_element->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tile_element->base_height = 14;
tile_element->clearance_height = 14;
tile_element->AsSurface()->SetWaterHeight(0);
@ -957,7 +957,7 @@ void tile_element_remove(TileElement* tileElement)
}
// Mark the latest element with the last element flag.
(tileElement - 1)->flags |= TILE_ELEMENT_FLAG_LAST_TILE;
(tileElement - 1)->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement->base_height = 0xFF;
if ((tileElement + 1) == gNextFreeTileElement)
@ -1178,10 +1178,11 @@ TileElement* tile_element_insert(const TileCoordsXYZ& loc, int32_t flags)
originalTileElement++;
newTileElement++;
if ((newTileElement - 1)->flags & TILE_ELEMENT_FLAG_LAST_TILE)
if ((newTileElement - 1)->IsLastForTile())
{
// No more elements above the insert element
(newTileElement - 1)->flags &= ~TILE_ELEMENT_FLAG_LAST_TILE;
(newTileElement - 1)->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, false);
;
flags |= TILE_ELEMENT_FLAG_LAST_TILE;
break;
}

View File

@ -131,7 +131,7 @@ static bool map_animation_invalidate_queue_banner(int32_t x, int32_t y, int32_t
continue;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
continue;
if (!(tileElement->flags & 1))
if (!(tileElement->AsPath()->IsQueue()))
continue;
if (!tileElement->AsPath()->HasQueueBanner())
continue;

View File

@ -154,6 +154,7 @@ void TileElement::ClearAs(uint8_t newType)
base_height = 2;
clearance_height = 2;
std::fill_n(pad_04, sizeof(pad_04), 0x00);
std::fill_n(pad_08, sizeof(pad_08), 0x00);
}
void TileElementBase::Remove()
@ -204,3 +205,16 @@ const QuarterTile QuarterTile::Rotate(uint8_t amount) const
return QuarterTile{ 0 };
}
}
bool TileElementBase::HasFlag(uint8_t flag) const
{
return (flags & flag);
}
void TileElementBase::SetFlag(uint8_t flag, bool on)
{
if (on)
flags |= flag;
else
flags &= ~flag;
}

View File

@ -74,6 +74,9 @@ struct TileElementBase
bool IsGhost() const;
void SetGhost(bool isGhost);
void Remove();
bool HasFlag(uint8_t flag) const;
void SetFlag(uint8_t flag, bool on);
};
/**
@ -123,10 +126,6 @@ public:
{
return as<BannerElement, TileElementType::Banner>();
}
CorruptElement* AsCorrupt() const
{
return as<CorruptElement, TileElementType::Corrupt>();
}
void ClearAs(uint8_t newType);
};
@ -246,8 +245,6 @@ public:
uint8_t GetAdditionStatus() const;
void SetAdditionStatus(uint8_t newStatus);
uint8_t GetRCT1PathType() const;
bool ShouldDrawPathOverSupports();
void SetShouldDrawPathOverSupports(bool on);
};

View File

@ -65,8 +65,8 @@ static bool map_swap_elements_at(CoordsXY loc, int16_t first, int16_t second)
// Swap the 'last map element for tile' flag if either one of them was last
if ((firstElement)->IsLastForTile() || (secondElement)->IsLastForTile())
{
firstElement->flags ^= TILE_ELEMENT_FLAG_LAST_TILE;
secondElement->flags ^= TILE_ELEMENT_FLAG_LAST_TILE;
firstElement->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, !firstElement->IsLastForTile());
secondElement->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, !secondElement->IsLastForTile());
}
return true;
@ -324,11 +324,7 @@ GameActionResult::Ptr tile_inspector_paste_element_at(CoordsXY loc, TileElement
bool lastForTile = pastedElement->IsLastForTile();
*pastedElement = element;
pastedElement->flags &= ~TILE_ELEMENT_FLAG_LAST_TILE;
if (lastForTile)
{
pastedElement->flags |= TILE_ELEMENT_FLAG_LAST_TILE;
}
pastedElement->SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, lastForTile);
map_invalidate_tile_full(loc.x, loc.y);

View File

@ -155,6 +155,19 @@ rct_sprite* get_sprite(size_t sprite_idx)
return &sprite_list[sprite_idx];
}
bool TileElementBase::HasFlag(uint8_t flag) const
{
return (flags & flag);
}
void TileElementBase::SetFlag(uint8_t flag, bool on)
{
if (on)
flags |= flag;
else
flags &= ~flag;
}
bool TileElementBase::IsLastForTile() const
{
return (this->flags & TILE_ELEMENT_FLAG_LAST_TILE) != 0;

View File

@ -101,14 +101,7 @@ public:
uint8_t rideType, uint8_t trackType, int variant, TileElement* tileElement, TileElement* surfaceElement, Ride* ride,
rct_ride_entry* rideEntry) override
{
if (variant == 0)
{
tileElement->type &= ~TRACK_ELEMENT_TYPE_FLAG_CHAIN_LIFT;
}
else
{
tileElement->type |= TRACK_ELEMENT_TYPE_FLAG_CHAIN_LIFT;
}
tileElement->AsTrack()->SetHasChain(variant != 0);
}
};
@ -269,13 +262,13 @@ static uint8_t TestTrackElementPaintCalls(uint8_t rideType, uint8_t trackType, u
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = height / 16;
g_currently_drawn_item = &tileElement;
TileElement surfaceElement = {};
surfaceElement.type = TILE_ELEMENT_TYPE_SURFACE;
surfaceElement.SetType(TILE_ELEMENT_TYPE_SURFACE);
surfaceElement.base_height = 2;
gSurfaceElement = &surfaceElement;
gDidPassSurface = true;
@ -432,13 +425,13 @@ static uint8_t TestTrackElementSegmentSupportHeight(
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = height / 16;
g_currently_drawn_item = &tileElement;
TileElement surfaceElement = {};
surfaceElement.type = TILE_ELEMENT_TYPE_SURFACE;
surfaceElement.SetType(TILE_ELEMENT_TYPE_SURFACE);
surfaceElement.base_height = 2;
gSurfaceElement = &surfaceElement;
gDidPassSurface = true;
@ -519,13 +512,13 @@ static uint8_t TestTrackElementGeneralSupportHeight(
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = height / 16;
g_currently_drawn_item = &tileElement;
TileElement surfaceElement = {};
surfaceElement.type = TILE_ELEMENT_TYPE_SURFACE;
surfaceElement.SetType(TILE_ELEMENT_TYPE_SURFACE);
surfaceElement.base_height = 2;
gSurfaceElement = &surfaceElement;
gDidPassSurface = true;
@ -620,13 +613,13 @@ static uint8_t TestTrackElementSideTunnels(uint8_t rideType, uint8_t trackType,
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = height / 16;
g_currently_drawn_item = &tileElement;
TileElement surfaceElement = {};
surfaceElement.type = TILE_ELEMENT_TYPE_SURFACE;
surfaceElement.SetType(TILE_ELEMENT_TYPE_SURFACE);
surfaceElement.base_height = 2;
gSurfaceElement = &surfaceElement;
gDidPassSurface = true;
@ -748,13 +741,13 @@ static uint8_t TestTrackElementVerticalTunnels(uint8_t rideType, uint8_t trackTy
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = height / 16;
g_currently_drawn_item = &tileElement;
TileElement surfaceElement = {};
surfaceElement.type = TILE_ELEMENT_TYPE_SURFACE;
surfaceElement.SetType(TILE_ELEMENT_TYPE_SURFACE);
surfaceElement.base_height = 2;
gSurfaceElement = &surfaceElement;
gDidPassSurface = true;

View File

@ -446,7 +446,7 @@ private:
{
TileElement tileElement = {};
tileElement.SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement.flags |= TILE_ELEMENT_FLAG_LAST_TILE;
tileElement.SetFlag(TILE_ELEMENT_FLAG_LAST_TILE, true);
tileElement.AsTrack()->SetTrackType(trackType);
tileElement.base_height = 3;
if (_invertedTrack)
@ -482,7 +482,7 @@ private:
}
// Get chain lift calls
tileElement.type |= 0x80;
tileElement.AsTrack()->SetHasChain(true);
PaintIntercept::ClearCalls();
CallOriginal(trackType, direction, trackSequence, height, &tileElement);
numCalls = PaintIntercept::GetCalls(callBuffer);