Browse Source

Add helper for selecting animation sprites from Direction

The use on PlayerAnimationData could be further simplified by adding a helper to PlayerStruct but that'd be introducing another changed file to the PR... Something for later.

The monster version is only used once thanks to the helpers added in previous commits. This was mainly to highlight the similarity between PlayerAnimationData and AnimStruct, AnimStruct could inherit/extend PlayerAnimationData without much trouble.
pull/2845/head
ephphatha 5 years ago committed by Anders Jenbo
parent
commit
956dcc7fc9
  1. 4
      Source/items.cpp
  2. 8
      Source/monster.h
  3. 5
      Source/player.h

4
Source/items.cpp

@ -2966,10 +2966,10 @@ void CalcPlrItemVals(Player &player, bool loadgfx)
SetPlrAnims(player);
if (player._pmode == PM_STAND) {
LoadPlrGFX(player, player_graphic::Stand);
player.AnimInfo.ChangeAnimationData(&*player.AnimationData[static_cast<size_t>(player_graphic::Stand)].CelSpritesForDirections[static_cast<size_t>(player._pdir)], player._pNFrames, 4);
player.AnimInfo.ChangeAnimationData(&*player.AnimationData[static_cast<size_t>(player_graphic::Stand)].GetCelSpritesForDirection(player._pdir), player._pNFrames, 4);
} else {
LoadPlrGFX(player, player_graphic::Walk);
player.AnimInfo.ChangeAnimationData(&*player.AnimationData[static_cast<size_t>(player_graphic::Walk)].CelSpritesForDirections[static_cast<size_t>(player._pdir)], player._pWFrames, 1);
player.AnimInfo.ChangeAnimationData(&*player.AnimationData[static_cast<size_t>(player_graphic::Walk)].GetCelSpritesForDirection(player._pdir), player._pWFrames, 1);
}
} else {
player._pgfxnum = gfxNum;

8
Source/monster.h

@ -133,6 +133,12 @@ enum class LeaderRelation : uint8_t {
struct AnimStruct {
std::unique_ptr<byte[]> CMem;
std::array<std::optional<CelSprite>, 8> CelSpritesForDirections;
inline const std::optional<CelSprite> &GetCelSpritesForDirection(Direction direction) const
{
return CelSpritesForDirections[static_cast<size_t>(direction)];
}
int Frames;
int Rate;
};
@ -220,7 +226,7 @@ struct Monster { // note: missing field _mAFNum
*/
void ActivateAnimation(MonsterGraphic graphic, Direction direction)
{
auto &celSprite = this->MType->GetAnimData(graphic).CelSpritesForDirections[static_cast<size_t>(direction)];
auto &celSprite = this->MType->GetAnimData(graphic).GetCelSpritesForDirection(direction);
this->AnimInfo.pCelSprite = celSprite ? &*celSprite : nullptr;
}

5
Source/player.h

@ -159,6 +159,11 @@ struct PlayerAnimationData {
* Is referenced from CelSprite in CelSpritesForDirections
*/
std::unique_ptr<byte[]> RawData;
inline const std::optional<CelSprite> &GetCelSpritesForDirection(Direction direction) const
{
return CelSpritesForDirections[static_cast<size_t>(direction)];
}
};
struct Player {

Loading…
Cancel
Save