Compare commits

...

8 Commits

Author SHA1 Message Date
Aaron van Geffen 637ca6ba44
Merge ca2080f408 into 9266a6f0d3 2024-04-28 15:10:47 +02:00
Aaron van Geffen ca2080f408 When painting peeps, don't use rotations for 'picked up' sprites 2024-04-28 15:10:09 +02:00
Aaron van Geffen d8d91c7170 When setting animation, override any queued NextActionSpriteType as well 2024-04-28 15:09:49 +02:00
Aaron van Geffen fde4d9ac17 Use named constants in Peep::Paint 2024-04-28 14:40:19 +02:00
Aaron van Geffen ba32881a7f Use WalkingFrameNum if peep is walking 2024-04-28 13:14:35 +02:00
Aaron van Geffen f3ffcd65dc Reset ActionSpriteImageOffset after setting ActionFrame 2024-04-28 12:04:11 +02:00
Aaron van Geffen 2fa26cc8a1 Fixup: same for guests... 2024-04-28 11:52:58 +02:00
Aaron van Geffen fc3b597969 Split off Peep::UpdateSpriteBoundingBox 2024-04-28 11:42:31 +02:00
4 changed files with 54 additions and 17 deletions

View File

@ -36,6 +36,7 @@
#include "../paint/Paint.h"
#include "../peep/GuestPathfinding.h"
#include "../peep/PeepAnimationData.h"
#include "../peep/PeepSpriteIds.h"
#include "../profiling/Profiling.h"
#include "../ride/Ride.h"
#include "../ride/RideData.h"
@ -344,9 +345,15 @@ void Peep::UpdateCurrentActionSpriteType()
return;
}
Invalidate();
ActionSpriteType = newActionSpriteType;
UpdateSpriteBoundingBox();
}
void Peep::UpdateSpriteBoundingBox()
{
Invalidate();
const SpriteBounds* spriteBounds = &GetSpriteBounds(SpriteType, ActionSpriteType);
SpriteData.Width = spriteBounds->sprite_width;
SpriteData.HeightMin = spriteBounds->sprite_height_negative;
@ -2792,7 +2799,14 @@ void Peep::Paint(PaintSession& session, int32_t imageDirection) const
// In the following 4 calls to PaintAddImageAsParent/PaintAddImageAsChild, 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) + GetPeepAnimation(SpriteType, actionSpriteType).base_image + imageOffset * 4;
uint32_t baseImageId = GetPeepAnimation(SpriteType, actionSpriteType).base_image;
// Offset frame onto the base image, using rotation except for the 'picked up' state
if (actionSpriteType != PeepActionSpriteType::Ui)
baseImageId += (imageDirection >> 3) + imageOffset * 4;
else
baseImageId += imageOffset;
auto imageId = ImageId(baseImageId, TshirtColour, TrousersColour);
auto bb = BoundBoxXYZ{ { 0, 0, z + 5 }, { 1, 1, 11 } };
@ -2802,21 +2816,21 @@ void Peep::Paint(PaintSession& session, int32_t imageDirection) const
auto* guest = As<Guest>();
if (guest != nullptr)
{
if (baseImageId >= 10717 && baseImageId < 10749)
if (baseImageId >= kPeepSpriteHatStateWatchRideId && baseImageId < (kPeepSpriteHatStateSittingIdleId + 4))
{
imageId = ImageId(baseImageId + 32, guest->HatColour);
PaintAddImageAsChild(session, imageId, offset, bb);
return;
}
if (baseImageId >= 10781 && baseImageId < 10813)
if (baseImageId >= kPeepSpriteBalloonStateWatchRideId && baseImageId < (kPeepSpriteBalloonStateSittingIdleId + 4))
{
imageId = ImageId(baseImageId + 32, guest->BalloonColour);
PaintAddImageAsChild(session, imageId, offset, bb);
return;
}
if (baseImageId >= 11197 && baseImageId < 11229)
if (baseImageId >= kPeepSpriteUmbrellaStateNoneId && baseImageId < (kPeepSpriteUmbrellaStateSittingIdleId + 4))
{
imageId = ImageId(baseImageId + 32, guest->UmbrellaColour);
PaintAddImageAsChild(session, imageId, offset, bb);

View File

@ -379,6 +379,7 @@ public: // Peep
void SetState(PeepState new_state);
void Remove();
void UpdateCurrentActionSpriteType();
void UpdateSpriteBoundingBox();
void SwitchToSpecialSprite(uint8_t special_sprite_id);
void StateReset();
[[nodiscard]] uint8_t GetNextDirection() const;

View File

@ -858,12 +858,17 @@ namespace OpenRCT2::Scripting
}
auto* peep = GetGuest();
peep->ActionSpriteType = *newType;
peep->ActionFrame = 0;
peep->ActionSpriteType = peep->NextActionSpriteType = *newType;
auto offset = 0;
if (peep->IsActionWalking())
peep->WalkingFrameNum = offset;
else
peep->ActionFrame = offset;
auto& animationGroup = GetPeepAnimation(peep->SpriteType, peep->ActionSpriteType);
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[peep->ActionFrame];
peep->UpdateCurrentActionSpriteType();
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[offset];
peep->UpdateSpriteBoundingBox();
}
uint8_t ScGuest::animationOffset_get() const
@ -885,9 +890,15 @@ namespace OpenRCT2::Scripting
auto& animationGroup = GetPeepAnimation(peep->SpriteType, peep->ActionSpriteType);
auto length = animationGroup.frame_offsets.size();
offset %= length;
peep->ActionFrame = offset % length;
peep->UpdateCurrentActionSpriteType();
if (peep->IsActionWalking())
peep->WalkingFrameNum = offset;
else
peep->ActionFrame = offset;
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[offset];
peep->UpdateSpriteBoundingBox();
}
uint8_t ScGuest::animationLength_get() const

View File

@ -248,12 +248,17 @@ namespace OpenRCT2::Scripting
return;
}
peep->ActionSpriteType = *newType;
peep->ActionFrame = 0;
peep->ActionSpriteType = peep->NextActionSpriteType = *newType;
auto offset = 0;
if (peep->IsActionWalking())
peep->WalkingFrameNum = offset;
else
peep->ActionFrame = offset;
auto& animationGroup = GetPeepAnimation(peep->SpriteType, peep->ActionSpriteType);
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[peep->ActionFrame];
peep->UpdateCurrentActionSpriteType();
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[offset];
peep->UpdateSpriteBoundingBox();
}
uint8_t ScStaff::animationOffset_get() const
@ -275,9 +280,15 @@ namespace OpenRCT2::Scripting
auto& animationGroup = GetPeepAnimation(peep->SpriteType, peep->ActionSpriteType);
auto length = animationGroup.frame_offsets.size();
offset %= length;
peep->ActionFrame = offset % length;
peep->UpdateCurrentActionSpriteType();
if (peep->IsActionWalking())
peep->WalkingFrameNum = offset;
else
peep->ActionFrame = offset;
peep->ActionSpriteImageOffset = animationGroup.frame_offsets[offset];
peep->UpdateSpriteBoundingBox();
}
uint8_t ScStaff::animationLength_get() const