From 67bd23ed589ec2777bf504ede1673743468c3bfb Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 13 May 2024 00:18:21 -0700 Subject: [PATCH] make names more consistent --- src/openrct2/libopenrct2.vcxproj | 4 +- src/openrct2/object/LargeSceneryEntry.h | 2 +- src/openrct2/object/LargeSceneryObject.cpp | 38 +-- src/openrct2/object/SceneryBoundingBox.cpp | 261 --------------------- src/openrct2/object/SceneryBoundingBox.h | 49 ---- src/openrct2/object/SmallSceneryEntry.h | 2 +- src/openrct2/object/SmallSceneryObject.cpp | 12 +- 7 files changed, 29 insertions(+), 339 deletions(-) delete mode 100644 src/openrct2/object/SceneryBoundingBox.cpp delete mode 100644 src/openrct2/object/SceneryBoundingBox.h diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index df292a4b0e67..ede1fb4ac3b0 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -339,7 +339,7 @@ - + @@ -843,7 +843,7 @@ - + diff --git a/src/openrct2/object/LargeSceneryEntry.h b/src/openrct2/object/LargeSceneryEntry.h index 53b675514d36..9ed717518b48 100644 --- a/src/openrct2/object/LargeSceneryEntry.h +++ b/src/openrct2/object/LargeSceneryEntry.h @@ -24,7 +24,7 @@ struct LargeSceneryTile uint8_t z_clearance; // CCCC WWWW 0SS0 0000 uint16_t flags; - SceneryBoundBoxes boundBoxes = {}; + SceneryBoundboxes boundBoxes = {}; CoordsXYZ spriteOffset = {}; }; diff --git a/src/openrct2/object/LargeSceneryObject.cpp b/src/openrct2/object/LargeSceneryObject.cpp index b89c949e6ca6..947842689a03 100644 --- a/src/openrct2/object/LargeSceneryObject.cpp +++ b/src/openrct2/object/LargeSceneryObject.cpp @@ -19,28 +19,28 @@ #include "../localisation/Language.h" #include "../world/Banner.h" #include "../world/Location.hpp" -#include "SceneryBoundingBox.h" +#include "SceneryBoundbox.h" #include #include -static DefaultBoundingBoxType boundBoxTypes[16] = { - DefaultBoundingBoxType::FullTileBox, // 0000 - DefaultBoundingBoxType::FullTileSouthQuadrantBox, // 0001 - DefaultBoundingBoxType::FullTileWestQuadrantBox, // 0010 - DefaultBoundingBoxType::FullTileSouthwestSideBox, // 0011 - DefaultBoundingBoxType::FullTileNorthQuadrantBox, // 0100 - DefaultBoundingBoxType::FullTileBox, // 0101 (diagonal of South and North corners) - DefaultBoundingBoxType::FullTileNorthwestSideBox, // 0110 - DefaultBoundingBoxType::FullTileBox, // 0111 (triangle of South, West, and North corners) - DefaultBoundingBoxType::FullTileEastQuadrantBox, // 1000 - DefaultBoundingBoxType::FullTileSoutheastSideBox, // 1001 - DefaultBoundingBoxType::FullTileBox, // 1010 (diagonal of East and West corners) - DefaultBoundingBoxType::FullTileBox, // 1011 (triangle of South, West, and East corners) - DefaultBoundingBoxType::FullTileNortheastSideBox, // 1100 - DefaultBoundingBoxType::FullTileBox, // 1101 (triangle of South, West, and North corners) - DefaultBoundingBoxType::FullTileBox, // 1110 (triangle of West, North, and East corners) - DefaultBoundingBoxType::FullTileBox, // 1111 +static DefaultBoundBoxType boundBoxTypes[16] = { + DefaultBoundBoxType::FullTileBox, // 0000 + DefaultBoundBoxType::FullTileSouthQuadrantBox, // 0001 + DefaultBoundBoxType::FullTileWestQuadrantBox, // 0010 + DefaultBoundBoxType::FullTileSouthwestSideBox, // 0011 + DefaultBoundBoxType::FullTileNorthQuadrantBox, // 0100 + DefaultBoundBoxType::FullTileBox, // 0101 (diagonal of South and North corners) + DefaultBoundBoxType::FullTileNorthwestSideBox, // 0110 + DefaultBoundBoxType::FullTileBox, // 0111 (triangle of South, West, and North corners) + DefaultBoundBoxType::FullTileEastQuadrantBox, // 1000 + DefaultBoundBoxType::FullTileSoutheastSideBox, // 1001 + DefaultBoundBoxType::FullTileBox, // 1010 (diagonal of East and West corners) + DefaultBoundBoxType::FullTileBox, // 1011 (triangle of South, West, and East corners) + DefaultBoundBoxType::FullTileNortheastSideBox, // 1100 + DefaultBoundBoxType::FullTileBox, // 1101 (triangle of South, West, and North corners) + DefaultBoundBoxType::FullTileBox, // 1110 (triangle of West, North, and East corners) + DefaultBoundBoxType::FullTileBox, // 1111 }; static int32_t getBoundBoxHeight(uint8_t clearanceHeight) @@ -56,7 +56,7 @@ static void SetTileBoundingBox(LargeSceneryTile& tile) } else { - tile.boundBoxes = GetDefaultSceneryBoundBoxes(DefaultBoundingBoxType::FullTileLargeBox); + tile.boundBoxes = GetDefaultSceneryBoundBoxes(DefaultBoundBoxType::FullTileLargeBox); } tile.spriteOffset = GetDefaultSpriteOffset(DefaultSpriteOffsetType::LargeSceneryOffset); diff --git a/src/openrct2/object/SceneryBoundingBox.cpp b/src/openrct2/object/SceneryBoundingBox.cpp deleted file mode 100644 index 5c8ade07b480..000000000000 --- a/src/openrct2/object/SceneryBoundingBox.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/***************************************************************************** - * 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 "SceneryBoundingBox.h" - -static constexpr std::array DefaultSpriteOffsets = { - CoordsXYZ(7, 7, 0), // quarter tile - CoordsXYZ(15, 15, 0), // small scenery full tile w/o VOFFSET_CENTRE - CoordsXYZ(3, 3, 0), // small scenery halftile/VOFFSET_CENTRE - CoordsXYZ(1, 1, 0), // small scenery VOFFSET_CENTER+NO_WALLS - CoordsXYZ(0, 0, 0), // large scenery -}; - -static constexpr SceneryBoundBoxes QuarterTile = { - BoundBoxXYZ({ 7, 7, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 7, 7, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 7, 7, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 7, 7, 0 }, { 2, 2, 0 }), -}; - -static constexpr SceneryBoundBoxes HalfTile = { - BoundBoxXYZ({ 3, 3, 0 }, { 12, 26, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 26, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 26, 12, 0 }), -}; - -// LargeSpecial corner/side match sub-fulltile large scenery boundboxes -static constexpr SceneryBoundBoxes FullTileNorthQuadrant = { - BoundBoxXYZ({ 3, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileNortheastSide = { - BoundBoxXYZ({ 3, 3, 0 }, { 12, 28, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 26, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 28, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileEastQuadrant = { - BoundBoxXYZ({ 3, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileSoutheastSide = { - BoundBoxXYZ({ 3, 17, 0 }, { 26, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 28, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 28, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileSouthQuadrant = { - BoundBoxXYZ({ 17, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 12, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileSouthwestSide = { - BoundBoxXYZ({ 17, 3, 0 }, { 12, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 28, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 28, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 26, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileWestQuadrant = { - BoundBoxXYZ({ 17, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 12, 12, 0 }), - BoundBoxXYZ({ 17, 17, 0 }, { 12, 12, 0 }), -}; -static constexpr SceneryBoundBoxes FullTileNorthwestSide = { - BoundBoxXYZ({ 3, 3, 0 }, { 28, 12, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 12, 28, 0 }), - BoundBoxXYZ({ 3, 17, 0 }, { 26, 12, 0 }), - BoundBoxXYZ({ 17, 3, 0 }, { 12, 26, 0 }), -}; - -// LargeSpecialCenter matches large scenery with allowed walls and small scenery with SMALL_SCENERY_FLAG_VOFFSET_CENTRE -static constexpr SceneryBoundBoxes FullTile = { - BoundBoxXYZ({ 3, 3, 0 }, { 26, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 26, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 26, 26, 0 }), - BoundBoxXYZ({ 3, 3, 0 }, { 26, 26, 0 }), -}; - -// Large matches large scenery and small scenery that do not allow walls. -static constexpr SceneryBoundBoxes FullTileLarge = { - BoundBoxXYZ({ 1, 1, 0 }, { 30, 30, 0 }), - BoundBoxXYZ({ 1, 1, 0 }, { 30, 30, 0 }), - BoundBoxXYZ({ 1, 1, 0 }, { 30, 30, 0 }), - BoundBoxXYZ({ 1, 1, 0 }, { 30, 30, 0 }), -}; - -// Small Scenery without VOFFSET_CENTRE flag set -static constexpr SceneryBoundBoxes FullTileThin = { - BoundBoxXYZ({ 15, 15, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 15, 15, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 15, 15, 0 }, { 2, 2, 0 }), - BoundBoxXYZ({ 15, 15, 0 }, { 2, 2, 0 }), -}; - -static constexpr std::array boundBoxes = { - QuarterTile, - HalfTile, - FullTileNorthQuadrant, - FullTileNortheastSide, - FullTileEastQuadrant, - FullTileSoutheastSide, - FullTileSouthQuadrant, - FullTileSouthwestSide, - FullTileWestQuadrant, - FullTileNorthwestSide, - FullTile, - FullTileLarge, - FullTileThin, -}; - -#pragma endregion - -static const EnumMap BBoxTypeLookup = { - { "quarterTile", DefaultBoundingBoxType::QuarterTileBox }, - { "halfTile", DefaultBoundingBoxType::HalfTileBox }, - { "cornerNorth", DefaultBoundingBoxType::FullTileNorthQuadrantBox }, - { "sideNortheast", DefaultBoundingBoxType::FullTileNortheastSideBox }, - { "cornerEast", DefaultBoundingBoxType::FullTileEastQuadrantBox }, - { "sideSoutheast", DefaultBoundingBoxType::FullTileSoutheastSideBox }, - { "cornerSouth", DefaultBoundingBoxType::FullTileSouthQuadrantBox }, - { "sideSouthwest", DefaultBoundingBoxType::FullTileSouthwestSideBox }, - { "cornerEast", DefaultBoundingBoxType::FullTileWestQuadrantBox }, - { "sideNorthwest", DefaultBoundingBoxType::FullTileNorthwestSideBox }, - { "fullTile", DefaultBoundingBoxType::FullTileBox }, - { "fullTileLarge", DefaultBoundingBoxType::FullTileLargeBox }, - { "fullTileThin", DefaultBoundingBoxType::FullTileThinBox } -}; - -static DefaultBoundingBoxType GetBoundingBoxTypeFromString(const std::string& s) -{ - auto result = BBoxTypeLookup.find(s); - return (result != BBoxTypeLookup.end()) ? result->second : DefaultBoundingBoxType::FullTileBox; -} - -SceneryBoundBoxes GetDefaultSceneryBoundBoxes(DefaultBoundingBoxType type) -{ - if (type >= DefaultBoundingBoxType::CountBox) - return boundBoxes[DefaultBoundingBoxType::FullTileBox]; - return boundBoxes[type]; -} - -static BoundBoxXYZ ReadBoundBox(json_t& box) -{ - auto jOffset = box["offset"]; - auto jLength = box["size"]; - - Guard::Assert( - jOffset.is_array() && jLength.is_array() && jOffset.size() >= 3 && jLength.size() >= 3, - "ReadBoundBox expects arrays 'offset' and 'size' with 3 elements"); - BoundBoxXYZ boundBox = { - { - Json::GetNumber(jOffset[0], 0), - Json::GetNumber(jOffset[1], 0), - Json::GetNumber(jOffset[2], 0), - }, - { - Json::GetNumber(jLength[0], 0), - Json::GetNumber(jLength[1], 0), - Json::GetNumber(jLength[2], 0), - }, - }; - return boundBox; -} - -// Rotates a BoundBoxXYZ clockwise 90 degrees around the vertical axis. -static BoundBoxXYZ RotateBoundBox(BoundBoxXYZ box, CoordsXY rotationCenter) -{ - CoordsXYZ rotatedLength = { box.length.y, box.length.x, box.length.z }; - // equations are performed in double scale to avoid decimals - CoordsXY relativeCentroid = box.offset * 2 + box.length - rotationCenter * 2; - CoordsXY rotatedCentroid = { relativeCentroid.y, -relativeCentroid.x }; - CoordsXY newCorner = (rotatedCentroid - rotatedLength) / 2 + rotationCenter; - return { { newCorner.x, newCorner.y, box.offset.z }, rotatedLength }; -} - -SceneryBoundBoxes ReadBoundBoxes(json_t& jBBox, int32_t defaultHeight, bool fullTile) -{ - SceneryBoundBoxes boxes; - if (jBBox.is_array()) - { - Guard::Assert(jBBox.size() >= 4, "boundBox arrays require four elements, one for each view angle"); - // array of four bboxes - for (uint8_t i = 0; i < NumOrthogonalDirections; i++) - boxes[i] = ReadBoundBox(jBBox[i]); - } - else if (jBBox.is_object()) - { - // single box, rotated around (16, 16) if fulltile or (8,8) if quarter tile - CoordsXY rotationCenter = { 8, 8 }; - if (fullTile) - { - rotationCenter = { 16, 16 }; - } - auto bBox = ReadBoundBox(jBBox); - boxes[0] = bBox; - boxes[1] = RotateBoundBox(bBox, rotationCenter); - boxes[2] = RotateBoundBox(boxes[1], rotationCenter); - boxes[3] = RotateBoundBox(boxes[2], rotationCenter); - } - else - { - Guard::Assert( - jBBox.is_string(), - "boundBox must be an array of four boundBox objects, a single boundBox object, or a string matching the " - "DefaultBoundingBoxType enum."); - boxes = GetDefaultSceneryBoundBoxes(GetBoundingBoxTypeFromString(Json::GetString(jBBox))); - for (uint8_t i = 0; i < NumOrthogonalDirections; i++) - boxes[i].length.z = defaultHeight; - } - return boxes; -} - -static const EnumMap SpriteOffsetLookup = { - { "quarterTile", DefaultSpriteOffsetType::QuarterTileOffset }, - { "fullTileThin", DefaultSpriteOffsetType::FullTileThinOffset }, - { "halfTile", DefaultSpriteOffsetType::FullTileOffset }, - { "fullTile", DefaultSpriteOffsetType::FullTileOffset }, - { "fullTileLarge", DefaultSpriteOffsetType::FullTileLargeOffset }, - { "largeScenery", DefaultSpriteOffsetType::LargeSceneryOffset }, -}; - -static DefaultSpriteOffsetType GetSpriteOffsetTypeFromString(const std::string& s) -{ - auto result = SpriteOffsetLookup.find(s); - return (result != SpriteOffsetLookup.end()) ? result->second : DefaultSpriteOffsetType::LargeSceneryOffset; -} - -CoordsXYZ GetDefaultSpriteOffset(DefaultSpriteOffsetType type) -{ - if (type >= DefaultSpriteOffsetType::CountOffset) - return DefaultSpriteOffsets[DefaultSpriteOffsetType::LargeSceneryOffset]; - return DefaultSpriteOffsets[type]; -} - -CoordsXYZ ReadSpriteOffset(json_t& jCoords) -{ - if (jCoords.is_string()) - { - return DefaultSpriteOffsets[GetSpriteOffsetTypeFromString(Json::GetString(jCoords))]; - } - Guard::Assert(jCoords.is_array() && jCoords.size() >= 3, "spriteOffsetCoordinates must be an array with three elements"); - CoordsXYZ coordinates = { - Json::GetNumber(jCoords[0], 0), - Json::GetNumber(jCoords[1], 0), - Json::GetNumber(jCoords[2], 0), - }; - return coordinates; -} diff --git a/src/openrct2/object/SceneryBoundingBox.h b/src/openrct2/object/SceneryBoundingBox.h deleted file mode 100644 index 92aac01280dd..000000000000 --- a/src/openrct2/object/SceneryBoundingBox.h +++ /dev/null @@ -1,49 +0,0 @@ -/***************************************************************************** - * 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 "../core/EnumMap.hpp" -#include "../core/Json.hpp" -#include "../core/Memory.hpp" -#include "../paint/Boundbox.h" -#include "../world/Scenery.h" - -enum DefaultBoundingBoxType : uint8_t -{ - QuarterTileBox, - HalfTileBox, - FullTileNorthQuadrantBox, - FullTileNortheastSideBox, - FullTileEastQuadrantBox, - FullTileSoutheastSideBox, - FullTileSouthQuadrantBox, - FullTileSouthwestSideBox, - FullTileWestQuadrantBox, - FullTileNorthwestSideBox, - FullTileBox, - FullTileLargeBox, - FullTileThinBox, - CountBox -}; - -enum DefaultSpriteOffsetType : uint8_t -{ - QuarterTileOffset, - FullTileThinOffset, - FullTileOffset, - FullTileLargeOffset, - LargeSceneryOffset, - CountOffset -}; - -SceneryBoundBoxes GetDefaultSceneryBoundBoxes(DefaultBoundingBoxType type); -SceneryBoundBoxes ReadBoundBoxes(json_t& jBBox, int32_t defaultHeight, bool fullTile); -CoordsXYZ GetDefaultSpriteOffset(DefaultSpriteOffsetType type); -CoordsXYZ ReadSpriteOffset(json_t& jCoords); diff --git a/src/openrct2/object/SmallSceneryEntry.h b/src/openrct2/object/SmallSceneryEntry.h index 26dc38569cd5..052f51a68bf7 100644 --- a/src/openrct2/object/SmallSceneryEntry.h +++ b/src/openrct2/object/SmallSceneryEntry.h @@ -68,7 +68,7 @@ struct SmallSceneryEntry uint16_t animation_mask; uint16_t num_frames; ObjectEntryIndex scenery_tab_id; - SceneryBoundBoxes boundBoxes; + SceneryBoundboxes boundBoxes; CoordsXYZ spriteOffset; constexpr bool HasFlag(const uint32_t _flags) const diff --git a/src/openrct2/object/SmallSceneryObject.cpp b/src/openrct2/object/SmallSceneryObject.cpp index 18f1bef2874b..7ac8da1ea894 100644 --- a/src/openrct2/object/SmallSceneryObject.cpp +++ b/src/openrct2/object/SmallSceneryObject.cpp @@ -19,7 +19,7 @@ #include "../interface/Cursors.h" #include "../localisation/Language.h" #include "../world/Scenery.h" -#include "SceneryBoundingBox.h" +#include "SceneryBoundbox.h" #include @@ -297,26 +297,26 @@ static int32_t getBoundBoxHeight(uint8_t clearanceHeight) void SmallSceneryObject::SetBoundingBoxFromFlags() { - DefaultBoundingBoxType boundBoxType = DefaultBoundingBoxType::QuarterTileBox; + DefaultBoundBoxType boundBoxType = DefaultBoundBoxType::QuarterTileBox; DefaultSpriteOffsetType spriteOffsetType = DefaultSpriteOffsetType::QuarterTileOffset; if (_legacyType.HasFlag(SMALL_SCENERY_FLAG_FULL_TILE)) { - boundBoxType = DefaultBoundingBoxType::FullTileThinBox; + boundBoxType = DefaultBoundBoxType::FullTileThinBox; spriteOffsetType = DefaultSpriteOffsetType::FullTileThinOffset; if (_legacyType.HasFlag(SMALL_SCENERY_FLAG_HALF_SPACE)) { spriteOffsetType = DefaultSpriteOffsetType::FullTileOffset; - boundBoxType = DefaultBoundingBoxType::HalfTileBox; + boundBoxType = DefaultBoundBoxType::HalfTileBox; } else { if (_legacyType.HasFlag(SMALL_SCENERY_FLAG_VOFFSET_CENTRE)) { - boundBoxType = DefaultBoundingBoxType::FullTileBox; + boundBoxType = DefaultBoundBoxType::FullTileBox; spriteOffsetType = DefaultSpriteOffsetType::FullTileOffset; if (_legacyType.HasFlag(SMALL_SCENERY_FLAG_NO_WALLS)) { - boundBoxType = DefaultBoundingBoxType::FullTileLargeBox; + boundBoxType = DefaultBoundBoxType::FullTileLargeBox; spriteOffsetType = DefaultSpriteOffsetType::FullTileLargeOffset; } }