Browse Source

Remove PlayerStruct._pXYZWidth and replace it with calls to GetAnimationWidth

pull/2049/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
3067aeacb8
  1. 4
      Source/items.cpp
  2. 42
      Source/loadsave.cpp
  3. 76
      Source/player.cpp
  4. 12
      Source/player.h
  5. 7
      test/writehero_test.cpp

4
Source/items.cpp

@ -888,10 +888,10 @@ void CalcPlrItemVals(int playerId, bool Loadgfx)
SetPlrAnims(player);
LoadPlrGFX(player, static_cast<player_graphic>(PFILE_STAND | PFILE_WALK));
if (player._pmode == PM_STAND) {
player._pAnimWidth = player._pNWidth;
player._pAnimWidth = player.GetAnimationWidth(PFILE_STAND);
player.AnimInfo.ChangeAnimationData(player._pNAnim[player._pdir], player._pNFrames, 3);
} else {
player._pAnimWidth = player._pWWidth;
player._pAnimWidth = player.GetAnimationWidth(PFILE_WALK);
player.AnimInfo.ChangeAnimationData(player._pWAnim[player._pdir], player._pWFrames, 0);
}
} else {

42
Source/loadsave.cpp

@ -434,29 +434,36 @@ static void LoadPlayer(LoadHelper *file, int p)
pPlayer->_pGFXLoad = file->nextLE<int32_t>();
file->skip(4 * 8); // Skip pointers _pNAnim
pPlayer->_pNFrames = file->nextLE<int32_t>();
pPlayer->_pNWidth = file->nextLE<int32_t>();
// skip _pNWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pWAnim
pPlayer->_pWFrames = file->nextLE<int32_t>();
pPlayer->_pWWidth = file->nextLE<int32_t>();
// skip _pWWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pAAnim
pPlayer->_pAFrames = file->nextLE<int32_t>();
pPlayer->_pAWidth = file->nextLE<int32_t>();
// skip _pAWidth
file->skip(4);
pPlayer->_pAFNum = file->nextLE<int32_t>();
file->skip(4 * 8); // Skip pointers _pLAnim
file->skip(4 * 8); // Skip pointers _pFAnim
file->skip(4 * 8); // Skip pointers _pTAnim
pPlayer->_pSFrames = file->nextLE<int32_t>();
pPlayer->_pSWidth = file->nextLE<int32_t>();
// skip _pSWidth
file->skip(4);
pPlayer->_pSFNum = file->nextLE<int32_t>();
file->skip(4 * 8); // Skip pointers _pHAnim
pPlayer->_pHFrames = file->nextLE<int32_t>();
pPlayer->_pHWidth = file->nextLE<int32_t>();
// skip _pHWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pDAnim
pPlayer->_pDFrames = file->nextLE<int32_t>();
pPlayer->_pDWidth = file->nextLE<int32_t>();
// skip _pDWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pBAnim
pPlayer->_pBFrames = file->nextLE<int32_t>();
pPlayer->_pBWidth = file->nextLE<int32_t>();
// skip _pBWidth
file->skip(4);
LoadItems(file, NUM_INVLOC, pPlayer->InvBody);
LoadItems(file, NUM_INV_GRID_ELEM, pPlayer->InvList);
@ -1421,29 +1428,36 @@ static void SavePlayer(SaveHelper *file, int p)
file->writeLE<int32_t>(pPlayer->_pGFXLoad);
file->skip(4 * 8); // Skip pointers _pNAnim
file->writeLE<int32_t>(pPlayer->_pNFrames);
file->writeLE<int32_t>(pPlayer->_pNWidth);
// Skip _pNWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pWAnim
file->writeLE<int32_t>(pPlayer->_pWFrames);
file->writeLE<int32_t>(pPlayer->_pWWidth);
// Skip _pWWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pAAnim
file->writeLE<int32_t>(pPlayer->_pAFrames);
file->writeLE<int32_t>(pPlayer->_pAWidth);
// Skip _pAWidth
file->skip(4);
file->writeLE<int32_t>(pPlayer->_pAFNum);
file->skip(4 * 8); // Skip pointers _pLAnim
file->skip(4 * 8); // Skip pointers _pFAnim
file->skip(4 * 8); // Skip pointers _pTAnim
file->writeLE<int32_t>(pPlayer->_pSFrames);
file->writeLE<int32_t>(pPlayer->_pSWidth);
// Skip _pSWidth
file->skip(4);
file->writeLE<int32_t>(pPlayer->_pSFNum);
file->skip(4 * 8); // Skip pointers _pHAnim
file->writeLE<int32_t>(pPlayer->_pHFrames);
file->writeLE<int32_t>(pPlayer->_pHWidth);
// Skip _pHWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pDAnim
file->writeLE<int32_t>(pPlayer->_pDFrames);
file->writeLE<int32_t>(pPlayer->_pDWidth);
// Skip _pDWidth
file->skip(4);
file->skip(4 * 8); // Skip pointers _pBAnim
file->writeLE<int32_t>(pPlayer->_pBFrames);
file->writeLE<int32_t>(pPlayer->_pBWidth);
// Skip _pBWidth
file->skip(4);
SaveItems(file, pPlayer->InvBody, NUM_INVLOC);
SaveItems(file, pPlayer->InvList, NUM_INV_GRID_ELEM);

76
Source/player.cpp

@ -374,6 +374,52 @@ void PlayerStruct::Reset()
*this = std::move(*emptyPlayer);
}
int PlayerStruct::GetAnimationWidth(player_graphic graphic)
{
switch (graphic) {
case PFILE_STAND:
if (_pClass == HeroClass::Monk)
return 112;
return 96;
case PFILE_WALK:
if (_pClass == HeroClass::Monk)
return 112;
return 96;
case PFILE_ATTACK:
if (_pClass == HeroClass::Monk)
return 130;
if (_pClass == HeroClass::Warrior || _pClass == HeroClass::Barbarian) {
auto gn = static_cast<anim_weapon_id>(_pgfxnum & 0xF);
if (gn == ANIM_ID_BOW)
return 96;
}
return 128;
case PFILE_HIT:
if (_pClass == HeroClass::Monk)
return 98;
return 96;
case PFILE_LIGHTNING:
case PFILE_FIRE:
case PFILE_MAGIC:
if (_pClass == HeroClass::Monk)
return 114;
if (_pClass == HeroClass::Sorcerer)
return 128;
return 96;
case PFILE_DEATH:
if (_pClass == HeroClass::Monk)
return 160;
return 128;
case PFILE_BLOCK:
if (_pClass == HeroClass::Monk)
return 98;
return 96;
default:
Log("GetAnimationWidth: Unkown graphic {}", graphic);
return 96;
}
}
void SetPlayerGPtrs(byte *pData, byte **pAnim)
{
int i;
@ -625,43 +671,34 @@ void NewPlrAnim(PlayerStruct &player, player_graphic graphic, Direction dir, int
if ((player._pGFXLoad & graphic) != graphic)
LoadPlrGFX(player, graphic);
int width = 96;
int width = player.GetAnimationWidth(graphic);
byte *pData = nullptr;
switch (graphic) {
case PFILE_STAND:
width = player._pNWidth;
pData = player._pNAnim[dir];
break;
case PFILE_WALK:
width = player._pWWidth;
pData = player._pWAnim[dir];
break;
case PFILE_ATTACK:
width = player._pAWidth;
pData = player._pAAnim[dir];
break;
case PFILE_HIT:
width = player._pHWidth;
pData = player._pHAnim[dir];
break;
case PFILE_LIGHTNING:
width = player._pSWidth;
pData = player._pLAnim[dir];
break;
case PFILE_FIRE:
width = player._pSWidth;
pData = player._pFAnim[dir];
break;
case PFILE_MAGIC:
width = player._pSWidth;
pData = player._pTAnim[dir];
break;
case PFILE_DEATH:
width = player._pDWidth;
pData = player._pDAnim[dir];
break;
case PFILE_BLOCK:
width = player._pBWidth;
pData = player._pBAnim[dir];
break;
default:
@ -685,14 +722,6 @@ static void ClearPlrPVars(PlayerStruct &player)
void SetPlrAnims(PlayerStruct &player)
{
player._pNWidth = 96;
player._pWWidth = 96;
player._pAWidth = 128;
player._pHWidth = 96;
player._pSWidth = 96;
player._pDWidth = 128;
player._pBWidth = 96;
HeroClass pc = player._pClass;
if (leveltype == DTYPE_TOWN) {
@ -718,7 +747,6 @@ void SetPlrAnims(PlayerStruct &player)
if (leveltype != DTYPE_TOWN) {
player._pNFrames = 8;
}
player._pAWidth = 96;
player._pAFNum = 11;
} else if (gn == ANIM_ID_AXE) {
player._pAFrames = 20;
@ -739,7 +767,6 @@ void SetPlrAnims(PlayerStruct &player)
player._pAFNum = 11;
}
} else if (pc == HeroClass::Sorcerer) {
player._pSWidth = 128;
if (gn == ANIM_ID_UNARMED) {
player._pAFrames = 20;
} else if (gn == ANIM_ID_UNARMED_SHIELD) {
@ -752,14 +779,6 @@ void SetPlrAnims(PlayerStruct &player)
player._pAFNum = 16;
}
} else if (pc == HeroClass::Monk) {
player._pNWidth = 112;
player._pWWidth = 112;
player._pAWidth = 130;
player._pHWidth = 98;
player._pSWidth = 114;
player._pDWidth = 160;
player._pBWidth = 98;
switch (gn) {
case ANIM_ID_UNARMED:
case ANIM_ID_UNARMED_SHIELD:
@ -800,7 +819,6 @@ void SetPlrAnims(PlayerStruct &player)
if (leveltype != DTYPE_TOWN) {
player._pNFrames = 8;
}
player._pAWidth = 96;
player._pAFNum = 11;
} else if (gn == ANIM_ID_STAFF) {
player._pAFrames = 16;

12
Source/player.h

@ -241,29 +241,22 @@ struct PlayerStruct {
int _pGFXLoad;
byte *_pNAnim[8]; // Stand animations
int _pNFrames;
int _pNWidth;
byte *_pWAnim[8]; // Walk animations
int _pWFrames;
int _pWWidth;
byte *_pAAnim[8]; // Attack animations
int _pAFrames;
int _pAWidth;
int _pAFNum;
byte *_pLAnim[8]; // Lightning spell cast animations
byte *_pFAnim[8]; // Fire spell cast animations
byte *_pTAnim[8]; // Generic spell cast animations
int _pSFrames;
int _pSWidth;
int _pSFNum;
byte *_pHAnim[8]; // Getting hit animations
int _pHFrames;
int _pHWidth;
byte *_pDAnim[8]; // Death animations
int _pDFrames;
int _pDWidth;
byte *_pBAnim[8]; // Block animations
int _pBFrames;
int _pBWidth;
ItemStruct InvBody[NUM_INVLOC];
ItemStruct InvList[NUM_INV_GRID_ELEM];
int _pNumInv;
@ -403,6 +396,11 @@ struct PlayerStruct {
* @brief Resets all Data of the current PlayerStruct
*/
void Reset();
/**
* @brief Gets the width for the specified player animation
*/
int GetAnimationWidth(player_graphic graphic);
};
extern int myplr;

7
test/writehero_test.cpp

@ -324,21 +324,14 @@ static void AssertPlayer(PlayerStruct *pPlayer)
ASSERT_EQ(CountBool(pPlayer->_pLvlVisited, NUMLEVELS), 0);
ASSERT_EQ(CountBool(pPlayer->_pSLvlVisited, NUMLEVELS), 0);
ASSERT_EQ(pPlayer->_pNFrames, 20);
ASSERT_EQ(pPlayer->_pNWidth, 96);
ASSERT_EQ(pPlayer->_pWFrames, 8);
ASSERT_EQ(pPlayer->_pWWidth, 96);
ASSERT_EQ(pPlayer->_pAFrames, 0);
ASSERT_EQ(pPlayer->_pAWidth, 128);
ASSERT_EQ(pPlayer->_pAFNum, 0);
ASSERT_EQ(pPlayer->_pSFrames, 16);
ASSERT_EQ(pPlayer->_pSWidth, 96);
ASSERT_EQ(pPlayer->_pSFNum, 12);
ASSERT_EQ(pPlayer->_pHFrames, 0);
ASSERT_EQ(pPlayer->_pHWidth, 96);
ASSERT_EQ(pPlayer->_pDFrames, 20);
ASSERT_EQ(pPlayer->_pDWidth, 128);
ASSERT_EQ(pPlayer->_pBFrames, 0);
ASSERT_EQ(pPlayer->_pBWidth, 96);
ASSERT_EQ(pPlayer->_pIMinDam, 1);
ASSERT_EQ(pPlayer->_pIMaxDam, 14);
ASSERT_EQ(pPlayer->_pIAC, 115);

Loading…
Cancel
Save