1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Use EnumValue to get the underlying value of an enum

Applied to objects of the enum class PeepActionSpriteType when they are
used as arrays subscripts.
This commit is contained in:
Vinicius Sa
2020-09-28 23:48:43 -03:00
parent f8dd0a57aa
commit ca8fa55fdb
6 changed files with 26 additions and 20 deletions

View File

@@ -1170,7 +1170,7 @@ void window_guest_overview_tool_update(rct_window* w, rct_widgetindex widgetInde
}
uint32_t imageId = g_peep_animation_entries[peep->SpriteType]
.sprite_animation[static_cast<uint8_t>(PeepActionSpriteType::Ui)]
.sprite_animation[EnumValue(PeepActionSpriteType::Ui)]
.base_image;
imageId += w->picked_peep_frame >> 2;

View File

@@ -26,6 +26,7 @@
#include <openrct2/network/network.h>
#include <openrct2/peep/Staff.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Park.h>
@@ -1183,7 +1184,7 @@ void window_staff_overview_tool_update(rct_window* w, rct_widgetindex widgetInde
}
uint32_t imageId = g_peep_animation_entries[peep->SpriteType]
.sprite_animation[static_cast<uint8_t>(PeepActionSpriteType::Ui)]
.sprite_animation[EnumValue(PeepActionSpriteType::Ui)]
.base_image;
imageId += w->picked_peep_frame >> 2;

View File

@@ -11,6 +11,7 @@
#include "../../drawing/LightFX.h"
#include "../../interface/Viewport.h"
#include "../../peep/Peep.h"
#include "../../util/Util.h"
#include "../../world/Sprite.h"
#include "../Paint.h"
#include "Paint.Sprite.h"
@@ -80,8 +81,7 @@ 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[static_cast<uint8_t>(spriteType)].base_image
+ imageOffset * 4;
uint32_t baseImageId = (imageDirection >> 3) + sprite.sprite_animation[EnumValue(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);

View File

@@ -509,9 +509,9 @@ void Peep::UpdateCurrentActionSpriteType()
ActionSpriteType = newActionSpriteType;
const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[SpriteType].sprite_bounds;
sprite_width = spriteBounds[static_cast<uint8_t>(ActionSpriteType)].sprite_width;
sprite_height_negative = spriteBounds[static_cast<uint8_t>(ActionSpriteType)].sprite_height_negative;
sprite_height_positive = spriteBounds[static_cast<uint8_t>(ActionSpriteType)].sprite_height_positive;
sprite_width = spriteBounds[EnumValue(ActionSpriteType)].sprite_width;
sprite_height_negative = spriteBounds[EnumValue(ActionSpriteType)].sprite_height_negative;
sprite_height_positive = spriteBounds[EnumValue(ActionSpriteType)].sprite_height_positive;
Invalidate();
}
@@ -598,8 +598,8 @@ std::optional<CoordsXY> 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[static_cast<uint8_t>(ActionSpriteType)].frame_offsets;
if (WalkingFrameNum >= peepAnimation[static_cast<uint8_t>(ActionSpriteType)].num_frames)
const uint8_t* imageOffset = peepAnimation[EnumValue(ActionSpriteType)].frame_offsets;
if (WalkingFrameNum >= peepAnimation[EnumValue(ActionSpriteType)].num_frames)
{
WalkingFrameNum = 0;
}
@@ -611,14 +611,14 @@ std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
ActionFrame++;
// If last frame of action
if (ActionFrame >= peepAnimation[static_cast<uint8_t>(ActionSpriteType)].num_frames)
if (ActionFrame >= peepAnimation[EnumValue(ActionSpriteType)].num_frames)
{
ActionSpriteImageOffset = 0;
Action = PEEP_ACTION_NONE_2;
UpdateCurrentActionSpriteType();
return { { x, y } };
}
ActionSpriteImageOffset = peepAnimation[static_cast<uint8_t>(ActionSpriteType)].frame_offsets[ActionFrame];
ActionSpriteImageOffset = peepAnimation[EnumValue(ActionSpriteType)].frame_offsets[ActionFrame];
// If not throwing up and not at the frame where sick appears.
if (Action != PEEP_ACTION_THROW_UP || ActionFrame != 15)
@@ -1591,9 +1591,9 @@ Peep* Peep::Generate(const CoordsXYZ& coords)
peep->FavouriteRideRating = 0;
const rct_sprite_bounds* spriteBounds = g_peep_animation_entries[peep->SpriteType].sprite_bounds;
peep->sprite_width = spriteBounds[static_cast<uint8_t>(peep->ActionSpriteType)].sprite_width;
peep->sprite_height_negative = spriteBounds[static_cast<uint8_t>(peep->ActionSpriteType)].sprite_height_negative;
peep->sprite_height_positive = spriteBounds[static_cast<uint8_t>(peep->ActionSpriteType)].sprite_height_positive;
peep->sprite_width = spriteBounds[EnumValue(peep->ActionSpriteType)].sprite_width;
peep->sprite_height_negative = spriteBounds[EnumValue(peep->ActionSpriteType)].sprite_height_negative;
peep->sprite_height_positive = spriteBounds[EnumValue(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[static_cast<uint8_t>(NextActionSpriteType)].sprite_width;
sprite_height_negative = spriteBounds[static_cast<uint8_t>(NextActionSpriteType)].sprite_height_negative;
sprite_height_positive = spriteBounds[static_cast<uint8_t>(NextActionSpriteType)].sprite_height_positive;
sprite_width = spriteBounds[EnumValue(NextActionSpriteType)].sprite_width;
sprite_height_negative = spriteBounds[EnumValue(NextActionSpriteType)].sprite_height_negative;
sprite_height_positive = spriteBounds[EnumValue(NextActionSpriteType)].sprite_height_positive;
Invalidate();
}
}

View File

@@ -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[static_cast<uint8_t>(dst->ActionSpriteType)].sprite_width;
dst->sprite_height_negative = spriteBounds[static_cast<uint8_t>(dst->ActionSpriteType)].sprite_height_negative;
dst->sprite_height_positive = spriteBounds[static_cast<uint8_t>(dst->ActionSpriteType)].sprite_height_positive;
dst->sprite_width = spriteBounds[EnumValue(dst->ActionSpriteType)].sprite_width;
dst->sprite_height_negative = spriteBounds[EnumValue(dst->ActionSpriteType)].sprite_height_negative;
dst->sprite_height_positive = spriteBounds[EnumValue(dst->ActionSpriteType)].sprite_height_positive;
dst->MoveTo({ src->x, src->y, src->z });
dst->Invalidate2();

View File

@@ -81,4 +81,9 @@ template<typename... T>[[nodiscard]] constexpr uint64_t EnumsToFlags(T... types)
return (EnumToFlag(types) | ...);
}
template<typename TEnum> constexpr auto EnumValue(TEnum enumerator) noexcept
{
return static_cast<std::underlying_type_t<TEnum>>(enumerator);
}
#endif