forked from rosebudai/OpenRCT2-Web
Merge pull request #20741 from ZehMatt/object-madness
Cleanup painting code, refactor some things regarding object indices
This commit is contained in:
15 files changed
+123
-171
No files matched your search
@@ -1059,7 +1059,7 @@ private:
|
||||
return 0;
|
||||
|
||||
uint16_t colour = MapColour(PALETTE_INDEX_0);
|
||||
const auto* surfaceObject = surfaceElement->GetSurfaceStyleObject();
|
||||
const auto* surfaceObject = surfaceElement->GetSurfaceObject();
|
||||
if (surfaceObject != nullptr)
|
||||
colour = MapColour2(surfaceObject->MapColours[0], surfaceObject->MapColours[1]);
|
||||
|
||||
|
||||
@@ -1055,7 +1055,7 @@ public:
|
||||
// Details
|
||||
// Terrain texture name
|
||||
StringId terrainNameId = STR_EMPTY;
|
||||
auto surfaceStyle = tileElement->AsSurface()->GetSurfaceStyleObject();
|
||||
auto surfaceStyle = tileElement->AsSurface()->GetSurfaceObject();
|
||||
if (surfaceStyle != nullptr)
|
||||
terrainNameId = surfaceStyle->NameStringId;
|
||||
auto ft = Formatter();
|
||||
@@ -1064,7 +1064,7 @@ public:
|
||||
|
||||
// Edge texture name
|
||||
StringId terrainEdgeNameId = STR_EMPTY;
|
||||
auto edgeStyle = tileElement->AsSurface()->GetEdgeStyleObject();
|
||||
auto edgeStyle = tileElement->AsSurface()->GetEdgeObject();
|
||||
if (edgeStyle != nullptr)
|
||||
terrainEdgeNameId = edgeStyle->NameStringId;
|
||||
ft = Formatter();
|
||||
|
||||
@@ -150,8 +150,8 @@ void SetupInUseSelectionFlags()
|
||||
case TileElementType::Surface:
|
||||
{
|
||||
auto surfaceEl = iter.element->AsSurface();
|
||||
auto surfaceIndex = surfaceEl->GetSurfaceStyle();
|
||||
auto edgeIndex = surfaceEl->GetEdgeStyle();
|
||||
auto surfaceIndex = surfaceEl->GetSurfaceObjectIndex();
|
||||
auto edgeIndex = surfaceEl->GetEdgeObjectIndex();
|
||||
|
||||
Editor::SetSelectedObject(ObjectType::TerrainSurface, surfaceIndex, ObjectSelectionFlags::InUse);
|
||||
Editor::SetSelectedObject(ObjectType::TerrainEdge, edgeIndex, ObjectSelectionFlags::InUse);
|
||||
|
||||
@@ -113,7 +113,7 @@ GameActions::Result SurfaceSetStyleAction::Query() const
|
||||
|
||||
if (_surfaceStyle != OBJECT_ENTRY_INDEX_NULL)
|
||||
{
|
||||
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceStyle();
|
||||
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceObjectIndex();
|
||||
|
||||
if (_surfaceStyle != curSurfaceStyle)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ GameActions::Result SurfaceSetStyleAction::Query() const
|
||||
|
||||
if (_edgeStyle != OBJECT_ENTRY_INDEX_NULL)
|
||||
{
|
||||
uint8_t curEdgeStyle = surfaceElement->GetEdgeStyle();
|
||||
uint8_t curEdgeStyle = surfaceElement->GetEdgeObjectIndex();
|
||||
|
||||
if (_edgeStyle != curEdgeStyle)
|
||||
{
|
||||
@@ -181,7 +181,7 @@ GameActions::Result SurfaceSetStyleAction::Execute() const
|
||||
|
||||
if (_surfaceStyle != OBJECT_ENTRY_INDEX_NULL)
|
||||
{
|
||||
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceStyle();
|
||||
uint8_t curSurfaceStyle = surfaceElement->GetSurfaceObjectIndex();
|
||||
|
||||
if (_surfaceStyle != curSurfaceStyle)
|
||||
{
|
||||
@@ -192,7 +192,7 @@ GameActions::Result SurfaceSetStyleAction::Execute() const
|
||||
{
|
||||
surfaceCost += surfaceObject->Price;
|
||||
|
||||
surfaceElement->SetSurfaceStyle(_surfaceStyle);
|
||||
surfaceElement->SetSurfaceObjectIndex(_surfaceStyle);
|
||||
|
||||
MapInvalidateTileFull(coords);
|
||||
FootpathRemoveLitter({ coords, TileElementHeight(coords) });
|
||||
@@ -202,13 +202,13 @@ GameActions::Result SurfaceSetStyleAction::Execute() const
|
||||
|
||||
if (_edgeStyle != OBJECT_ENTRY_INDEX_NULL)
|
||||
{
|
||||
uint8_t curEdgeStyle = surfaceElement->GetEdgeStyle();
|
||||
uint8_t curEdgeStyle = surfaceElement->GetEdgeObjectIndex();
|
||||
|
||||
if (_edgeStyle != curEdgeStyle)
|
||||
{
|
||||
edgeCost += 100;
|
||||
|
||||
surfaceElement->SetEdgeStyle(_edgeStyle);
|
||||
surfaceElement->SetEdgeObjectIndex(_edgeStyle);
|
||||
MapInvalidateTileFull(coords);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,7 @@
|
||||
#include "../../Game.h"
|
||||
#include "../../config/Config.h"
|
||||
#include "../../core/Numerics.hpp"
|
||||
#include "../../drawing/LightFX.h"
|
||||
#include "../../entity/EntityRegistry.h"
|
||||
#include "../../entity/PatrolArea.h"
|
||||
#include "../../entity/Peep.h"
|
||||
#include "../../entity/Staff.h"
|
||||
#include "../../interface/Viewport.h"
|
||||
#include "../../localisation/Formatter.h"
|
||||
#include "../../localisation/Formatting.h"
|
||||
@@ -25,8 +21,6 @@
|
||||
#include "../../object/FootpathObject.h"
|
||||
#include "../../object/FootpathRailingsObject.h"
|
||||
#include "../../object/FootpathSurfaceObject.h"
|
||||
#include "../../object/ObjectList.h"
|
||||
#include "../../object/ObjectManager.h"
|
||||
#include "../../object/PathAdditionEntry.h"
|
||||
#include "../../profiling/Profiling.h"
|
||||
#include "../../ride/Ride.h"
|
||||
|
||||
@@ -217,7 +217,7 @@ struct TileDescriptor
|
||||
{
|
||||
TileCoordsXY tile_coords;
|
||||
const TileElement* tile_element;
|
||||
uint8_t terrain;
|
||||
const TerrainSurfaceObject* surfaceObject;
|
||||
uint8_t slope;
|
||||
CornerHeight corner_heights;
|
||||
};
|
||||
@@ -300,95 +300,64 @@ static constexpr TileSurfaceBoundaryData _tileSurfaceBoundaries[4] = {
|
||||
},
|
||||
};
|
||||
|
||||
static const TerrainSurfaceObject* GetSurfaceObject(size_t index)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
TerrainSurfaceObject* result{};
|
||||
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
||||
auto obj = objMgr.GetLoadedObject(ObjectType::TerrainSurface, index);
|
||||
if (obj != nullptr)
|
||||
{
|
||||
return static_cast<TerrainSurfaceObject*>(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ImageId GetSurfaceImage(
|
||||
const PaintSession& session, ObjectEntryIndex index, int32_t offset, uint8_t rotation, int32_t grassLength, bool grid,
|
||||
bool underground)
|
||||
const PaintSession& session, const TerrainSurfaceObject* surfaceObject, int32_t offset, uint8_t rotation,
|
||||
int32_t grassLength, bool grid, bool underground)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
ImageId image;
|
||||
auto obj = GetSurfaceObject(index);
|
||||
if (obj != nullptr)
|
||||
if (surfaceObject != nullptr)
|
||||
{
|
||||
image = ImageId(obj->GetImageId(
|
||||
image = ImageId(surfaceObject->GetImageId(
|
||||
{ session.MapPosition.x >> 5, session.MapPosition.y >> 5 }, grassLength, rotation, offset, grid, underground));
|
||||
if (obj->Colour != 255)
|
||||
if (surfaceObject->Colour != 255)
|
||||
{
|
||||
image = image.WithPrimary(obj->Colour);
|
||||
image = image.WithPrimary(surfaceObject->Colour);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
static ImageId GetSurfacePattern(uint8_t index, int32_t offset)
|
||||
static ImageId GetSurfacePattern(const TerrainSurfaceObject* surfaceObject, int32_t offset)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
ImageId image;
|
||||
auto obj = GetSurfaceObject(index);
|
||||
if (obj != nullptr)
|
||||
if (surfaceObject != nullptr)
|
||||
{
|
||||
image = ImageId(obj->PatternBaseImageId + offset);
|
||||
if (obj->Colour != 255)
|
||||
image = ImageId(surfaceObject->PatternBaseImageId + offset);
|
||||
if (surfaceObject->Colour != 255)
|
||||
{
|
||||
image = image.WithPrimary(obj->Colour);
|
||||
image = image.WithPrimary(surfaceObject->Colour);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
static bool SurfaceShouldSmoothSelf(uint8_t index)
|
||||
static bool SurfaceShouldSmoothSelf(const TerrainSurfaceObject* surfaceObject)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
if (surfaceObject == nullptr)
|
||||
return false;
|
||||
|
||||
auto obj = GetSurfaceObject(index);
|
||||
if (obj != nullptr)
|
||||
{
|
||||
return obj->Flags & TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_SELF;
|
||||
}
|
||||
return false;
|
||||
return surfaceObject->Flags & TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_SELF;
|
||||
}
|
||||
|
||||
static bool SurfaceShouldSmooth(uint8_t index)
|
||||
static bool SurfaceShouldSmooth(const TerrainSurfaceObject* surfaceObject)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
if (surfaceObject == nullptr)
|
||||
return false;
|
||||
|
||||
auto obj = GetSurfaceObject(index);
|
||||
if (obj != nullptr)
|
||||
{
|
||||
return obj->Flags & TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_OTHER;
|
||||
}
|
||||
return false;
|
||||
return surfaceObject->Flags & TERRAIN_SURFACE_FLAGS::SMOOTH_WITH_OTHER;
|
||||
}
|
||||
|
||||
static ImageId GetEdgeImageWithOffset(uint8_t index, uint32_t offset)
|
||||
static ImageId GetEdgeImageWithOffset(const TerrainEdgeObject* edgeObject, uint32_t offset)
|
||||
{
|
||||
ImageId result;
|
||||
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
||||
auto obj = objMgr.GetLoadedObject(ObjectType::TerrainEdge, index);
|
||||
if (obj != nullptr)
|
||||
if (edgeObject != nullptr)
|
||||
{
|
||||
auto tobj = static_cast<TerrainEdgeObject*>(obj);
|
||||
result = ImageId(tobj->BaseImageId + offset);
|
||||
result = ImageId(edgeObject->BaseImageId + offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ImageId GetEdgeImage(uint8_t index, uint8_t type)
|
||||
static ImageId GetEdgeImage(const TerrainEdgeObject* edgeObject, uint8_t type)
|
||||
{
|
||||
static constexpr uint32_t offsets[] = {
|
||||
0,
|
||||
@@ -400,25 +369,20 @@ static ImageId GetEdgeImage(uint8_t index, uint8_t type)
|
||||
ImageId result;
|
||||
if (type < std::size(offsets))
|
||||
{
|
||||
result = GetEdgeImageWithOffset(index, offsets[type]);
|
||||
result = GetEdgeImageWithOffset(edgeObject, offsets[type]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ImageId GetTunnelImage(ObjectEntryIndex index, uint8_t type, edge_t edge)
|
||||
static ImageId GetTunnelImage(const TerrainEdgeObject* edgeObject, uint8_t type, edge_t edge)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
|
||||
static constexpr uint32_t offsets[TUNNEL_TYPE_COUNT] = { 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80,
|
||||
36, 48, 60, 72, 76, 80, 84, 88, 92, 96, 100 };
|
||||
|
||||
bool hasDoors = false;
|
||||
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
||||
auto obj = objMgr.GetLoadedObject(ObjectType::TerrainEdge, index);
|
||||
if (obj != nullptr)
|
||||
if (edgeObject != nullptr)
|
||||
{
|
||||
auto tobj = static_cast<TerrainEdgeObject*>(obj);
|
||||
hasDoors = tobj->HasDoors && !tobj->UsesFallbackImages();
|
||||
hasDoors = edgeObject->HasDoors && !edgeObject->UsesFallbackImages();
|
||||
}
|
||||
|
||||
if (!hasDoors && type >= REGULAR_TUNNEL_TYPE_COUNT && type < std::size(offsets))
|
||||
@@ -427,7 +391,7 @@ static ImageId GetTunnelImage(ObjectEntryIndex index, uint8_t type, edge_t edge)
|
||||
ImageId result;
|
||||
if (type < std::size(offsets))
|
||||
{
|
||||
result = GetEdgeImageWithOffset(index, offsets[type]).WithIndexOffset(edge == EDGE_BOTTOMRIGHT ? 2 : 0);
|
||||
result = GetEdgeImageWithOffset(edgeObject, offsets[type]).WithIndexOffset(edge == EDGE_BOTTOMRIGHT ? 2 : 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -522,21 +486,21 @@ static void ViewportSurfaceSmoothenEdge(
|
||||
break;
|
||||
}
|
||||
|
||||
if (self.terrain == neighbour.terrain)
|
||||
if (self.surfaceObject == neighbour.surfaceObject)
|
||||
{
|
||||
// same tint
|
||||
if (cl == dh)
|
||||
return;
|
||||
|
||||
if (!SurfaceShouldSmoothSelf(self.terrain))
|
||||
if (!SurfaceShouldSmoothSelf(self.surfaceObject))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SurfaceShouldSmooth(self.terrain))
|
||||
if (!SurfaceShouldSmooth(self.surfaceObject))
|
||||
return;
|
||||
|
||||
if (!SurfaceShouldSmooth(neighbour.terrain))
|
||||
if (!SurfaceShouldSmooth(neighbour.surfaceObject))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -546,7 +510,7 @@ static void ViewportSurfaceSmoothenEdge(
|
||||
{
|
||||
AttachedPaintStruct* out = session.LastAttachedPS;
|
||||
// set content and enable masking
|
||||
out->ColourImageId = GetSurfacePattern(neighbour.terrain, cl);
|
||||
out->ColourImageId = GetSurfacePattern(neighbour.surfaceObject, cl);
|
||||
out->IsMasked = true;
|
||||
}
|
||||
}
|
||||
@@ -569,7 +533,7 @@ static bool TileIsInsideClipView(const TileDescriptor& tile)
|
||||
}
|
||||
|
||||
static void ViewportSurfaceDrawTileSideBottom(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t edgeStyle, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour, bool isWater)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
@@ -648,10 +612,10 @@ static void ViewportSurfaceDrawTileSideBottom(
|
||||
return;
|
||||
}
|
||||
|
||||
auto baseImageId = GetEdgeImage(edgeStyle, 0);
|
||||
auto baseImageId = GetEdgeImage(edgeObject, 0);
|
||||
if (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE)
|
||||
{
|
||||
baseImageId = GetEdgeImage(edgeStyle, 1);
|
||||
baseImageId = GetEdgeImage(edgeObject, 1);
|
||||
}
|
||||
|
||||
if (edge == EDGE_BOTTOMRIGHT)
|
||||
@@ -739,7 +703,7 @@ static void ViewportSurfaceDrawTileSideBottom(
|
||||
boundBoxLength -= 16;
|
||||
}
|
||||
|
||||
auto imageId = GetTunnelImage(edgeStyle, tunnelType, edge);
|
||||
auto imageId = GetTunnelImage(edgeObject, tunnelType, edge);
|
||||
PaintAddImageAsParent(
|
||||
session, imageId, { offset, zOffset },
|
||||
{ { 0, 0, boundBoxOffsetZ }, { tunnelBounds.x, tunnelBounds.y, boundBoxLength - 1 } });
|
||||
@@ -753,7 +717,7 @@ static void ViewportSurfaceDrawTileSideBottom(
|
||||
boundBoxLength -= 16;
|
||||
}
|
||||
|
||||
imageId = GetTunnelImage(edgeStyle, tunnelType, edge).WithIndexOffset(1);
|
||||
imageId = GetTunnelImage(edgeObject, tunnelType, edge).WithIndexOffset(1);
|
||||
PaintAddImageAsParent(
|
||||
session, imageId, { offset, curHeight * COORDS_Z_PER_TINY_Z },
|
||||
{ { tunnelTopBoundBoxOffset.x, tunnelTopBoundBoxOffset.y, boundBoxOffsetZ },
|
||||
@@ -768,24 +732,24 @@ static void ViewportSurfaceDrawTileSideBottom(
|
||||
* rct2: 0x0065EB7D, 0x0065F0D8
|
||||
*/
|
||||
static void ViewportSurfaceDrawLandSideBottom(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t edgeStyle, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour)
|
||||
{
|
||||
ViewportSurfaceDrawTileSideBottom(session, edge, height, edgeStyle, self, neighbour, false);
|
||||
ViewportSurfaceDrawTileSideBottom(session, edge, height, edgeObject, self, neighbour, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* rct2: 0x0065F8B9, 0x0065FE26
|
||||
*/
|
||||
static void ViewportSurfaceDrawWaterSideBottom(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t edgeStyle, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour)
|
||||
{
|
||||
ViewportSurfaceDrawTileSideBottom(session, edge, height, edgeStyle, self, neighbour, true);
|
||||
ViewportSurfaceDrawTileSideBottom(session, edge, height, edgeObject, self, neighbour, true);
|
||||
}
|
||||
|
||||
static void ViewportSurfaceDrawTileSideTop(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t terrain, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour, bool isWater)
|
||||
{
|
||||
PROFILED_FUNCTION();
|
||||
@@ -855,10 +819,10 @@ static void ViewportSurfaceDrawTileSideTop(
|
||||
ImageId baseImageId;
|
||||
if (isWater)
|
||||
{
|
||||
baseImageId = GetEdgeImage(terrain, 2); // var_08
|
||||
baseImageId = GetEdgeImage(edgeObject, 2); // var_08
|
||||
if (session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE)
|
||||
{
|
||||
baseImageId = GetEdgeImage(terrain, 1); // var_04
|
||||
baseImageId = GetEdgeImage(edgeObject, 1); // var_04
|
||||
}
|
||||
baseImageId = baseImageId.WithIndexOffset(edge == EDGE_TOPLEFT ? 5 : 0);
|
||||
}
|
||||
@@ -867,12 +831,12 @@ static void ViewportSurfaceDrawTileSideTop(
|
||||
if (!(session.ViewFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE))
|
||||
{
|
||||
const uint8_t incline = (cornerHeight2 - cornerHeight1) + 1;
|
||||
const auto imageId = GetEdgeImage(terrain, 3).WithIndexOffset((edge == EDGE_TOPLEFT ? 3 : 0) + incline);
|
||||
const auto imageId = GetEdgeImage(edgeObject, 3).WithIndexOffset((edge == EDGE_TOPLEFT ? 3 : 0) + incline);
|
||||
const int16_t y = (height - cornerHeight1) * COORDS_Z_PER_TINY_Z;
|
||||
PaintAttachToPreviousPS(session, imageId, 0, y);
|
||||
return;
|
||||
}
|
||||
baseImageId = GetEdgeImage(terrain, 1).WithIndexOffset(edge == EDGE_TOPLEFT ? 5 : 0);
|
||||
baseImageId = GetEdgeImage(edgeObject, 1).WithIndexOffset(edge == EDGE_TOPLEFT ? 5 : 0);
|
||||
}
|
||||
|
||||
uint8_t cur_height = std::min(neighbourCornerHeight2, neighbourCornerHeight1);
|
||||
@@ -927,20 +891,20 @@ static void ViewportSurfaceDrawTileSideTop(
|
||||
* rct2: 0x0065F63B, 0x0065F77D
|
||||
*/
|
||||
static void ViewportSurfaceDrawLandSideTop(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t terrain, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour)
|
||||
{
|
||||
ViewportSurfaceDrawTileSideTop(session, edge, height, terrain, self, neighbour, false);
|
||||
ViewportSurfaceDrawTileSideTop(session, edge, height, edgeObject, self, neighbour, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* rct2: 0x0066039B, 0x006604F1
|
||||
*/
|
||||
static void ViewportSurfaceDrawWaterSideTop(
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, uint8_t terrain, struct TileDescriptor self,
|
||||
PaintSession& session, enum edge_t edge, uint16_t height, const TerrainEdgeObject* edgeObject, struct TileDescriptor self,
|
||||
struct TileDescriptor neighbour)
|
||||
{
|
||||
ViewportSurfaceDrawTileSideTop(session, edge, height, terrain, self, neighbour, true);
|
||||
ViewportSurfaceDrawTileSideTop(session, edge, height, edgeObject, self, neighbour, true);
|
||||
}
|
||||
|
||||
static std::pair<int32_t, int32_t> SurfaceGetHeightAboveWater(
|
||||
@@ -1029,16 +993,18 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
|
||||
const auto zoomLevel = session.DPI.zoom_level;
|
||||
const uint8_t rotation = session.CurrentRotation;
|
||||
const auto terrain_type = tileElement.GetSurfaceStyle();
|
||||
const uint8_t surfaceShape = ViewportSurfacePaintSetupGetRelativeSlope(tileElement, rotation);
|
||||
const CoordsXY& base = session.SpritePosition;
|
||||
const CornerHeight& cornerHeights = corner_heights[surfaceShape];
|
||||
const TileElement* elementPtr = &reinterpret_cast<const TileElement&>(tileElement);
|
||||
|
||||
const auto* surfaceObject = tileElement.GetSurfaceObject();
|
||||
const auto* edgeObject = tileElement.GetEdgeObject();
|
||||
|
||||
TileDescriptor selfDescriptor = {
|
||||
TileCoordsXY(base),
|
||||
elementPtr,
|
||||
static_cast<uint8_t>(terrain_type),
|
||||
surfaceObject,
|
||||
surfaceShape,
|
||||
{
|
||||
static_cast<uint8_t>(height / 16 + cornerHeights.top),
|
||||
@@ -1076,7 +1042,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
|
||||
descriptor.tile_coords = TileCoordsXY{ position };
|
||||
descriptor.tile_element = reinterpret_cast<TileElement*>(surfaceElement);
|
||||
descriptor.terrain = surfaceElement->GetSurfaceStyle();
|
||||
descriptor.surfaceObject = surfaceElement->GetSurfaceObject();
|
||||
descriptor.slope = surfaceSlope;
|
||||
descriptor.corner_heights.top = baseHeight + ch.top;
|
||||
descriptor.corner_heights.right = baseHeight + ch.right;
|
||||
@@ -1131,7 +1097,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
}
|
||||
else
|
||||
{
|
||||
imageId = GetSurfaceImage(session, terrain_type, image_offset, rotation, grassLength, showGridlines, false);
|
||||
imageId = GetSurfaceImage(session, surfaceObject, image_offset, rotation, grassLength, showGridlines, false);
|
||||
}
|
||||
if (session.ViewFlags & (VIEWPORT_FLAG_UNDERGROUND_INSIDE | VIEWPORT_FLAG_HIDE_BASE))
|
||||
{
|
||||
@@ -1300,22 +1266,17 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
&& !(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)))
|
||||
{
|
||||
const uint8_t image_offset = Byte97B444[surfaceShape];
|
||||
auto imageId = GetSurfaceImage(session, terrain_type, image_offset, rotation, 1, false, true);
|
||||
auto imageId = GetSurfaceImage(session, surfaceObject, image_offset, rotation, 1, false, true);
|
||||
PaintAttachToPreviousPS(session, imageId, 0, 0);
|
||||
}
|
||||
|
||||
if (!(session.ViewFlags & VIEWPORT_FLAG_HIDE_VERTICAL))
|
||||
{
|
||||
const auto edgeStyle = tileElement.GetEdgeStyle();
|
||||
if (static_cast<int32_t>(edgeStyle) >= object_entry_group_counts[EnumValue(ObjectType::TerrainEdge)])
|
||||
{
|
||||
LOG_VERBOSE("edgeStyle: %d", edgeStyle);
|
||||
}
|
||||
|
||||
ViewportSurfaceDrawLandSideTop(session, EDGE_TOPLEFT, height, edgeStyle, tileDescriptors[0], tileDescriptors[3]);
|
||||
ViewportSurfaceDrawLandSideTop(session, EDGE_TOPRIGHT, height, edgeStyle, tileDescriptors[0], tileDescriptors[4]);
|
||||
ViewportSurfaceDrawLandSideBottom(session, EDGE_BOTTOMLEFT, height, edgeStyle, tileDescriptors[0], tileDescriptors[1]);
|
||||
ViewportSurfaceDrawLandSideBottom(session, EDGE_BOTTOMRIGHT, height, edgeStyle, tileDescriptors[0], tileDescriptors[2]);
|
||||
ViewportSurfaceDrawLandSideTop(session, EDGE_TOPLEFT, height, edgeObject, tileDescriptors[0], tileDescriptors[3]);
|
||||
ViewportSurfaceDrawLandSideTop(session, EDGE_TOPRIGHT, height, edgeObject, tileDescriptors[0], tileDescriptors[4]);
|
||||
ViewportSurfaceDrawLandSideBottom(session, EDGE_BOTTOMLEFT, height, edgeObject, tileDescriptors[0], tileDescriptors[1]);
|
||||
ViewportSurfaceDrawLandSideBottom(
|
||||
session, EDGE_BOTTOMRIGHT, height, edgeObject, tileDescriptors[0], tileDescriptors[2]);
|
||||
}
|
||||
|
||||
const uint16_t waterHeight = tileElement.GetWaterHeight();
|
||||
@@ -1345,18 +1306,14 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
|
||||
|
||||
if (!(session.ViewFlags & VIEWPORT_FLAG_HIDE_VERTICAL))
|
||||
{
|
||||
// This wasn't in the original, but the code depended on globals that were only set in a different conditional
|
||||
const uint32_t edgeStyle = tileElement.GetEdgeStyle();
|
||||
// end new code
|
||||
|
||||
ViewportSurfaceDrawWaterSideBottom(
|
||||
session, EDGE_BOTTOMLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[1]);
|
||||
session, EDGE_BOTTOMLEFT, waterHeight, edgeObject, tileDescriptors[0], tileDescriptors[1]);
|
||||
ViewportSurfaceDrawWaterSideBottom(
|
||||
session, EDGE_BOTTOMRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[2]);
|
||||
session, EDGE_BOTTOMRIGHT, waterHeight, edgeObject, tileDescriptors[0], tileDescriptors[2]);
|
||||
ViewportSurfaceDrawWaterSideTop(
|
||||
session, EDGE_TOPLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[3]);
|
||||
session, EDGE_TOPLEFT, waterHeight, edgeObject, tileDescriptors[0], tileDescriptors[3]);
|
||||
ViewportSurfaceDrawWaterSideTop(
|
||||
session, EDGE_TOPRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[4]);
|
||||
session, EDGE_TOPRIGHT, waterHeight, edgeObject, tileDescriptors[0], tileDescriptors[4]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1579,8 +1579,8 @@ namespace RCT1
|
||||
auto edgeStyle = _terrainEdgeTypeToEntryMap[src2->GetEdgeStyle()];
|
||||
|
||||
dst2->SetSlope(src2->GetSlope());
|
||||
dst2->SetSurfaceStyle(surfaceStyle);
|
||||
dst2->SetEdgeStyle(edgeStyle);
|
||||
dst2->SetSurfaceObjectIndex(surfaceStyle);
|
||||
dst2->SetEdgeObjectIndex(edgeStyle);
|
||||
dst2->SetGrassLength(src2->GetGrassLength());
|
||||
dst2->SetOwnership(src2->GetOwnership());
|
||||
dst2->SetParkFences(src2->GetParkFences());
|
||||
|
||||
@@ -1373,8 +1373,8 @@ namespace RCT2
|
||||
|
||||
dst2->SetSlope(src2->GetSlope());
|
||||
|
||||
dst2->SetSurfaceStyle(src2->GetSurfaceStyle());
|
||||
dst2->SetEdgeStyle(src2->GetEdgeStyle());
|
||||
dst2->SetSurfaceObjectIndex(src2->GetSurfaceStyle());
|
||||
dst2->SetEdgeObjectIndex(src2->GetEdgeStyle());
|
||||
|
||||
dst2->SetGrassLength(src2->GetGrassLength());
|
||||
dst2->SetOwnership(src2->GetOwnership());
|
||||
|
||||
@@ -2228,8 +2228,8 @@ static void TrackDesignPreviewClearMap()
|
||||
element->SetLastForTile(true);
|
||||
element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
element->AsSurface()->SetWaterHeight(0);
|
||||
element->AsSurface()->SetSurfaceStyle(0);
|
||||
element->AsSurface()->SetEdgeStyle(0);
|
||||
element->AsSurface()->SetSurfaceObjectIndex(0);
|
||||
element->AsSurface()->SetEdgeObjectIndex(0);
|
||||
element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
element->AsSurface()->SetOwnership(OWNERSHIP_OWNED);
|
||||
element->AsSurface()->SetParkFences(0);
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace OpenRCT2::Scripting
|
||||
auto* el = _element->AsSurface();
|
||||
if (el != nullptr)
|
||||
{
|
||||
duk_push_int(ctx, el->GetSurfaceStyle());
|
||||
duk_push_int(ctx, el->GetSurfaceObjectIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -243,7 +243,7 @@ namespace OpenRCT2::Scripting
|
||||
return;
|
||||
}
|
||||
|
||||
el->SetSurfaceStyle(value);
|
||||
el->SetSurfaceObjectIndex(value);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace OpenRCT2::Scripting
|
||||
auto* el = _element->AsSurface();
|
||||
if (el != nullptr)
|
||||
{
|
||||
duk_push_int(ctx, el->GetEdgeStyle());
|
||||
duk_push_int(ctx, el->GetEdgeObjectIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -274,7 +274,7 @@ namespace OpenRCT2::Scripting
|
||||
return;
|
||||
}
|
||||
|
||||
el->SetEdgeStyle(value);
|
||||
el->SetEdgeObjectIndex(value);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ static TileElement GetDefaultSurfaceElement()
|
||||
el.AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
el.AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
|
||||
el.AsSurface()->SetParkFences(0);
|
||||
el.AsSurface()->SetSurfaceStyle(0);
|
||||
el.AsSurface()->SetEdgeStyle(0);
|
||||
el.AsSurface()->SetSurfaceObjectIndex(0);
|
||||
el.AsSurface()->SetEdgeObjectIndex(0);
|
||||
return el;
|
||||
}
|
||||
|
||||
@@ -1352,8 +1352,8 @@ void MapRemoveOutOfRangeElements()
|
||||
|
||||
static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile, SurfaceElement& destTile)
|
||||
{
|
||||
destTile.SetSurfaceStyle(sourceTile.GetSurfaceStyle());
|
||||
destTile.SetEdgeStyle(sourceTile.GetEdgeStyle());
|
||||
destTile.SetSurfaceObjectIndex(sourceTile.GetSurfaceObjectIndex());
|
||||
destTile.SetEdgeObjectIndex(sourceTile.GetEdgeObjectIndex());
|
||||
destTile.SetGrassLength(sourceTile.GetGrassLength());
|
||||
destTile.SetOwnership(OWNERSHIP_UNOWNED);
|
||||
destTile.SetWaterHeight(sourceTile.GetWaterHeight());
|
||||
@@ -1439,8 +1439,8 @@ static void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr)
|
||||
element->ClearanceHeight = MINIMUM_LAND_HEIGHT;
|
||||
element->Owner = 0;
|
||||
element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
element->AsSurface()->SetSurfaceStyle(0);
|
||||
element->AsSurface()->SetEdgeStyle(0);
|
||||
element->AsSurface()->SetSurfaceObjectIndex(0);
|
||||
element->AsSurface()->SetEdgeObjectIndex(0);
|
||||
element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
element->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
|
||||
element->AsSurface()->SetParkFences(0);
|
||||
|
||||
@@ -129,8 +129,8 @@ void MapGenGenerateBlank(MapGenSettings* settings)
|
||||
auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
|
||||
if (surfaceElement != nullptr)
|
||||
{
|
||||
surfaceElement->SetSurfaceStyle(settings->floor);
|
||||
surfaceElement->SetEdgeStyle(settings->wall);
|
||||
surfaceElement->SetSurfaceObjectIndex(settings->floor);
|
||||
surfaceElement->SetEdgeObjectIndex(settings->wall);
|
||||
surfaceElement->BaseHeight = settings->height;
|
||||
surfaceElement->ClearanceHeight = settings->height;
|
||||
}
|
||||
@@ -193,8 +193,8 @@ void MapGenGenerate(MapGenSettings* settings)
|
||||
auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
|
||||
if (surfaceElement != nullptr)
|
||||
{
|
||||
surfaceElement->SetSurfaceStyle(floorTextureId);
|
||||
surfaceElement->SetEdgeStyle(edgeTextureId);
|
||||
surfaceElement->SetSurfaceObjectIndex(floorTextureId);
|
||||
surfaceElement->SetEdgeObjectIndex(edgeTextureId);
|
||||
surfaceElement->BaseHeight = settings->height;
|
||||
surfaceElement->ClearanceHeight = settings->height;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ void MapGenGenerate(MapGenSettings* settings)
|
||||
auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y });
|
||||
|
||||
if (surfaceElement != nullptr && surfaceElement->BaseHeight < waterLevel + 6)
|
||||
surfaceElement->SetSurfaceStyle(beachTextureId);
|
||||
surfaceElement->SetSurfaceObjectIndex(beachTextureId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ static void MapGenPlaceTrees()
|
||||
// vegetation
|
||||
float oasisScore = 0.0f;
|
||||
ObjectEntryIndex treeObjectEntryIndex = OBJECT_ENTRY_INDEX_NULL;
|
||||
const auto& surfaceStyleObject = *TerrainSurfaceObject::GetById(surfaceElement->GetSurfaceStyle());
|
||||
const auto& surfaceStyleObject = *TerrainSurfaceObject::GetById(surfaceElement->GetSurfaceObjectIndex());
|
||||
if (MapGenSurfaceTakesSandTrees(surfaceStyleObject))
|
||||
{
|
||||
oasisScore = -0.5f;
|
||||
|
||||
@@ -17,36 +17,36 @@
|
||||
#include "Location.hpp"
|
||||
#include "Map.h"
|
||||
|
||||
uint32_t SurfaceElement::GetSurfaceStyle() const
|
||||
ObjectEntryIndex SurfaceElement::GetSurfaceObjectIndex() const
|
||||
{
|
||||
return SurfaceStyle;
|
||||
}
|
||||
|
||||
TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const
|
||||
TerrainSurfaceObject* SurfaceElement::GetSurfaceObject() const
|
||||
{
|
||||
auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
|
||||
return static_cast<TerrainSurfaceObject*>(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceStyle()));
|
||||
return static_cast<TerrainSurfaceObject*>(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex()));
|
||||
}
|
||||
|
||||
uint32_t SurfaceElement::GetEdgeStyle() const
|
||||
ObjectEntryIndex SurfaceElement::GetEdgeObjectIndex() const
|
||||
{
|
||||
return EdgeStyle;
|
||||
return EdgeObjectIndex;
|
||||
}
|
||||
|
||||
TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const
|
||||
TerrainEdgeObject* SurfaceElement::GetEdgeObject() const
|
||||
{
|
||||
auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
|
||||
return static_cast<TerrainEdgeObject*>(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeStyle()));
|
||||
return static_cast<TerrainEdgeObject*>(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeObjectIndex()));
|
||||
}
|
||||
|
||||
void SurfaceElement::SetSurfaceStyle(uint32_t newStyle)
|
||||
void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle)
|
||||
{
|
||||
SurfaceStyle = newStyle;
|
||||
SurfaceStyle = static_cast<ObjectEntryIndex>(newStyle);
|
||||
}
|
||||
|
||||
void SurfaceElement::SetEdgeStyle(uint32_t newStyle)
|
||||
void SurfaceElement::SetEdgeObjectIndex(ObjectEntryIndex newIndex)
|
||||
{
|
||||
EdgeStyle = newStyle;
|
||||
EdgeObjectIndex = static_cast<ObjectEntryIndex>(newIndex);
|
||||
}
|
||||
|
||||
int32_t SurfaceElement::GetWaterHeight() const
|
||||
@@ -61,7 +61,7 @@ void SurfaceElement::SetWaterHeight(int32_t newWaterHeight)
|
||||
|
||||
bool SurfaceElement::CanGrassGrow() const
|
||||
{
|
||||
auto surfaceStyle = GetSurfaceStyle();
|
||||
auto surfaceStyle = GetSurfaceObjectIndex();
|
||||
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
||||
auto obj = objMgr.GetLoadedObject(ObjectType::TerrainSurface, surfaceStyle);
|
||||
if (obj != nullptr)
|
||||
|
||||
@@ -195,7 +195,7 @@ private:
|
||||
uint8_t GrassLength;
|
||||
uint8_t Ownership;
|
||||
uint8_t SurfaceStyle;
|
||||
uint8_t EdgeStyle;
|
||||
uint8_t EdgeObjectIndex;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-private-field"
|
||||
uint8_t Pad0B[5];
|
||||
@@ -205,12 +205,13 @@ public:
|
||||
uint8_t GetSlope() const;
|
||||
void SetSlope(uint8_t newSlope);
|
||||
|
||||
uint32_t GetSurfaceStyle() const;
|
||||
TerrainSurfaceObject* GetSurfaceStyleObject() const;
|
||||
void SetSurfaceStyle(uint32_t newStyle);
|
||||
uint32_t GetEdgeStyle() const;
|
||||
TerrainEdgeObject* GetEdgeStyleObject() const;
|
||||
void SetEdgeStyle(uint32_t newStyle);
|
||||
ObjectEntryIndex GetSurfaceObjectIndex() const;
|
||||
TerrainSurfaceObject* GetSurfaceObject() const;
|
||||
void SetSurfaceObjectIndex(ObjectEntryIndex newStyle);
|
||||
|
||||
ObjectEntryIndex GetEdgeObjectIndex() const;
|
||||
TerrainEdgeObject* GetEdgeObject() const;
|
||||
void SetEdgeObjectIndex(ObjectEntryIndex newStyle);
|
||||
|
||||
bool CanGrassGrow() const;
|
||||
uint8_t GetGrassLength() const;
|
||||
|
||||
@@ -136,7 +136,7 @@ protected:
|
||||
static ::testing::AssertionResult AssertIsStartPosition(const char*, const TileCoordsXYZ& location)
|
||||
{
|
||||
const uint32_t expectedSurfaceStyle = 11u;
|
||||
const uint32_t style = MapGetSurfaceElementAt(location.ToCoordsXYZ())->GetSurfaceStyle();
|
||||
const uint32_t style = MapGetSurfaceElementAt(location.ToCoordsXYZ())->GetSurfaceObjectIndex();
|
||||
|
||||
if (style != expectedSurfaceStyle)
|
||||
return ::testing::AssertionFailure()
|
||||
@@ -151,7 +151,7 @@ protected:
|
||||
{
|
||||
const uint32_t forbiddenSurfaceStyle = 8u;
|
||||
|
||||
const uint32_t style = MapGetSurfaceElementAt(location.ToCoordsXYZ())->GetSurfaceStyle();
|
||||
const uint32_t style = MapGetSurfaceElementAt(location.ToCoordsXYZ())->GetSurfaceObjectIndex();
|
||||
|
||||
if (style == forbiddenSurfaceStyle)
|
||||
return ::testing::AssertionFailure()
|
||||
|
||||
Reference in new issue
Block a user