From 7582006e1081f30c54a342774f3ea520ca0360e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 26 Aug 2023 20:40:01 +0300 Subject: [PATCH 1/7] Use ObjectEntryIndex for surface object --- src/openrct2/paint/tile_element/Paint.Surface.cpp | 4 ++-- src/openrct2/world/Surface.cpp | 6 +++--- src/openrct2/world/TileElement.h | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index d6fa6d5992..e059180154 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -217,7 +217,7 @@ struct TileDescriptor { TileCoordsXY tile_coords; const TileElement* tile_element; - uint8_t terrain; + ObjectEntryIndex terrain; uint8_t slope; CornerHeight corner_heights; }; @@ -1038,7 +1038,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con TileDescriptor selfDescriptor = { TileCoordsXY(base), elementPtr, - static_cast(terrain_type), + terrain_type, surfaceShape, { static_cast(height / 16 + cornerHeights.top), diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 127adba5e0..73209d4fdc 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -17,7 +17,7 @@ #include "Location.hpp" #include "Map.h" -uint32_t SurfaceElement::GetSurfaceStyle() const +ObjectEntryIndex SurfaceElement::GetSurfaceStyle() const { return SurfaceStyle; } @@ -39,9 +39,9 @@ TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const return static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeStyle())); } -void SurfaceElement::SetSurfaceStyle(uint32_t newStyle) +void SurfaceElement::SetSurfaceStyle(ObjectEntryIndex newStyle) { - SurfaceStyle = newStyle; + SurfaceStyle = static_cast(newStyle); } void SurfaceElement::SetEdgeStyle(uint32_t newStyle) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index f11cd55b5b..a4d46079be 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -205,9 +205,10 @@ public: uint8_t GetSlope() const; void SetSlope(uint8_t newSlope); - uint32_t GetSurfaceStyle() const; + ObjectEntryIndex GetSurfaceStyle() const; TerrainSurfaceObject* GetSurfaceStyleObject() const; - void SetSurfaceStyle(uint32_t newStyle); + void SetSurfaceStyle(ObjectEntryIndex newStyle); + uint32_t GetEdgeStyle() const; TerrainEdgeObject* GetEdgeStyleObject() const; void SetEdgeStyle(uint32_t newStyle); From ae3c1037ad04dea9611b5864dadf52ec66a86913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 26 Aug 2023 20:50:06 +0300 Subject: [PATCH 2/7] Properly name what the getter/setter for surface object index is --- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/actions/SurfaceSetStyleAction.cpp | 6 +++--- src/openrct2/paint/tile_element/Paint.Surface.cpp | 4 ++-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/scripting/bindings/world/ScTileElement.cpp | 4 ++-- src/openrct2/world/Map.cpp | 6 +++--- src/openrct2/world/MapGen.cpp | 8 ++++---- src/openrct2/world/Surface.cpp | 8 ++++---- src/openrct2/world/TileElement.h | 4 ++-- test/tests/Pathfinding.cpp | 4 ++-- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index e00d02cfee..de6c3a36a6 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -150,7 +150,7 @@ void SetupInUseSelectionFlags() case TileElementType::Surface: { auto surfaceEl = iter.element->AsSurface(); - auto surfaceIndex = surfaceEl->GetSurfaceStyle(); + auto surfaceIndex = surfaceEl->GetSurfaceObjectIndex(); auto edgeIndex = surfaceEl->GetEdgeStyle(); Editor::SetSelectedObject(ObjectType::TerrainSurface, surfaceIndex, ObjectSelectionFlags::InUse); diff --git a/src/openrct2/actions/SurfaceSetStyleAction.cpp b/src/openrct2/actions/SurfaceSetStyleAction.cpp index 217667c29e..266bf1614a 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.cpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.cpp @@ -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) { @@ -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) }); diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index e059180154..ecb093a8f6 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1029,7 +1029,7 @@ 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 auto terrain_type = tileElement.GetSurfaceObjectIndex(); const uint8_t surfaceShape = ViewportSurfacePaintSetupGetRelativeSlope(tileElement, rotation); const CoordsXY& base = session.SpritePosition; const CornerHeight& cornerHeights = corner_heights[surfaceShape]; @@ -1076,7 +1076,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con descriptor.tile_coords = TileCoordsXY{ position }; descriptor.tile_element = reinterpret_cast(surfaceElement); - descriptor.terrain = surfaceElement->GetSurfaceStyle(); + descriptor.terrain = surfaceElement->GetSurfaceObjectIndex(); descriptor.slope = surfaceSlope; descriptor.corner_heights.top = baseHeight + ch.top; descriptor.corner_heights.right = baseHeight + ch.right; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index a40003c398..16c7a26e58 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1579,7 +1579,7 @@ namespace RCT1 auto edgeStyle = _terrainEdgeTypeToEntryMap[src2->GetEdgeStyle()]; dst2->SetSlope(src2->GetSlope()); - dst2->SetSurfaceStyle(surfaceStyle); + dst2->SetSurfaceObjectIndex(surfaceStyle); dst2->SetEdgeStyle(edgeStyle); dst2->SetGrassLength(src2->GetGrassLength()); dst2->SetOwnership(src2->GetOwnership()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 8cf091931d..e38f701a2f 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1373,7 +1373,7 @@ namespace RCT2 dst2->SetSlope(src2->GetSlope()); - dst2->SetSurfaceStyle(src2->GetSurfaceStyle()); + dst2->SetSurfaceObjectIndex(src2->GetSurfaceStyle()); dst2->SetEdgeStyle(src2->GetEdgeStyle()); dst2->SetGrassLength(src2->GetGrassLength()); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 12a7782b1d..2f4356f01a 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -2228,7 +2228,7 @@ static void TrackDesignPreviewClearMap() element->SetLastForTile(true); element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT); element->AsSurface()->SetWaterHeight(0); - element->AsSurface()->SetSurfaceStyle(0); + element->AsSurface()->SetSurfaceObjectIndex(0); element->AsSurface()->SetEdgeStyle(0); element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0); element->AsSurface()->SetOwnership(OWNERSHIP_OWNED); diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 1fd3c55e88..94c494b702 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -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(); } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 3882cbd1e6..6d7a5eab54 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -158,7 +158,7 @@ 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()->SetSurfaceObjectIndex(0); el.AsSurface()->SetEdgeStyle(0); return el; } @@ -1352,7 +1352,7 @@ void MapRemoveOutOfRangeElements() static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile, SurfaceElement& destTile) { - destTile.SetSurfaceStyle(sourceTile.GetSurfaceStyle()); + destTile.SetSurfaceObjectIndex(sourceTile.GetSurfaceObjectIndex()); destTile.SetEdgeStyle(sourceTile.GetEdgeStyle()); destTile.SetGrassLength(sourceTile.GetGrassLength()); destTile.SetOwnership(OWNERSHIP_UNOWNED); @@ -1439,7 +1439,7 @@ 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()->SetSurfaceObjectIndex(0); element->AsSurface()->SetEdgeStyle(0); element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0); element->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED); diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 5a74d19e6c..cd8026565d 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -129,7 +129,7 @@ void MapGenGenerateBlank(MapGenSettings* settings) auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); if (surfaceElement != nullptr) { - surfaceElement->SetSurfaceStyle(settings->floor); + surfaceElement->SetSurfaceObjectIndex(settings->floor); surfaceElement->SetEdgeStyle(settings->wall); surfaceElement->BaseHeight = settings->height; surfaceElement->ClearanceHeight = settings->height; @@ -193,7 +193,7 @@ void MapGenGenerate(MapGenSettings* settings) auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); if (surfaceElement != nullptr) { - surfaceElement->SetSurfaceStyle(floorTextureId); + surfaceElement->SetSurfaceObjectIndex(floorTextureId); surfaceElement->SetEdgeStyle(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; diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 73209d4fdc..3f3ab83963 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -17,7 +17,7 @@ #include "Location.hpp" #include "Map.h" -ObjectEntryIndex SurfaceElement::GetSurfaceStyle() const +ObjectEntryIndex SurfaceElement::GetSurfaceObjectIndex() const { return SurfaceStyle; } @@ -25,7 +25,7 @@ ObjectEntryIndex SurfaceElement::GetSurfaceStyle() const TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const { auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceStyle())); + return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex())); } uint32_t SurfaceElement::GetEdgeStyle() const @@ -39,7 +39,7 @@ TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const return static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeStyle())); } -void SurfaceElement::SetSurfaceStyle(ObjectEntryIndex newStyle) +void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle) { SurfaceStyle = static_cast(newStyle); } @@ -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) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index a4d46079be..6b0b9937d5 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -205,9 +205,9 @@ public: uint8_t GetSlope() const; void SetSlope(uint8_t newSlope); - ObjectEntryIndex GetSurfaceStyle() const; + ObjectEntryIndex GetSurfaceObjectIndex() const; TerrainSurfaceObject* GetSurfaceStyleObject() const; - void SetSurfaceStyle(ObjectEntryIndex newStyle); + void SetSurfaceObjectIndex(ObjectEntryIndex newStyle); uint32_t GetEdgeStyle() const; TerrainEdgeObject* GetEdgeStyleObject() const; diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index b956ead827..aba206e43e 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -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() From 263079f3882cb8ebe6eedaf7e1a370bc952a16cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 26 Aug 2023 20:55:32 +0300 Subject: [PATCH 3/7] Use ObjectEntryIndex for edge object index --- src/openrct2/world/Surface.cpp | 8 ++++---- src/openrct2/world/TileElement.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 3f3ab83963..347a767088 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -28,9 +28,9 @@ TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex())); } -uint32_t SurfaceElement::GetEdgeStyle() const +ObjectEntryIndex SurfaceElement::GetEdgeStyle() const { - return EdgeStyle; + return EdgeObjectIndex; } TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const @@ -44,9 +44,9 @@ void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle) SurfaceStyle = static_cast(newStyle); } -void SurfaceElement::SetEdgeStyle(uint32_t newStyle) +void SurfaceElement::SetEdgeStyle(ObjectEntryIndex newIndex) { - EdgeStyle = newStyle; + EdgeObjectIndex = static_cast(newIndex); } int32_t SurfaceElement::GetWaterHeight() const diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 6b0b9937d5..e5d0bff3cc 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -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]; @@ -209,9 +209,9 @@ public: TerrainSurfaceObject* GetSurfaceStyleObject() const; void SetSurfaceObjectIndex(ObjectEntryIndex newStyle); - uint32_t GetEdgeStyle() const; + ObjectEntryIndex GetEdgeStyle() const; TerrainEdgeObject* GetEdgeStyleObject() const; - void SetEdgeStyle(uint32_t newStyle); + void SetEdgeStyle(ObjectEntryIndex newStyle); bool CanGrassGrow() const; uint8_t GetGrassLength() const; From 45afc1f67bccb2b55ffb3f02752440f5e0782104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 26 Aug 2023 21:01:27 +0300 Subject: [PATCH 4/7] Properly name setter/getter for edge object index --- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/actions/SurfaceSetStyleAction.cpp | 6 +++--- src/openrct2/paint/tile_element/Paint.Surface.cpp | 4 ++-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/scripting/bindings/world/ScTileElement.cpp | 4 ++-- src/openrct2/world/Map.cpp | 6 +++--- src/openrct2/world/MapGen.cpp | 4 ++-- src/openrct2/world/Surface.cpp | 8 ++++---- src/openrct2/world/TileElement.h | 6 +++--- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a8642f5e8f..e821c68513 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -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(); diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index de6c3a36a6..d6bd5f1fb4 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -151,7 +151,7 @@ void SetupInUseSelectionFlags() { auto surfaceEl = iter.element->AsSurface(); auto surfaceIndex = surfaceEl->GetSurfaceObjectIndex(); - auto edgeIndex = surfaceEl->GetEdgeStyle(); + auto edgeIndex = surfaceEl->GetEdgeObjectIndex(); Editor::SetSelectedObject(ObjectType::TerrainSurface, surfaceIndex, ObjectSelectionFlags::InUse); Editor::SetSelectedObject(ObjectType::TerrainEdge, edgeIndex, ObjectSelectionFlags::InUse); diff --git a/src/openrct2/actions/SurfaceSetStyleAction.cpp b/src/openrct2/actions/SurfaceSetStyleAction.cpp index 266bf1614a..e4c9e8b6b1 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.cpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.cpp @@ -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) { @@ -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); } } diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index ecb093a8f6..a09298289a 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1306,7 +1306,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con if (!(session.ViewFlags & VIEWPORT_FLAG_HIDE_VERTICAL)) { - const auto edgeStyle = tileElement.GetEdgeStyle(); + const auto edgeStyle = tileElement.GetEdgeObjectIndex(); if (static_cast(edgeStyle) >= object_entry_group_counts[EnumValue(ObjectType::TerrainEdge)]) { LOG_VERBOSE("edgeStyle: %d", edgeStyle); @@ -1346,7 +1346,7 @@ 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(); + const uint32_t edgeStyle = tileElement.GetEdgeObjectIndex(); // end new code ViewportSurfaceDrawWaterSideBottom( diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 16c7a26e58..d17d7bf052 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1580,7 +1580,7 @@ namespace RCT1 dst2->SetSlope(src2->GetSlope()); dst2->SetSurfaceObjectIndex(surfaceStyle); - dst2->SetEdgeStyle(edgeStyle); + dst2->SetEdgeObjectIndex(edgeStyle); dst2->SetGrassLength(src2->GetGrassLength()); dst2->SetOwnership(src2->GetOwnership()); dst2->SetParkFences(src2->GetParkFences()); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index e38f701a2f..0c9b780677 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1374,7 +1374,7 @@ namespace RCT2 dst2->SetSlope(src2->GetSlope()); dst2->SetSurfaceObjectIndex(src2->GetSurfaceStyle()); - dst2->SetEdgeStyle(src2->GetEdgeStyle()); + dst2->SetEdgeObjectIndex(src2->GetEdgeStyle()); dst2->SetGrassLength(src2->GetGrassLength()); dst2->SetOwnership(src2->GetOwnership()); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 2f4356f01a..c400d922d2 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -2229,7 +2229,7 @@ static void TrackDesignPreviewClearMap() element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT); element->AsSurface()->SetWaterHeight(0); element->AsSurface()->SetSurfaceObjectIndex(0); - element->AsSurface()->SetEdgeStyle(0); + element->AsSurface()->SetEdgeObjectIndex(0); element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0); element->AsSurface()->SetOwnership(OWNERSHIP_OWNED); element->AsSurface()->SetParkFences(0); diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 94c494b702..17f7072ac4 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -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(); } diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 6d7a5eab54..921d887654 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -159,7 +159,7 @@ static TileElement GetDefaultSurfaceElement() el.AsSurface()->SetOwnership(OWNERSHIP_UNOWNED); el.AsSurface()->SetParkFences(0); el.AsSurface()->SetSurfaceObjectIndex(0); - el.AsSurface()->SetEdgeStyle(0); + el.AsSurface()->SetEdgeObjectIndex(0); return el; } @@ -1353,7 +1353,7 @@ void MapRemoveOutOfRangeElements() static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile, SurfaceElement& destTile) { destTile.SetSurfaceObjectIndex(sourceTile.GetSurfaceObjectIndex()); - destTile.SetEdgeStyle(sourceTile.GetEdgeStyle()); + destTile.SetEdgeObjectIndex(sourceTile.GetEdgeObjectIndex()); destTile.SetGrassLength(sourceTile.GetGrassLength()); destTile.SetOwnership(OWNERSHIP_UNOWNED); destTile.SetWaterHeight(sourceTile.GetWaterHeight()); @@ -1440,7 +1440,7 @@ static void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) element->Owner = 0; element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT); element->AsSurface()->SetSurfaceObjectIndex(0); - element->AsSurface()->SetEdgeStyle(0); + element->AsSurface()->SetEdgeObjectIndex(0); element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0); element->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED); element->AsSurface()->SetParkFences(0); diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index cd8026565d..3111d04391 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -130,7 +130,7 @@ void MapGenGenerateBlank(MapGenSettings* settings) if (surfaceElement != nullptr) { surfaceElement->SetSurfaceObjectIndex(settings->floor); - surfaceElement->SetEdgeStyle(settings->wall); + surfaceElement->SetEdgeObjectIndex(settings->wall); surfaceElement->BaseHeight = settings->height; surfaceElement->ClearanceHeight = settings->height; } @@ -194,7 +194,7 @@ void MapGenGenerate(MapGenSettings* settings) if (surfaceElement != nullptr) { surfaceElement->SetSurfaceObjectIndex(floorTextureId); - surfaceElement->SetEdgeStyle(edgeTextureId); + surfaceElement->SetEdgeObjectIndex(edgeTextureId); surfaceElement->BaseHeight = settings->height; surfaceElement->ClearanceHeight = settings->height; } diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 347a767088..8ad69c7236 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -28,15 +28,15 @@ TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex())); } -ObjectEntryIndex SurfaceElement::GetEdgeStyle() const +ObjectEntryIndex SurfaceElement::GetEdgeObjectIndex() const { return EdgeObjectIndex; } -TerrainEdgeObject* SurfaceElement::GetEdgeStyleObject() const +TerrainEdgeObject* SurfaceElement::GetEdgeObject() const { auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeStyle())); + return static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeObjectIndex())); } void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle) @@ -44,7 +44,7 @@ void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle) SurfaceStyle = static_cast(newStyle); } -void SurfaceElement::SetEdgeStyle(ObjectEntryIndex newIndex) +void SurfaceElement::SetEdgeObjectIndex(ObjectEntryIndex newIndex) { EdgeObjectIndex = static_cast(newIndex); } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index e5d0bff3cc..d71716ab04 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -209,9 +209,9 @@ public: TerrainSurfaceObject* GetSurfaceStyleObject() const; void SetSurfaceObjectIndex(ObjectEntryIndex newStyle); - ObjectEntryIndex GetEdgeStyle() const; - TerrainEdgeObject* GetEdgeStyleObject() const; - void SetEdgeStyle(ObjectEntryIndex newStyle); + ObjectEntryIndex GetEdgeObjectIndex() const; + TerrainEdgeObject* GetEdgeObject() const; + void SetEdgeObjectIndex(ObjectEntryIndex newStyle); bool CanGrassGrow() const; uint8_t GetGrassLength() const; From 1f496173b170173bae686734a6bcc7b65110f7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:05:38 +0300 Subject: [PATCH 5/7] Pass the surface and edge style object instead of repetitive lookups --- .../paint/tile_element/Paint.Surface.cpp | 179 +++++++----------- 1 file changed, 68 insertions(+), 111 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index a09298289a..45259ceb8b 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -217,7 +217,7 @@ struct TileDescriptor { TileCoordsXY tile_coords; const TileElement* tile_element; - ObjectEntryIndex 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(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(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(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 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.GetSurfaceObjectIndex(); const uint8_t surfaceShape = ViewportSurfacePaintSetupGetRelativeSlope(tileElement, rotation); const CoordsXY& base = session.SpritePosition; const CornerHeight& cornerHeights = corner_heights[surfaceShape]; const TileElement* elementPtr = &reinterpret_cast(tileElement); + const auto* surfaceObject = tileElement.GetSurfaceStyleObject(); + const auto* edgeObject = tileElement.GetEdgeObject(); + TileDescriptor selfDescriptor = { TileCoordsXY(base), elementPtr, - terrain_type, + surfaceObject, surfaceShape, { static_cast(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(surfaceElement); - descriptor.terrain = surfaceElement->GetSurfaceObjectIndex(); + descriptor.surfaceObject = surfaceElement->GetSurfaceStyleObject(); 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.GetEdgeObjectIndex(); - if (static_cast(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.GetEdgeObjectIndex(); - // 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]); } } From 9ee785c7c0f3f322b278b9c5cf35c504206f6450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:18:25 +0300 Subject: [PATCH 6/7] Remove unused includes --- src/openrct2/paint/tile_element/Paint.Path.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 0e667c06b1..a03eed8ba0 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -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" From cb6e9e5df360d48d4229f6dac6b6f74f287ac70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:25:25 +0300 Subject: [PATCH 7/7] Rename GetSurfaceStyleObject to GetSurfaceObject --- src/openrct2-ui/windows/Map.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2/paint/tile_element/Paint.Surface.cpp | 4 ++-- src/openrct2/world/Surface.cpp | 2 +- src/openrct2/world/TileElement.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 15caa4aa41..63be554ad9 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -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]); diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index e821c68513..735d857a0a 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -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(); diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 45259ceb8b..5fb3803850 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -998,7 +998,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con const CornerHeight& cornerHeights = corner_heights[surfaceShape]; const TileElement* elementPtr = &reinterpret_cast(tileElement); - const auto* surfaceObject = tileElement.GetSurfaceStyleObject(); + const auto* surfaceObject = tileElement.GetSurfaceObject(); const auto* edgeObject = tileElement.GetEdgeObject(); TileDescriptor selfDescriptor = { @@ -1042,7 +1042,7 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con descriptor.tile_coords = TileCoordsXY{ position }; descriptor.tile_element = reinterpret_cast(surfaceElement); - descriptor.surfaceObject = surfaceElement->GetSurfaceStyleObject(); + descriptor.surfaceObject = surfaceElement->GetSurfaceObject(); descriptor.slope = surfaceSlope; descriptor.corner_heights.top = baseHeight + ch.top; descriptor.corner_heights.right = baseHeight + ch.right; diff --git a/src/openrct2/world/Surface.cpp b/src/openrct2/world/Surface.cpp index 8ad69c7236..11c09b46a6 100644 --- a/src/openrct2/world/Surface.cpp +++ b/src/openrct2/world/Surface.cpp @@ -22,7 +22,7 @@ ObjectEntryIndex SurfaceElement::GetSurfaceObjectIndex() const return SurfaceStyle; } -TerrainSurfaceObject* SurfaceElement::GetSurfaceStyleObject() const +TerrainSurfaceObject* SurfaceElement::GetSurfaceObject() const { auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex())); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index d71716ab04..40df792e67 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -206,7 +206,7 @@ public: void SetSlope(uint8_t newSlope); ObjectEntryIndex GetSurfaceObjectIndex() const; - TerrainSurfaceObject* GetSurfaceStyleObject() const; + TerrainSurfaceObject* GetSurfaceObject() const; void SetSurfaceObjectIndex(ObjectEntryIndex newStyle); ObjectEntryIndex GetEdgeObjectIndex() const;