diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index 00131be3ec..6710bead7b 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -10,6 +10,7 @@ #include "Entrance.h" #include "../Cheats.h" +#include "../Context.h" #include "../Game.h" #include "../OpenRCT2.h" #include "../actions/ParkEntranceRemoveAction.h" @@ -19,6 +20,8 @@ #include "../management/Finance.h" #include "../network/network.h" #include "../object/FootpathObject.h" +#include "../object/FootpathSurfaceObject.h" +#include "../object/ObjectManager.h" #include "../ride/Station.h" #include "../ride/Track.h" #include "Footpath.h" @@ -255,21 +258,65 @@ void EntranceElement::SetSequenceIndex(uint8_t newSequenceIndex) SequenceIndex |= (newSequenceIndex & 0xF); } +bool EntranceElement::HasLegacyPathEntry() const +{ + return (flags2 & ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) != 0; +} + ObjectEntryIndex EntranceElement::GetLegacyPathEntryIndex() const { - return PathType; + if (HasLegacyPathEntry()) + return PathType; + else + return OBJECT_ENTRY_INDEX_NULL; +} + +const FootpathObject* EntranceElement::GetLegacyPathEntry() const +{ + auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objMgr.GetLoadedObject(ObjectType::Paths, GetLegacyPathEntryIndex())); } void EntranceElement::SetLegacyPathEntryIndex(ObjectEntryIndex newPathType) { PathType = newPathType; + flags2 |= ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY; +} + +ObjectEntryIndex EntranceElement::GetSurfaceEntryIndex() const +{ + if (HasLegacyPathEntry()) + return OBJECT_ENTRY_INDEX_NULL; + else + return PathType; +} + +const FootpathSurfaceObject* EntranceElement::GetSurfaceEntry() const +{ + auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathSurface, GetSurfaceEntryIndex())); +} + +void EntranceElement::SetSurfaceEntryIndex(ObjectEntryIndex newIndex) +{ + PathType = newIndex; + flags2 &= ~ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY; } const PathSurfaceDescriptor* EntranceElement::GetPathSurfaceDescriptor() const { - const auto* legacyPathEntry = GetLegacyFootpathEntry(PathType); - if (legacyPathEntry == nullptr) + if (HasLegacyPathEntry()) + { + const auto* legacyPathEntry = GetLegacyPathEntry(); + if (legacyPathEntry == nullptr) + return nullptr; + + return &legacyPathEntry->GetPathSurfaceDescriptor(); + } + + const auto* surfaceEntry = GetSurfaceEntry(); + if (surfaceEntry == nullptr) return nullptr; - return &legacyPathEntry->GetPathSurfaceDescriptor(); + return &surfaceEntry->GetDescriptor(); } diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index 8d3b20eade..cd89adbe4b 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -28,6 +28,11 @@ assert_struct_size(rct_entrance_type, 8); struct TileElement; +enum +{ + ENTRANCE_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY = (1 << 0), +}; + constexpr const uint8_t ParkEntranceHeight = 12 * COORDS_Z_STEP; constexpr const uint8_t RideEntranceHeight = 7 * COORDS_Z_STEP; constexpr const uint8_t RideExitHeight = 5 * COORDS_Z_STEP; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index fe59e4e6d1..a1452df224 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -20,6 +20,8 @@ #include "../management/Finance.h" #include "../network/network.h" #include "../object/FootpathObject.h" +#include "../object/FootpathRailingsObject.h" +#include "../object/FootpathSurfaceObject.h" #include "../object/ObjectList.h" #include "../object/ObjectManager.h" #include "../paint/VirtualFloor.h" @@ -1644,7 +1646,10 @@ void PathElement::SetAdditionIsGhost(bool isGhost) ObjectEntryIndex PathElement::GetLegacyPathEntryIndex() const { - return SurfaceIndex; + if (Flags2 & FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) + return SurfaceIndex; + else + return OBJECT_ENTRY_INDEX_NULL; } const FootpathObject* PathElement::GetLegacyPathEntry() const @@ -1652,30 +1657,95 @@ const FootpathObject* PathElement::GetLegacyPathEntry() const return GetLegacyFootpathEntry(GetLegacyPathEntryIndex()); } +void PathElement::SetLegacyPathEntryIndex(ObjectEntryIndex newIndex) +{ + SurfaceIndex = newIndex & ~FOOTPATH_ELEMENT_INSERT_QUEUE; + RailingsIndex = OBJECT_ENTRY_INDEX_NULL; + Flags2 |= FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY; +} + +bool PathElement::HasLegacyPathEntry() const +{ + return (Flags2 & FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) != 0; +} + const PathSurfaceDescriptor* PathElement::GetSurfaceDescriptor() const { - const auto* legacyPathEntry = GetLegacyPathEntry(); - if (legacyPathEntry == nullptr) + if (HasLegacyPathEntry()) + { + const auto* legacyPathEntry = GetLegacyPathEntry(); + if (legacyPathEntry == nullptr) + return nullptr; + + if (IsQueue()) + return &legacyPathEntry->GetQueueSurfaceDescriptor(); + + return &legacyPathEntry->GetPathSurfaceDescriptor(); + } + + const auto* surfaceEntry = GetSurfaceEntry(); + if (surfaceEntry == nullptr) return nullptr; - if (IsQueue()) - return &legacyPathEntry->GetQueueSurfaceDescriptor(); - - return &legacyPathEntry->GetPathSurfaceDescriptor(); + return &surfaceEntry->GetDescriptor(); } const PathRailingsDescriptor* PathElement::GetRailingsDescriptor() const { - const auto* legacyPathEntry = GetLegacyPathEntry(); - if (legacyPathEntry == nullptr) + if (HasLegacyPathEntry()) + { + const auto* legacyPathEntry = GetLegacyPathEntry(); + if (legacyPathEntry == nullptr) + return nullptr; + + return &legacyPathEntry->GetPathRailingsDescriptor(); + } + + const auto* railingsEntry = GetRailingsEntry(); + if (railingsEntry == nullptr) return nullptr; - return &legacyPathEntry->GetPathRailingsDescriptor(); + return &railingsEntry->GetDescriptor(); } -void PathElement::SetLegacyPathEntryIndex(ObjectEntryIndex newIndex) +ObjectEntryIndex PathElement::GetSurfaceEntryIndex() const { - SurfaceIndex = newIndex & ~FOOTPATH_ELEMENT_INSERT_QUEUE; + if (Flags2 & FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) + return OBJECT_ENTRY_INDEX_NULL; + else + return SurfaceIndex; +} + +const FootpathSurfaceObject* PathElement::GetSurfaceEntry() const +{ + auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathSurface, GetSurfaceEntryIndex())); +} + +void PathElement::SetSurfaceEntryIndex(ObjectEntryIndex newIndex) +{ + SurfaceIndex = newIndex; + Flags2 &= ~FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY; +} + +ObjectEntryIndex PathElement::GetRailingsEntryIndex() const +{ + if (Flags2 & FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY) + return OBJECT_ENTRY_INDEX_NULL; + else + return RailingsIndex; +} + +const FootpathRailingsObject* PathElement::GetRailingsEntry() const +{ + auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); + return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathRailings, GetRailingsEntryIndex())); +} + +void PathElement::SetRailingsEntryIndex(ObjectEntryIndex newEntryIndex) +{ + RailingsIndex = newEntryIndex; + Flags2 &= ~FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY; } uint8_t PathElement::GetQueueBannerDirection() const diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 1dc6e10f2a..8072c7ab10 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -142,6 +142,7 @@ enum FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_GHOST = (1 << 2), FOOTPATH_ELEMENT_FLAGS2_BLOCKED_BY_VEHICLE = (1 << 3), FOOTPATH_ELEMENT_FLAGS2_ADDITION_IS_BROKEN = (1 << 4), + FOOTPATH_ELEMENT_FLAGS2_LEGACY_PATH_ENTRY = (1 << 5), }; enum diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index b683684571..68f289c8ce 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -26,6 +26,9 @@ struct rct_footpath_entry; class LargeSceneryObject; class TerrainSurfaceObject; class TerrainEdgeObject; +class FootpathObject; +class FootpathSurfaceObject; +class FootpathRailingsObject; using track_type_t = uint16_t; constexpr const uint8_t MAX_ELEMENT_HEIGHT = 255; @@ -260,30 +263,32 @@ struct PathElement : TileElementBase static constexpr TileElementType ElementType = TileElementType::Path; private: - ObjectEntryIndex SurfaceIndex; // 5 -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t RailingsIndex; // 7 -#pragma clang diagnostic pop - uint8_t Additions; // 8 (0 means no addition) - uint8_t EdgesAndCorners; // 9 (edges in lower 4 bits, corners in upper 4) - uint8_t Flags2; // 10 - uint8_t SlopeDirection; // 11 + ObjectEntryIndex SurfaceIndex; // 5 + ObjectEntryIndex RailingsIndex; // 7 + uint8_t Additions; // 9 (0 means no addition) + uint8_t EdgesAndCorners; // 10 (edges in lower 4 bits, corners in upper 4) + uint8_t Flags2; // 11 + uint8_t SlopeDirection; // 12 union { - uint8_t AdditionStatus; // 12, only used for litter bins - ride_id_t rideIndex; // 12 + uint8_t AdditionStatus; // 13, only used for litter bins + ride_id_t rideIndex; // 13 }; - ::StationIndex StationIndex; // 14 -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad_0F[1]; -#pragma clang diagnostic pop + ::StationIndex StationIndex; // 15 public: ObjectEntryIndex GetLegacyPathEntryIndex() const; const FootpathObject* GetLegacyPathEntry() const; void SetLegacyPathEntryIndex(ObjectEntryIndex newIndex); + bool HasLegacyPathEntry() const; + + ObjectEntryIndex GetSurfaceEntryIndex() const; + const FootpathSurfaceObject* GetSurfaceEntry() const; + void SetSurfaceEntryIndex(ObjectEntryIndex newIndex); + + ObjectEntryIndex GetRailingsEntryIndex() const; + const FootpathRailingsObject* GetRailingsEntry() const; + void SetRailingsEntryIndex(ObjectEntryIndex newIndex); const PathSurfaceDescriptor* GetSurfaceDescriptor() const; const PathRailingsDescriptor* GetRailingsDescriptor() const; @@ -569,10 +574,11 @@ private: uint8_t SequenceIndex; // 6. Only uses the lower nibble. uint8_t StationIndex; // 7 ObjectEntryIndex PathType; // 8 - ride_id_t rideIndex; // 9 + ride_id_t rideIndex; // A + uint8_t flags2; // C #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-private-field" - uint8_t pad_0C[4]; + uint8_t pad_0D[3]; #pragma clang diagnostic pop public: @@ -588,9 +594,16 @@ public: uint8_t GetSequenceIndex() const; void SetSequenceIndex(uint8_t newSequenceIndex); + bool HasLegacyPathEntry() const; + ObjectEntryIndex GetLegacyPathEntryIndex() const; + const FootpathObject* GetLegacyPathEntry() const; void SetLegacyPathEntryIndex(ObjectEntryIndex newPathType); + ObjectEntryIndex GetSurfaceEntryIndex() const; + const FootpathSurfaceObject* GetSurfaceEntry() const; + void SetSurfaceEntryIndex(ObjectEntryIndex newIndex); + const PathSurfaceDescriptor* GetPathSurfaceDescriptor() const; int32_t GetDirections() const;