Large scenery tiles 2 (#22888)

* Use std::span for tiles

* Add an index helper parameter

* Use coordsxyz

* Split up corners and walls

* Use bools for the two flags

* Apply coding style

* Refer only to LargeSceneryObject where required

* Address comments
This commit is contained in:
Duncan authored and GitHub committed 2024-10-16 22:35:29 +01:00
1 parent 8063c5caa7
commit f6582647f5
17 files changed
+151 -212

No files matched your search

+4 -5
View File
@@ -1965,10 +1965,9 @@ namespace OpenRCT2::Ui::Windows
auto* sceneryEntry = OpenRCT2::ObjectManager::GetObjectEntry<LargeSceneryEntry>(selection.EntryIndex);
gMapSelectionTiles.clear();
for (auto* tile = sceneryEntry->tiles;
tile->x_offset != static_cast<int16_t>(static_cast<uint16_t>(0xFFFF)); tile++)
for (auto& tile : sceneryEntry->tiles)
{
CoordsXY tileLocation = { tile->x_offset, tile->y_offset };
CoordsXY tileLocation = { tile.offset };
auto rotatedTileCoords = tileLocation.Rotate(direction);
rotatedTileCoords.x += mapTile.x;
@@ -2775,9 +2774,9 @@ namespace OpenRCT2::Ui::Windows
if (sceneryEntry)
{
int16_t maxClearZ = 0;
for (int32_t i = 0; sceneryEntry->tiles[i].x_offset != -1; ++i)
for (auto& tile : sceneryEntry->tiles)
{
maxClearZ = std::max<int16_t>(maxClearZ, sceneryEntry->tiles[i].z_clearance);
maxClearZ = std::max<int16_t>(maxClearZ, tile.zClearance);
}
maxPossibleHeight = std::max(0, maxPossibleHeight - maxClearZ);
}
@@ -108,7 +108,7 @@ GameActions::Result LargeSceneryPlaceAction::Query() const
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE);
}
uint32_t totalNumTiles = GetTotalNumTiles(sceneryEntry->tiles);
const auto totalNumTiles = sceneryEntry->tiles.size();
int16_t maxHeight = GetMaxSurfaceHeight(sceneryEntry->tiles);
if (_loc.z != 0)
@@ -128,18 +128,17 @@ GameActions::Result LargeSceneryPlaceAction::Query() const
}
}
uint8_t tileNum = 0;
for (LargeSceneryTile* tile = sceneryEntry->tiles; tile->x_offset != -1; tile++, tileNum++)
for (auto& tile : sceneryEntry->tiles)
{
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction);
curTile.x += _loc.x;
curTile.y += _loc.y;
int32_t zLow = tile->z_offset + maxHeight;
int32_t zHigh = tile->z_clearance + zLow;
int32_t zLow = tile.offset.z + maxHeight;
int32_t zHigh = tile.zClearance + zLow;
QuarterTile quarterTile = QuarterTile{ static_cast<uint8_t>(tile->flags >> 12), 0 }.Rotate(_loc.direction);
QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction);
const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0;
auto canBuild = MapCanConstructWithClearAt(
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree);
@@ -222,7 +221,7 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE);
}
if (sceneryEntry->tiles == nullptr)
if (sceneryEntry->tiles.empty())
{
LOG_ERROR("Invalid large scenery object, sceneryType = %u", _sceneryType);
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_NONE);
@@ -266,18 +265,17 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
resultData.bannerId = banner->id;
}
uint8_t tileNum = 0;
for (LargeSceneryTile* tile = sceneryEntry->tiles; tile->x_offset != -1; tile++, tileNum++)
for (auto& tile : sceneryEntry->tiles)
{
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction);
curTile.x += _loc.x;
curTile.y += _loc.y;
int32_t zLow = tile->z_offset + maxHeight;
int32_t zHigh = tile->z_clearance + zLow;
int32_t zLow = tile.offset.z + maxHeight;
int32_t zHigh = tile.zClearance + zLow;
QuarterTile quarterTile = QuarterTile{ static_cast<uint8_t>(tile->flags >> 12), 0 }.Rotate(_loc.direction);
QuarterTile quarterTile = QuarterTile{ tile.corners, 0 }.Rotate(_loc.direction);
const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0;
auto canBuild = MapCanConstructWithClearAt(
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree);
@@ -310,7 +308,7 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
Guard::Assert(newSceneryElement != nullptr);
newSceneryElement->SetClearanceZ(zHigh);
SetNewLargeSceneryElement(*newSceneryElement, tileNum);
SetNewLargeSceneryElement(*newSceneryElement, tile.index);
if (banner != nullptr)
{
newSceneryElement->SetBannerIndex(banner->id);
@@ -319,7 +317,7 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
MapAnimationCreate(MAP_ANIMATION_TYPE_LARGE_SCENERY, { curTile, zLow });
MapInvalidateTileFull(curTile);
if (tileNum == 0)
if (tile.index == 0)
{
resultData.firstTileHeight = zLow;
}
@@ -334,21 +332,11 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
return res;
}
int16_t LargeSceneryPlaceAction::GetTotalNumTiles(LargeSceneryTile* tiles) const
bool LargeSceneryPlaceAction::CheckMapCapacity(std::span<const LargeSceneryTile> tiles, size_t numTiles) const
{
uint32_t totalNumTiles = 0;
for (LargeSceneryTile* tile = tiles; tile->x_offset != -1; tile++)
for (auto& tile : tiles)
{
totalNumTiles++;
}
return totalNumTiles;
}
bool LargeSceneryPlaceAction::CheckMapCapacity(LargeSceneryTile* tiles, int16_t numTiles) const
{
for (LargeSceneryTile* tile = tiles; tile->x_offset != -1; tile++)
{
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction);
curTile.x += _loc.x;
curTile.y += _loc.y;
@@ -360,12 +348,12 @@ bool LargeSceneryPlaceAction::CheckMapCapacity(LargeSceneryTile* tiles, int16_t
return true;
}
int16_t LargeSceneryPlaceAction::GetMaxSurfaceHeight(LargeSceneryTile* tiles) const
int16_t LargeSceneryPlaceAction::GetMaxSurfaceHeight(std::span<const LargeSceneryTile> tiles) const
{
int16_t maxHeight = -1;
for (LargeSceneryTile* tile = tiles; tile->x_offset != -1; tile++)
for (auto& tile : tiles)
{
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
auto curTile = CoordsXY{ tile.offset }.Rotate(_loc.direction);
curTile.x += _loc.x;
curTile.y += _loc.y;
@@ -46,8 +46,7 @@ public:
OpenRCT2::GameActions::Result Execute() const override;
private:
int16_t GetTotalNumTiles(LargeSceneryTile* tiles) const;
bool CheckMapCapacity(LargeSceneryTile* tiles, int16_t numTiles) const;
int16_t GetMaxSurfaceHeight(LargeSceneryTile* tiles) const;
bool CheckMapCapacity(std::span<const LargeSceneryTile> tiles, size_t numTiles) const;
int16_t GetMaxSurfaceHeight(std::span<const LargeSceneryTile> tiles) const;
void SetNewLargeSceneryElement(LargeSceneryElement& sceneryElement, uint8_t tileNum) const;
};
@@ -77,20 +77,15 @@ GameActions::Result LargeSceneryRemoveAction::Query() const
return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REMOVE_THIS, STR_UNKNOWN_OBJECT_TYPE);
}
auto rotatedOffsets = CoordsXYZ{
CoordsXY{ sceneryEntry->tiles[_tileIndex].x_offset, sceneryEntry->tiles[_tileIndex].y_offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].z_offset
};
auto rotatedOffsets = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].offset.z };
auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedOffsets;
bool calculate_cost = true;
for (int32_t i = 0; sceneryEntry->tiles[i].x_offset != -1; i++)
for (auto& tile : sceneryEntry->tiles)
{
auto currentTileRotatedOffset = CoordsXYZ{
CoordsXY{ sceneryEntry->tiles[i].x_offset, sceneryEntry->tiles[i].y_offset }.Rotate(_loc.direction),
sceneryEntry->tiles[i].z_offset
};
auto currentTileRotatedOffset = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z };
auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + currentTileRotatedOffset;
@@ -163,19 +158,14 @@ GameActions::Result LargeSceneryRemoveAction::Execute() const
tileElement->RemoveBannerEntry();
auto rotatedFirstTile = CoordsXYZ{
CoordsXY{ sceneryEntry->tiles[_tileIndex].x_offset, sceneryEntry->tiles[_tileIndex].y_offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].z_offset
};
auto rotatedFirstTile = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].offset.z };
auto firstTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedFirstTile;
for (int32_t i = 0; sceneryEntry->tiles[i].x_offset != -1; i++)
for (auto& tile : sceneryEntry->tiles)
{
auto rotatedCurrentTile = CoordsXYZ{
CoordsXY{ sceneryEntry->tiles[i].x_offset, sceneryEntry->tiles[i].y_offset }.Rotate(_loc.direction),
sceneryEntry->tiles[i].z_offset
};
auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z };
auto currentTile = CoordsXYZ{ firstTile.x, firstTile.y, firstTile.z } + rotatedCurrentTile;
@@ -187,7 +177,7 @@ GameActions::Result LargeSceneryRemoveAction::Execute() const
}
}
auto* sceneryElement = FindLargeSceneryElement(currentTile, i);
auto* sceneryElement = FindLargeSceneryElement(currentTile, tile.index);
if (sceneryElement == nullptr)
{
LOG_ERROR("Tile not found when trying to remove element!");
@@ -116,18 +116,15 @@ GameActions::Result LargeScenerySetColourAction::QueryExecute(bool isExecuting)
return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, STR_NONE);
}
// Work out the base tile coordinates (Tile with index 0)
auto rotatedBaseCoordsOffset = CoordsXYZ{
CoordsXY{ sceneryEntry->tiles[_tileIndex].x_offset, sceneryEntry->tiles[_tileIndex].y_offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].z_offset
};
auto rotatedBaseCoordsOffset = CoordsXYZ{ CoordsXY{ sceneryEntry->tiles[_tileIndex].offset }.Rotate(_loc.direction),
sceneryEntry->tiles[_tileIndex].offset.z };
auto baseTile = CoordsXYZ{ _loc.x, _loc.y, _loc.z } - rotatedBaseCoordsOffset;
auto i = 0;
for (auto tile = sceneryEntry->tiles; tile->x_offset != -1; ++tile, ++i)
for (auto& tile : sceneryEntry->tiles)
{
// Work out the current tile coordinates
auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction), tile->z_offset };
auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(_loc.direction), tile.offset.z };
auto currentTile = CoordsXYZ{ baseTile.x, baseTile.y, baseTile.z } + rotatedTileCoords;
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode)
@@ -143,7 +140,7 @@ GameActions::Result LargeScenerySetColourAction::QueryExecute(bool isExecuting)
return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP);
}
auto tileElement = MapGetLargeScenerySegment({ currentTile.x, currentTile.y, _loc.z, _loc.direction }, i);
auto tileElement = MapGetLargeScenerySegment({ currentTile.x, currentTile.y, _loc.z, _loc.direction }, tile.index);
if (tileElement == nullptr)
{
+2 -2
View File
@@ -569,8 +569,8 @@ GameActions::Result WallPlaceAction::WallCheckObstruction(
auto sequence = largeSceneryElement->GetSequenceIndex();
const LargeSceneryTile& tile = sceneryEntry->tiles[sequence];
int32_t direction = ((_edge - tileElement->GetDirection()) & kTileElementDirectionMask) + 8;
if (!(tile.flags & (1 << direction)))
int32_t direction = ((_edge - tileElement->GetDirection()) & kTileElementDirectionMask);
if (!(tile.walls & (1 << direction)))
{
MapGetObstructionErrorText(tileElement, res);
return res;
+9 -13
View File
@@ -14,6 +14,7 @@
#include "../world/Location.hpp"
#include "ObjectTypes.h"
#include <span>
#include <string_view>
enum class CursorID : uint8_t;
@@ -22,18 +23,13 @@ struct LargeSceneryText;
struct LargeSceneryTile
{
int16_t x_offset;
int16_t y_offset;
int16_t z_offset;
uint8_t z_clearance;
// CCCC WWWW 0SS0 0000
uint16_t flags;
};
enum
{
LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS = 0x20,
LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE = 0x40,
CoordsXYZ offset;
int32_t zClearance; // BigZ
bool hasSupports;
bool allowSupportsAbove;
uint8_t corners; // occupied corners of the tile
uint8_t walls; // sides that walls can be placed on
uint8_t index; // Purely to save having to look this up all the time
};
struct LargeSceneryTextGlyph
@@ -74,7 +70,7 @@ struct LargeSceneryEntry
uint16_t flags;
money64 price;
money64 removal_price;
LargeSceneryTile* tiles;
std::span<const LargeSceneryTile> tiles;
ObjectEntryIndex scenery_tab_id;
uint8_t scrolling_mode;
LargeSceneryText* text;
+31 -36
View File
@@ -117,7 +117,7 @@ void LargeSceneryObject::Load()
_baseImageId = LoadImages();
_legacyType.image = _baseImageId;
_legacyType.tiles = _tiles.data();
_legacyType.tiles = _tiles;
if (_legacyType.flags & LARGE_SCENERY_FLAG_3D_TEXT)
{
@@ -158,17 +158,27 @@ void LargeSceneryObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t
GfxDrawSprite(dpi, image, screenCoords);
}
enum
{
LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS = 0x20,
LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE = 0x40,
};
std::vector<LargeSceneryTile> LargeSceneryObject::ReadTiles(OpenRCT2::IStream* stream)
{
auto tiles = std::vector<LargeSceneryTile>();
auto ReadLegacyTile = [&stream]() {
LargeSceneryTile tile{};
tile.x_offset = stream->ReadValue<int16_t>();
tile.y_offset = stream->ReadValue<int16_t>();
tile.z_offset = stream->ReadValue<int16_t>();
tile.z_clearance = stream->ReadValue<uint8_t>();
tile.flags = stream->ReadValue<uint16_t>();
tile.offset.x = stream->ReadValue<int16_t>();
tile.offset.y = stream->ReadValue<int16_t>();
tile.offset.z = stream->ReadValue<int16_t>();
tile.zClearance = stream->ReadValue<uint8_t>();
uint16_t flags = stream->ReadValue<uint16_t>();
tile.walls = (flags >> 8) & 0xF;
tile.corners = (flags >> 12) & 0xF;
tile.allowSupportsAbove = flags & LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE;
tile.hasSupports = !(flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS);
return tile;
};
@@ -177,7 +187,11 @@ std::vector<LargeSceneryTile> LargeSceneryObject::ReadTiles(OpenRCT2::IStream* s
stream->Seek(-2, OpenRCT2::STREAM_SEEK_CURRENT);
tiles.push_back(ReadLegacyTile());
}
tiles.push_back({ -1, -1, -1, 255, 0xFFFF });
uint8_t index = 0;
for (auto& tile : tiles)
{
tile.index = index++;
}
return tiles;
}
@@ -231,41 +245,30 @@ void LargeSceneryObject::ReadJson(IReadObjectContext* context, json_t& root)
std::vector<LargeSceneryTile> LargeSceneryObject::ReadJsonTiles(json_t& jTiles)
{
std::vector<LargeSceneryTile> tiles;
for (auto& jTile : jTiles)
{
if (jTile.is_object())
{
LargeSceneryTile tile = {};
tile.x_offset = Json::GetNumber<int16_t>(jTile["x"]);
tile.y_offset = Json::GetNumber<int16_t>(jTile["y"]);
tile.z_offset = Json::GetNumber<int16_t>(jTile["z"]);
tile.z_clearance = Json::GetNumber<int8_t>(jTile["clearance"]);
tile.offset.x = Json::GetNumber<int16_t>(jTile["x"]);
tile.offset.y = Json::GetNumber<int16_t>(jTile["y"]);
tile.offset.z = Json::GetNumber<int16_t>(jTile["z"]);
tile.zClearance = Json::GetNumber<int8_t>(jTile["clearance"]);
// clang-format off
tile.flags = Json::GetFlags<uint16_t>(
jTile,
{
{"hasSupports", LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS, Json::FlagType::Inverted},
{"allowSupportsAbove", LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE, Json::FlagType::Normal}
});
// clang-format on
tile.hasSupports = Json::GetBoolean(jTile["hasSupports"], true);
tile.allowSupportsAbove = Json::GetBoolean(jTile["allowSupportsAbove"]);
// All corners are by default occupied
uint16_t corners = Json::GetNumber<uint16_t>(jTile["corners"], 0xF);
tile.flags |= (corners & 0xFF) << 12;
tile.corners = Json::GetNumber<uint16_t>(jTile["corners"], 0xF);
auto walls = Json::GetNumber<int16_t>(jTile["walls"]);
tile.flags |= (walls & 0xFF) << 8;
tile.walls = Json::GetNumber<int16_t>(jTile["walls"]);
tile.index = static_cast<uint8_t>(tiles.size());
tiles.push_back(std::move(tile));
}
}
// HACK Add end of tiles marker
// We should remove this later by improving the code base to use tiles array length
tiles.push_back({ -1, -1, -1, 0xFF, 0xFFFF });
return tiles;
}
@@ -336,11 +339,3 @@ std::vector<LargeSceneryTextGlyph> LargeSceneryObject::ReadJsonGlyphs(json_t& jG
}
return glyphs;
}
const LargeSceneryTile* LargeSceneryObject::GetTileForSequence(uint8_t SequenceIndex) const
{
if (SequenceIndex >= _tiles.size())
return nullptr;
return &_tiles[SequenceIndex];
}
-1
View File
@@ -37,7 +37,6 @@ public:
void Unload() override;
void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override;
const LargeSceneryTile* GetTileForSequence(uint8_t SequenceIndex) const;
private:
[[nodiscard]] static std::vector<LargeSceneryTile> ReadTiles(OpenRCT2::IStream* stream);
@@ -18,7 +18,7 @@
#include "../../interface/Viewport.h"
#include "../../localisation/Formatting.h"
#include "../../localisation/StringIds.h"
#include "../../object/LargeSceneryObject.h"
#include "../../object/LargeSceneryEntry.h"
#include "../../profiling/Profiling.h"
#include "../../ride/Ride.h"
#include "../../ride/TrackDesign.h"
@@ -63,7 +63,7 @@ static void PaintLargeScenerySupports(
{
PROFILED_FUNCTION();
if (tile.flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS)
if (!tile.hasSupports)
return;
auto transitionType = WoodenSupportTransitionType::None;
@@ -78,7 +78,7 @@ static void PaintLargeScenerySupports(
session, WoodenSupportType::Truss, WoodenSupportSubType::NeSw, direction, supportHeight, imageTemplate, transitionType);
int32_t clearanceHeight = Ceil2(tileElement.GetClearanceZ() + 15, 16);
if (tile.flags & LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE)
if (tile.allowSupportsAbove)
{
PaintUtilSetSegmentSupportHeight(session, kSegmentsAll, clearanceHeight, 0x20);
}
@@ -192,7 +192,7 @@ static void PaintLargeScenery3DText(
{
PROFILED_FUNCTION();
if (sceneryEntry.tiles[1].x_offset != -1)
if (sceneryEntry.tiles.size() != 1)
{
auto sequenceDirection = (tileElement.GetSequenceIndex() - 1) & 3;
if (sequenceDirection != direction)
@@ -341,18 +341,16 @@ void PaintLargeScenery(PaintSession& session, uint8_t direction, uint16_t height
return;
auto sequenceNum = tileElement.GetSequenceIndex();
const auto* object = tileElement.GetObject();
if (object == nullptr)
return;
const auto* sceneryEntry = tileElement.GetEntry();
if (sceneryEntry == nullptr)
return;
const auto* tile = object->GetTileForSequence(sequenceNum);
if (tile == nullptr)
if (sequenceNum >= sceneryEntry->tiles.size())
return;
auto& tile = sceneryEntry->tiles[sequenceNum];
session.InteractionType = ViewportInteractionItem::LargeScenery;
auto isGhost = false;
@@ -389,14 +387,16 @@ void PaintLargeScenery(PaintSession& session, uint8_t direction, uint16_t height
}
}
auto boxlengthZ = std::min<uint8_t>(tile->z_clearance, 128) - 3;
auto flags = tile->flags;
auto boxlengthZ = std::min(tile.zClearance, 128) - 3;
auto bbIndex = 16;
if (flags & 0xF00)
// This matches vanilla but its odd that its a branch on walls
// and then operates on corners. I guess its because if you
// have no walls then you must be occupying the whole tile
// and all the connecting tiles so using an even bigger boundbox
// makes sense.
if (tile.walls)
{
flags &= 0xF000;
flags = Numerics::rol16(flags, direction);
bbIndex = (flags & 0xF) | (flags >> 12);
bbIndex = Numerics::rol4(tile.corners, direction);
}
const CoordsXYZ& bbOffset = { LargeSceneryBoundBoxes[bbIndex].offset, height };
const CoordsXYZ& bbLength = { LargeSceneryBoundBoxes[bbIndex].length, boxlengthZ };
@@ -408,7 +408,7 @@ void PaintLargeScenery(PaintSession& session, uint8_t direction, uint16_t height
{
if (sceneryEntry->flags & LARGE_SCENERY_FLAG_3D_TEXT)
{
PaintLargeScenery3DText(session, *sceneryEntry, *tile, tileElement, direction, height, isGhost);
PaintLargeScenery3DText(session, *sceneryEntry, tile, tileElement, direction, height, isGhost);
}
else if (session.DPI.zoom_level <= ZoomLevel{ 0 })
{
@@ -420,5 +420,5 @@ void PaintLargeScenery(PaintSession& session, uint8_t direction, uint16_t height
}
}
PaintLargeScenerySupports(
session, direction, height, tileElement, isGhost ? imageTemplate : ImageId(0, COLOUR_BLACK), *tile);
session, direction, height, tileElement, isGhost ? imageTemplate : ImageId(0, COLOUR_BLACK), tile);
}
+9 -9
View File
@@ -760,23 +760,23 @@ static void TrackDesignMirrorScenery(TrackDesign& td)
{
auto* sceneryEntry = reinterpret_cast<const LargeSceneryEntry*>(obj->GetLegacyData());
int16_t x1 = 0, x2 = 0, y1 = 0, y2 = 0;
for (LargeSceneryTile* tile = sceneryEntry->tiles; tile->x_offset != -1; tile++)
for (auto& tile : sceneryEntry->tiles)
{
if (x1 > tile->x_offset)
if (x1 > tile.offset.x)
{
x1 = tile->x_offset;
x1 = tile.offset.x;
}
if (x2 < tile->x_offset)
if (x2 < tile.offset.x)
{
x2 = tile->x_offset;
x2 = tile.offset.x;
}
if (y1 > tile->y_offset)
if (y1 > tile.offset.y)
{
y1 = tile->y_offset;
y1 = tile.offset.y;
}
if (y2 < tile->y_offset)
if (y2 < tile.offset.y)
{
y2 = tile->y_offset;
y2 = tile.offset.y;
}
}
+13 -25
View File
@@ -148,11 +148,8 @@ bool TrackDesignSaveContainsTileElement(const TileElement* tileElement)
return false;
}
static int32_t TrackDesignSaveGetTotalElementCount(TileElement* tileElement)
static size_t TrackDesignSaveGetTotalElementCount(TileElement* tileElement)
{
int32_t elementCount;
LargeSceneryTile* tile;
switch (tileElement->GetType())
{
case TileElementType::Path:
@@ -163,14 +160,7 @@ static int32_t TrackDesignSaveGetTotalElementCount(TileElement* tileElement)
case TileElementType::LargeScenery:
{
auto* sceneryEntry = tileElement->AsLargeScenery()->GetEntry();
tile = sceneryEntry->tiles;
elementCount = 0;
do
{
tile++;
elementCount++;
} while (tile->x_offset != static_cast<int16_t>(static_cast<uint16_t>(0xFFFF)));
return elementCount;
return sceneryEntry->tiles.size();
}
default:
return 0;
@@ -287,7 +277,7 @@ static TrackDesignAddStatus TrackDesignSaveAddLargeScenery(const CoordsXY& loc,
if (obj != nullptr && TrackDesignSaveIsSupportedObject(obj))
{
auto sceneryEntry = reinterpret_cast<const LargeSceneryEntry*>(obj->GetLegacyData());
auto sceneryTiles = sceneryEntry->tiles;
auto& sceneryTiles = sceneryEntry->tiles;
int32_t z = tileElement->BaseHeight;
auto direction = tileElement->GetDirection();
@@ -301,18 +291,17 @@ static TrackDesignAddStatus TrackDesignSaveAddLargeScenery(const CoordsXY& loc,
}
// Iterate through each tile of the large scenery element
sequence = 0;
for (auto tile = sceneryTiles; tile->x_offset != -1; tile++, sequence++)
for (auto& tile : sceneryTiles)
{
CoordsXY offsetPos{ tile->x_offset, tile->y_offset };
CoordsXY offsetPos{ tile.offset };
auto rotatedOffsetPos = offsetPos.Rotate(direction);
CoordsXYZ tileLoc = { sceneryOrigin->x + rotatedOffsetPos.x, sceneryOrigin->y + rotatedOffsetPos.y,
sceneryOrigin->z + tile->z_offset };
auto largeElement = MapGetLargeScenerySegment({ tileLoc, static_cast<Direction>(direction) }, sequence);
sceneryOrigin->z + tile.offset.z };
auto largeElement = MapGetLargeScenerySegment({ tileLoc, static_cast<Direction>(direction) }, tile.index);
if (largeElement != nullptr)
{
if (sequence == 0)
if (tile.index == 0)
{
auto item = TrackDesignSaveCreateLargeSceneryDesc(*obj, tileLoc, *largeElement);
_trackSavedTileElementsDesc.push_back(std::move(item));
@@ -518,18 +507,17 @@ static void TrackDesignSaveRemoveLargeScenery(const CoordsXY& loc, LargeSceneryE
}
// Iterate through each tile of the large scenery element
sequence = 0;
for (auto tile = sceneryTiles; tile->x_offset != -1; tile++, sequence++)
for (auto& tile : sceneryTiles)
{
CoordsXY offsetPos{ tile->x_offset, tile->y_offset };
CoordsXY offsetPos{ tile.offset };
auto rotatedOffsetPos = offsetPos.Rotate(direction);
CoordsXYZ tileLoc = { sceneryOrigin->x + rotatedOffsetPos.x, sceneryOrigin->y + rotatedOffsetPos.y,
sceneryOrigin->z + tile->z_offset };
auto largeElement = MapGetLargeScenerySegment({ tileLoc, static_cast<Direction>(direction) }, sequence);
sceneryOrigin->z + tile.offset.z };
auto largeElement = MapGetLargeScenerySegment({ tileLoc, static_cast<Direction>(direction) }, tile.index);
if (largeElement != nullptr)
{
if (sequence == 0)
if (tile.index == 0)
{
auto item = TrackDesignSaveCreateLargeSceneryDesc(*obj, tileLoc, *largeElement);
TrackDesignSavePopTileElementDesc(item);
@@ -925,33 +925,33 @@ namespace OpenRCT2::Scripting
{
auto ctx = GetContext()->GetScriptEngine().GetContext();
auto start = CoordsXYZ(_tile.x_offset, _tile.y_offset, _tile.z_offset);
auto start = _tile.offset;
return ToDuk(ctx, start);
}
int32_t zClearance_get() const
{
return _tile.z_clearance;
return _tile.zClearance;
}
bool hasSupports_get() const
{
return !(_tile.flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS);
return _tile.hasSupports;
}
bool allowSupportsAbove_get() const
{
return _tile.flags & LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE;
return _tile.allowSupportsAbove;
}
uint8_t corners_get() const
{
return (_tile.flags >> 12) & 0xF;
return _tile.corners;
}
uint8_t walls_get() const
{
return (_tile.flags >> 8) & 0xF;
return _tile.walls;
}
};
@@ -977,9 +977,9 @@ namespace OpenRCT2::Scripting
auto entry = GetEntry();
if (entry != nullptr)
{
for (auto* tile = entry->tiles; tile->x_offset != -1; ++tile)
for (auto& tile : entry->tiles)
{
result.push_back(std::make_shared<ScLargeSceneryObjectTile>(*tile));
result.push_back(std::make_shared<ScLargeSceneryObjectTile>(tile));
}
}
return result;
@@ -2161,18 +2161,17 @@ namespace OpenRCT2::Scripting
const auto* const largeEntry = largeScenery->GetEntry();
const auto direction = largeScenery->GetDirection();
const auto sequenceIndex = largeScenery->GetSequenceIndex();
const auto* tiles = largeEntry->tiles;
const auto& tile = tiles[sequenceIndex];
const auto& tiles = largeEntry->tiles;
const auto& initialTile = tiles[sequenceIndex];
const auto rotatedFirstTile = CoordsXYZ{
CoordsXY{ tile.x_offset, tile.y_offset }.Rotate(direction),
tile.z_offset,
CoordsXY{ initialTile.offset }.Rotate(direction),
initialTile.offset.z,
};
const auto firstTile = CoordsXYZ{ loc, largeScenery->GetBaseZ() } - rotatedFirstTile;
for (int32_t i = 0; tiles[i].x_offset != -1; i++)
for (auto& tile : tiles)
{
const auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tiles[i].x_offset, tiles[i].y_offset }.Rotate(direction),
tiles[i].z_offset };
const auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(direction), tile.offset.z };
const auto currentTile = firstTile + rotatedCurrentTile;
@@ -2192,7 +2191,7 @@ namespace OpenRCT2::Scripting
continue;
if (tileElement->AsLargeScenery()->GetEntryIndex() != largeScenery->GetEntryIndex())
continue;
if (tileElement->AsLargeScenery()->GetSequenceIndex() != i)
if (tileElement->AsLargeScenery()->GetSequenceIndex() != tile.index)
continue;
return tileElement->AsLargeScenery();
+7 -12
View File
@@ -1678,20 +1678,18 @@ SmallSceneryElement* MapGetSmallSceneryElementAt(const CoordsXYZ& sceneryCoords,
std::optional<CoordsXYZ> MapLargeSceneryGetOrigin(
const CoordsXYZD& sceneryPos, int32_t sequence, LargeSceneryElement** outElement)
{
LargeSceneryTile* tile;
auto tileElement = MapGetLargeScenerySegment(sceneryPos, sequence);
if (tileElement == nullptr)
return std::nullopt;
auto* sceneryEntry = tileElement->GetEntry();
tile = &sceneryEntry->tiles[sequence];
auto& tile = sceneryEntry->tiles[sequence];
CoordsXY offsetPos{ tile->x_offset, tile->y_offset };
CoordsXY offsetPos{ tile.offset };
auto rotatedOffsetPos = offsetPos.Rotate(sceneryPos.direction);
auto origin = CoordsXYZ{ sceneryPos.x - rotatedOffsetPos.x, sceneryPos.y - rotatedOffsetPos.y,
sceneryPos.z - tile->z_offset };
sceneryPos.z - tile.offset.z };
if (outElement != nullptr)
*outElement = tileElement;
return origin;
@@ -1704,7 +1702,6 @@ std::optional<CoordsXYZ> MapLargeSceneryGetOrigin(
bool MapLargeScenerySignSetColour(const CoordsXYZD& signPos, int32_t sequence, uint8_t mainColour, uint8_t textColour)
{
LargeSceneryElement* tileElement;
LargeSceneryTile *sceneryTiles, *tile;
auto sceneryOrigin = MapLargeSceneryGetOrigin(signPos, sequence, &tileElement);
if (!sceneryOrigin)
@@ -1713,18 +1710,16 @@ bool MapLargeScenerySignSetColour(const CoordsXYZD& signPos, int32_t sequence, u
}
auto* sceneryEntry = tileElement->GetEntry();
sceneryTiles = sceneryEntry->tiles;
// Iterate through each tile of the large scenery element
sequence = 0;
for (tile = sceneryTiles; tile->x_offset != -1; tile++, sequence++)
for (auto& tile : sceneryEntry->tiles)
{
CoordsXY offsetPos{ tile->x_offset, tile->y_offset };
CoordsXY offsetPos{ tile.offset };
auto rotatedOffsetPos = offsetPos.Rotate(signPos.direction);
auto tmpSignPos = CoordsXYZD{ sceneryOrigin->x + rotatedOffsetPos.x, sceneryOrigin->y + rotatedOffsetPos.y,
sceneryOrigin->z + tile->z_offset, signPos.direction };
tileElement = MapGetLargeScenerySegment(tmpSignPos, sequence);
sceneryOrigin->z + tile.offset.z, signPos.direction };
tileElement = MapGetLargeScenerySegment(tmpSignPos, tile.index);
if (tileElement != nullptr)
{
tileElement->SetPrimaryColour(mainColour);
+7 -8
View File
@@ -93,19 +93,18 @@ namespace OpenRCT2::TileInspector
const auto* const largeEntry = largeScenery->GetEntry();
const auto direction = largeScenery->GetDirection();
const auto sequenceIndex = largeScenery->GetSequenceIndex();
const auto* tiles = largeEntry->tiles;
const auto& tile = tiles[sequenceIndex];
const auto& tiles = largeEntry->tiles;
const auto& initialTile = tiles[sequenceIndex];
const auto rotatedFirstTile = CoordsXYZ{
CoordsXY{ tile.x_offset, tile.y_offset }.Rotate(direction),
tile.z_offset,
CoordsXY{ initialTile.offset }.Rotate(direction),
initialTile.offset.z,
};
const auto firstTile = CoordsXYZ{ loc, largeScenery->GetBaseZ() } - rotatedFirstTile;
auto numFoundElements = 0;
for (int32_t i = 0; tiles[i].x_offset != -1; i++)
for (auto& tile : tiles)
{
const auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tiles[i].x_offset, tiles[i].y_offset }.Rotate(direction),
tiles[i].z_offset };
const auto rotatedCurrentTile = CoordsXYZ{ CoordsXY{ tile.offset }.Rotate(direction), tile.offset.z };
const auto currentTile = firstTile + rotatedCurrentTile;
@@ -120,7 +119,7 @@ namespace OpenRCT2::TileInspector
if (tileElement->GetDirection() != direction)
continue;
if (tileElement->AsLargeScenery()->GetSequenceIndex() != i)
if (tileElement->AsLargeScenery()->GetSequenceIndex() != tile.index)
continue;
if (tileElement->GetBaseZ() != currentTile.z)
@@ -9,7 +9,7 @@
#include "LargeSceneryElement.h"
#include "../../object/LargeSceneryObject.h"
#include "../../object/LargeSceneryEntry.h"
#include "../../object/ObjectEntryManager.h"
#include "../../object/ObjectManager.h"
#include "../Banner.h"
@@ -91,11 +91,6 @@ const LargeSceneryEntry* LargeSceneryElement::GetEntry() const
return OpenRCT2::ObjectManager::GetObjectEntry<LargeSceneryEntry>(GetEntryIndex());
}
const LargeSceneryObject* LargeSceneryElement::GetObject() const
{
return static_cast<const LargeSceneryObject*>(ObjectEntryGetObject(ObjectType::LargeScenery, GetEntryIndex()));
}
uint8_t LargeSceneryElement::GetSequenceIndex() const
{
return SequenceIndex;