From f8dd0a57aa032ad907b099dc3dca031f00686d5d Mon Sep 17 00:00:00 2001 From: Vinicius Sa Date: Sat, 26 Sep 2020 20:52:45 -0300 Subject: [PATCH] Refactor PeepActionSpriteType to use strong enum --- src/openrct2-ui/windows/Guest.cpp | 4 +- src/openrct2-ui/windows/Staff.cpp | 4 +- src/openrct2/actions/StaffHireNewAction.hpp | 2 +- src/openrct2/paint/sprite/Paint.Peep.cpp | 3 +- src/openrct2/peep/Guest.cpp | 12 +-- src/openrct2/peep/Peep.cpp | 106 ++++++++++---------- src/openrct2/peep/Peep.h | 78 +++++++------- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 6 +- 9 files changed, 111 insertions(+), 106 deletions(-) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 7be15e3544..4e364b147d 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1169,7 +1169,9 @@ void window_guest_overview_tool_update(rct_window* w, rct_widgetindex widgetInde return; } - uint32_t imageId = g_peep_animation_entries[peep->SpriteType].sprite_animation[PEEP_ACTION_SPRITE_TYPE_UI].base_image; + uint32_t imageId = g_peep_animation_entries[peep->SpriteType] + .sprite_animation[static_cast(PeepActionSpriteType::Ui)] + .base_image; imageId += w->picked_peep_frame >> 2; imageId |= (peep->TshirtColour << 19) | (peep->TrousersColour << 24) | IMAGE_TYPE_REMAP | IMAGE_TYPE_REMAP_2_PLUS; diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 0e1d2fdb70..e5ec586c2b 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -1182,7 +1182,9 @@ void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetInde return; } - uint32_t imageId = g_peep_animation_entries[peep->SpriteType].sprite_animation[PEEP_ACTION_SPRITE_TYPE_UI].base_image; + uint32_t imageId = g_peep_animation_entries[peep->SpriteType] + .sprite_animation[static_cast(PeepActionSpriteType::Ui)] + .base_image; imageId += w->picked_peep_frame >> 2; imageId |= (peep->TshirtColour << 19) | (peep->TrousersColour << 24) | IMAGE_TYPE_REMAP | IMAGE_TYPE_REMAP_2_PLUS; diff --git a/src/openrct2/actions/StaffHireNewAction.hpp b/src/openrct2/actions/StaffHireNewAction.hpp index 1e7ff452a6..39195a11d3 100644 --- a/src/openrct2/actions/StaffHireNewAction.hpp +++ b/src/openrct2/actions/StaffHireNewAction.hpp @@ -164,7 +164,7 @@ private: newPeep->SpecialSprite = 0; newPeep->ActionSpriteImageOffset = 0; newPeep->WalkingFrameNum = 0; - newPeep->ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_NONE; + newPeep->ActionSpriteType = PeepActionSpriteType::None; newPeep->PathCheckOptimisation = 0; newPeep->AssignedPeepType = PeepType::Staff; newPeep->OutsideOfPark = false; diff --git a/src/openrct2/paint/sprite/Paint.Peep.cpp b/src/openrct2/paint/sprite/Paint.Peep.cpp index f94f913c2e..90ff5182f9 100644 --- a/src/openrct2/paint/sprite/Paint.Peep.cpp +++ b/src/openrct2/paint/sprite/Paint.Peep.cpp @@ -80,7 +80,8 @@ void peep_paint(paint_session* session, const Peep* peep, int32_t imageDirection // In the following 4 calls to sub_98197C/sub_98199C, we add 5 (instead of 3) to the // bound_box_offset_z to make sure peeps are drawn on top of railways - uint32_t baseImageId = (imageDirection >> 3) + sprite.sprite_animation[spriteType].base_image + imageOffset * 4; + uint32_t baseImageId = (imageDirection >> 3) + sprite.sprite_animation[static_cast(spriteType)].base_image + + imageOffset * 4; uint32_t imageId = baseImageId | peep->TshirtColour << 19 | peep->TrousersColour << 24 | IMAGE_TYPE_REMAP | IMAGE_TYPE_REMAP_2_PLUS; sub_98197C(session, imageId, 0, 0, 1, 1, 11, peep->z, 0, 0, peep->z + 5); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index d867f948ae..4f92717023 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -1244,7 +1244,7 @@ void Guest::UpdateSitting() sprite_direction = ((Var37 + 2) & 3) * 8; Action = PEEP_ACTION_NONE_1; - NextActionSpriteType = PEEP_ACTION_SPRITE_TYPE_SITTING_IDLE; + NextActionSpriteType = PeepActionSpriteType::SittingIdle; SwitchNextActionSpriteType(); SittingSubState = PeepSittingSubState::SatDown; @@ -5618,7 +5618,7 @@ void Guest::UpdateQueuing() } else { - if (!(TimeInQueue & 0x3F) && Action == PEEP_ACTION_NONE_1 && NextActionSpriteType == 2) + if (!(TimeInQueue & 0x3F) && Action == PEEP_ACTION_NONE_1 && NextActionSpriteType == PeepActionSpriteType::WatchRide) { switch (SpriteType) { @@ -5757,7 +5757,7 @@ void Guest::UpdateWatching() sprite_direction = (Var37 & 3) * 8; Action = PEEP_ACTION_NONE_1; - NextActionSpriteType = PEEP_ACTION_SPRITE_TYPE_WATCH_RIDE; + NextActionSpriteType = PeepActionSpriteType::WatchRide; SwitchNextActionSpriteType(); @@ -6777,19 +6777,19 @@ void Guest::SetSpriteType(PeepSpriteType new_sprite_type) PeepFlags |= PEEP_FLAGS_SLOW_WALK; } - ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_INVALID; + ActionSpriteType = PeepActionSpriteType::Invalid; UpdateCurrentActionSpriteType(); if (State == PeepState::Sitting) { Action = PEEP_ACTION_NONE_1; - NextActionSpriteType = PEEP_ACTION_SPRITE_TYPE_SITTING_IDLE; + NextActionSpriteType = PeepActionSpriteType::SittingIdle; SwitchNextActionSpriteType(); } if (State == PeepState::Watching) { Action = PEEP_ACTION_NONE_1; - NextActionSpriteType = PEEP_ACTION_SPRITE_TYPE_WATCH_RIDE; + NextActionSpriteType = PeepActionSpriteType::WatchRide; SwitchNextActionSpriteType(); } } diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 6fe21eedbf..4c7cd41f42 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -266,43 +266,43 @@ static struct }; static PeepActionSpriteType PeepSpecialSpriteToSpriteTypeMap[] = { - PEEP_ACTION_SPRITE_TYPE_NONE, - PEEP_ACTION_SPRITE_TYPE_HOLD_MAT, - PEEP_ACTION_SPRITE_TYPE_STAFF_MOWER + PeepActionSpriteType::None, + PeepActionSpriteType::HoldMat, + PeepActionSpriteType::StaffMower }; static PeepActionSpriteType PeepActionToSpriteTypeMap[] = { - PEEP_ACTION_SPRITE_TYPE_CHECK_TIME, - PEEP_ACTION_SPRITE_TYPE_EAT_FOOD, - PEEP_ACTION_SPRITE_TYPE_SHAKE_HEAD, - PEEP_ACTION_SPRITE_TYPE_EMPTY_POCKETS, - PEEP_ACTION_SPRITE_TYPE_SITTING_EAT_FOOD, - PEEP_ACTION_SPRITE_TYPE_SITTING_LOOK_AROUND_LEFT, - PEEP_ACTION_SPRITE_TYPE_SITTING_LOOK_AROUND_RIGHT, - PEEP_ACTION_SPRITE_TYPE_WOW, - PEEP_ACTION_SPRITE_TYPE_THROW_UP, - PEEP_ACTION_SPRITE_TYPE_JUMP, - PEEP_ACTION_SPRITE_TYPE_STAFF_SWEEP, - PEEP_ACTION_SPRITE_TYPE_DROWNING, - PEEP_ACTION_SPRITE_TYPE_STAFF_ANSWER_CALL, - PEEP_ACTION_SPRITE_TYPE_STAFF_ANSWER_CALL_2, - PEEP_ACTION_SPRITE_TYPE_STAFF_CHECKBOARD, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_2, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_GROUND, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_3, - PEEP_ACTION_SPRITE_TYPE_STAFF_WATERING, - PEEP_ACTION_SPRITE_TYPE_JOY, - PEEP_ACTION_SPRITE_TYPE_READ_MAP, - PEEP_ACTION_SPRITE_TYPE_WAVE, - PEEP_ACTION_SPRITE_TYPE_STAFF_EMPTY_BIN, - PEEP_ACTION_SPRITE_TYPE_WAVE_2, - PEEP_ACTION_SPRITE_TYPE_TAKE_PHOTO, - PEEP_ACTION_SPRITE_TYPE_CLAP, - PEEP_ACTION_SPRITE_TYPE_DISGUST, - PEEP_ACTION_SPRITE_TYPE_DRAW_PICTURE, - PEEP_ACTION_SPRITE_TYPE_BEING_WATCHED, - PEEP_ACTION_SPRITE_TYPE_WITHDRAW_MONEY + PeepActionSpriteType::CheckTime, + PeepActionSpriteType::EatFood, + PeepActionSpriteType::ShakeHead, + PeepActionSpriteType::EmptyPockets, + PeepActionSpriteType::SittingEatFood, + PeepActionSpriteType::SittingLookAroundLeft, + PeepActionSpriteType::SittingLookAroundRight, + PeepActionSpriteType::Wow, + PeepActionSpriteType::ThrowUp, + PeepActionSpriteType::Jump, + PeepActionSpriteType::StaffSweep, + PeepActionSpriteType::Drowning, + PeepActionSpriteType::StaffAnswerCall, + PeepActionSpriteType::StaffAnswerCall2, + PeepActionSpriteType::StaffCheckboard, + PeepActionSpriteType::StaffFix, + PeepActionSpriteType::StaffFix2, + PeepActionSpriteType::StaffFixGround, + PeepActionSpriteType::StaffFix3, + PeepActionSpriteType::StaffWatering, + PeepActionSpriteType::Joy, + PeepActionSpriteType::ReadMap, + PeepActionSpriteType::Wave, + PeepActionSpriteType::StaffEmptyBin, + PeepActionSpriteType::Wave2, + PeepActionSpriteType::TakePhoto, + PeepActionSpriteType::Clap, + PeepActionSpriteType::Disgust, + PeepActionSpriteType::DrawPicture, + PeepActionSpriteType::BeingWatched, + PeepActionSpriteType::WithdrawMoney }; const bool gSpriteTypeToSlowWalkMap[] = { @@ -486,7 +486,7 @@ PeepActionSpriteType Peep::GetActionSpriteType() { openrct2_assert( Action >= std::size(PeepActionToSpriteTypeMap) && Action < PEEP_ACTION_NONE_1, "Invalid peep action %u", Action); - return PEEP_ACTION_SPRITE_TYPE_NONE; + return PeepActionSpriteType::None; } } @@ -509,9 +509,9 @@ void Peep::UpdateCurrentActionSpriteType() ActionSpriteType = newActionSpriteType; const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[SpriteType].sprite_bounds; - sprite_width = spriteBounds[ActionSpriteType].sprite_width; - sprite_height_negative = spriteBounds[ActionSpriteType].sprite_height_negative; - sprite_height_positive = spriteBounds[ActionSpriteType].sprite_height_positive; + sprite_width = spriteBounds[static_cast(ActionSpriteType)].sprite_width; + sprite_height_negative = spriteBounds[static_cast(ActionSpriteType)].sprite_height_negative; + sprite_height_positive = spriteBounds[static_cast(ActionSpriteType)].sprite_height_positive; Invalidate(); } @@ -598,8 +598,8 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) loc += word_981D7C[nextDirection / 8]; WalkingFrameNum++; const rct_peep_animation* peepAnimation = g_peep_animation_entries[SpriteType].sprite_animation; - const uint8_t* imageOffset = peepAnimation[ActionSpriteType].frame_offsets; - if (WalkingFrameNum >= peepAnimation[ActionSpriteType].num_frames) + const uint8_t* imageOffset = peepAnimation[static_cast(ActionSpriteType)].frame_offsets; + if (WalkingFrameNum >= peepAnimation[static_cast(ActionSpriteType)].num_frames) { WalkingFrameNum = 0; } @@ -611,14 +611,14 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) ActionFrame++; // If last frame of action - if (ActionFrame >= peepAnimation[ActionSpriteType].num_frames) + if (ActionFrame >= peepAnimation[static_cast(ActionSpriteType)].num_frames) { ActionSpriteImageOffset = 0; Action = PEEP_ACTION_NONE_2; UpdateCurrentActionSpriteType(); return { { x, y } }; } - ActionSpriteImageOffset = peepAnimation[ActionSpriteType].frame_offsets[ActionFrame]; + ActionSpriteImageOffset = peepAnimation[static_cast(ActionSpriteType)].frame_offsets[ActionFrame]; // If not throwing up and not at the frame where sick appears. if (Action != PEEP_ACTION_THROW_UP || ActionFrame != 15) @@ -722,7 +722,7 @@ void Peep::PickupAbort(int32_t old_x) Action = PEEP_ACTION_NONE_2; SpecialSprite = 0; ActionSpriteImageOffset = 0; - ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_NONE; + ActionSpriteType = PeepActionSpriteType::None; PathCheckOptimisation = 0; } @@ -772,13 +772,13 @@ std::unique_ptr Peep::Place(const TileCoordsXYZ& location, boo Action = PEEP_ACTION_NONE_2; SpecialSprite = 0; ActionSpriteImageOffset = 0; - ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_NONE; + ActionSpriteType = PeepActionSpriteType::None; PathCheckOptimisation = 0; sprite_position_tween_reset(); if (AssignedPeepType == PeepType::Guest) { - ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_INVALID; + ActionSpriteType = PeepActionSpriteType::Invalid; HappinessTarget = std::max(HappinessTarget - 10, 0); UpdateCurrentActionSpriteType(); } @@ -1585,15 +1585,15 @@ Peep* Peep::Generate(const CoordsXYZ& coords) peep->SpecialSprite = 0; peep->ActionSpriteImageOffset = 0; peep->WalkingFrameNum = 0; - peep->ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_NONE; + peep->ActionSpriteType = PeepActionSpriteType::None; peep->PeepFlags = 0; peep->FavouriteRide = RIDE_ID_NULL; peep->FavouriteRideRating = 0; const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[peep->SpriteType].sprite_bounds; - peep->sprite_width = spriteBounds[peep->ActionSpriteType].sprite_width; - peep->sprite_height_negative = spriteBounds[peep->ActionSpriteType].sprite_height_negative; - peep->sprite_height_positive = spriteBounds[peep->ActionSpriteType].sprite_height_positive; + peep->sprite_width = spriteBounds[static_cast(peep->ActionSpriteType)].sprite_width; + peep->sprite_height_negative = spriteBounds[static_cast(peep->ActionSpriteType)].sprite_height_negative; + peep->sprite_height_positive = spriteBounds[static_cast(peep->ActionSpriteType)].sprite_height_positive; peep->MoveTo(coords); peep->sprite_direction = 0; @@ -2192,9 +2192,9 @@ void Peep::SwitchNextActionSpriteType() Invalidate(); ActionSpriteType = NextActionSpriteType; const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[SpriteType].sprite_bounds; - sprite_width = spriteBounds[NextActionSpriteType].sprite_width; - sprite_height_negative = spriteBounds[NextActionSpriteType].sprite_height_negative; - sprite_height_positive = spriteBounds[NextActionSpriteType].sprite_height_positive; + sprite_width = spriteBounds[static_cast(NextActionSpriteType)].sprite_width; + sprite_height_negative = spriteBounds[static_cast(NextActionSpriteType)].sprite_height_negative; + sprite_height_positive = spriteBounds[static_cast(NextActionSpriteType)].sprite_height_positive; Invalidate(); } } @@ -2267,7 +2267,7 @@ static bool peep_update_queue_position(Peep* peep, uint8_t previous_action) return true; peep->Action = PEEP_ACTION_NONE_1; - peep->NextActionSpriteType = PEEP_ACTION_SPRITE_TYPE_WATCH_RIDE; + peep->NextActionSpriteType = PeepActionSpriteType::WatchRide; if (previous_action != PEEP_ACTION_NONE_1) peep->Invalidate(); return true; diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 997dd0e958..92d75246cd 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -319,47 +319,47 @@ enum PeepActionType : uint8_t PEEP_ACTION_NONE_2 = 255, }; -enum PeepActionSpriteType : uint8_t +enum class PeepActionSpriteType : uint8_t { - PEEP_ACTION_SPRITE_TYPE_NONE = 0, - PEEP_ACTION_SPRITE_TYPE_CHECK_TIME = 1, - PEEP_ACTION_SPRITE_TYPE_WATCH_RIDE = 2, - PEEP_ACTION_SPRITE_TYPE_EAT_FOOD = 3, - PEEP_ACTION_SPRITE_TYPE_SHAKE_HEAD = 4, - PEEP_ACTION_SPRITE_TYPE_EMPTY_POCKETS = 5, - PEEP_ACTION_SPRITE_TYPE_HOLD_MAT = 6, - PEEP_ACTION_SPRITE_TYPE_SITTING_IDLE = 7, - PEEP_ACTION_SPRITE_TYPE_SITTING_EAT_FOOD = 8, - PEEP_ACTION_SPRITE_TYPE_SITTING_LOOK_AROUND_LEFT = 9, - PEEP_ACTION_SPRITE_TYPE_SITTING_LOOK_AROUND_RIGHT = 10, - PEEP_ACTION_SPRITE_TYPE_UI = 11, - PEEP_ACTION_SPRITE_TYPE_STAFF_MOWER = 12, - PEEP_ACTION_SPRITE_TYPE_WOW = 13, - PEEP_ACTION_SPRITE_TYPE_THROW_UP = 14, - PEEP_ACTION_SPRITE_TYPE_JUMP = 15, - PEEP_ACTION_SPRITE_TYPE_STAFF_SWEEP = 16, - PEEP_ACTION_SPRITE_TYPE_DROWNING = 17, - PEEP_ACTION_SPRITE_TYPE_STAFF_ANSWER_CALL = 18, - PEEP_ACTION_SPRITE_TYPE_STAFF_ANSWER_CALL_2 = 19, - PEEP_ACTION_SPRITE_TYPE_STAFF_CHECKBOARD = 20, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX = 21, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_2 = 22, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_GROUND = 23, - PEEP_ACTION_SPRITE_TYPE_STAFF_FIX_3 = 24, - PEEP_ACTION_SPRITE_TYPE_STAFF_WATERING = 25, - PEEP_ACTION_SPRITE_TYPE_JOY = 26, - PEEP_ACTION_SPRITE_TYPE_READ_MAP = 27, - PEEP_ACTION_SPRITE_TYPE_WAVE = 28, - PEEP_ACTION_SPRITE_TYPE_STAFF_EMPTY_BIN = 29, - PEEP_ACTION_SPRITE_TYPE_WAVE_2 = 30, - PEEP_ACTION_SPRITE_TYPE_TAKE_PHOTO = 31, - PEEP_ACTION_SPRITE_TYPE_CLAP = 32, - PEEP_ACTION_SPRITE_TYPE_DISGUST = 33, - PEEP_ACTION_SPRITE_TYPE_DRAW_PICTURE = 34, - PEEP_ACTION_SPRITE_TYPE_BEING_WATCHED = 35, - PEEP_ACTION_SPRITE_TYPE_WITHDRAW_MONEY = 36, + None = 0, + CheckTime = 1, + WatchRide = 2, + EatFood = 3, + ShakeHead = 4, + EmptyPockets = 5, + HoldMat = 6, + SittingIdle = 7, + SittingEatFood = 8, + SittingLookAroundLeft = 9, + SittingLookAroundRight = 10, + Ui = 11, + StaffMower = 12, + Wow = 13, + ThrowUp = 14, + Jump = 15, + StaffSweep = 16, + Drowning = 17, + StaffAnswerCall = 18, + StaffAnswerCall2 = 19, + StaffCheckboard = 20, + StaffFix = 21, + StaffFix2 = 22, + StaffFixGround = 23, + StaffFix3 = 24, + StaffWatering = 25, + Joy = 26, + ReadMap = 27, + Wave = 28, + StaffEmptyBin = 29, + Wave2 = 30, + TakePhoto = 31, + Clap = 32, + Disgust = 33, + DrawPicture = 34, + BeingWatched = 35, + WithdrawMoney = 36, - PEEP_ACTION_SPRITE_TYPE_INVALID = 255 + Invalid = 255 }; enum PeepFlags : uint32_t diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index e765b9c53c..0866a2c404 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1815,7 +1815,7 @@ void Staff::Tick128UpdateStaff() PeepFlags |= PEEP_FLAGS_SLOW_WALK; } - ActionSpriteType = PEEP_ACTION_SPRITE_TYPE_INVALID; + ActionSpriteType = PeepActionSpriteType::Invalid; UpdateCurrentActionSpriteType(); } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index e610fbccee..c855b63847 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1406,9 +1406,9 @@ private: dst->ActionFrame = src->action_frame; const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[dst->SpriteType].sprite_bounds; - dst->sprite_width = spriteBounds[dst->ActionSpriteType].sprite_width; - dst->sprite_height_negative = spriteBounds[dst->ActionSpriteType].sprite_height_negative; - dst->sprite_height_positive = spriteBounds[dst->ActionSpriteType].sprite_height_positive; + dst->sprite_width = spriteBounds[static_cast(dst->ActionSpriteType)].sprite_width; + dst->sprite_height_negative = spriteBounds[static_cast(dst->ActionSpriteType)].sprite_height_negative; + dst->sprite_height_positive = spriteBounds[static_cast(dst->ActionSpriteType)].sprite_height_positive; dst->MoveTo({ src->x, src->y, src->z }); dst->Invalidate2();