From fc33dd3dff66f0b6a669c3368d6a1cd2df414715 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 3 Oct 2024 21:54:10 +0200 Subject: [PATCH 1/4] Move all TileElementBase::As...() functions to .cpp --- src/openrct2/world/TileElement.cpp | 58 +++++++++++++++++++++++++ src/openrct2/world/TileElement.h | 70 ++++++------------------------ 2 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index e2cba7d7f3..c42080c9ab 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -161,6 +161,55 @@ const QuarterTile QuarterTile::Rotate(uint8_t amount) const } } +const SurfaceElement* TileElementBase::AsSurface() const +{ + return as(); +} +SurfaceElement* TileElementBase::AsSurface() +{ + return as(); +} +const PathElement* TileElementBase::AsPath() const +{ + return as(); +} +PathElement* TileElementBase::AsPath() +{ + return as(); +} +const TrackElement* TileElementBase::AsTrack() const +{ + return as(); +} +TrackElement* TileElementBase::AsTrack() +{ + return as(); +} +const SmallSceneryElement* TileElementBase::AsSmallScenery() const +{ + return as(); +} +SmallSceneryElement* TileElementBase::AsSmallScenery() +{ + return as(); +} +const LargeSceneryElement* TileElementBase::AsLargeScenery() const +{ + return as(); +} +LargeSceneryElement* TileElementBase::AsLargeScenery() +{ + return as(); +} +const WallElement* TileElementBase::AsWall() const +{ + return as(); +} +WallElement* TileElementBase::AsWall() +{ + return as(); +} + const EntranceElement* TileElementBase::AsEntrance() const { return as(); @@ -170,3 +219,12 @@ EntranceElement* TileElementBase::AsEntrance() { return as(); } + +const BannerElement* TileElementBase::AsBanner() const +{ + return as(); +} +BannerElement* TileElementBase::AsBanner() +{ + return as(); +} diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index acce7757b0..dd037d49ab 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -101,64 +101,22 @@ struct TileElementBase return GetType() == TType::ElementType ? reinterpret_cast(this) : nullptr; } - const SurfaceElement* AsSurface() const - { - return as(); - } - SurfaceElement* AsSurface() - { - return as(); - } - const PathElement* AsPath() const - { - return as(); - } - PathElement* AsPath() - { - return as(); - } - const TrackElement* AsTrack() const - { - return as(); - } - TrackElement* AsTrack() - { - return as(); - } - const SmallSceneryElement* AsSmallScenery() const - { - return as(); - } - SmallSceneryElement* AsSmallScenery() - { - return as(); - } - const LargeSceneryElement* AsLargeScenery() const - { - return as(); - } - LargeSceneryElement* AsLargeScenery() - { - return as(); - } - const WallElement* AsWall() const - { - return as(); - } - WallElement* AsWall() - { - return as(); - } + const SurfaceElement* AsSurface() const; + SurfaceElement* AsSurface(); + const PathElement* AsPath() const; + PathElement* AsPath(); + const TrackElement* AsTrack() const; + TrackElement* AsTrack(); + const SmallSceneryElement* AsSmallScenery() const; + SmallSceneryElement* AsSmallScenery(); + const LargeSceneryElement* AsLargeScenery() const; + LargeSceneryElement* AsLargeScenery(); + const WallElement* AsWall() const; + WallElement* AsWall(); const EntranceElement* AsEntrance() const; EntranceElement* AsEntrance(); - const BannerElement* AsBanner() const - { - return as(); - } - BannerElement* AsBanner() - { - return as(); - } + const BannerElement* AsBanner() const; + BannerElement* AsBanner(); }; /** From efe0c11784ce6cea3dfc81395d75e11da5bca229 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 3 Oct 2024 22:09:15 +0200 Subject: [PATCH 2/4] Move all TileElementBase functions to TileElementBase.cpp --- src/openrct2/libopenrct2.vcxproj | 2 +- src/openrct2/world/TileElement.cpp | 68 ----------------- .../{ => tile_element}/TileElementBase.cpp | 73 ++++++++++++++++++- 3 files changed, 72 insertions(+), 71 deletions(-) rename src/openrct2/world/{ => tile_element}/TileElementBase.cpp (66%) diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index f1878287a4..65e4f442e2 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -1085,6 +1085,7 @@ + @@ -1101,7 +1102,6 @@ - diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index c42080c9ab..c8bae8ceaa 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -160,71 +160,3 @@ const QuarterTile QuarterTile::Rotate(uint8_t amount) const return QuarterTile{ 0 }; } } - -const SurfaceElement* TileElementBase::AsSurface() const -{ - return as(); -} -SurfaceElement* TileElementBase::AsSurface() -{ - return as(); -} -const PathElement* TileElementBase::AsPath() const -{ - return as(); -} -PathElement* TileElementBase::AsPath() -{ - return as(); -} -const TrackElement* TileElementBase::AsTrack() const -{ - return as(); -} -TrackElement* TileElementBase::AsTrack() -{ - return as(); -} -const SmallSceneryElement* TileElementBase::AsSmallScenery() const -{ - return as(); -} -SmallSceneryElement* TileElementBase::AsSmallScenery() -{ - return as(); -} -const LargeSceneryElement* TileElementBase::AsLargeScenery() const -{ - return as(); -} -LargeSceneryElement* TileElementBase::AsLargeScenery() -{ - return as(); -} -const WallElement* TileElementBase::AsWall() const -{ - return as(); -} -WallElement* TileElementBase::AsWall() -{ - return as(); -} - -const EntranceElement* TileElementBase::AsEntrance() const -{ - return as(); -} - -EntranceElement* TileElementBase::AsEntrance() -{ - return as(); -} - -const BannerElement* TileElementBase::AsBanner() const -{ - return as(); -} -BannerElement* TileElementBase::AsBanner() -{ - return as(); -} diff --git a/src/openrct2/world/TileElementBase.cpp b/src/openrct2/world/tile_element/TileElementBase.cpp similarity index 66% rename from src/openrct2/world/TileElementBase.cpp rename to src/openrct2/world/tile_element/TileElementBase.cpp index 5a3ce735bb..3541e6c02e 100644 --- a/src/openrct2/world/TileElementBase.cpp +++ b/src/openrct2/world/tile_element/TileElementBase.cpp @@ -7,8 +7,9 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "Map.h" -#include "TileElement.h" +#include "../Map.h" +#include "../TileElement.h" +#include "EntranceElement.h" TileElementType TileElementBase::GetType() const { @@ -126,3 +127,71 @@ void TileElementBase::SetOwner(uint8_t newOwner) Owner &= ~OWNER_MASK; Owner |= (newOwner & OWNER_MASK); } + +const SurfaceElement* TileElementBase::AsSurface() const +{ + return as(); +} +SurfaceElement* TileElementBase::AsSurface() +{ + return as(); +} +const PathElement* TileElementBase::AsPath() const +{ + return as(); +} +PathElement* TileElementBase::AsPath() +{ + return as(); +} +const TrackElement* TileElementBase::AsTrack() const +{ + return as(); +} +TrackElement* TileElementBase::AsTrack() +{ + return as(); +} +const SmallSceneryElement* TileElementBase::AsSmallScenery() const +{ + return as(); +} +SmallSceneryElement* TileElementBase::AsSmallScenery() +{ + return as(); +} +const LargeSceneryElement* TileElementBase::AsLargeScenery() const +{ + return as(); +} +LargeSceneryElement* TileElementBase::AsLargeScenery() +{ + return as(); +} +const WallElement* TileElementBase::AsWall() const +{ + return as(); +} +WallElement* TileElementBase::AsWall() +{ + return as(); +} + +const EntranceElement* TileElementBase::AsEntrance() const +{ + return as(); +} + +EntranceElement* TileElementBase::AsEntrance() +{ + return as(); +} + +const BannerElement* TileElementBase::AsBanner() const +{ + return as(); +} +BannerElement* TileElementBase::AsBanner() +{ + return as(); +} From 20173f22a1fcbb46caa180b3aaaebaf29167e94b Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 3 Oct 2024 22:24:18 +0200 Subject: [PATCH 3/4] Split off QuarterTile --- .../actions/FootpathLayoutPlaceAction.cpp | 1 + src/openrct2/actions/FootpathPlaceAction.cpp | 1 + .../actions/LargeSceneryPlaceAction.cpp | 1 + .../actions/SmallSceneryPlaceAction.cpp | 1 + src/openrct2/actions/TrackPlaceAction.cpp | 1 + src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/ride/Track.h | 1 + src/openrct2/world/ConstructionClearance.cpp | 1 + src/openrct2/world/QuarterTile.cpp | 65 +++++++++++++++++++ src/openrct2/world/QuarterTile.h | 42 ++++++++++++ src/openrct2/world/TileElement.cpp | 43 ------------ src/openrct2/world/TileElement.h | 38 ----------- 12 files changed, 116 insertions(+), 81 deletions(-) create mode 100644 src/openrct2/world/QuarterTile.cpp create mode 100644 src/openrct2/world/QuarterTile.h diff --git a/src/openrct2/actions/FootpathLayoutPlaceAction.cpp b/src/openrct2/actions/FootpathLayoutPlaceAction.cpp index 01f4173a28..982c5cc262 100644 --- a/src/openrct2/actions/FootpathLayoutPlaceAction.cpp +++ b/src/openrct2/actions/FootpathLayoutPlaceAction.cpp @@ -21,6 +21,7 @@ #include "../world/Footpath.h" #include "../world/Location.hpp" #include "../world/Park.h" +#include "../world/QuarterTile.h" #include "../world/Surface.h" #include "../world/Wall.h" #include "../world/tile_element/EntranceElement.h" diff --git a/src/openrct2/actions/FootpathPlaceAction.cpp b/src/openrct2/actions/FootpathPlaceAction.cpp index 4529e7a491..14a19f47cf 100644 --- a/src/openrct2/actions/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/FootpathPlaceAction.cpp @@ -25,6 +25,7 @@ #include "../world/Footpath.h" #include "../world/Location.hpp" #include "../world/Park.h" +#include "../world/QuarterTile.h" #include "../world/Scenery.h" #include "../world/Surface.h" #include "../world/TileElementsView.h" diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.cpp b/src/openrct2/actions/LargeSceneryPlaceAction.cpp index e4958df2ea..86967f1b03 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.cpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.cpp @@ -21,6 +21,7 @@ #include "../world/Banner.h" #include "../world/ConstructionClearance.h" #include "../world/MapAnimation.h" +#include "../world/QuarterTile.h" #include "../world/Surface.h" #include "../world/tile_element/Slope.h" diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.cpp b/src/openrct2/actions/SmallSceneryPlaceAction.cpp index eef9547df4..876f04bb09 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.cpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.cpp @@ -24,6 +24,7 @@ #include "../world/ConstructionClearance.h" #include "../world/MapAnimation.h" #include "../world/Park.h" +#include "../world/QuarterTile.h" #include "../world/Scenery.h" #include "../world/Surface.h" #include "../world/TileElement.h" diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 0e2cd1e04b..277670afe4 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -20,6 +20,7 @@ #include "../util/Math.hpp" #include "../world/ConstructionClearance.h" #include "../world/MapAnimation.h" +#include "../world/QuarterTile.h" #include "../world/Surface.h" #include "../world/tile_element/Slope.h" #include "RideSetSettingAction.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 65e4f442e2..1765cdb9ed 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -614,6 +614,7 @@ + @@ -1097,6 +1098,7 @@ + diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index 068741ac28..6a891e51dd 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -11,6 +11,7 @@ #include "../object/Object.h" #include "../world/Map.h" +#include "../world/QuarterTile.h" #include "../world/TileElement.h" #include diff --git a/src/openrct2/world/ConstructionClearance.cpp b/src/openrct2/world/ConstructionClearance.cpp index 39f1ab7113..7335bda579 100644 --- a/src/openrct2/world/ConstructionClearance.cpp +++ b/src/openrct2/world/ConstructionClearance.cpp @@ -19,6 +19,7 @@ #include "../ride/Ride.h" #include "../ride/RideData.h" #include "Park.h" +#include "QuarterTile.h" #include "Scenery.h" #include "Surface.h" #include "tile_element/EntranceElement.h" diff --git a/src/openrct2/world/QuarterTile.cpp b/src/openrct2/world/QuarterTile.cpp new file mode 100644 index 0000000000..ff30d51b68 --- /dev/null +++ b/src/openrct2/world/QuarterTile.cpp @@ -0,0 +1,65 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "QuarterTile.h" + +#include "../Diagnostic.h" + +// Rotate both of the values amount +const QuarterTile QuarterTile::Rotate(uint8_t amount) const +{ + switch (amount) + { + case 0: + return QuarterTile{ *this }; + case 1: + { + auto rotVal1 = _val << 1; + auto rotVal2 = rotVal1 >> 4; + // Clear the bit from the tileQuarter + rotVal1 &= 0b11101110; + // Clear the bit from the zQuarter + rotVal2 &= 0b00010001; + return QuarterTile{ static_cast(rotVal1 | rotVal2) }; + } + case 2: + { + auto rotVal1 = _val << 2; + auto rotVal2 = rotVal1 >> 4; + // Clear the bit from the tileQuarter + rotVal1 &= 0b11001100; + // Clear the bit from the zQuarter + rotVal2 &= 0b00110011; + return QuarterTile{ static_cast(rotVal1 | rotVal2) }; + } + case 3: + { + auto rotVal1 = _val << 3; + auto rotVal2 = rotVal1 >> 4; + // Clear the bit from the tileQuarter + rotVal1 &= 0b10001000; + // Clear the bit from the zQuarter + rotVal2 &= 0b01110111; + return QuarterTile{ static_cast(rotVal1 | rotVal2) }; + } + default: + LOG_ERROR("Tried to rotate QuarterTile invalid amount."); + return QuarterTile{ 0 }; + } +} + +uint8_t QuarterTile::GetBaseQuarterOccupied() const +{ + return _val & 0xF; +} + +uint8_t QuarterTile::GetZQuarterOccupied() const +{ + return (_val >> 4) & 0xF; +} diff --git a/src/openrct2/world/QuarterTile.h b/src/openrct2/world/QuarterTile.h new file mode 100644 index 0000000000..0b70ad0caa --- /dev/null +++ b/src/openrct2/world/QuarterTile.h @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include + +class QuarterTile +{ +private: + uint8_t _val{ 0 }; + +public: + constexpr QuarterTile(uint8_t tileQuarter, uint8_t zQuarter) + : _val(tileQuarter | (zQuarter << 4)) + { + } + + QuarterTile(uint8_t tileAndZQuarter) + : _val(tileAndZQuarter) + { + } + + // Rotate both of the values amount. Returns new RValue QuarterTile + const QuarterTile Rotate(uint8_t amount) const; + uint8_t GetBaseQuarterOccupied() const; + uint8_t GetZQuarterOccupied() const; +}; + +enum +{ + TILE_ELEMENT_QUADRANT_SW, + TILE_ELEMENT_QUADRANT_NW, + TILE_ELEMENT_QUADRANT_NE, + TILE_ELEMENT_QUADRANT_SE +}; diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index c8bae8ceaa..bc298b743b 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -117,46 +117,3 @@ void TileElement::ClearAs(TileElementType newType) std::fill_n(Pad05, sizeof(Pad05), 0x00); std::fill_n(Pad08, sizeof(Pad08), 0x00); } - -// Rotate both of the values amount -const QuarterTile QuarterTile::Rotate(uint8_t amount) const -{ - switch (amount) - { - case 0: - return QuarterTile{ *this }; - case 1: - { - auto rotVal1 = _val << 1; - auto rotVal2 = rotVal1 >> 4; - // Clear the bit from the tileQuarter - rotVal1 &= 0b11101110; - // Clear the bit from the zQuarter - rotVal2 &= 0b00010001; - return QuarterTile{ static_cast(rotVal1 | rotVal2) }; - } - case 2: - { - auto rotVal1 = _val << 2; - auto rotVal2 = rotVal1 >> 4; - // Clear the bit from the tileQuarter - rotVal1 &= 0b11001100; - // Clear the bit from the zQuarter - rotVal2 &= 0b00110011; - return QuarterTile{ static_cast(rotVal1 | rotVal2) }; - } - case 3: - { - auto rotVal1 = _val << 3; - auto rotVal2 = rotVal1 >> 4; - // Clear the bit from the tileQuarter - rotVal1 &= 0b10001000; - // Clear the bit from the zQuarter - rotVal2 &= 0b01110111; - return QuarterTile{ static_cast(rotVal1 | rotVal2) }; - } - default: - LOG_ERROR("Tried to rotate QuarterTile invalid amount."); - return QuarterTile{ 0 }; - } -} diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index dd037d49ab..da3545cb0c 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -531,44 +531,6 @@ static_assert(sizeof(BannerElement) == 16); #pragma pack(pop) -class QuarterTile -{ -private: - uint8_t _val{ 0 }; - -public: - constexpr QuarterTile(uint8_t tileQuarter, uint8_t zQuarter) - : _val(tileQuarter | (zQuarter << 4)) - { - } - - QuarterTile(uint8_t tileAndZQuarter) - : _val(tileAndZQuarter) - { - } - - // Rotate both of the values amount. Returns new RValue QuarterTile - const QuarterTile Rotate(uint8_t amount) const; - - uint8_t GetBaseQuarterOccupied() const - { - return _val & 0xF; - } - - uint8_t GetZQuarterOccupied() const - { - return (_val >> 4) & 0xF; - } -}; - -enum -{ - TILE_ELEMENT_QUADRANT_SW, - TILE_ELEMENT_QUADRANT_NW, - TILE_ELEMENT_QUADRANT_NE, - TILE_ELEMENT_QUADRANT_SE -}; - enum { SURFACE_ELEMENT_HAS_TRACK_THAT_NEEDS_WATER = (1 << 6), From 892f05f046e73366069baa77649054f8e8aed5f3 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 5 Oct 2024 11:03:44 +0200 Subject: [PATCH 4/4] Make both QuarterTile constructors constexpr --- src/openrct2/world/QuarterTile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/world/QuarterTile.h b/src/openrct2/world/QuarterTile.h index 0b70ad0caa..11cf0e8fae 100644 --- a/src/openrct2/world/QuarterTile.h +++ b/src/openrct2/world/QuarterTile.h @@ -22,7 +22,7 @@ public: { } - QuarterTile(uint8_t tileAndZQuarter) + constexpr QuarterTile(uint8_t tileAndZQuarter) : _val(tileAndZQuarter) { }