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),