From bb16ca075b9f53a0093b8685605f0b926d47660a Mon Sep 17 00:00:00 2001 From: ju-pinheiro <66486603+ju-pinheiro@users.noreply.github.com> Date: Tue, 27 Oct 2020 13:07:04 -0300 Subject: [PATCH] Close #12450: Refactor SPRITE_IDENTIFIER to use strong enum --- .../interface/ViewportInteraction.cpp | 14 ++--- src/openrct2/Game.cpp | 2 +- src/openrct2/GameStateSnapshots.cpp | 44 ++++++++-------- src/openrct2/GameStateSnapshots.h | 2 +- src/openrct2/actions/PeepPickupAction.hpp | 4 +- src/openrct2/actions/StaffHireNewAction.hpp | 4 +- src/openrct2/interface/InteractiveConsole.cpp | 2 +- src/openrct2/interface/Viewport.cpp | 6 +-- src/openrct2/paint/sprite/Paint.Sprite.cpp | 10 ++-- src/openrct2/peep/Peep.cpp | 10 ++-- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 20 +++---- src/openrct2/rct12/RCT12.h | 40 +++++++------- src/openrct2/rct2/S6Exporter.cpp | 10 ++-- src/openrct2/rct2/S6Importer.cpp | 12 ++--- src/openrct2/ride/CableLift.cpp | 4 +- src/openrct2/ride/Ride.cpp | 4 +- src/openrct2/ride/Vehicle.cpp | 6 +-- src/openrct2/scripting/ScEntity.hpp | 16 +++--- src/openrct2/scripting/ScMap.hpp | 6 +-- src/openrct2/world/Balloon.cpp | 6 +-- src/openrct2/world/Duck.cpp | 6 +-- src/openrct2/world/Fountain.cpp | 6 +-- src/openrct2/world/MoneyEffect.cpp | 6 +-- src/openrct2/world/Particle.cpp | 12 ++--- src/openrct2/world/Sprite.cpp | 52 +++++++++---------- src/openrct2/world/Sprite.h | 16 +++--- src/openrct2/world/SpriteBase.h | 3 +- test/testpaint/Compat.cpp | 4 +- test/tests/S6ImportExportTests.cpp | 14 ++--- 30 files changed, 173 insertions(+), 170 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 7cd7bcddf1..d2b8049587 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -87,7 +87,7 @@ InteractionInfo viewport_interaction_get_item_left(const ScreenCoordsXY& screenC case VIEWPORT_INTERACTION_ITEM_SPRITE: switch (sprite->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: { auto vehicle = sprite->As(); if (vehicle != nullptr && vehicle->ride_subtype != RIDE_ENTRY_INDEX_NULL) @@ -96,7 +96,7 @@ InteractionInfo viewport_interaction_get_item_left(const ScreenCoordsXY& screenC info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; } break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: { auto peep = sprite->As(); if (peep != nullptr) @@ -173,21 +173,21 @@ bool viewport_interaction_left_click(const ScreenCoordsXY& screenCoords) auto entity = info.Entity; switch (entity->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: { auto intent = Intent(WD_VEHICLE); intent.putExtra(INTENT_EXTRA_VEHICLE, entity); context_open_intent(&intent); break; } - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: { auto intent = Intent(WC_PEEP); intent.putExtra(INTENT_EXTRA_PEEP, entity); context_open_intent(&intent); break; } - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: if (game_is_not_paused()) { switch (entity->type) @@ -254,7 +254,7 @@ InteractionInfo viewport_interaction_get_item_right(const ScreenCoordsXY& screen case VIEWPORT_INTERACTION_ITEM_SPRITE: { auto sprite = info.Entity; - if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || sprite->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) + if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || sprite->sprite_identifier != SpriteIdentifier::Vehicle) { info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE; return info; @@ -523,7 +523,7 @@ bool viewport_interaction_right_click(const ScreenCoordsXY& screenCoords) case VIEWPORT_INTERACTION_ITEM_SPRITE: { auto entity = info.Entity; - if (entity->sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) + if (entity->sprite_identifier == SpriteIdentifier::Vehicle) { auto vehicle = entity->As(); if (vehicle == nullptr) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index e6a4302914..2cd7921dff 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -615,7 +615,7 @@ void reset_all_sprite_quadrant_placements() for (size_t i = 0; i < MAX_SPRITES; i++) { auto* spr = GetEntity(i); - if (spr != nullptr && spr->sprite_identifier != SPRITE_IDENTIFIER_NULL) + if (spr != nullptr && spr->sprite_identifier != SpriteIdentifier::Null) { spr->MoveTo({ spr->x, spr->y, spr->z }); } diff --git a/src/openrct2/GameStateSnapshots.cpp b/src/openrct2/GameStateSnapshots.cpp index ff04cba251..3f48ff3b2a 100644 --- a/src/openrct2/GameStateSnapshots.cpp +++ b/src/openrct2/GameStateSnapshots.cpp @@ -49,7 +49,7 @@ struct GameStateSnapshot_t for (size_t i = 0; i < numSprites; i++) { auto entity = getEntity(i); - if (entity == nullptr || entity->generic.sprite_identifier == SPRITE_IDENTIFIER_NULL) + if (entity == nullptr || entity->generic.sprite_identifier == SpriteIdentifier::Null) continue; indexTable.push_back(static_cast(i)); } @@ -80,16 +80,16 @@ struct GameStateSnapshot_t switch (sprite.generic.sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: ds << reinterpret_cast(sprite.vehicle); break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: ds << reinterpret_cast(sprite.peep); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: ds << reinterpret_cast(sprite.litter); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: { ds << sprite.generic.type; switch (sprite.generic.type) @@ -172,7 +172,7 @@ struct GameStateSnapshots final : public IGameStateSnapshots for (auto& sprite : spriteList) { // By default they don't exist. - sprite.generic.sprite_identifier = SPRITE_IDENTIFIER_NULL; + sprite.generic.sprite_identifier = SpriteIdentifier::Null; } snapshot.SerialiseSprites([&spriteList](const size_t index) { return &spriteList[index]; }, MAX_SPRITES, false); @@ -479,16 +479,16 @@ struct GameStateSnapshots final : public IGameStateSnapshots { switch (spriteBase.generic.sprite_identifier) { - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: CompareSpriteDataPeep(spriteBase.peep, spriteCmp.peep, changeData); break; - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: CompareSpriteDataVehicle(spriteBase.vehicle, spriteCmp.vehicle, changeData); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: CompareSpriteDataLitter(spriteBase.litter, spriteCmp.litter, changeData); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: // This is not expected to happen, as misc sprites do not constitute sprite checksum CompareSpriteDataGeneric(spriteBase.generic, spriteCmp.generic, changeData); switch (spriteBase.generic.type) @@ -546,24 +546,24 @@ struct GameStateSnapshots final : public IGameStateSnapshots changeData.spriteIdentifier = spriteBase.generic.sprite_identifier; changeData.miscIdentifier = spriteBase.generic.type; - if (spriteBase.generic.sprite_identifier == SPRITE_IDENTIFIER_NULL - && spriteCmp.generic.sprite_identifier != SPRITE_IDENTIFIER_NULL) + if (spriteBase.generic.sprite_identifier == SpriteIdentifier::Null + && spriteCmp.generic.sprite_identifier != SpriteIdentifier::Null) { // Sprite was added. changeData.changeType = GameStateSpriteChange_t::ADDED; changeData.spriteIdentifier = spriteCmp.generic.sprite_identifier; } else if ( - spriteBase.generic.sprite_identifier != SPRITE_IDENTIFIER_NULL - && spriteCmp.generic.sprite_identifier == SPRITE_IDENTIFIER_NULL) + spriteBase.generic.sprite_identifier != SpriteIdentifier::Null + && spriteCmp.generic.sprite_identifier == SpriteIdentifier::Null) { // Sprite was removed. changeData.changeType = GameStateSpriteChange_t::REMOVED; changeData.spriteIdentifier = spriteBase.generic.sprite_identifier; } else if ( - spriteBase.generic.sprite_identifier == SPRITE_IDENTIFIER_NULL - && spriteCmp.generic.sprite_identifier == SPRITE_IDENTIFIER_NULL) + spriteBase.generic.sprite_identifier == SpriteIdentifier::Null + && spriteCmp.generic.sprite_identifier == SpriteIdentifier::Null) { // Do nothing. changeData.changeType = GameStateSpriteChange_t::EQUAL; @@ -587,19 +587,19 @@ struct GameStateSnapshots final : public IGameStateSnapshots return res; } - static const char* GetSpriteIdentifierName(uint32_t spriteIdentifier, uint8_t miscIdentifier) + static const char* GetSpriteIdentifierName(SpriteIdentifier spriteIdentifier, uint8_t miscIdentifier) { switch (spriteIdentifier) { - case SPRITE_IDENTIFIER_NULL: + case SpriteIdentifier::Null: return "Null"; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: return "Peep"; - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: return "Vehicle"; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: return "Litter"; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: switch (miscIdentifier) { case SPRITE_MISC_STEAM_PARTICLE: diff --git a/src/openrct2/GameStateSnapshots.h b/src/openrct2/GameStateSnapshots.h index e978851a62..01bc20bf2b 100644 --- a/src/openrct2/GameStateSnapshots.h +++ b/src/openrct2/GameStateSnapshots.h @@ -39,7 +39,7 @@ struct GameStateSpriteChange_t }; uint8_t changeType; - uint8_t spriteIdentifier; + SpriteIdentifier spriteIdentifier; uint8_t miscIdentifier; uint32_t spriteIndex; diff --git a/src/openrct2/actions/PeepPickupAction.hpp b/src/openrct2/actions/PeepPickupAction.hpp index b35a4eb7cc..3bf32f36e7 100644 --- a/src/openrct2/actions/PeepPickupAction.hpp +++ b/src/openrct2/actions/PeepPickupAction.hpp @@ -67,7 +67,7 @@ public: } auto* const peep = TryGetEntity(_spriteId); - if (!peep || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP) + if (!peep || peep->sprite_identifier != SpriteIdentifier::Peep) { log_error("Failed to pick up peep for sprite %d", _spriteId); return MakeResult(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE); @@ -126,7 +126,7 @@ public: GameActions::Result::Ptr Execute() const override { Peep* const peep = TryGetEntity(_spriteId); - if (!peep || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP) + if (!peep || peep->sprite_identifier != SpriteIdentifier::Peep) { log_error("Failed to pick up peep for sprite %d", _spriteId); return MakeResult(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE); diff --git a/src/openrct2/actions/StaffHireNewAction.hpp b/src/openrct2/actions/StaffHireNewAction.hpp index f046d1b19a..9c9d334a8a 100644 --- a/src/openrct2/actions/StaffHireNewAction.hpp +++ b/src/openrct2/actions/StaffHireNewAction.hpp @@ -144,7 +144,7 @@ private: return MakeResult(GameActions::Status::NoFreeElements, STR_TOO_MANY_STAFF_IN_GAME); } - Peep* newPeep = &(create_sprite(SPRITE_IDENTIFIER_PEEP)->peep); + Peep* newPeep = &(create_sprite(SpriteIdentifier::Peep)->peep); if (newPeep == nullptr) { // Too many peeps exist already. @@ -158,7 +158,7 @@ private: } else { - newPeep->sprite_identifier = 1; + newPeep->sprite_identifier = SpriteIdentifier::Peep; newPeep->WindowInvalidateFlags = 0; newPeep->Action = PeepActionType::None2; newPeep->SpecialSprite = 0; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 6c1cb21b75..36e5a59fa1 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1578,7 +1578,7 @@ static int32_t cc_mp_desync(InteractiveConsole& console, const arguments_t& argv for (int i = 0; i < MAX_SPRITES; i++) { auto* sprite = GetEntity(i); - if (sprite == nullptr || sprite->sprite_identifier == SPRITE_IDENTIFIER_NULL) + if (sprite == nullptr || sprite->sprite_identifier == SpriteIdentifier::Null) continue; auto peep = sprite->As(); diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index d91aa0fa31..7334131c86 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -654,7 +654,7 @@ void viewport_update_smart_sprite_follow(rct_window* window) window->viewport_smart_follow_sprite = SPRITE_INDEX_NULL; window->viewport_target_sprite = SPRITE_INDEX_NULL; } - else if (entity->sprite_identifier == SPRITE_IDENTIFIER_PEEP) + else if (entity->sprite_identifier == SpriteIdentifier::Peep) { Peep* peep = TryGetEntity(window->viewport_smart_follow_sprite); if (peep == nullptr) @@ -670,11 +670,11 @@ void viewport_update_smart_sprite_follow(rct_window* window) else if (peep->AssignedPeepType == PeepType::Staff) viewport_update_smart_staff_follow(window, peep); } - else if (entity->sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) + else if (entity->sprite_identifier == SpriteIdentifier::Vehicle) { viewport_update_smart_vehicle_follow(window); } - else if (entity->sprite_identifier == SPRITE_IDENTIFIER_MISC || entity->sprite_identifier == SPRITE_IDENTIFIER_LITTER) + else if (entity->sprite_identifier == SpriteIdentifier::Misc || entity->sprite_identifier == SpriteIdentifier::Litter) { window->viewport_focus_sprite.sprite_id = window->viewport_smart_follow_sprite; window->viewport_target_sprite = window->viewport_smart_follow_sprite; diff --git a/src/openrct2/paint/sprite/Paint.Sprite.cpp b/src/openrct2/paint/sprite/Paint.Sprite.cpp index e43799c26e..6994470754 100644 --- a/src/openrct2/paint/sprite/Paint.Sprite.cpp +++ b/src/openrct2/paint/sprite/Paint.Sprite.cpp @@ -55,7 +55,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t continue; } } - else if (spr->sprite_identifier != SPRITE_IDENTIFIER_LITTER) + else if (spr->sprite_identifier != SpriteIdentifier::Litter) { continue; } @@ -101,7 +101,7 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t switch (spr->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: vehicle_paint(session, spr->As(), image_direction); #ifdef __ENABLE_LIGHTFX__ if (lightfx_for_vehicles_is_available()) @@ -110,14 +110,14 @@ void sprite_paint_setup(paint_session* session, const uint16_t x, const uint16_t } #endif break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: peep_paint(session, spr->As(), image_direction); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: // TODO: Update misc_paint to take a specific sprite type misc_paint(session, spr, image_direction); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: litter_paint(session, spr->As(), image_direction); break; default: diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index aea3f2340f..1751e714bb 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -318,7 +318,7 @@ const bool gSpriteTypeToSlowWalkMap[] = { template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_PEEP; + return sprite_identifier == SpriteIdentifier::Peep; } Guest* Peep::AsGuest() @@ -398,7 +398,7 @@ void peep_update_all() else { peep_128_tick_update(peep, i); - if (peep->sprite_identifier == SPRITE_IDENTIFIER_PEEP) + if (peep->sprite_identifier == SpriteIdentifier::Peep) { peep->Update(); } @@ -806,7 +806,7 @@ void peep_sprite_remove(Peep* peep) window_close_by_number(WC_PEEP, peep->sprite_index); - window_close_by_number(WC_FIRE_PROMPT, peep->sprite_identifier); + window_close_by_number(WC_FIRE_PROMPT, EnumValue(peep->sprite_identifier)); // Needed for invalidations after sprite removal bool wasGuest = peep->AssignedPeepType == PeepType::Guest; @@ -1580,8 +1580,8 @@ Peep* Peep::Generate(const CoordsXYZ& coords) if (GetEntityListCount(EntityListId::Free) < 400) return nullptr; - Peep* peep = &create_sprite(SPRITE_IDENTIFIER_PEEP)->peep; - peep->sprite_identifier = SPRITE_IDENTIFIER_PEEP; + Peep* peep = &create_sprite(SpriteIdentifier::Peep)->peep; + peep->sprite_identifier = SpriteIdentifier::Peep; peep->SpriteType = PeepSpriteType::Normal; peep->OutsideOfPark = true; peep->State = PeepState::Falling; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 9e3c6a17d3..0f6deb9c5f 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1832,7 +1832,7 @@ void Staff::Tick128UpdateStaff() bool Staff::IsMechanic() const { return ( - sprite_identifier == SPRITE_IDENTIFIER_PEEP && AssignedPeepType == PeepType::Staff + sprite_identifier == SpriteIdentifier::Peep && AssignedPeepType == PeepType::Staff && AssignedStaffType == StaffType::Mechanic); } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index a052ec05d0..a5b064bd90 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1127,7 +1127,7 @@ private: for (int i = 0; i < RCT1_MAX_SPRITES; i++) { spriteIndexMap[i] = SPRITE_INDEX_NULL; - if (_s4.sprites[i].unknown.sprite_identifier == SPRITE_IDENTIFIER_VEHICLE) + if (_s4.sprites[i].unknown.sprite_identifier == SpriteIdentifier::Vehicle) { rct1_vehicle* srcVehicle = &_s4.sprites[i].vehicle; if (srcVehicle->x != LOCATION_NULL) @@ -1136,7 +1136,7 @@ private: auto isFirstCar = srcVehicle->type == static_cast(Vehicle::Type::Head); auto llt = isFirstCar ? EntityListId::TrainHead : EntityListId::Vehicle; - Vehicle* vehicle = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_VEHICLE, llt)); + Vehicle* vehicle = reinterpret_cast(create_sprite(SpriteIdentifier::Vehicle, llt)); spriteIndexMap[i] = vehicle->sprite_index; vehicles.push_back(vehicle); @@ -1159,7 +1159,7 @@ private: uint8_t vehicleEntryIndex = RCT1::GetVehicleSubEntryIndex(src->vehicle_type); - dst->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; + dst->sprite_identifier = SpriteIdentifier::Vehicle; dst->ride = src->ride; dst->ride_subtype = RCTEntryIndexToOpenRCT2EntryIndex(ride->subtype); @@ -1341,10 +1341,10 @@ private: for (size_t i = 0; i < RCT1_MAX_SPRITES; i++) { spriteIndexMap[i] = SPRITE_INDEX_NULL; - if (_s4.sprites[i].unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP) + if (_s4.sprites[i].unknown.sprite_identifier == SpriteIdentifier::Peep) { rct1_peep* srcPeep = &_s4.sprites[i].peep; - Peep* peep = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_PEEP)); + Peep* peep = reinterpret_cast(create_sprite(SpriteIdentifier::Peep)); spriteIndexMap[i] = peep->sprite_index; ImportPeep(peep, srcPeep); @@ -1398,7 +1398,7 @@ private: void ImportPeep(Peep* dst, rct1_peep* src) { - dst->sprite_identifier = SPRITE_IDENTIFIER_PEEP; + dst->sprite_identifier = SpriteIdentifier::Peep; // Peep vs. staff (including which kind) dst->SpriteType = RCT1::GetPeepSpriteType(src->sprite_type); dst->Action = static_cast(src->action); @@ -1640,11 +1640,11 @@ private: { for (auto& sprite : _s4.sprites) { - if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_LITTER) + if (sprite.unknown.sprite_identifier == SpriteIdentifier::Litter) { const auto* srcLitter = &sprite.litter; - Litter* litter = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_LITTER)); + Litter* litter = reinterpret_cast(create_sprite(SpriteIdentifier::Litter)); litter->sprite_identifier = srcLitter->sprite_identifier; litter->type = srcLitter->type; @@ -1666,10 +1666,10 @@ private: { for (auto& sprite : _s4.sprites) { - if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_MISC) + if (sprite.unknown.sprite_identifier == SpriteIdentifier::Misc) { rct1_unk_sprite* src = &sprite.unknown; - SpriteGeneric* dst = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_MISC)); + SpriteGeneric* dst = reinterpret_cast(create_sprite(SpriteIdentifier::Misc)); if (dst == nullptr) { log_warning("SV4 has too many misc entities. No more misc entities will be imported!"); diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index 39e1212413..74c95298c6 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -72,6 +72,8 @@ constexpr const uint8_t RCT12_MAX_ELEMENT_HEIGHT = 255; constexpr const uint16_t RCT12_PEEP_SPAWN_UNDEFINED = 0xFFFF; +enum class SpriteIdentifier : uint8_t; + enum class RCT12TrackDesignVersion : uint8_t { TD4, @@ -627,25 +629,25 @@ assert_struct_size(RCT12EightCarsCorruptElement15, 8); struct RCT12SpriteBase { - uint8_t sprite_identifier; // 0x00 - uint8_t type; // 0x01 - uint16_t next_in_quadrant; // 0x02 - uint16_t next; // 0x04 - uint16_t previous; // 0x06 - uint8_t linked_list_type_offset; // 0x08 - uint8_t sprite_height_negative; // 0x09 - uint16_t sprite_index; // 0x0A - uint16_t flags; // 0x0C - int16_t x; // 0x0E - int16_t y; // 0x10 - int16_t z; // 0x12 - uint8_t sprite_width; // 0x14 - uint8_t sprite_height_positive; // 0x15 - int16_t sprite_left; // 0x16 - int16_t sprite_top; // 0x18 - int16_t sprite_right; // 0x1A - int16_t sprite_bottom; // 0x1C - uint8_t sprite_direction; // 0x1E + SpriteIdentifier sprite_identifier; // 0x00 + uint8_t type; // 0x01 + uint16_t next_in_quadrant; // 0x02 + uint16_t next; // 0x04 + uint16_t previous; // 0x06 + uint8_t linked_list_type_offset; // 0x08 + uint8_t sprite_height_negative; // 0x09 + uint16_t sprite_index; // 0x0A + uint16_t flags; // 0x0C + int16_t x; // 0x0E + int16_t y; // 0x10 + int16_t z; // 0x12 + uint8_t sprite_width; // 0x14 + uint8_t sprite_height_positive; // 0x15 + int16_t sprite_left; // 0x16 + int16_t sprite_top; // 0x18 + int16_t sprite_right; // 0x1A + int16_t sprite_bottom; // 0x1C + uint8_t sprite_direction; // 0x1E }; assert_struct_size(RCT12SpriteBase, 0x1F); diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 82b409a65c..59d319be11 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -964,19 +964,19 @@ void S6Exporter::ExportSprite(RCT2Sprite* dst, const rct_sprite* src) std::memset(dst, 0, sizeof(rct_sprite)); switch (src->generic.sprite_identifier) { - case SPRITE_IDENTIFIER_NULL: + case SpriteIdentifier::Null: ExportSpriteCommonProperties(&dst->unknown, &src->generic); break; - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: ExportSpriteVehicle(&dst->vehicle, &src->vehicle); break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: ExportSpritePeep(&dst->peep, &src->peep); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: ExportSpriteMisc(&dst->unknown, &src->generic); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: ExportSpriteLitter(&dst->litter, &src->litter); break; default: diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 67d0a0367d..41c85717ae 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1021,7 +1021,7 @@ public: uint16_t numRiders = 0; for (const auto& sprite : _s6.sprites) { - if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP) + if (sprite.unknown.sprite_identifier == SpriteIdentifier::Peep) { if (sprite.peep.current_ride == rideIndex && (static_cast(sprite.peep.state) == PeepState::OnRide @@ -1313,19 +1313,19 @@ public: std::memset(&dst->pad_00, 0, sizeof(rct_sprite)); switch (src->unknown.sprite_identifier) { - case SPRITE_IDENTIFIER_NULL: + case SpriteIdentifier::Null: ImportSpriteCommonProperties(reinterpret_cast(dst), &src->unknown); break; - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: ImportSpriteVehicle(&dst->vehicle, &src->vehicle); break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: ImportSpritePeep(&dst->peep, &src->peep); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: ImportSpriteMisc(&dst->generic, &src->unknown); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: ImportSpriteLitter(&dst->litter, &src->litter); break; default: diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index b47b588512..b0f59a2371 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -24,8 +24,8 @@ Vehicle* cable_lift_segment_create( Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head) { Vehicle* current = &( - create_sprite(SPRITE_IDENTIFIER_VEHICLE, head ? EntityListId::TrainHead : EntityListId::Vehicle)->vehicle); - current->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; + create_sprite(SpriteIdentifier::Vehicle, head ? EntityListId::TrainHead : EntityListId::Vehicle)->vehicle); + current->sprite_identifier = SpriteIdentifier::Vehicle; current->ride = ride.id; current->ride_subtype = RIDE_ENTRY_INDEX_NULL; if (head) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 5bcfedfac0..1078f1a401 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4371,12 +4371,12 @@ static Vehicle* vehicle_create_car( return nullptr; auto vehicleEntry = &rideEntry->vehicles[vehicleEntryIndex]; - auto vehicle = &create_sprite(SPRITE_IDENTIFIER_VEHICLE, carIndex == 0 ? EntityListId::TrainHead : EntityListId::Vehicle) + auto vehicle = &create_sprite(SpriteIdentifier::Vehicle, carIndex == 0 ? EntityListId::TrainHead : EntityListId::Vehicle) ->vehicle; if (vehicle == nullptr) return nullptr; - vehicle->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; + vehicle->sprite_identifier = SpriteIdentifier::Vehicle; vehicle->ride = rideIndex; vehicle->ride_subtype = ride->subtype; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bf6020ba2e..baf8e9c45f 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -733,7 +733,7 @@ static const struct template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_VEHICLE; + return sprite_identifier == SpriteIdentifier::Vehicle; } static bool vehicle_move_info_valid(VehicleTrackSubposition trackSubposition, int32_t typeAndDirection, int32_t offset) @@ -7222,14 +7222,14 @@ static void steam_particle_create(const CoordsXYZ& coords) auto surfaceElement = map_get_surface_element_at(coords); if (surfaceElement != nullptr && coords.z > surfaceElement->GetBaseZ()) { - SteamParticle* steam = &create_sprite(SPRITE_IDENTIFIER_MISC)->steam_particle; + SteamParticle* steam = &create_sprite(SpriteIdentifier::Misc)->steam_particle; if (steam == nullptr) return; steam->sprite_width = 20; steam->sprite_height_negative = 18; steam->sprite_height_positive = 16; - steam->sprite_identifier = SPRITE_IDENTIFIER_MISC; + steam->sprite_identifier = SpriteIdentifier::Misc; steam->type = SPRITE_MISC_STEAM_PARTICLE; steam->frame = 256; steam->time_to_move = 0; diff --git a/src/openrct2/scripting/ScEntity.hpp b/src/openrct2/scripting/ScEntity.hpp index d9dbe3755a..df75647555 100644 --- a/src/openrct2/scripting/ScEntity.hpp +++ b/src/openrct2/scripting/ScEntity.hpp @@ -52,11 +52,11 @@ namespace OpenRCT2::Scripting { switch (entity->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: return "car"; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: return "peep"; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: switch (entity->type) { case SPRITE_MISC_BALLOON: @@ -65,7 +65,7 @@ namespace OpenRCT2::Scripting return "duck"; } break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: return "litter"; } } @@ -135,10 +135,10 @@ namespace OpenRCT2::Scripting entity->Invalidate2(); switch (entity->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: duk_error(ctx, DUK_ERR_ERROR, "Removing a vehicle is currently unsupported."); break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: { auto peep = static_cast(entity); // We can't remove a single peep from a ride at the moment as this can cause complications with the @@ -153,8 +153,8 @@ namespace OpenRCT2::Scripting } break; } - case SPRITE_IDENTIFIER_MISC: - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Misc: + case SpriteIdentifier::Litter: sprite_remove(entity); break; } diff --git a/src/openrct2/scripting/ScMap.hpp b/src/openrct2/scripting/ScMap.hpp index 560d460b66..fdd71ada7b 100644 --- a/src/openrct2/scripting/ScMap.hpp +++ b/src/openrct2/scripting/ScMap.hpp @@ -87,7 +87,7 @@ namespace OpenRCT2::Scripting { auto spriteId = static_cast(id); auto sprite = GetEntity(spriteId); - if (sprite != nullptr && sprite->sprite_identifier != SPRITE_IDENTIFIER_NULL) + if (sprite != nullptr && sprite->sprite_identifier != SpriteIdentifier::Null) { return GetEntityAsDukValue(sprite); } @@ -176,9 +176,9 @@ namespace OpenRCT2::Scripting auto spriteId = sprite->sprite_index; switch (sprite->sprite_identifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: return GetObjectAsDukValue(_context, std::make_shared(spriteId)); - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: { if (sprite->Is()) return GetObjectAsDukValue(_context, std::make_shared(spriteId)); diff --git a/src/openrct2/world/Balloon.cpp b/src/openrct2/world/Balloon.cpp index edcceb1522..eb94b3e0e3 100644 --- a/src/openrct2/world/Balloon.cpp +++ b/src/openrct2/world/Balloon.cpp @@ -16,7 +16,7 @@ template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_BALLOON; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_BALLOON; } void Balloon::Update() @@ -81,10 +81,10 @@ void Balloon::Pop() void create_balloon(const CoordsXYZ& balloonPos, int32_t colour, bool isPopped) { - rct_sprite* sprite = create_sprite(SPRITE_IDENTIFIER_MISC); + rct_sprite* sprite = create_sprite(SpriteIdentifier::Misc); if (sprite == nullptr) return; - sprite->generic.sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->generic.sprite_identifier = SpriteIdentifier::Misc; sprite->generic.type = SPRITE_MISC_BALLOON; auto balloon = sprite->generic.As(); if (balloon == nullptr) diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index 6a67a9c6e2..d6e416435b 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -76,7 +76,7 @@ static constexpr const uint8_t * DuckAnimations[] = template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_DUCK; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_DUCK; } void Duck::Invalidate() @@ -295,7 +295,7 @@ uint32_t Duck::GetFrameImage(int32_t direction) const void create_duck(const CoordsXY& pos) { - rct_sprite* sprite = create_sprite(SPRITE_IDENTIFIER_MISC); + rct_sprite* sprite = create_sprite(SpriteIdentifier::Misc); if (sprite == nullptr) return; @@ -305,7 +305,7 @@ void create_duck(const CoordsXY& pos) targetPos.x += offsetXY; targetPos.y += offsetXY; - sprite->generic.sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->generic.sprite_identifier = SpriteIdentifier::Misc; sprite->generic.type = SPRITE_MISC_DUCK; auto duck = sprite->generic.As(); if (duck == nullptr) diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index c854c88510..759b3c792a 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -72,7 +72,7 @@ const uint8_t _fountainPatternFlags[] = { template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC + return sprite_identifier == SpriteIdentifier::Misc && (type == SPRITE_MISC_JUMPING_FOUNTAIN_SNOW || type == SPRITE_MISC_JUMPING_FOUNTAIN_WATER); } @@ -128,7 +128,7 @@ void JumpingFountain::StartAnimation(const int32_t newType, const CoordsXY& newL void JumpingFountain::Create( const int32_t newType, const CoordsXYZ& newLoc, const int32_t direction, const int32_t newFlags, const int32_t iteration) { - auto* jumpingFountain = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_MISC)); + auto* jumpingFountain = reinterpret_cast(create_sprite(SpriteIdentifier::Misc)); if (jumpingFountain != nullptr) { jumpingFountain->Iteration = iteration; @@ -137,7 +137,7 @@ void JumpingFountain::Create( jumpingFountain->sprite_width = 33; jumpingFountain->sprite_height_negative = 36; jumpingFountain->sprite_height_positive = 12; - jumpingFountain->sprite_identifier = SPRITE_IDENTIFIER_MISC; + jumpingFountain->sprite_identifier = SpriteIdentifier::Misc; jumpingFountain->MoveTo(newLoc); jumpingFountain->type = newType == JUMPING_FOUNTAIN_TYPE_SNOW ? SPRITE_MISC_JUMPING_FOUNTAIN_SNOW : SPRITE_MISC_JUMPING_FOUNTAIN_WATER; diff --git a/src/openrct2/world/MoneyEffect.cpp b/src/openrct2/world/MoneyEffect.cpp index 31b635771b..69140e2652 100644 --- a/src/openrct2/world/MoneyEffect.cpp +++ b/src/openrct2/world/MoneyEffect.cpp @@ -20,7 +20,7 @@ static constexpr const CoordsXY _moneyEffectMoveOffset[] = { { 1, -1 }, { 1, 1 } template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_MONEY_EFFECT; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_MONEY_EFFECT; } /** @@ -32,7 +32,7 @@ void MoneyEffect::CreateAt(money32 value, const CoordsXYZ& effectPos, bool verti if (value == MONEY(0, 00)) return; - MoneyEffect* moneyEffect = &create_sprite(SPRITE_IDENTIFIER_MISC)->money_effect; + MoneyEffect* moneyEffect = &create_sprite(SpriteIdentifier::Misc)->money_effect; if (moneyEffect == nullptr) return; @@ -41,7 +41,7 @@ void MoneyEffect::CreateAt(money32 value, const CoordsXYZ& effectPos, bool verti moneyEffect->sprite_width = 64; moneyEffect->sprite_height_negative = 20; moneyEffect->sprite_height_positive = 30; - moneyEffect->sprite_identifier = SPRITE_IDENTIFIER_MISC; + moneyEffect->sprite_identifier = SpriteIdentifier::Misc; moneyEffect->MoveTo(effectPos); moneyEffect->type = SPRITE_MISC_MONEY_EFFECT; moneyEffect->NumMovements = 0; diff --git a/src/openrct2/world/Particle.cpp b/src/openrct2/world/Particle.cpp index 129f030991..0374d3ab43 100644 --- a/src/openrct2/world/Particle.cpp +++ b/src/openrct2/world/Particle.cpp @@ -16,12 +16,12 @@ template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_CRASHED_VEHICLE_PARTICLE; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_CRASHED_VEHICLE_PARTICLE; } template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_CRASH_SPLASH; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_CRASH_SPLASH; } /** * @@ -29,7 +29,7 @@ template<> bool SpriteBase::Is() const */ void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ& vehiclePos) { - VehicleCrashParticle* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->crashed_vehicle_particle; + VehicleCrashParticle* sprite = &create_sprite(SpriteIdentifier::Misc)->crashed_vehicle_particle; if (sprite != nullptr) { sprite->colour[0] = colours.body_colour; @@ -37,7 +37,7 @@ void crashed_vehicle_particle_create(rct_vehicle_colour colours, const CoordsXYZ sprite->sprite_width = 8; sprite->sprite_height_negative = 8; sprite->sprite_height_positive = 8; - sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->sprite_identifier = SpriteIdentifier::Misc; sprite->MoveTo(vehiclePos); sprite->type = SPRITE_MISC_CRASHED_VEHICLE_PARTICLE; @@ -121,13 +121,13 @@ void VehicleCrashParticle::Update() */ void crash_splash_create(const CoordsXYZ& splashPos) { - SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; + SpriteGeneric* sprite = &create_sprite(SpriteIdentifier::Misc)->generic; if (sprite != nullptr) { sprite->sprite_width = 33; sprite->sprite_height_negative = 51; sprite->sprite_height_positive = 16; - sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->sprite_identifier = SpriteIdentifier::Misc; sprite->MoveTo(splashPos + CoordsXYZ{ 0, 0, 3 }); sprite->type = SPRITE_MISC_CRASH_SPLASH; sprite->frame = 0; diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index 340a3482aa..5db58b9343 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -60,22 +60,22 @@ template<> bool SpriteBase::Is() const template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_LITTER; + return sprite_identifier == SpriteIdentifier::Litter; } template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_STEAM_PARTICLE; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_STEAM_PARTICLE; } template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_EXPLOSION_FLARE; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_EXPLOSION_FLARE; } template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_MISC && type == SPRITE_MISC_EXPLOSION_CLOUD; + return sprite_identifier == SpriteIdentifier::Misc && type == SPRITE_MISC_EXPLOSION_CLOUD; } uint16_t GetEntityListCount(EntityListId list) @@ -186,7 +186,7 @@ void reset_sprite_list() continue; } - spr->sprite_identifier = SPRITE_IDENTIFIER_NULL; + spr->sprite_identifier = SpriteIdentifier::Null; spr->sprite_index = i; spr->next = SPRITE_INDEX_NULL; spr->linked_list_index = EntityListId::Free; @@ -222,7 +222,7 @@ void reset_sprite_spatial_index() for (size_t i = 0; i < MAX_SPRITES; i++) { auto* spr = GetEntity(i); - if (spr != nullptr && spr->sprite_identifier != SPRITE_IDENTIFIER_NULL) + if (spr != nullptr && spr->sprite_identifier != SpriteIdentifier::Null) { size_t index = GetSpatialIndexOffset(spr->x, spr->y); uint32_t nextSpriteId = gSpriteSpatialIndex[index]; @@ -276,8 +276,8 @@ rct_sprite_checksum sprite_checksum() { // TODO create a way to copy only the specific type auto sprite = GetEntity(i); - if (sprite != nullptr && sprite->sprite_identifier != SPRITE_IDENTIFIER_NULL - && sprite->sprite_identifier != SPRITE_IDENTIFIER_MISC) + if (sprite != nullptr && sprite->sprite_identifier != SpriteIdentifier::Null + && sprite->sprite_identifier != SpriteIdentifier::Misc) { // Upconvert it to rct_sprite so that the full size is copied. auto copy = *reinterpret_cast(sprite); @@ -289,7 +289,7 @@ rct_sprite_checksum sprite_checksum() // Next in quadrant might be a misc sprite, set first non-misc sprite in quadrant. while (auto* nextSprite = GetEntity(copy.generic.next_in_quadrant)) { - if (nextSprite->sprite_identifier == SPRITE_IDENTIFIER_MISC) + if (nextSprite->sprite_identifier == SpriteIdentifier::Misc) copy.generic.next_in_quadrant = nextSprite->next_in_quadrant; else break; @@ -346,7 +346,7 @@ static void sprite_reset(SpriteBase* sprite) sprite->next_in_quadrant = next_in_quadrant; sprite->previous = prev; sprite->sprite_index = sprite_index; - sprite->sprite_identifier = SPRITE_IDENTIFIER_NULL; + sprite->sprite_identifier = SpriteIdentifier::Null; } /** @@ -375,7 +375,7 @@ static void SpriteSpatialInsert(SpriteBase* sprite, const CoordsXY& newLoc); static constexpr uint16_t MAX_MISC_SPRITES = 300; -rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, EntityListId linkedListIndex) +rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier, EntityListId linkedListIndex) { if (GetEntityListCount(EntityListId::Free) == 0) { @@ -420,21 +420,21 @@ rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, EntityListId linke return reinterpret_cast(sprite); } -rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier) +rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier) { EntityListId linkedListIndex = EntityListId::Free; switch (spriteIdentifier) { - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: linkedListIndex = EntityListId::Vehicle; break; - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: linkedListIndex = EntityListId::Peep; break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: linkedListIndex = EntityListId::Misc; break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: linkedListIndex = EntityListId::Litter; break; default: @@ -549,13 +549,13 @@ void SteamParticle::Update() */ void sprite_misc_explosion_cloud_create(const CoordsXYZ& cloudPos) { - SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; + SpriteGeneric* sprite = &create_sprite(SpriteIdentifier::Misc)->generic; if (sprite != nullptr) { sprite->sprite_width = 44; sprite->sprite_height_negative = 32; sprite->sprite_height_positive = 34; - sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->sprite_identifier = SpriteIdentifier::Misc; sprite->MoveTo(cloudPos + CoordsXYZ{ 0, 0, 4 }); sprite->type = SPRITE_MISC_EXPLOSION_CLOUD; sprite->frame = 0; @@ -582,13 +582,13 @@ void ExplosionCloud::Update() */ void sprite_misc_explosion_flare_create(const CoordsXYZ& flarePos) { - SpriteGeneric* sprite = &create_sprite(SPRITE_IDENTIFIER_MISC)->generic; + SpriteGeneric* sprite = &create_sprite(SpriteIdentifier::Misc)->generic; if (sprite != nullptr) { sprite->sprite_width = 25; sprite->sprite_height_negative = 85; sprite->sprite_height_positive = 8; - sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->sprite_identifier = SpriteIdentifier::Misc; sprite->MoveTo(flarePos + CoordsXYZ{ 0, 0, 4 }); sprite->type = SPRITE_MISC_EXPLOSION_FLARE; sprite->frame = 0; @@ -770,7 +770,7 @@ void sprite_remove(SpriteBase* sprite) } move_sprite_to_list(sprite, EntityListId::Free); - sprite->sprite_identifier = SPRITE_IDENTIFIER_NULL; + sprite->sprite_identifier = SpriteIdentifier::Null; _spriteFlashingList[sprite->sprite_index] = false; SpriteSpatialRemove(sprite); @@ -836,7 +836,7 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type) } } - Litter* litter = reinterpret_cast(create_sprite(SPRITE_IDENTIFIER_LITTER)); + Litter* litter = reinterpret_cast(create_sprite(SpriteIdentifier::Litter)); if (litter == nullptr) return; @@ -844,7 +844,7 @@ void litter_create(const CoordsXYZD& litterPos, int32_t type) litter->sprite_width = 6; litter->sprite_height_negative = 6; litter->sprite_height_positive = 3; - litter->sprite_identifier = SPRITE_IDENTIFIER_LITTER; + litter->sprite_identifier = SpriteIdentifier::Litter; litter->type = type; litter->MoveTo(offsetLitterPos); litter->Invalidate0(); @@ -910,8 +910,8 @@ static bool sprite_should_tween(SpriteBase* sprite) { switch (sprite->sprite_identifier) { - case SPRITE_IDENTIFIER_PEEP: - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Peep: + case SpriteIdentifier::Vehicle: return true; } return false; @@ -1138,7 +1138,7 @@ int32_t fix_disjoint_sprites() for (uint16_t sprite_idx = 0; sprite_idx < MAX_SPRITES; sprite_idx++) { auto* spr = GetEntity(sprite_idx); - if (spr != nullptr && spr->sprite_identifier == SPRITE_IDENTIFIER_NULL) + if (spr != nullptr && spr->sprite_identifier == SpriteIdentifier::Null) { openrct2_assert(null_list_tail != nullptr, "Null list is empty, yet found null sprites"); spr->sprite_index = sprite_idx; diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 416fdbf667..ce0a3285f4 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -19,13 +19,13 @@ #define SPRITE_INDEX_NULL 0xFFFF #define MAX_SPRITES 10000 -enum SPRITE_IDENTIFIER +enum class SpriteIdentifier : uint8_t { - SPRITE_IDENTIFIER_VEHICLE = 0, - SPRITE_IDENTIFIER_PEEP = 1, - SPRITE_IDENTIFIER_MISC = 2, - SPRITE_IDENTIFIER_LITTER = 3, - SPRITE_IDENTIFIER_NULL = 255 + Vehicle = 0, + Peep = 1, + Misc = 2, + Litter = 3, + Null = 255 }; enum class EntityListId : uint8_t @@ -225,8 +225,8 @@ extern uint16_t gSpriteSpatialIndex[SPATIAL_INDEX_SIZE]; extern const rct_string_id litterNames[12]; -rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier); -rct_sprite* create_sprite(SPRITE_IDENTIFIER spriteIdentifier, EntityListId linkedListIndex); +rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier); +rct_sprite* create_sprite(SpriteIdentifier spriteIdentifier, EntityListId linkedListIndex); void reset_sprite_list(); void reset_sprite_spatial_index(); void sprite_clear_all_unused(); diff --git a/src/openrct2/world/SpriteBase.h b/src/openrct2/world/SpriteBase.h index 13a4c14ada..81d582b07d 100644 --- a/src/openrct2/world/SpriteBase.h +++ b/src/openrct2/world/SpriteBase.h @@ -4,10 +4,11 @@ struct CoordsXYZ; enum class EntityListId : uint8_t; +enum class SpriteIdentifier : uint8_t; struct SpriteBase { - uint8_t sprite_identifier; + SpriteIdentifier sprite_identifier; uint8_t type; uint16_t next_in_quadrant; uint16_t next; diff --git a/test/testpaint/Compat.cpp b/test/testpaint/Compat.cpp index f0e0dd893e..f214499691 100644 --- a/test/testpaint/Compat.cpp +++ b/test/testpaint/Compat.cpp @@ -153,7 +153,7 @@ template<> bool SpriteBase::Is() const template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_PEEP; + return sprite_identifier == SpriteIdentifier::Peep; } template<> bool SpriteBase::Is() const @@ -164,7 +164,7 @@ template<> bool SpriteBase::Is() const template<> bool SpriteBase::Is() const { - return sprite_identifier == SPRITE_IDENTIFIER_VEHICLE; + return sprite_identifier == SpriteIdentifier::Vehicle; } SpriteBase* get_sprite(size_t sprite_idx) diff --git a/test/tests/S6ImportExportTests.cpp b/test/tests/S6ImportExportTests.cpp index a569c8d65a..491d1bf0b5 100644 --- a/test/tests/S6ImportExportTests.cpp +++ b/test/tests/S6ImportExportTests.cpp @@ -110,7 +110,7 @@ static std::unique_ptr GetGameState(std::unique_ptr& cont { rct_sprite* sprite = reinterpret_cast(GetEntity(spriteIdx)); if (sprite == nullptr) - res->sprites[spriteIdx].generic.sprite_identifier = SPRITE_IDENTIFIER_NULL; + res->sprites[spriteIdx].generic.sprite_identifier = SpriteIdentifier::Null; else res->sprites[spriteIdx] = *sprite; } @@ -410,16 +410,16 @@ static void CompareSpriteData(const rct_sprite& left, const rct_sprite& right) { switch (left.generic.sprite_identifier) { - case SPRITE_IDENTIFIER_PEEP: + case SpriteIdentifier::Peep: CompareSpriteDataPeep(left.peep, right.peep); break; - case SPRITE_IDENTIFIER_VEHICLE: + case SpriteIdentifier::Vehicle: CompareSpriteDataVehicle(left.vehicle, right.vehicle); break; - case SPRITE_IDENTIFIER_LITTER: + case SpriteIdentifier::Litter: CompareSpriteDataLitter(left.litter, right.litter); break; - case SPRITE_IDENTIFIER_MISC: + case SpriteIdentifier::Misc: switch (left.generic.type) { case SPRITE_MISC_STEAM_PARTICLE: @@ -461,8 +461,8 @@ static void CompareStates( for (size_t spriteIdx = 0; spriteIdx < MAX_SPRITES; ++spriteIdx) { - if (importedState->sprites[spriteIdx].generic.sprite_identifier == SPRITE_IDENTIFIER_NULL - && exportedState->sprites[spriteIdx].generic.sprite_identifier == SPRITE_IDENTIFIER_NULL) + if (importedState->sprites[spriteIdx].generic.sprite_identifier == SpriteIdentifier::Null + && exportedState->sprites[spriteIdx].generic.sprite_identifier == SpriteIdentifier::Null) { continue; }