1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 08:14:38 +01:00

Remove fixed sizes from legacy structs

This commit is contained in:
Duncan
2023-01-11 22:34:12 +00:00
committed by GitHub
parent f68b705f9f
commit d8cb15bd50
2 changed files with 41 additions and 7 deletions

View File

@@ -24,6 +24,34 @@
#include <algorithm>
#include <iterator>
static rct_large_scenery_text ReadLegacy3DFont(OpenRCT2::IStream& stream)
{
rct_large_scenery_text _3dFontLegacy = {};
_3dFontLegacy.offset[0].x = stream.ReadValue<int16_t>();
_3dFontLegacy.offset[0].y = stream.ReadValue<int16_t>();
_3dFontLegacy.offset[1].x = stream.ReadValue<int16_t>();
_3dFontLegacy.offset[1].y = stream.ReadValue<int16_t>();
_3dFontLegacy.max_width = stream.ReadValue<uint16_t>();
stream.ReadValue<uint16_t>();
_3dFontLegacy.flags = stream.ReadValue<uint8_t>();
_3dFontLegacy.num_images = stream.ReadValue<uint8_t>();
auto ReadLegacyTextGlyph = [&stream]() {
rct_large_scenery_text_glyph glyph{};
glyph.image_offset = stream.ReadValue<uint8_t>();
glyph.width = stream.ReadValue<uint8_t>();
glyph.height = stream.ReadValue<uint8_t>();
stream.ReadValue<uint8_t>();
return glyph;
};
for (size_t i = 0; i < std::size(_3dFontLegacy.glyphs); ++i)
{
_3dFontLegacy.glyphs[i] = ReadLegacyTextGlyph();
}
return _3dFontLegacy;
}
void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
{
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
@@ -43,8 +71,7 @@ void LargeSceneryObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStre
if (_legacyType.flags & LARGE_SCENERY_FLAG_3D_TEXT)
{
rct_large_scenery_text _3dFontLegacy = {};
stream->Read(&_3dFontLegacy);
rct_large_scenery_text _3dFontLegacy = ReadLegacy3DFont(*stream);
_3dFont = std::make_unique<LargeSceneryText>(_3dFontLegacy);
_legacyType.text = _3dFont.get();
}
@@ -129,11 +156,21 @@ void LargeSceneryObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int3
std::vector<rct_large_scenery_tile> LargeSceneryObject::ReadTiles(OpenRCT2::IStream* stream)
{
auto tiles = std::vector<rct_large_scenery_tile>();
auto ReadLegacyTile = [&stream]() {
rct_large_scenery_tile 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>();
return tile;
};
while (stream->ReadValue<uint16_t>() != 0xFFFF)
{
stream->Seek(-2, OpenRCT2::STREAM_SEEK_CURRENT);
auto tile = stream->ReadValue<rct_large_scenery_tile>();
tiles.push_back(std::move(tile));
tiles.push_back(ReadLegacyTile());
}
tiles.push_back({ -1, -1, -1, 255, 0xFFFF });
return tiles;