Skip to content

Commit

Permalink
Merge pull request #13310 from ju-pinheiro/sprite-identifier-strong-enum
Browse files Browse the repository at this point in the history
Close #12450: Refactor SPRITE_IDENTIFIER to use strong enum
  • Loading branch information
Gymnasiast committed Nov 6, 2020
2 parents 3c1aaa9 + a31c958 commit 92a5f1a
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 171 deletions.
21 changes: 14 additions & 7 deletions src/openrct2-ui/interface/ViewportInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoord
case VIEWPORT_INTERACTION_ITEM_SPRITE:
switch (sprite->sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
case SpriteIdentifier::Vehicle:
{
auto vehicle = sprite->As<Vehicle>();
if (vehicle != nullptr && vehicle->ride_subtype != RIDE_ENTRY_INDEX_NULL)
Expand All @@ -96,7 +96,7 @@ InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoord
info.SpriteType = VIEWPORT_INTERACTION_ITEM_NONE;
}
break;
case SPRITE_IDENTIFIER_PEEP:
case SpriteIdentifier::Peep:
{
auto peep = sprite->As<Peep>();
if (peep != nullptr)
Expand All @@ -109,6 +109,10 @@ InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoord
}
}
break;
case SpriteIdentifier::Misc:
case SpriteIdentifier::Litter:
case SpriteIdentifier::Null:
break;
}
break;
case VIEWPORT_INTERACTION_ITEM_RIDE:
Expand Down Expand Up @@ -173,21 +177,21 @@ bool ViewportInteractionLeftClick(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)
Expand All @@ -210,6 +214,9 @@ bool ViewportInteractionLeftClick(const ScreenCoordsXY& screenCoords)
}
}
break;
case SpriteIdentifier::Litter:
case SpriteIdentifier::Null:
break;
}
return true;
}
Expand Down Expand Up @@ -254,7 +261,7 @@ InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoor
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;
Expand Down Expand Up @@ -523,7 +530,7 @@ bool ViewportInteractionRightClick(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<Vehicle>();
if (vehicle == nullptr)
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,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 });
}
Expand Down
50 changes: 27 additions & 23 deletions src/openrct2/GameStateSnapshots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(i));
}
Expand Down Expand Up @@ -80,16 +80,16 @@ struct GameStateSnapshot_t

switch (sprite.generic.sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
case SpriteIdentifier::Vehicle:
ds << reinterpret_cast<uint8_t(&)[sizeof(Vehicle)]>(sprite.vehicle);
break;
case SPRITE_IDENTIFIER_PEEP:
case SpriteIdentifier::Peep:
ds << reinterpret_cast<uint8_t(&)[sizeof(Peep)]>(sprite.peep);
break;
case SPRITE_IDENTIFIER_LITTER:
case SpriteIdentifier::Litter:
ds << reinterpret_cast<uint8_t(&)[sizeof(Litter)]>(sprite.litter);
break;
case SPRITE_IDENTIFIER_MISC:
case SpriteIdentifier::Misc:
{
ds << sprite.generic.type;
switch (sprite.generic.type)
Expand All @@ -110,8 +110,10 @@ struct GameStateSnapshot_t
ds << reinterpret_cast<uint8_t(&)[sizeof(SteamParticle)]>(sprite.steam_particle);
break;
}
break;
}
break;
case SpriteIdentifier::Null:
break;
}
}
}
Expand Down Expand Up @@ -172,7 +174,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);
Expand Down Expand Up @@ -479,16 +481,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)
Expand Down Expand Up @@ -521,6 +523,8 @@ struct GameStateSnapshots final : public IGameStateSnapshots
break;
}
break;
case SpriteIdentifier::Null:
break;
}
}
}
Expand All @@ -546,24 +550,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;
Expand All @@ -587,19 +591,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:
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/GameStateSnapshots.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct GameStateSpriteChange_t
};

uint8_t changeType;
uint8_t spriteIdentifier;
SpriteIdentifier spriteIdentifier;
uint8_t miscIdentifier;
uint32_t spriteIndex;

Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/PeepPickupAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ DEFINE_GAME_ACTION(PeepPickupAction, GAME_COMMAND_PICKUP_GUEST, GameActions::Res
}

auto* const peep = TryGetEntity<Peep>(_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);
Expand Down Expand Up @@ -126,7 +126,7 @@ DEFINE_GAME_ACTION(PeepPickupAction, GAME_COMMAND_PICKUP_GUEST, GameActions::Res
GameActions::Result::Ptr Execute() const override
{
Peep* const peep = TryGetEntity<Peep>(_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);
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/StaffHireNewAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ DEFINE_GAME_ACTION(StaffHireNewAction, GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, Staff
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.
Expand All @@ -158,7 +158,7 @@ DEFINE_GAME_ACTION(StaffHireNewAction, GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, Staff
}
else
{
newPeep->sprite_identifier = 1;
newPeep->sprite_identifier = SpriteIdentifier::Peep;
newPeep->WindowInvalidateFlags = 0;
newPeep->Action = PeepActionType::None2;
newPeep->SpecialSprite = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/interface/InteractiveConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Peep>();
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/interface/Viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Peep>(window->viewport_smart_follow_sprite);
if (peep == nullptr)
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/openrct2/paint/sprite/Paint.Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<Vehicle>(), image_direction);
#ifdef __ENABLE_LIGHTFX__
if (lightfx_for_vehicles_is_available())
Expand All @@ -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<Peep>(), 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<Litter>(), image_direction);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions src/openrct2/peep/Peep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const bool gSpriteTypeToSlowWalkMap[] = {

template<> bool SpriteBase::Is<Peep>() const
{
return sprite_identifier == SPRITE_IDENTIFIER_PEEP;
return sprite_identifier == SpriteIdentifier::Peep;
}

Guest* Peep::AsGuest()
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/peep/Staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit 92a5f1a

Please sign in to comment.