mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #22898 from Gymnasiast/refactor/more-tile-element
Split off TileElementBase and QuarterTile
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -614,6 +614,7 @@
|
||||
<ClInclude Include="world\MapGen.h" />
|
||||
<ClInclude Include="world\MapHelpers.h" />
|
||||
<ClInclude Include="world\Park.h" />
|
||||
<ClInclude Include="world\QuarterTile.h" />
|
||||
<ClInclude Include="world\Scenery.h" />
|
||||
<ClInclude Include="world\ScenerySelection.h" />
|
||||
<ClInclude Include="world\SmallScenery.h" />
|
||||
@@ -1085,6 +1086,7 @@
|
||||
<ClCompile Include="Version.cpp" />
|
||||
<ClCompile Include="windows\Intent.cpp" />
|
||||
<ClCompile Include="world\tile_element\EntranceElement.cpp" />
|
||||
<ClCompile Include="world\tile_element\TileElementBase.cpp" />
|
||||
<ClCompile Include="world\Banner.cpp" />
|
||||
<ClCompile Include="world\Climate.cpp" />
|
||||
<ClCompile Include="world\ConstructionClearance.cpp" />
|
||||
@@ -1096,12 +1098,12 @@
|
||||
<ClCompile Include="world\MapGen.cpp" />
|
||||
<ClCompile Include="world\MapHelpers.cpp" />
|
||||
<ClCompile Include="world\Park.cpp" />
|
||||
<ClCompile Include="world\QuarterTile.cpp" />
|
||||
<ClCompile Include="world\Scenery.cpp" />
|
||||
<ClCompile Include="world\SmallScenery.cpp" />
|
||||
<ClCompile Include="world\Surface.cpp" />
|
||||
<ClCompile Include="world\SurfaceData.cpp" />
|
||||
<ClCompile Include="world\TileElement.cpp" />
|
||||
<ClCompile Include="world/TileElementBase.cpp" />
|
||||
<ClCompile Include="world\TileInspector.cpp" />
|
||||
<ClCompile Include="world\Wall.cpp" />
|
||||
<ClCompile Include="..\thirdparty\duktape\duktape.cpp">
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../object/Object.h"
|
||||
#include "../world/Map.h"
|
||||
#include "../world/QuarterTile.h"
|
||||
#include "../world/TileElement.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
@@ -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"
|
||||
|
||||
65
src/openrct2/world/QuarterTile.cpp
Normal file
65
src/openrct2/world/QuarterTile.cpp
Normal file
@@ -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<uint8_t>(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<uint8_t>(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<uint8_t>(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;
|
||||
}
|
||||
42
src/openrct2/world/QuarterTile.h
Normal file
42
src/openrct2/world/QuarterTile.h
Normal file
@@ -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 <cstdint>
|
||||
|
||||
class QuarterTile
|
||||
{
|
||||
private:
|
||||
uint8_t _val{ 0 };
|
||||
|
||||
public:
|
||||
constexpr QuarterTile(uint8_t tileQuarter, uint8_t zQuarter)
|
||||
: _val(tileQuarter | (zQuarter << 4))
|
||||
{
|
||||
}
|
||||
|
||||
constexpr 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
|
||||
};
|
||||
@@ -117,56 +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<uint8_t>(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<uint8_t>(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<uint8_t>(rotVal1 | rotVal2) };
|
||||
}
|
||||
default:
|
||||
LOG_ERROR("Tried to rotate QuarterTile invalid amount.");
|
||||
return QuarterTile{ 0 };
|
||||
}
|
||||
}
|
||||
|
||||
const EntranceElement* TileElementBase::AsEntrance() const
|
||||
{
|
||||
return as<EntranceElement>();
|
||||
}
|
||||
|
||||
EntranceElement* TileElementBase::AsEntrance()
|
||||
{
|
||||
return as<EntranceElement>();
|
||||
}
|
||||
|
||||
@@ -101,64 +101,22 @@ struct TileElementBase
|
||||
return GetType() == TType::ElementType ? reinterpret_cast<TType*>(this) : nullptr;
|
||||
}
|
||||
|
||||
const SurfaceElement* AsSurface() const
|
||||
{
|
||||
return as<SurfaceElement>();
|
||||
}
|
||||
SurfaceElement* AsSurface()
|
||||
{
|
||||
return as<SurfaceElement>();
|
||||
}
|
||||
const PathElement* AsPath() const
|
||||
{
|
||||
return as<PathElement>();
|
||||
}
|
||||
PathElement* AsPath()
|
||||
{
|
||||
return as<PathElement>();
|
||||
}
|
||||
const TrackElement* AsTrack() const
|
||||
{
|
||||
return as<TrackElement>();
|
||||
}
|
||||
TrackElement* AsTrack()
|
||||
{
|
||||
return as<TrackElement>();
|
||||
}
|
||||
const SmallSceneryElement* AsSmallScenery() const
|
||||
{
|
||||
return as<SmallSceneryElement>();
|
||||
}
|
||||
SmallSceneryElement* AsSmallScenery()
|
||||
{
|
||||
return as<SmallSceneryElement>();
|
||||
}
|
||||
const LargeSceneryElement* AsLargeScenery() const
|
||||
{
|
||||
return as<LargeSceneryElement>();
|
||||
}
|
||||
LargeSceneryElement* AsLargeScenery()
|
||||
{
|
||||
return as<LargeSceneryElement>();
|
||||
}
|
||||
const WallElement* AsWall() const
|
||||
{
|
||||
return as<WallElement>();
|
||||
}
|
||||
WallElement* AsWall()
|
||||
{
|
||||
return as<WallElement>();
|
||||
}
|
||||
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>();
|
||||
}
|
||||
BannerElement* AsBanner()
|
||||
{
|
||||
return as<BannerElement>();
|
||||
}
|
||||
const BannerElement* AsBanner() const;
|
||||
BannerElement* AsBanner();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -573,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),
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
SurfaceElement* TileElementBase::AsSurface()
|
||||
{
|
||||
return as<SurfaceElement>();
|
||||
}
|
||||
const PathElement* TileElementBase::AsPath() const
|
||||
{
|
||||
return as<PathElement>();
|
||||
}
|
||||
PathElement* TileElementBase::AsPath()
|
||||
{
|
||||
return as<PathElement>();
|
||||
}
|
||||
const TrackElement* TileElementBase::AsTrack() const
|
||||
{
|
||||
return as<TrackElement>();
|
||||
}
|
||||
TrackElement* TileElementBase::AsTrack()
|
||||
{
|
||||
return as<TrackElement>();
|
||||
}
|
||||
const SmallSceneryElement* TileElementBase::AsSmallScenery() const
|
||||
{
|
||||
return as<SmallSceneryElement>();
|
||||
}
|
||||
SmallSceneryElement* TileElementBase::AsSmallScenery()
|
||||
{
|
||||
return as<SmallSceneryElement>();
|
||||
}
|
||||
const LargeSceneryElement* TileElementBase::AsLargeScenery() const
|
||||
{
|
||||
return as<LargeSceneryElement>();
|
||||
}
|
||||
LargeSceneryElement* TileElementBase::AsLargeScenery()
|
||||
{
|
||||
return as<LargeSceneryElement>();
|
||||
}
|
||||
const WallElement* TileElementBase::AsWall() const
|
||||
{
|
||||
return as<WallElement>();
|
||||
}
|
||||
WallElement* TileElementBase::AsWall()
|
||||
{
|
||||
return as<WallElement>();
|
||||
}
|
||||
|
||||
const EntranceElement* TileElementBase::AsEntrance() const
|
||||
{
|
||||
return as<EntranceElement>();
|
||||
}
|
||||
|
||||
EntranceElement* TileElementBase::AsEntrance()
|
||||
{
|
||||
return as<EntranceElement>();
|
||||
}
|
||||
|
||||
const BannerElement* TileElementBase::AsBanner() const
|
||||
{
|
||||
return as<BannerElement>();
|
||||
}
|
||||
BannerElement* TileElementBase::AsBanner()
|
||||
{
|
||||
return as<BannerElement>();
|
||||
}
|
||||
Reference in New Issue
Block a user