Browse Source

Enable ADL for Monsters

pull/2231/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
a4cacfbcbe
  1. 20
      Source/engine/animationinfo.cpp
  2. 4
      Source/engine/animationinfo.h
  3. 23
      Source/monster.cpp
  4. 4
      Source/scrollrt.cpp

20
Source/engine/animationinfo.cpp

@ -170,16 +170,26 @@ void AnimationInfo::ChangeAnimationData(CelSprite *pCelSprite, int numberOfFrame
DelayLen = delayLen;
}
void AnimationInfo::ProcessAnimation()
void AnimationInfo::ProcessAnimation(bool reverseAnimation /*= false*/, bool dontProgressAnimation /*= false*/)
{
DelayCounter++;
if (dontProgressAnimation)
return;
TicksSinceSequenceStarted++;
if (DelayCounter > DelayLen) {
DelayCounter = 0;
CurrentFrame++;
if (CurrentFrame > NumberOfFrames) {
CurrentFrame = 1;
TicksSinceSequenceStarted = 0;
if (reverseAnimation) {
CurrentFrame--;
if (CurrentFrame == 0) {
CurrentFrame = NumberOfFrames;
TicksSinceSequenceStarted = 0;
}
} else {
CurrentFrame++;
if (CurrentFrame > NumberOfFrames) {
CurrentFrame = 1;
TicksSinceSequenceStarted = 0;
}
}
}
}

4
Source/engine/animationinfo.h

@ -89,8 +89,10 @@ public:
/*
* @brief Process the Animation for a game tick (for example advances the frame)
* @param reverseAnimation Play the animation backwards (for example is used for "unseen" monster fading)
* @param dontProgressAnimation Increase DelayCounter but don't change CurrentFrame
*/
void ProcessAnimation();
void ProcessAnimation(bool reverseAnimation = false, bool dontProgressAnimation = false);
private:
/**

23
Source/monster.cpp

@ -1268,11 +1268,8 @@ void monster_43C785(int i)
void NewMonsterAnim(int i, AnimStruct *anim, Direction md)
{
MonsterStruct *Monst = &monster[i];
Monst->AnimInfo.pCelSprite = &*anim->CelSpritesForDirections[md];
Monst->AnimInfo.NumberOfFrames = anim->Frames;
Monst->AnimInfo.DelayCounter = 0;
Monst->AnimInfo.CurrentFrame = 1;
Monst->AnimInfo.DelayLen = anim->Rate;
auto *pCelSprite = &*anim->CelSpritesForDirections[md];
Monst->AnimInfo.SetNewAnimation(pCelSprite, anim->Frames, anim->Rate);
Monst->_mFlags &= ~(MFLAG_LOCK_ANIMATION | MFLAG_ALLOW_SPECIAL);
Monst->_mdir = md;
}
@ -4624,21 +4621,7 @@ void ProcessMonsters()
}
} while (raflag);
if (Monst->_mmode != MM_STONE) {
Monst->AnimInfo.DelayCounter++;
if (!(Monst->_mFlags & MFLAG_ALLOW_SPECIAL) && Monst->AnimInfo.DelayCounter >= Monst->AnimInfo.DelayLen) {
Monst->AnimInfo.DelayCounter = 0;
if (Monst->_mFlags & MFLAG_LOCK_ANIMATION) {
Monst->AnimInfo.CurrentFrame--;
if (Monst->AnimInfo.CurrentFrame == 0) {
Monst->AnimInfo.CurrentFrame = Monst->AnimInfo.NumberOfFrames;
}
} else {
Monst->AnimInfo.CurrentFrame++;
if (Monst->AnimInfo.CurrentFrame > Monst->AnimInfo.NumberOfFrames) {
Monst->AnimInfo.CurrentFrame = 1;
}
}
}
Monst->AnimInfo.ProcessAnimation(Monst->_mFlags & MFLAG_LOCK_ANIMATION, Monst->_mFlags & MFLAG_ALLOW_SPECIAL);
}
}

4
Source/scrollrt.cpp

@ -320,7 +320,7 @@ static void DrawMonster(const CelOutputBuffer &out, int x, int y, int mx, int my
return;
}
int nCel = monster[m].AnimInfo.CurrentFrame;
int nCel = monster[m].AnimInfo.GetFrameToUseForRendering();
auto frameTable = reinterpret_cast<const uint32_t *>(monster[m].AnimInfo.pCelSprite->Data());
int frames = SDL_SwapLE32(frameTable[0]);
if (nCel < 1 || frames > 50 || nCel > frames) {
@ -701,7 +701,7 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy,
px = sx + pMonster->position.offset.x - CalculateWidth2(cel.Width());
py = sy + pMonster->position.offset.y;
if (mi == pcursmonst) {
Cl2DrawOutline(out, 233, px, py, cel, pMonster->AnimInfo.CurrentFrame);
Cl2DrawOutline(out, 233, px, py, cel, pMonster->AnimInfo.GetFrameToUseForRendering());
}
DrawMonster(out, x, y, px, py, mi);
}

Loading…
Cancel
Save