Browse Source

Remove PlayerStruct.actionFrame and enable ADL for Walking/Run (#1939)

- Remove (unused) actionFrame for PM_DEATH
- Remove actionFrame for PM_SPELL
- Remove actionFrame for PM_WALK
- Remove actionFrame
pull/1936/head
obligaron 5 years ago committed by GitHub
parent
commit
7ed009ecb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Source/loadsave.cpp
  2. 1
      Source/msg.cpp
  3. 1
      Source/multi.cpp
  4. 60
      Source/player.cpp
  5. 2
      Source/player.h
  6. 2
      Source/track.cpp

6
Source/loadsave.cpp

@ -421,7 +421,8 @@ static void LoadPlayer(LoadHelper *file, int p)
pPlayer->_pVar5 = file->nextLE<int32_t>();
pPlayer->position.offset2.x = file->nextLE<int32_t>();
pPlayer->position.offset2.y = file->nextLE<int32_t>();
pPlayer->actionFrame = file->nextLE<int32_t>();
// Skip actionFrame
file->skip(4);
for (uint8_t i = 0; i < giNumberOfLevels; i++)
pPlayer->_pLvlVisited[i] = file->nextBool8();
for (uint8_t i = 0; i < giNumberOfLevels; i++)
@ -1407,7 +1408,8 @@ static void SavePlayer(SaveHelper *file, int p)
file->writeLE<int32_t>(pPlayer->_pVar5);
file->writeLE<int32_t>(pPlayer->position.offset2.x);
file->writeLE<int32_t>(pPlayer->position.offset2.y);
file->writeLE<int32_t>(pPlayer->actionFrame);
// Write actionFrame for vanilla compatibility
file->writeLE<int32_t>(0);
for (uint8_t i = 0; i < giNumberOfLevels; i++)
file->writeLE<uint8_t>(pPlayer->_pLvlVisited[i]);
for (uint8_t i = 0; i < giNumberOfLevels; i++)

1
Source/msg.cpp

@ -2237,7 +2237,6 @@ static DWORD On_PLAYER_JOINLEVEL(TCmd *pCmd, int pnum)
plr[pnum]._pmode = PM_DEATH;
NewPlrAnim(pnum, plr[pnum]._pDAnim[DIR_S], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth);
plr[pnum].AnimInfo.CurrentFrame = plr[pnum].AnimInfo.NumberOfFrames - 1;
plr[pnum].actionFrame = plr[pnum].AnimInfo.NumberOfFrames * 2;
dFlags[plr[pnum].position.tile.x][plr[pnum].position.tile.y] |= BFLAG_DEAD_PLAYER;
}

1
Source/multi.cpp

@ -881,7 +881,6 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv)
plr[pnum]._pmode = PM_DEATH;
NewPlrAnim(pnum, plr[pnum]._pDAnim[DIR_S], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth);
plr[pnum].AnimInfo.CurrentFrame = plr[pnum].AnimInfo.NumberOfFrames - 1;
plr[pnum].actionFrame = 2 * plr[pnum].AnimInfo.NumberOfFrames;
dFlags[plr[pnum].position.tile.x][plr[pnum].position.tile.y] |= BFLAG_DEAD_PLAYER;
}
}

60
Source/player.cpp

@ -637,7 +637,6 @@ void ClearPlrPVars(int pnum)
plr[pnum]._pVar4 = 0;
plr[pnum]._pVar5 = 0;
plr[pnum].position.offset2 = { 0, 0 };
plr[pnum].actionFrame = 0;
plr[pnum].deathFrame = 0;
}
@ -1148,7 +1147,6 @@ void InitPlayer(int pnum, bool FirstTime)
plr[pnum]._pmode = PM_DEATH;
NewPlrAnim(pnum, plr[pnum]._pDAnim[DIR_S], plr[pnum]._pDFrames, 1, plr[pnum]._pDWidth);
plr[pnum].AnimInfo.CurrentFrame = plr[pnum].AnimInfo.NumberOfFrames - 1;
plr[pnum].actionFrame = 2 * plr[pnum].AnimInfo.NumberOfFrames;
}
plr[pnum]._pdir = DIR_S;
@ -1391,7 +1389,6 @@ void PM_ChangeOffset(int pnum)
app_fatal("PM_ChangeOffset: illegal player %d", pnum);
}
plr[pnum].actionFrame++;
px = plr[pnum].position.offset2.x / 256;
py = plr[pnum].position.offset2.y / 256;
@ -1419,7 +1416,7 @@ void PM_ChangeOffset(int pnum)
/**
* @brief Start moving a player to a new tile
*/
void StartWalk(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, direction EndDir, _scroll_direction sdir, int variant)
void StartWalk(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int yadd, int mapx, int mapy, direction EndDir, _scroll_direction sdir, int variant, bool pmWillBeCalled)
{
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StartWalk: illegal player %d", pnum);
@ -1503,10 +1500,14 @@ void StartWalk(int pnum, int xvel, int yvel, int xoff, int yoff, int xadd, int y
}
//Start walk animation
NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth);
int skippedFrames = -2;
if (currlevel == 0 && sgGameInitInfo.bRunInTown)
skippedFrames = 2;
if (pmWillBeCalled)
skippedFrames += 1;
NewPlrAnim(pnum, plr[pnum]._pWAnim[EndDir], plr[pnum]._pWFrames, 0, plr[pnum]._pWWidth, AnimationDistributionFlags::ProcessAnimationPending, skippedFrames);
plr[pnum]._pdir = EndDir;
plr[pnum].actionFrame = 0;
if (pnum != myplr) {
return;
@ -1668,7 +1669,6 @@ void StartSpell(int pnum, direction d, int cx, int cy)
plr[pnum].position.temp = { cx, cy };
plr[pnum]._pVar4 = GetSpellLevel(pnum, plr[pnum]._pSpell);
plr[pnum].actionFrame = 1;
}
void FixPlrWalkTags(int pnum)
@ -2291,27 +2291,15 @@ bool PM_DoWalk(int pnum, int variant)
}
//Play walking sound effect on certain animation frames
if (sgOptions.Audio.bWalkingSound) {
if (plr[pnum].AnimInfo.CurrentFrame == 3
|| (plr[pnum]._pWFrames == 8 && plr[pnum].AnimInfo.CurrentFrame == 7)
|| (plr[pnum]._pWFrames != 8 && plr[pnum].AnimInfo.CurrentFrame == 4)) {
if (sgOptions.Audio.bWalkingSound && (currlevel != 0 || !sgGameInitInfo.bRunInTown)) {
if (plr[pnum].AnimInfo.CurrentFrame == 1
|| plr[pnum].AnimInfo.CurrentFrame == 5) {
PlaySfxLoc(PS_WALK1, plr[pnum].position.tile.x, plr[pnum].position.tile.y);
}
}
//"Jog" in town which works by doubling movement speed and skipping every other animation frame
if (currlevel == 0 && sgGameInitInfo.bRunInTown) {
if (plr[pnum].AnimInfo.CurrentFrame % 2 == 0) {
plr[pnum].AnimInfo.CurrentFrame++;
plr[pnum].actionFrame++;
}
if (plr[pnum].AnimInfo.CurrentFrame >= plr[pnum]._pWFrames) {
plr[pnum].AnimInfo.CurrentFrame = 0;
}
}
//Check if we reached new tile
if (plr[pnum].actionFrame >= plr[pnum]._pWFrames) {
if (plr[pnum].AnimInfo.CurrentFrame >= plr[pnum]._pWFrames) {
//Update the player's tile position
switch (variant) {
@ -3088,7 +3076,7 @@ bool PM_DoSpell(int pnum)
app_fatal("PM_DoSpell: illegal player %d", pnum);
}
if (plr[pnum].actionFrame == plr[pnum]._pSFNum) {
if (plr[pnum].AnimInfo.CurrentFrame == (plr[pnum]._pSFNum + 1)) {
CastSpell(
pnum,
plr[pnum]._pSpell,
@ -3103,10 +3091,8 @@ bool PM_DoSpell(int pnum)
}
}
plr[pnum].actionFrame++;
if (leveltype == DTYPE_TOWN) {
if (plr[pnum].actionFrame > plr[pnum]._pSFrames) {
if (plr[pnum].AnimInfo.CurrentFrame > plr[pnum]._pSFrames) {
StartWalkStand(pnum);
ClearPlrPVars(pnum);
return true;
@ -3168,7 +3154,7 @@ bool PM_DoDeath(int pnum)
return false;
}
void CheckNewPath(int pnum)
void CheckNewPath(int pnum, bool pmWillBeCalled)
{
int i, x, y;
int xvel3, xvel, yvel;
@ -3228,28 +3214,28 @@ void CheckNewPath(int pnum)
switch (plr[pnum].walkpath[0]) {
case WALK_N:
StartWalk(pnum, 0, -xvel, 0, 0, -1, -1, 0, 0, DIR_N, SDIR_N, PM_WALK);
StartWalk(pnum, 0, -xvel, 0, 0, -1, -1, 0, 0, DIR_N, SDIR_N, PM_WALK, pmWillBeCalled);
break;
case WALK_NE:
StartWalk(pnum, xvel, -yvel, 0, 0, 0, -1, 0, 0, DIR_NE, SDIR_NE, PM_WALK);
StartWalk(pnum, xvel, -yvel, 0, 0, 0, -1, 0, 0, DIR_NE, SDIR_NE, PM_WALK, pmWillBeCalled);
break;
case WALK_E:
StartWalk(pnum, xvel3, 0, -32, -16, 1, -1, 1, 0, DIR_E, SDIR_E, PM_WALK3);
StartWalk(pnum, xvel3, 0, -32, -16, 1, -1, 1, 0, DIR_E, SDIR_E, PM_WALK3, pmWillBeCalled);
break;
case WALK_SE:
StartWalk(pnum, xvel, yvel, -32, -16, 1, 0, 0, 0, DIR_SE, SDIR_SE, PM_WALK2);
StartWalk(pnum, xvel, yvel, -32, -16, 1, 0, 0, 0, DIR_SE, SDIR_SE, PM_WALK2, pmWillBeCalled);
break;
case WALK_S:
StartWalk(pnum, 0, xvel, 0, -32, 1, 1, 0, 0, DIR_S, SDIR_S, PM_WALK2);
StartWalk(pnum, 0, xvel, 0, -32, 1, 1, 0, 0, DIR_S, SDIR_S, PM_WALK2, pmWillBeCalled);
break;
case WALK_SW:
StartWalk(pnum, -xvel, yvel, 32, -16, 0, 1, 0, 0, DIR_SW, SDIR_SW, PM_WALK2);
StartWalk(pnum, -xvel, yvel, 32, -16, 0, 1, 0, 0, DIR_SW, SDIR_SW, PM_WALK2, pmWillBeCalled);
break;
case WALK_W:
StartWalk(pnum, -xvel3, 0, 32, -16, -1, 1, 0, 1, DIR_W, SDIR_W, PM_WALK3);
StartWalk(pnum, -xvel3, 0, 32, -16, -1, 1, 0, 1, DIR_W, SDIR_W, PM_WALK3, pmWillBeCalled);
break;
case WALK_NW:
StartWalk(pnum, -xvel, -yvel, 0, 0, -1, 0, 0, 0, DIR_NW, SDIR_NW, PM_WALK);
StartWalk(pnum, -xvel, -yvel, 0, 0, -1, 0, 0, 0, DIR_NW, SDIR_NW, PM_WALK, pmWillBeCalled);
break;
}
@ -3681,7 +3667,7 @@ void ProcessPlayers()
tplayer = PM_DoDeath(pnum);
break;
}
CheckNewPath(pnum);
CheckNewPath(pnum, tplayer);
} while (tplayer);
plr[pnum].AnimInfo.ProcessAnimation();

2
Source/player.h

@ -229,8 +229,6 @@ struct PlayerStruct {
int _pVar4;
/** Used for storing position of a tile which should have its BFLAG_PLAYERLR flag removed after walking. When starting to walk the game places the player in the dPlayer array -1 in the Y coordinate, and uses BFLAG_PLAYERLR to check if it should be using -1 to the Y coordinate when rendering the player (also used for storing the level of a spell when the player casts it) */
int _pVar5;
/** Used for counting how close we are to reaching the next tile when walking (usually counts to 8, which is equal to the walk animation length). */
int actionFrame;
/** Used for stalling the appearance of the options screen after dying in singleplayer */
int deathFrame;
bool _pLvlVisited[NUMLEVELS];

2
Source/track.cpp

@ -26,7 +26,7 @@ void track_process()
if (cursmx < 0 || cursmx >= MAXDUNX - 1 || cursmy < 0 || cursmy >= MAXDUNY - 1)
return;
if (plr[myplr].actionFrame <= 6 && plr[myplr]._pmode != PM_STAND)
if (plr[myplr].AnimInfo.GetFrameToUseForRendering() <= 6 || (plr[myplr]._pmode != PM_WALK && plr[myplr]._pmode != PM_WALK2 && plr[myplr]._pmode != PM_WALK3 && plr[myplr]._pmode != PM_STAND))
return;
const Point target = plr[myplr].GetTargetPosition();

Loading…
Cancel
Save