From 04e4b160b354906403987e745658742a2943e373 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 12 Apr 2021 22:42:37 +0100 Subject: [PATCH] Improve path railing code --- .../paint/tile_element/Paint.Path.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 56 +++++++++++-------- src/openrct2/rct1/Tables.cpp | 44 +++++++++------ src/openrct2/rct1/Tables.h | 1 + src/openrct2/rct12/RCT12.cpp | 7 --- src/openrct2/world/Footpath.cpp | 9 ++- src/openrct2/world/TileElement.h | 3 +- 7 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index a4cc361124..6a8e60fd9d 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -945,7 +945,7 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile } PathSurfaceEntry* footpathEntry = tile_element->AsPath()->GetSurfaceEntry(); - auto railingEntry = get_path_railings_entry(0); + auto railingEntry = tile_element->AsPath()->GetRailingEntry(); if (footpathEntry != nullptr && railingEntry != nullptr) { diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index cc1a8f3d16..ac5670d62d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -122,6 +122,7 @@ private: EntryList _pathAdditionEntries; EntryList _sceneryGroupEntries; EntryList _waterEntry; + EntryList _footpathRailingsEntries; // Lookup tables for converting from RCT1 hard coded types to the new dynamic object entries ObjectEntryIndex _rideTypeToRideEntryMap[RCT1_RIDE_TYPE_COUNT]{}; @@ -132,6 +133,7 @@ private: ObjectEntryIndex _pathTypeToEntryMap[24]{}; ObjectEntryIndex _pathAdditionTypeToEntryMap[16]{}; ObjectEntryIndex _sceneryThemeTypeToEntryMap[24]{}; + ObjectEntryIndex _footpathRailingsTypeToEntryMap[4]{}; // Research std::bitset _researchRideEntryUsed{}; @@ -369,6 +371,8 @@ private: std::fill(std::begin(_pathTypeToEntryMap), std::end(_pathTypeToEntryMap), OBJECT_ENTRY_INDEX_NULL); std::fill(std::begin(_pathAdditionTypeToEntryMap), std::end(_pathAdditionTypeToEntryMap), OBJECT_ENTRY_INDEX_NULL); std::fill(std::begin(_sceneryThemeTypeToEntryMap), std::end(_sceneryThemeTypeToEntryMap), OBJECT_ENTRY_INDEX_NULL); + std::fill( + std::begin(_footpathRailingsTypeToEntryMap), std::end(_footpathRailingsTypeToEntryMap), OBJECT_ENTRY_INDEX_NULL); } /** @@ -399,6 +403,9 @@ private: // Add default footpaths _pathEntries.AddRange({ "rct1.path.tarmac", "rct1.path.dirt", "rct1.path.crazy", "rct1.path.tile.pink" }); + + _footpathRailingsEntries.AddRange({ "rct2.railings.wood", "rct2.railings.concrete", "rct2.railings.space", + "rct2.railings.black", "rct2.railings.brown" }); } void AddAvailableEntriesFromResearchList() @@ -457,9 +464,15 @@ private: { uint8_t pathType = tileElement->AsPath()->GetRCT1PathType(); uint8_t pathAdditionsType = tileElement->AsPath()->GetAddition(); + uint8_t footpathRailingsType = RCT1_PATH_SUPPORT_TYPE_TRUSS; + if (_gameVersion == FILE_VERSION_RCT1_LL) + { + footpathRailingsType = tileElement->AsPath()->GetRCT1SupportType(); + } AddEntryForPath(pathType); AddEntryForPathAddition(pathAdditionsType); + AddEntryForFootpathRailings(footpathRailingsType); break; } case TILE_ELEMENT_TYPE_SMALL_SCENERY: @@ -685,6 +698,20 @@ private: } } + void AddEntryForFootpathRailings(ObjectEntryIndex railingsType) + { + assert(railingsType < std::size(_footpathRailingsTypeToEntryMap)); + if (_footpathRailingsTypeToEntryMap[railingsType] == OBJECT_ENTRY_INDEX_NULL) + { + auto identifier = RCT1::GetFootpathRailingsObject(railingsType); + if (!identifier.empty()) + { + auto entryIndex = _footpathRailingsEntries.GetOrAddEntry(identifier); + _footpathRailingsTypeToEntryMap[railingsType] = entryIndex; + } + } + } + void ImportRides() { for (int32_t i = 0; i < RCT12_MAX_RIDES_IN_PARK; i++) @@ -1535,6 +1562,7 @@ private: })); AppendRequiredObjects(result, ObjectType::ParkEntrance, std::vector({ "rct2.pkent1" })); AppendRequiredObjects(result, ObjectType::Water, _waterEntry); + AppendRequiredObjects(result, ObjectType::FootpathRailings, _footpathRailingsEntries); RCT12AddDefaultObjects(result); return result; } @@ -1652,30 +1680,14 @@ private: { dst2->SetIsQueue(true); } - if (_gameVersion != FILE_VERSION_RCT1_LL) + + uint8_t railingsType = RCT1_PATH_SUPPORT_TYPE_TRUSS; + if (_gameVersion == FILE_VERSION_RCT1_LL) { - dst2->SetRailingEntryIndex(0); - } - else - { - ObjectEntryIndex railingsEntryIndex; - switch (src2->GetRCT1SupportType()) - { - case RCT1_PATH_SUPPORT_TYPE_COATED_WOOD: - railingsEntryIndex = 3; - break; - case RCT1_PATH_SUPPORT_TYPE_SPACE: - railingsEntryIndex = 4; - break; - case RCT1_PATH_SUPPORT_TYPE_BAMBOO: - railingsEntryIndex = 5; - break; - case RCT1_PATH_SUPPORT_TYPE_TRUSS: - default: - railingsEntryIndex = 0; - } - dst2->SetRailingEntryIndex(railingsEntryIndex); + railingsType = src2->GetRCT1SupportType(); } + auto railingsEntryIndex = _footpathRailingsTypeToEntryMap[railingsType]; + dst2->SetRailingEntryIndex(railingsEntryIndex); // Additions ObjectEntryIndex additionType = dst2->GetAddition(); diff --git a/src/openrct2/rct1/Tables.cpp b/src/openrct2/rct1/Tables.cpp index 63957af56c..1e9522c3de 100644 --- a/src/openrct2/rct1/Tables.cpp +++ b/src/openrct2/rct1/Tables.cpp @@ -1256,35 +1256,35 @@ namespace RCT1 { static constexpr const char * map[] = { - "rct1.path.tarmac", // RCT1_FOOTPATH_TYPE_QUEUE_BLUE - "rct1.aa.path.space", // RCT1_FOOTPATH_TYPE_QUEUE_RED - "rct1.path.dirt", // RCT1_FOOTPATH_TYPE_QUEUE_YELLOW - "rct1.aa.tarmac.green", // RCT1_FOOTPATH_TYPE_QUEUE_GREEN + "rct1.path.tarmac", // RCT1_FOOTPATH_TYPE_QUEUE_BLUE + "rct1.aa.path.space", // RCT1_FOOTPATH_TYPE_QUEUE_RED + "rct1.path.dirt", // RCT1_FOOTPATH_TYPE_QUEUE_YELLOW + "rct1.aa.path.tarmac.green", // RCT1_FOOTPATH_TYPE_QUEUE_GREEN - "rct1.path.tarmac", // RCT1_FOOTPATH_TYPE_TARMAC_GRAY - "rct1.aa.path.space", // RCT1_FOOTPATH_TYPE_TARMAC_RED - "rct1.aa.tarmac.brown", // RCT1_FOOTPATH_TYPE_TARMAC_BROWN - "rct1.aa.tarmac.green", // RCT1_FOOTPATH_TYPE_TARMAC_GREEN + "rct1.path.tarmac", // RCT1_FOOTPATH_TYPE_TARMAC_GRAY + "rct1.aa.path.space", // RCT1_FOOTPATH_TYPE_TARMAC_RED + "rct1.aa.path.tarmac.brown", // RCT1_FOOTPATH_TYPE_TARMAC_BROWN + "rct1.aa.path.tarmac.green", // RCT1_FOOTPATH_TYPE_TARMAC_GREEN - "rct1.path.dirt", // RCT1_FOOTPATH_TYPE_DIRT_RED - "rct1.aa.path.ash", // RCT1_FOOTPATH_TYPE_DIRT_BLACK + "rct1.path.dirt", // RCT1_FOOTPATH_TYPE_DIRT_RED + "rct1.aa.path.ash", // RCT1_FOOTPATH_TYPE_DIRT_BLACK "", "", - "rct1.path.crazy", // RCT1_FOOTPATH_TYPE_CRAZY_PAVING + "rct1.path.crazy", // RCT1_FOOTPATH_TYPE_CRAZY_PAVING "", "", "", - "rct2.road", // RCT1_FOOTPATH_TYPE_ROADS + "rct2.road", // RCT1_FOOTPATH_TYPE_ROADS "", "", "", - "rct1.path.tile.pink", // RCT1_FOOTPATH_TYPE_TILE_PINK - "rct1.aa.path.tile.grey", // RCT1_FOOTPATH_TYPE_TILE_GRAY - "rct1.ll.path.tile.red", // RCT1_FOOTPATH_TYPE_TILE_RED - "rct1.ll.path.tile.green", // RCT1_FOOTPATH_TYPE_TILE_GREEN + "rct1.path.tile.pink", // RCT1_FOOTPATH_TYPE_TILE_PINK + "rct1.aa.path.tile.grey", // RCT1_FOOTPATH_TYPE_TILE_GRAY + "rct1.ll.path.tile.red", // RCT1_FOOTPATH_TYPE_TILE_RED + "rct1.ll.path.tile.green", // RCT1_FOOTPATH_TYPE_TILE_GREEN }; return map[pathType]; } @@ -1312,6 +1312,18 @@ namespace RCT1 return map[pathAdditionType]; } + std::string_view GetFootpathRailingsObject(uint8_t footpathRailingsType) + { + static constexpr const char * map[] = + { + "rct2.railings.wood", // RCT1_PATH_SUPPORT_TYPE_TRUSS + "rct2.railings.concrete", // RCT1_PATH_SUPPORT_TYPE_COATED_WOOD + "rct2.railings.space", // RCT1_PATH_SUPPORT_TYPE_SPACE + "rct2.railings.brown", // RCT1_PATH_SUPPORT_TYPE_BAMBOO + }; + return map[footpathRailingsType]; + } + std::string_view GetSceneryGroupObject(uint8_t sceneryGroupType) { static constexpr const char * map[] = diff --git a/src/openrct2/rct1/Tables.h b/src/openrct2/rct1/Tables.h index c1ae5359ad..ea8169b0da 100644 --- a/src/openrct2/rct1/Tables.h +++ b/src/openrct2/rct1/Tables.h @@ -40,6 +40,7 @@ namespace RCT1 std::string_view GetWallObject(uint8_t wallType); std::string_view GetPathObject(uint8_t pathType); std::string_view GetPathAddtionObject(uint8_t pathAdditionType); + std::string_view GetFootpathRailingsObject(uint8_t footpathRailingsType); std::string_view GetSceneryGroupObject(uint8_t sceneryGroupType); std::string_view GetWaterObject(uint8_t waterType); diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index e62b5ef1c4..6306746c6c 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -1440,11 +1440,4 @@ void RCT12AddDefaultObjects(ObjectList& objectList) objectList.SetObject(ObjectType::Music, static_cast(i), _musicStyles[i]); } } - - // Path railings - objectList.SetObject(ObjectType::FootpathRailings, 0, "rct2.railings.wood"); - objectList.SetObject(ObjectType::FootpathRailings, 1, "rct2.railings.concrete"); - objectList.SetObject(ObjectType::FootpathRailings, 2, "rct2.railings.space"); - objectList.SetObject(ObjectType::FootpathRailings, 3, "rct2.railings.black"); - objectList.SetObject(ObjectType::FootpathRailings, 4, "rct2.railings.brown"); } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 6348f85f3b..784108b9ef 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1656,7 +1656,7 @@ PathSurfaceIndex PathElement::GetSurfaceEntryIndex() const PathRailingsIndex PathElement::GetRailingEntryIndex() const { - return GetSurfaceEntryIndex(); + return RailingsIndex; } PathSurfaceEntry* PathElement::GetSurfaceEntry() const @@ -1667,10 +1667,9 @@ PathSurfaceEntry* PathElement::GetSurfaceEntry() const return get_path_surface_entry(GetSurfaceEntryIndex() + MAX_PATH_OBJECTS); } -PathRailingsEntry* PathElement::GetRailingEntry() const +FootpathRailingsObject* PathElement::GetRailingEntry() const { - return nullptr; - // return get_path_railings_entry(GetRailingEntryIndex()); + return get_path_railings_entry(GetRailingEntryIndex()); } void PathElement::SetSurfaceEntryIndex(PathSurfaceIndex newIndex) @@ -1680,7 +1679,7 @@ void PathElement::SetSurfaceEntryIndex(PathSurfaceIndex newIndex) void PathElement::SetRailingEntryIndex(PathRailingsIndex newEntryIndex) { - log_verbose("Setting railing entry index to %d", newEntryIndex); + RailingsIndex = newEntryIndex; } uint8_t PathElement::GetQueueBannerDirection() const diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 01d01de5bc..0ecce3ff17 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -22,6 +22,7 @@ struct rct_footpath_entry; class LargeSceneryObject; class TerrainSurfaceObject; class TerrainEdgeObject; +class FootpathRailingsObject; using track_type_t = uint16_t; constexpr const uint8_t MAX_ELEMENT_HEIGHT = 255; @@ -279,7 +280,7 @@ public: void SetSurfaceEntryIndex(PathSurfaceIndex newIndex); PathRailingsIndex GetRailingEntryIndex() const; - PathRailingsEntry* GetRailingEntry() const; + FootpathRailingsObject* GetRailingEntry() const; void SetRailingEntryIndex(PathRailingsIndex newIndex); uint8_t GetQueueBannerDirection() const;