From 8063c5caa76bcb2d1db5559ba1df8e1e46c9c62e Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:12:25 +0200 Subject: [PATCH] Reduce casting for objects --- src/openrct2-ui/interface/LandTool.cpp | 8 ++++---- src/openrct2-ui/windows/EditorParkEntrance.cpp | 2 +- src/openrct2-ui/windows/Footpath.cpp | 2 +- src/openrct2-ui/windows/NewRide.cpp | 6 +++--- src/openrct2-ui/windows/Ride.cpp | 8 ++++---- src/openrct2/actions/SurfaceSetStyleAction.cpp | 2 +- src/openrct2/localisation/Formatting.cpp | 2 +- src/openrct2/object/AudioObject.h | 2 ++ src/openrct2/object/BannerObject.h | 2 ++ src/openrct2/object/EntranceObject.h | 2 ++ src/openrct2/object/FootpathObject.h | 2 ++ src/openrct2/object/FootpathRailingsObject.h | 2 ++ src/openrct2/object/FootpathSurfaceObject.h | 2 ++ src/openrct2/object/LargeSceneryObject.h | 2 ++ src/openrct2/object/MusicObject.h | 2 ++ src/openrct2/object/ObjectManager.h | 4 ++++ src/openrct2/object/PathAdditionObject.h | 2 ++ src/openrct2/object/PeepNamesObject.h | 2 ++ src/openrct2/object/RideObject.h | 2 ++ src/openrct2/object/SceneryGroupObject.h | 2 ++ src/openrct2/object/SmallSceneryObject.h | 2 ++ src/openrct2/object/StationObject.h | 2 ++ src/openrct2/object/TerrainEdgeObject.h | 2 ++ src/openrct2/object/TerrainSurfaceObject.h | 2 ++ src/openrct2/object/WallObject.h | 2 ++ src/openrct2/object/WaterObject.h | 2 ++ src/openrct2/ride/Ride.cpp | 6 +++--- src/openrct2/ride/RideAudio.cpp | 4 ++-- src/openrct2/scripting/bindings/object/ScObject.hpp | 10 ++++------ src/openrct2/world/Footpath.cpp | 2 +- src/openrct2/world/tile_element/EntranceElement.cpp | 4 ++-- src/openrct2/world/tile_element/PathElement.cpp | 4 ++-- src/openrct2/world/tile_element/SurfaceElement.cpp | 4 ++-- 33 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/openrct2-ui/interface/LandTool.cpp b/src/openrct2-ui/interface/LandTool.cpp index a52541b77b..aceeedf02d 100644 --- a/src/openrct2-ui/interface/LandTool.cpp +++ b/src/openrct2-ui/interface/LandTool.cpp @@ -60,7 +60,7 @@ void LandTool::ShowSurfaceStyleDropdown(WindowBase* w, Widget* widget, ObjectEnt auto itemIndex = 0; for (size_t i = 0; i < kMaxTerrainSurfaceObjects; i++) { - const auto surfaceObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, i)); + const auto surfaceObj = objManager.GetLoadedObject(i); // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. if (surfaceObj != nullptr && !surfaceObj->UsesFallbackImages()) { @@ -92,7 +92,7 @@ ObjectEntryIndex LandTool::GetSurfaceStyleFromDropdownIndex(size_t index) auto itemIndex = 0U; for (size_t i = 0; i < kMaxTerrainSurfaceObjects; i++) { - const auto surfaceObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, i)); + const auto surfaceObj = objManager.GetLoadedObject(i); // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. if (surfaceObj != nullptr && !surfaceObj->UsesFallbackImages()) { @@ -114,7 +114,7 @@ void LandTool::ShowEdgeStyleDropdown(WindowBase* w, Widget* widget, ObjectEntryI auto itemIndex = 0; for (size_t i = 0; i < kMaxTerrainEdgeObjects; i++) { - const auto edgeObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, i)); + const auto edgeObj = objManager.GetLoadedObject(i); // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. if (edgeObj != nullptr && !edgeObj->UsesFallbackImages()) { @@ -143,7 +143,7 @@ ObjectEntryIndex LandTool::GetEdgeStyleFromDropdownIndex(size_t index) auto itemIndex = 0U; for (size_t i = 0; i < kMaxTerrainEdgeObjects; i++) { - const auto edgeObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, i)); + const auto edgeObj = objManager.GetLoadedObject(i); // If fallback images are loaded, the RCT1 styles will just look like copies of already existing styles, so hide them. if (edgeObj != nullptr && !edgeObj->UsesFallbackImages()) { diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index fcaa1fdd42..05108e445e 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -79,7 +79,7 @@ namespace OpenRCT2::Ui::Windows for (ObjectEntryIndex objectIndex = 0; objectIndex < kMaxParkEntranceObjects; objectIndex++) { auto& objManager = GetContext()->GetObjectManager(); - auto* object = static_cast(objManager.GetLoadedObject(ObjectType::ParkEntrance, objectIndex)); + auto* object = objManager.GetLoadedObject(objectIndex); if (object != nullptr) { const auto* legacyData = reinterpret_cast(object->GetLegacyData()); diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 2cefec0636..b6f0a551b6 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -715,7 +715,7 @@ namespace OpenRCT2::Ui::Windows for (ObjectEntryIndex i = 0; i < kMaxPathObjects; i++) { - auto* pathObj = static_cast(objManager.GetLoadedObject(ObjectType::Paths, i)); + auto* pathObj = objManager.GetLoadedObject(i); if (pathObj == nullptr) { continue; diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index 490f2efba3..ef4043e3d9 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -638,7 +638,7 @@ namespace OpenRCT2::Ui::Windows ImageIndex GetRideImage(RideSelection rideSelection) { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - auto obj = static_cast(objMgr.GetLoadedObject(ObjectType::Ride, rideSelection.EntryIndex)); + auto obj = objMgr.GetLoadedObject(rideSelection.EntryIndex); return obj == nullptr ? ImageIndexUndefined : obj->GetPreviewImage(rideSelection.Type); } @@ -683,7 +683,7 @@ namespace OpenRCT2::Ui::Windows // Ride entries auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - auto rideObj = static_cast(objMgr.GetLoadedObject(ObjectType::Ride, rideEntryIndex)); + auto* rideObj = objMgr.GetLoadedObject(rideEntryIndex); // Skip if the vehicle isn't the preferred vehicle for this generic track type if (!Config::Get().interface.ListRideVehiclesSeparately @@ -918,7 +918,7 @@ namespace OpenRCT2::Ui::Windows void DrawRideInformation(DrawPixelInfo& dpi, RideSelection item, const ScreenCoordsXY& screenPos, int32_t textWidth) { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - auto rideObj = static_cast(objMgr.GetLoadedObject(ObjectType::Ride, item.EntryIndex)); + const auto* rideObj = objMgr.GetLoadedObject(item.EntryIndex); const auto& rideEntry = rideObj->GetEntry(); RideNaming rideNaming = GetRideNaming(item.Type, rideEntry); auto ft = Formatter(); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index a8d1b8363c..90038c6eed 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -2113,7 +2113,7 @@ namespace OpenRCT2::Ui::Windows for (ObjectEntryIndex i = 0; i < kMaxStationObjects; i++) { - auto stationObj = static_cast(objManager.GetLoadedObject(ObjectType::Station, i)); + auto stationObj = objManager.GetLoadedObject(i); if (stationObj != nullptr) { auto name = stationObj->NameStringId; @@ -5055,7 +5055,7 @@ namespace OpenRCT2::Ui::Windows static std::string GetMusicString(ObjectEntryIndex musicObjectIndex) { auto& objManager = GetContext()->GetObjectManager(); - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, musicObjectIndex)); + auto musicObj = objManager.GetLoadedObject(musicObjectIndex); return LanguageGetString(musicObj->NameStringId); } @@ -5080,7 +5080,7 @@ namespace OpenRCT2::Ui::Windows auto& objManager = GetContext()->GetObjectManager(); for (ObjectEntryIndex i = 0; i < kMaxMusicObjects; i++) { - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, i)); + auto musicObj = objManager.GetLoadedObject(i); if (musicObj != nullptr) { // Hide custom music if the WAV file does not exist @@ -5119,7 +5119,7 @@ namespace OpenRCT2::Ui::Windows auto numItems = musicOrder.size(); for (size_t i = 0; i < numItems; i++) { - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, musicOrder[i])); + auto musicObj = objManager.GetLoadedObject(musicOrder[i]); gDropdownItems[i].Format = STR_DROPDOWN_MENU_LABEL; gDropdownItems[i].Args = musicObj->NameStringId; } diff --git a/src/openrct2/actions/SurfaceSetStyleAction.cpp b/src/openrct2/actions/SurfaceSetStyleAction.cpp index ac39d49afa..950f291521 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.cpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.cpp @@ -67,7 +67,7 @@ GameActions::Result SurfaceSetStyleAction::Query() const if (_edgeStyle != OBJECT_ENTRY_INDEX_NULL) { - const auto edgeObj = static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, _edgeStyle)); + const auto edgeObj = objManager.GetLoadedObject(_edgeStyle); if (edgeObj == nullptr) { diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index fd66a30c8d..24df9fe32f 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -292,7 +292,7 @@ namespace OpenRCT2 if (IsRealNameStringId(id)) { auto& objManager = GetContext()->GetObjectManager(); - auto* peepNamesObj = static_cast(objManager.GetLoadedObject(ObjectType::PeepNames, 0)); + auto* peepNamesObj = objManager.GetLoadedObject(0); if (peepNamesObj != nullptr) { auto realNameIndex = id - kRealNameStart; diff --git a/src/openrct2/object/AudioObject.h b/src/openrct2/object/AudioObject.h index edd9dcee36..32c7aef5ec 100644 --- a/src/openrct2/object/AudioObject.h +++ b/src/openrct2/object/AudioObject.h @@ -23,6 +23,8 @@ private: AudioSampleTable _loadedSampleTable; public: + static constexpr ObjectType objectType = ObjectType::Audio; + void ReadJson(IReadObjectContext* context, json_t& root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/BannerObject.h b/src/openrct2/object/BannerObject.h index 08df37497f..18c077a987 100644 --- a/src/openrct2/object/BannerObject.h +++ b/src/openrct2/object/BannerObject.h @@ -19,6 +19,8 @@ private: BannerSceneryEntry _legacyType = {}; public: + static constexpr ObjectType objectType = ObjectType::Banners; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/EntranceObject.h b/src/openrct2/object/EntranceObject.h index 0abce30b8f..ce5fb15f28 100644 --- a/src/openrct2/object/EntranceObject.h +++ b/src/openrct2/object/EntranceObject.h @@ -20,6 +20,8 @@ private: EntranceEntry _legacyType = {}; public: + static constexpr ObjectType objectType = ObjectType::ParkEntrance; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/FootpathObject.h b/src/openrct2/object/FootpathObject.h index b6aba5f698..cce65563fd 100644 --- a/src/openrct2/object/FootpathObject.h +++ b/src/openrct2/object/FootpathObject.h @@ -22,6 +22,8 @@ private: PathRailingsDescriptor _pathRailingsDescriptor = {}; public: + static constexpr ObjectType objectType = ObjectType::Paths; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/FootpathRailingsObject.h b/src/openrct2/object/FootpathRailingsObject.h index 961d07c90e..028534f404 100644 --- a/src/openrct2/object/FootpathRailingsObject.h +++ b/src/openrct2/object/FootpathRailingsObject.h @@ -26,6 +26,8 @@ public: PathRailingsDescriptor _descriptor = {}; public: + static constexpr ObjectType objectType = ObjectType::FootpathRailings; + void ReadJson(IReadObjectContext* context, json_t& root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/FootpathSurfaceObject.h b/src/openrct2/object/FootpathSurfaceObject.h index 782b930d23..08aea17fb6 100644 --- a/src/openrct2/object/FootpathSurfaceObject.h +++ b/src/openrct2/object/FootpathSurfaceObject.h @@ -22,6 +22,8 @@ public: PathSurfaceDescriptor _descriptor = {}; public: + static constexpr ObjectType objectType = ObjectType::FootpathSurface; + void ReadJson(IReadObjectContext* context, json_t& root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/LargeSceneryObject.h b/src/openrct2/object/LargeSceneryObject.h index bba6e815de..f7174fc1ac 100644 --- a/src/openrct2/object/LargeSceneryObject.h +++ b/src/openrct2/object/LargeSceneryObject.h @@ -24,6 +24,8 @@ private: std::unique_ptr _3dFont; public: + static constexpr ObjectType objectType = ObjectType::LargeScenery; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/MusicObject.h b/src/openrct2/object/MusicObject.h index e71a81600e..274353736c 100644 --- a/src/openrct2/object/MusicObject.h +++ b/src/openrct2/object/MusicObject.h @@ -53,6 +53,8 @@ private: uint32_t _previewImageId{}; public: + static constexpr ObjectType objectType = ObjectType::Music; + StringId NameStringId{}; void ReadJson(IReadObjectContext* context, json_t& root) override; diff --git a/src/openrct2/object/ObjectManager.h b/src/openrct2/object/ObjectManager.h index 64c2eda918..98e0fb301e 100644 --- a/src/openrct2/object/ObjectManager.h +++ b/src/openrct2/object/ObjectManager.h @@ -26,6 +26,10 @@ struct IObjectManager } virtual Object* GetLoadedObject(ObjectType objectType, size_t index) = 0; + template TClass* GetLoadedObject(size_t index) + { + return static_cast(GetLoadedObject(TClass::objectType, index)); + } virtual Object* GetLoadedObject(const ObjectEntryDescriptor& entry) = 0; virtual ObjectEntryIndex GetLoadedObjectEntryIndex(std::string_view identifier) = 0; virtual ObjectEntryIndex GetLoadedObjectEntryIndex(const ObjectEntryDescriptor& descriptor) = 0; diff --git a/src/openrct2/object/PathAdditionObject.h b/src/openrct2/object/PathAdditionObject.h index bb24cf25ec..505cdc08f8 100644 --- a/src/openrct2/object/PathAdditionObject.h +++ b/src/openrct2/object/PathAdditionObject.h @@ -18,6 +18,8 @@ private: PathAdditionEntry _legacyType = {}; public: + static constexpr ObjectType objectType = ObjectType::PathAdditions; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/PeepNamesObject.h b/src/openrct2/object/PeepNamesObject.h index fc3fa120b1..919708c113 100644 --- a/src/openrct2/object/PeepNamesObject.h +++ b/src/openrct2/object/PeepNamesObject.h @@ -22,6 +22,8 @@ private: std::vector _surnames; public: + static constexpr ObjectType objectType = ObjectType::PeepNames; + void ReadJson(IReadObjectContext* context, json_t& root) override; void Load() override; void Unload() override; diff --git a/src/openrct2/object/RideObject.h b/src/openrct2/object/RideObject.h index bd3cea4dad..110dc3fb07 100644 --- a/src/openrct2/object/RideObject.h +++ b/src/openrct2/object/RideObject.h @@ -26,6 +26,8 @@ private: std::vector> _peepLoadingWaypoints[OpenRCT2::RCT2::ObjectLimits::MaxCarTypesPerRideEntry]; public: + static constexpr ObjectType objectType = ObjectType::Ride; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/SceneryGroupObject.h b/src/openrct2/object/SceneryGroupObject.h index a07c86c9be..91c270043e 100644 --- a/src/openrct2/object/SceneryGroupObject.h +++ b/src/openrct2/object/SceneryGroupObject.h @@ -25,6 +25,8 @@ private: std::vector _items; public: + static constexpr ObjectType objectType = ObjectType::SceneryGroup; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/SmallSceneryObject.h b/src/openrct2/object/SmallSceneryObject.h index fe2051bd18..906fa776a1 100644 --- a/src/openrct2/object/SmallSceneryObject.h +++ b/src/openrct2/object/SmallSceneryObject.h @@ -22,6 +22,8 @@ private: std::vector _frameOffsets; public: + static constexpr ObjectType objectType = ObjectType::SmallScenery; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/StationObject.h b/src/openrct2/object/StationObject.h index 372204e18d..ed119fd05f 100644 --- a/src/openrct2/object/StationObject.h +++ b/src/openrct2/object/StationObject.h @@ -24,6 +24,8 @@ namespace OpenRCT2::STATION_OBJECT_FLAGS class StationObject final : public Object { public: + static constexpr ObjectType objectType = ObjectType::Station; + StringId NameStringId{}; ImageIndex BaseImageId = ImageIndexUndefined; ImageIndex ShelterImageId = ImageIndexUndefined; diff --git a/src/openrct2/object/TerrainEdgeObject.h b/src/openrct2/object/TerrainEdgeObject.h index 1eab9695f6..113b3464b2 100644 --- a/src/openrct2/object/TerrainEdgeObject.h +++ b/src/openrct2/object/TerrainEdgeObject.h @@ -15,6 +15,8 @@ class TerrainEdgeObject final : public Object { private: public: + static constexpr ObjectType objectType = ObjectType::TerrainEdge; + StringId NameStringId{}; uint32_t IconImageId{}; uint32_t BaseImageId{}; diff --git a/src/openrct2/object/TerrainSurfaceObject.h b/src/openrct2/object/TerrainSurfaceObject.h index 18d78e1d8f..aebf3f9692 100644 --- a/src/openrct2/object/TerrainSurfaceObject.h +++ b/src/openrct2/object/TerrainSurfaceObject.h @@ -35,6 +35,8 @@ private: static constexpr auto kNumImagesInEntry = 19; public: + static constexpr ObjectType objectType = ObjectType::TerrainSurface; + static constexpr uint8_t kNoValue = 0xFF; StringId NameStringId{}; uint32_t IconImageId{}; diff --git a/src/openrct2/object/WallObject.h b/src/openrct2/object/WallObject.h index 6f90f14ad4..8b85548427 100644 --- a/src/openrct2/object/WallObject.h +++ b/src/openrct2/object/WallObject.h @@ -18,6 +18,8 @@ private: WallSceneryEntry _legacyType = {}; public: + static constexpr ObjectType objectType = ObjectType::Walls; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/object/WaterObject.h b/src/openrct2/object/WaterObject.h index ff7be845bd..096261f9d2 100644 --- a/src/openrct2/object/WaterObject.h +++ b/src/openrct2/object/WaterObject.h @@ -20,6 +20,8 @@ private: WaterObjectEntry _legacyType = {}; public: + static constexpr ObjectType objectType = ObjectType::Water; + void* GetLegacyData() override { return &_legacyType; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 1275005c85..a239f4b4c2 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1981,7 +1981,7 @@ void DefaultMusicUpdate(Ride& ride) if (ride.music_tune_id == TUNE_ID_NULL) { auto& objManager = GetContext()->GetObjectManager(); - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, ride.music)); + auto musicObj = objManager.GetLoadedObject(ride.music); if (musicObj != nullptr) { auto numTracks = musicObj->GetTrackCount(); @@ -5543,13 +5543,13 @@ int32_t RideGetEntryIndex(int32_t rideType, int32_t rideSubType) const StationObject* Ride::GetStationObject() const { auto& objManager = GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::Station, entrance_style)); + return objManager.GetLoadedObject(entrance_style); } const MusicObject* Ride::GetMusicObject() const { auto& objManager = GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::Music, music)); + return objManager.GetLoadedObject(music); } // Normally, a station has at most one entrance and one exit, which are at the same height diff --git a/src/openrct2/ride/RideAudio.cpp b/src/openrct2/ride/RideAudio.cpp index e07610a1f2..a8f73ef962 100644 --- a/src/openrct2/ride/RideAudio.cpp +++ b/src/openrct2/ride/RideAudio.cpp @@ -170,7 +170,7 @@ namespace OpenRCT2::RideAudio { auto& objManager = GetContext()->GetObjectManager(); auto ride = GetRide(instance.RideId); - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, ride->music)); + auto musicObj = objManager.GetLoadedObject(ride->music); if (musicObj != nullptr) { auto shouldLoop = musicObj->GetTrackCount() == 1; @@ -276,7 +276,7 @@ namespace OpenRCT2::RideAudio std::pair RideMusicGetTrackOffsetLength_Default(const Ride& ride) { auto& objManager = GetContext()->GetObjectManager(); - auto musicObj = static_cast(objManager.GetLoadedObject(ObjectType::Music, ride.music)); + auto musicObj = objManager.GetLoadedObject(ride.music); if (musicObj != nullptr) { auto numTracks = musicObj->GetTrackCount(); diff --git a/src/openrct2/scripting/bindings/object/ScObject.hpp b/src/openrct2/scripting/bindings/object/ScObject.hpp index a7e09d08e5..cf403a0b92 100644 --- a/src/openrct2/scripting/bindings/object/ScObject.hpp +++ b/src/openrct2/scripting/bindings/object/ScObject.hpp @@ -158,14 +158,12 @@ namespace OpenRCT2::Scripting class ScRideObjectVehicle { private: - ObjectType _objectType{}; ObjectEntryIndex _objectIndex{}; size_t _vehicleIndex{}; public: - ScRideObjectVehicle(ObjectType objectType, ObjectEntryIndex objectIndex, size_t vehicleIndex) - : _objectType(objectType) - , _objectIndex(objectIndex) + ScRideObjectVehicle(ObjectEntryIndex objectIndex, size_t vehicleIndex) + : _objectIndex(objectIndex) , _vehicleIndex(vehicleIndex) { } @@ -491,7 +489,7 @@ namespace OpenRCT2::Scripting const RideObject* GetObject() const { auto& objManager = GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(_objectType, _objectIndex)); + return objManager.GetLoadedObject(_objectIndex); } const CarEntry* GetEntry() const @@ -707,7 +705,7 @@ namespace OpenRCT2::Scripting { for (size_t i = 0; i < std::size(entry->Cars); i++) { - result.push_back(std::make_shared(static_cast(_type), _index, i)); + result.push_back(std::make_shared(_index, i)); } } return result; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 771050cb80..aca0df9433 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1862,7 +1862,7 @@ static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index) { bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode); auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - auto footpathObj = static_cast(objManager.GetLoadedObject(ObjectType::Paths, index)); + auto footpathObj = objManager.GetLoadedObject(index); if (footpathObj != nullptr) { auto pathEntry = reinterpret_cast(footpathObj->GetLegacyData()); diff --git a/src/openrct2/world/tile_element/EntranceElement.cpp b/src/openrct2/world/tile_element/EntranceElement.cpp index 385b26f0a4..60ffecc6c7 100644 --- a/src/openrct2/world/tile_element/EntranceElement.cpp +++ b/src/openrct2/world/tile_element/EntranceElement.cpp @@ -80,7 +80,7 @@ ObjectEntryIndex EntranceElement::GetLegacyPathEntryIndex() const const FootpathObject* EntranceElement::GetLegacyPathEntry() const { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objMgr.GetLoadedObject(ObjectType::Paths, GetLegacyPathEntryIndex())); + return objMgr.GetLoadedObject(GetLegacyPathEntryIndex()); } void EntranceElement::SetLegacyPathEntryIndex(ObjectEntryIndex newPathType) @@ -100,7 +100,7 @@ ObjectEntryIndex EntranceElement::GetSurfaceEntryIndex() const const FootpathSurfaceObject* EntranceElement::GetSurfaceEntry() const { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathSurface, GetSurfaceEntryIndex())); + return objMgr.GetLoadedObject(GetSurfaceEntryIndex()); } void EntranceElement::SetSurfaceEntryIndex(ObjectEntryIndex newIndex) diff --git a/src/openrct2/world/tile_element/PathElement.cpp b/src/openrct2/world/tile_element/PathElement.cpp index 36ba91b305..1c8b058b00 100644 --- a/src/openrct2/world/tile_element/PathElement.cpp +++ b/src/openrct2/world/tile_element/PathElement.cpp @@ -254,7 +254,7 @@ ObjectEntryIndex PathElement::GetSurfaceEntryIndex() const const FootpathSurfaceObject* PathElement::GetSurfaceEntry() const { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathSurface, GetSurfaceEntryIndex())); + return objMgr.GetLoadedObject(GetSurfaceEntryIndex()); } void PathElement::SetSurfaceEntryIndex(ObjectEntryIndex newIndex) @@ -274,7 +274,7 @@ ObjectEntryIndex PathElement::GetRailingsEntryIndex() const const FootpathRailingsObject* PathElement::GetRailingsEntry() const { auto& objMgr = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objMgr.GetLoadedObject(ObjectType::FootpathRailings, GetRailingsEntryIndex())); + return objMgr.GetLoadedObject(GetRailingsEntryIndex()); } void PathElement::SetRailingsEntryIndex(ObjectEntryIndex newEntryIndex) diff --git a/src/openrct2/world/tile_element/SurfaceElement.cpp b/src/openrct2/world/tile_element/SurfaceElement.cpp index aba3d12553..1d5711ff5a 100644 --- a/src/openrct2/world/tile_element/SurfaceElement.cpp +++ b/src/openrct2/world/tile_element/SurfaceElement.cpp @@ -26,7 +26,7 @@ ObjectEntryIndex SurfaceElement::GetSurfaceObjectIndex() const TerrainSurfaceObject* SurfaceElement::GetSurfaceObject() const { auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::TerrainSurface, GetSurfaceObjectIndex())); + return objManager.GetLoadedObject(GetSurfaceObjectIndex()); } ObjectEntryIndex SurfaceElement::GetEdgeObjectIndex() const @@ -37,7 +37,7 @@ ObjectEntryIndex SurfaceElement::GetEdgeObjectIndex() const TerrainEdgeObject* SurfaceElement::GetEdgeObject() const { auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - return static_cast(objManager.GetLoadedObject(ObjectType::TerrainEdge, GetEdgeObjectIndex())); + return objManager.GetLoadedObject(GetEdgeObjectIndex()); } void SurfaceElement::SetSurfaceObjectIndex(ObjectEntryIndex newStyle)