1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

ECreatureAnimType enum -> enum class

This commit is contained in:
Ivan Savenko 2022-12-22 01:04:58 +02:00
parent 4e190b95cc
commit 8b207fae63
7 changed files with 94 additions and 97 deletions

View File

@ -100,17 +100,17 @@ StackActionAnimation::StackActionAnimation(BattleInterface & owner, const CStack
{
}
ECreatureAnimType::Type StackActionAnimation::getGroup() const
ECreatureAnimType StackActionAnimation::getGroup() const
{
return currGroup;
}
void StackActionAnimation::setNextGroup( ECreatureAnimType::Type group )
void StackActionAnimation::setNextGroup( ECreatureAnimType group )
{
nextGroup = group;
}
void StackActionAnimation::setGroup( ECreatureAnimType::Type group )
void StackActionAnimation::setGroup( ECreatureAnimType group )
{
currGroup = group;
}
@ -145,7 +145,7 @@ StackActionAnimation::~StackActionAnimation()
}
ECreatureAnimType::Type AttackAnimation::findValidGroup( const std::vector<ECreatureAnimType::Type> candidates ) const
ECreatureAnimType AttackAnimation::findValidGroup( const std::vector<ECreatureAnimType> candidates ) const
{
for ( auto group : candidates)
{
@ -230,7 +230,7 @@ void DummyAnimation::nextFrame()
delete this;
}
ECreatureAnimType::Type MeleeAttackAnimation::getUpwardsGroup(bool multiAttack) const
ECreatureAnimType MeleeAttackAnimation::getUpwardsGroup(bool multiAttack) const
{
if (!multiAttack)
return ECreatureAnimType::ATTACK_UP;
@ -242,7 +242,7 @@ ECreatureAnimType::Type MeleeAttackAnimation::getUpwardsGroup(bool multiAttack)
});
}
ECreatureAnimType::Type MeleeAttackAnimation::getForwardGroup(bool multiAttack) const
ECreatureAnimType MeleeAttackAnimation::getForwardGroup(bool multiAttack) const
{
if (!multiAttack)
return ECreatureAnimType::ATTACK_FRONT;
@ -254,7 +254,7 @@ ECreatureAnimType::Type MeleeAttackAnimation::getForwardGroup(bool multiAttack)
});
}
ECreatureAnimType::Type MeleeAttackAnimation::getDownwardsGroup(bool multiAttack) const
ECreatureAnimType MeleeAttackAnimation::getDownwardsGroup(bool multiAttack) const
{
if (!multiAttack)
return ECreatureAnimType::ATTACK_DOWN;
@ -266,9 +266,9 @@ ECreatureAnimType::Type MeleeAttackAnimation::getDownwardsGroup(bool multiAttack
});
}
ECreatureAnimType::Type MeleeAttackAnimation::selectGroup(bool multiAttack)
ECreatureAnimType MeleeAttackAnimation::selectGroup(bool multiAttack)
{
const ECreatureAnimType::Type mutPosToGroup[] =
const ECreatureAnimType mutPosToGroup[] =
{
getUpwardsGroup (multiAttack),
getUpwardsGroup (multiAttack),
@ -757,17 +757,17 @@ uint32_t ShootingAnimation::getAttackClimaxFrame() const
return shooterInfo->animation.attackClimaxFrame;
}
ECreatureAnimType::Type ShootingAnimation::getUpwardsGroup() const
ECreatureAnimType ShootingAnimation::getUpwardsGroup() const
{
return ECreatureAnimType::SHOOT_UP;
}
ECreatureAnimType::Type ShootingAnimation::getForwardGroup() const
ECreatureAnimType ShootingAnimation::getForwardGroup() const
{
return ECreatureAnimType::SHOOT_FRONT;
}
ECreatureAnimType::Type ShootingAnimation::getDownwardsGroup() const
ECreatureAnimType ShootingAnimation::getDownwardsGroup() const
{
return ECreatureAnimType::SHOOT_DOWN;
}
@ -817,7 +817,7 @@ CastAnimation::CastAnimation(BattleInterface & owner_, const CStack * attacker,
dest = defender->getPosition();
}
ECreatureAnimType::Type CastAnimation::getUpwardsGroup() const
ECreatureAnimType CastAnimation::getUpwardsGroup() const
{
return findValidGroup({
ECreatureAnimType::CAST_UP,
@ -827,7 +827,7 @@ ECreatureAnimType::Type CastAnimation::getUpwardsGroup() const
});
}
ECreatureAnimType::Type CastAnimation::getForwardGroup() const
ECreatureAnimType CastAnimation::getForwardGroup() const
{
return findValidGroup({
ECreatureAnimType::CAST_FRONT,
@ -837,7 +837,7 @@ ECreatureAnimType::Type CastAnimation::getForwardGroup() const
});
}
ECreatureAnimType::Type CastAnimation::getDownwardsGroup() const
ECreatureAnimType CastAnimation::getDownwardsGroup() const
{
return findValidGroup({
ECreatureAnimType::CAST_DOWN,

View File

@ -68,15 +68,15 @@ public:
class StackActionAnimation : public BattleStackAnimation
{
ECreatureAnimType::Type nextGroup;
ECreatureAnimType::Type currGroup;
ECreatureAnimType nextGroup;
ECreatureAnimType currGroup;
std::string sound;
public:
void setNextGroup( ECreatureAnimType::Type group );
void setGroup( ECreatureAnimType::Type group );
void setNextGroup( ECreatureAnimType group );
void setGroup( ECreatureAnimType group );
void setSound( std::string sound );
ECreatureAnimType::Type getGroup() const;
ECreatureAnimType getGroup() const;
StackActionAnimation(BattleInterface & owner, const CStack * _stack);
~StackActionAnimation();
@ -198,7 +198,7 @@ protected:
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
const CCreature * getCreature() const;
ECreatureAnimType::Type findValidGroup( const std::vector<ECreatureAnimType::Type> candidates ) const;
ECreatureAnimType findValidGroup( const std::vector<ECreatureAnimType> candidates ) const;
public:
AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
@ -207,11 +207,11 @@ public:
/// Hand-to-hand attack
class MeleeAttackAnimation : public AttackAnimation
{
ECreatureAnimType::Type getUpwardsGroup(bool multiAttack) const;
ECreatureAnimType::Type getForwardGroup(bool multiAttack) const;
ECreatureAnimType::Type getDownwardsGroup(bool multiAttack) const;
ECreatureAnimType getUpwardsGroup(bool multiAttack) const;
ECreatureAnimType getForwardGroup(bool multiAttack) const;
ECreatureAnimType getDownwardsGroup(bool multiAttack) const;
ECreatureAnimType::Type selectGroup(bool multiAttack);
ECreatureAnimType selectGroup(bool multiAttack);
public:
MeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, bool multiAttack);
@ -230,9 +230,9 @@ class RangedAttackAnimation : public AttackAnimation
protected:
bool projectileEmitted;
virtual ECreatureAnimType::Type getUpwardsGroup() const = 0;
virtual ECreatureAnimType::Type getForwardGroup() const = 0;
virtual ECreatureAnimType::Type getDownwardsGroup() const = 0;
virtual ECreatureAnimType getUpwardsGroup() const = 0;
virtual ECreatureAnimType getForwardGroup() const = 0;
virtual ECreatureAnimType getDownwardsGroup() const = 0;
virtual void createProjectile(const Point & from, const Point & dest) const = 0;
virtual uint32_t getAttackClimaxFrame() const = 0;
@ -248,9 +248,9 @@ public:
/// Shooting attack
class ShootingAnimation : public RangedAttackAnimation
{
ECreatureAnimType::Type getUpwardsGroup() const override;
ECreatureAnimType::Type getForwardGroup() const override;
ECreatureAnimType::Type getDownwardsGroup() const override;
ECreatureAnimType getUpwardsGroup() const override;
ECreatureAnimType getForwardGroup() const override;
ECreatureAnimType getDownwardsGroup() const override;
void createProjectile(const Point & from, const Point & dest) const override;
uint32_t getAttackClimaxFrame() const override;
@ -278,9 +278,9 @@ class CastAnimation : public RangedAttackAnimation
{
const CSpell * spell;
ECreatureAnimType::Type getUpwardsGroup() const override;
ECreatureAnimType::Type getForwardGroup() const override;
ECreatureAnimType::Type getDownwardsGroup() const override;
ECreatureAnimType getUpwardsGroup() const override;
ECreatureAnimType getForwardGroup() const override;
ECreatureAnimType getDownwardsGroup() const override;
void createProjectile(const Point & from, const Point & dest) const override;
uint32_t getAttackClimaxFrame() const override;

View File

@ -52,9 +52,7 @@ enum class EHeroAnimType
CAST_SPELL = 4 // spellcasting
};
namespace ECreatureAnimType
{
enum Type // list of creature animations, numbers were taken from def files
enum class ECreatureAnimType
{
INVALID = -1,
@ -94,4 +92,3 @@ enum Type // list of creature animations, numbers were taken from def files
GROUP_ATTACK_FRONT = 41,
GROUP_ATTACK_DOWN = 42
};
}

View File

@ -46,10 +46,8 @@ std::shared_ptr<CreatureAnimation> AnimationControls::getAnimation(const CCreatu
return std::make_shared<CreatureAnimation>(creature->animDefName, func);
}
float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, const CreatureAnimation * anim, size_t group)
float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, const CreatureAnimation * anim, ECreatureAnimType type)
{
ECreatureAnimType::Type type = ECreatureAnimType::Type(group);
assert(creature->animation.walkAnimationTime != 0);
assert(creature->animation.attackAnimationTime != 0);
assert(anim->framesInGroup(type) != 0);
@ -150,12 +148,12 @@ float AnimationControls::getObstaclesSpeed()
return static_cast<float>(settings["battle"]["animationSpeed"].Float() * 30);
}
ECreatureAnimType::Type CreatureAnimation::getType() const
ECreatureAnimType CreatureAnimation::getType() const
{
return type;
}
void CreatureAnimation::setType(ECreatureAnimType::Type type)
void CreatureAnimation::setType(ECreatureAnimType type)
{
this->type = type;
currentFrame = 0;
@ -183,37 +181,37 @@ CreatureAnimation::CreatureAnimation(const std::string & name_, TSpeedController
reverse->preload();
// if necessary, add one frame into vcmi-only group DEAD
if(forward->size(ECreatureAnimType::DEAD) == 0)
if(forward->size(size_t(ECreatureAnimType::DEAD)) == 0)
{
forward->duplicateImage(ECreatureAnimType::DEATH, forward->size(ECreatureAnimType::DEATH)-1, ECreatureAnimType::DEAD);
reverse->duplicateImage(ECreatureAnimType::DEATH, reverse->size(ECreatureAnimType::DEATH)-1, ECreatureAnimType::DEAD);
forward->duplicateImage(size_t(ECreatureAnimType::DEATH), forward->size(size_t(ECreatureAnimType::DEATH))-1, size_t(ECreatureAnimType::DEAD));
reverse->duplicateImage(size_t(ECreatureAnimType::DEATH), reverse->size(size_t(ECreatureAnimType::DEATH))-1, size_t(ECreatureAnimType::DEAD));
}
if(forward->size(ECreatureAnimType::DEAD_RANGED) == 0 && forward->size(ECreatureAnimType::DEATH_RANGED) != 0)
if(forward->size(size_t(ECreatureAnimType::DEAD_RANGED)) == 0 && forward->size(size_t(ECreatureAnimType::DEATH_RANGED)) != 0)
{
forward->duplicateImage(ECreatureAnimType::DEATH_RANGED, forward->size(ECreatureAnimType::DEATH_RANGED)-1, ECreatureAnimType::DEAD_RANGED);
reverse->duplicateImage(ECreatureAnimType::DEATH_RANGED, reverse->size(ECreatureAnimType::DEATH_RANGED)-1, ECreatureAnimType::DEAD_RANGED);
forward->duplicateImage(size_t(ECreatureAnimType::DEATH_RANGED), forward->size(size_t(ECreatureAnimType::DEATH_RANGED))-1, size_t(ECreatureAnimType::DEAD_RANGED));
reverse->duplicateImage(size_t(ECreatureAnimType::DEATH_RANGED), reverse->size(size_t(ECreatureAnimType::DEATH_RANGED))-1, size_t(ECreatureAnimType::DEAD_RANGED));
}
if(forward->size(ECreatureAnimType::FROZEN) == 0)
if(forward->size(size_t(ECreatureAnimType::FROZEN)) == 0)
{
forward->duplicateImage(ECreatureAnimType::HOLDING, 0, ECreatureAnimType::FROZEN);
reverse->duplicateImage(ECreatureAnimType::HOLDING, 0, ECreatureAnimType::FROZEN);
forward->duplicateImage(size_t(ECreatureAnimType::HOLDING), 0, size_t(ECreatureAnimType::FROZEN));
reverse->duplicateImage(size_t(ECreatureAnimType::HOLDING), 0, size_t(ECreatureAnimType::FROZEN));
}
if(forward->size(ECreatureAnimType::RESURRECTION) == 0)
if(forward->size(size_t(ECreatureAnimType::RESURRECTION)) == 0)
{
for (size_t i = 0; i < forward->size(ECreatureAnimType::DEATH); ++i)
for (size_t i = 0; i < forward->size(size_t(ECreatureAnimType::DEATH)); ++i)
{
size_t current = forward->size(ECreatureAnimType::DEATH) - 1 - i;
size_t current = forward->size(size_t(ECreatureAnimType::DEATH)) - 1 - i;
forward->duplicateImage(ECreatureAnimType::DEATH, current, ECreatureAnimType::RESURRECTION);
reverse->duplicateImage(ECreatureAnimType::DEATH, current, ECreatureAnimType::RESURRECTION);
forward->duplicateImage(size_t(ECreatureAnimType::DEATH), current, size_t(ECreatureAnimType::RESURRECTION));
reverse->duplicateImage(size_t(ECreatureAnimType::DEATH), current, size_t(ECreatureAnimType::RESURRECTION));
}
}
//TODO: get dimensions form CAnimation
auto first = forward->getImage(0, type, true);
auto first = forward->getImage(0, size_t(type), true);
if(!first)
{
@ -282,7 +280,7 @@ float CreatureAnimation::getCurrentFrame() const
return currentFrame;
}
void CreatureAnimation::playOnce( ECreatureAnimType::Type type )
void CreatureAnimation::playOnce( ECreatureAnimType type )
{
setType(type);
once = true;
@ -336,9 +334,9 @@ void CreatureAnimation::nextFrame(Canvas & canvas, const ColorFilter & shifter,
std::shared_ptr<IImage> image;
if(facingRight)
image = forward->getImage(frame, type);
image = forward->getImage(frame, size_t(type));
else
image = reverse->getImage(frame, type);
image = reverse->getImage(frame, size_t(type));
if(image)
{
@ -353,9 +351,9 @@ void CreatureAnimation::nextFrame(Canvas & canvas, const ColorFilter & shifter,
}
}
int CreatureAnimation::framesInGroup(ECreatureAnimType::Type group) const
int CreatureAnimation::framesInGroup(ECreatureAnimType group) const
{
return static_cast<int>(forward->size(group));
return static_cast<int>(forward->size(size_t(group)));
}
bool CreatureAnimation::isDead() const
@ -409,6 +407,6 @@ void CreatureAnimation::play()
{
//logAnim->trace("Play %s group %d at %d:%d", name, static_cast<int>(getType()), pos.x, pos.y);
speed = 0;
if(speedController(this, type) != 0)
speed = 1 / speedController(this, type);
if(speedController(this, type) != 0)
speed = 1 / speedController(this, type);
}

View File

@ -29,7 +29,7 @@ namespace AnimationControls
std::shared_ptr<CreatureAnimation> getAnimation(const CCreature * creature);
/// returns animation speed of specific group, taking in mind game setting (in frames per second)
float getCreatureAnimationSpeed(const CCreature * creature, const CreatureAnimation * anim, size_t groupID);
float getCreatureAnimationSpeed(const CCreature * creature, const CreatureAnimation * anim, ECreatureAnimType groupID);
/// returns how far projectile should move each frame
/// TODO: make it time-based
@ -59,7 +59,7 @@ namespace AnimationControls
class CreatureAnimation : public CIntObject
{
public:
typedef std::function<float(CreatureAnimation *, size_t)> TSpeedController;
typedef std::function<float(CreatureAnimation *, ECreatureAnimType)> TSpeedController;
private:
std::string name;
@ -84,7 +84,7 @@ private:
float elapsedTime;
///type of animation being displayed
ECreatureAnimType::Type type;
ECreatureAnimType type;
/// current value of shadow transparency
uint8_t shadowAlpha;
@ -116,10 +116,10 @@ public:
CreatureAnimation(const std::string & name_, TSpeedController speedController);
/// sets type of animation and resets framecount
void setType(ECreatureAnimType::Type type);
void setType(ECreatureAnimType type);
/// returns currently rendered type of animation
ECreatureAnimType::Type getType() const;
ECreatureAnimType getType() const;
void nextFrame(Canvas & canvas, const ColorFilter & shifter, bool facingRight);
@ -132,10 +132,10 @@ public:
float getCurrentFrame() const;
/// plays once given type of animation, then resets to idle
void playOnce(ECreatureAnimType::Type type);
void playOnce(ECreatureAnimType type);
/// returns number of frames in selected animation type
int framesInGroup(ECreatureAnimType::Type group) const;
int framesInGroup(ECreatureAnimType group) const;
void pause();
void play();

View File

@ -466,8 +466,8 @@ void CShowableAnim::rotate(bool on, bool vertical)
flags &= ~flag;
}
CCreatureAnim::CCreatureAnim(int x, int y, std::string name, ui8 flags, ECreatureAnimType::Type type):
CShowableAnim(x,y,name,flags,4,type)
CCreatureAnim::CCreatureAnim(int x, int y, std::string name, ui8 flags, ECreatureAnimType type):
CShowableAnim(x,y,name,flags,4,size_t(type))
{
xOffset = 0;
yOffset = 0;
@ -475,16 +475,16 @@ CCreatureAnim::CCreatureAnim(int x, int y, std::string name, ui8 flags, ECreatur
void CCreatureAnim::loopPreview(bool warMachine)
{
std::vector<ECreatureAnimType::Type> available;
std::vector<ECreatureAnimType> available;
static const ECreatureAnimType::Type creaPreviewList[] = {
static const ECreatureAnimType creaPreviewList[] = {
ECreatureAnimType::HOLDING,
ECreatureAnimType::HITTED,
ECreatureAnimType::DEFENCE,
ECreatureAnimType::ATTACK_FRONT,
ECreatureAnimType::SPECIAL_FRONT
};
static const ECreatureAnimType::Type machPreviewList[] = {
static const ECreatureAnimType machPreviewList[] = {
ECreatureAnimType::HOLDING,
ECreatureAnimType::MOVING,
ECreatureAnimType::SHOOT_UP,
@ -495,34 +495,36 @@ void CCreatureAnim::loopPreview(bool warMachine)
auto & previewList = warMachine ? machPreviewList : creaPreviewList;
for (auto & elem : previewList)
if (anim->size(elem))
if (anim->size(size_t(elem)))
available.push_back(elem);
size_t rnd = CRandomGenerator::getDefault().nextInt((int)available.size() * 2 - 1);
if (rnd >= available.size())
{
ECreatureAnimType::Type type;
if ( anim->size(ECreatureAnimType::MOVING) == 0 )//no moving animation present
ECreatureAnimType type;
if ( anim->size(size_t(ECreatureAnimType::MOVING)) == 0 )//no moving animation present
type = ECreatureAnimType::HOLDING;
else
type = ECreatureAnimType::MOVING;
//display this anim for ~1 second (time is random, but it looks good)
for (size_t i=0; i< 12/anim->size(type) + 1; i++)
for (size_t i=0; i< 12/anim->size(size_t(type)) + 1; i++)
addLast(type);
}
else
addLast(available[rnd]);
}
void CCreatureAnim::addLast(ECreatureAnimType::Type newType)
void CCreatureAnim::addLast(ECreatureAnimType newType)
{
if (type != ECreatureAnimType::MOVING && newType == ECreatureAnimType::MOVING)//starting moving - play init sequence
auto currType = ECreatureAnimType(group);
if (currType != ECreatureAnimType::MOVING && newType == ECreatureAnimType::MOVING)//starting moving - play init sequence
{
queue.push( ECreatureAnimType::MOVE_START );
}
else if (type == ECreatureAnimType::MOVING && newType != ECreatureAnimType::MOVING )//previous anim was moving - finish it
else if (currType == ECreatureAnimType::MOVING && newType != ECreatureAnimType::MOVING )//previous anim was moving - finish it
{
queue.push( ECreatureAnimType::MOVE_END );
}
@ -535,28 +537,28 @@ void CCreatureAnim::addLast(ECreatureAnimType::Type newType)
void CCreatureAnim::reset()
{
//if we are in the middle of rotation - set flag
if (type == ECreatureAnimType::TURN_L && !queue.empty() && queue.front() == ECreatureAnimType::TURN_L)
if (group == size_t(ECreatureAnimType::TURN_L) && !queue.empty() && queue.front() == ECreatureAnimType::TURN_L)
rotate(true);
if (type == ECreatureAnimType::TURN_R && !queue.empty() && queue.front() == ECreatureAnimType::TURN_R)
if (group == size_t(ECreatureAnimType::TURN_R) && !queue.empty() && queue.front() == ECreatureAnimType::TURN_R)
rotate(false);
while (!queue.empty())
{
ECreatureAnimType::Type at = queue.front();
ECreatureAnimType at = queue.front();
queue.pop();
if (set(at))
if (set(size_t(at)))
return;
}
if (callback)
callback();
while (!queue.empty())
{
ECreatureAnimType::Type at = queue.front();
ECreatureAnimType at = queue.front();
queue.pop();
if (set(at))
if (set(size_t(at)))
return;
}
set(ECreatureAnimType::HOLDING);
set(size_t(ECreatureAnimType::HOLDING));
}
void CCreatureAnim::startPreview(bool warMachine)
@ -564,9 +566,9 @@ void CCreatureAnim::startPreview(bool warMachine)
callback = std::bind(&CCreatureAnim::loopPreview, this, warMachine);
}
void CCreatureAnim::clearAndSet(ECreatureAnimType::Type type)
void CCreatureAnim::clearAndSet(ECreatureAnimType type)
{
while (!queue.empty())
queue.pop();
set(type);
set(size_t(type));
}

View File

@ -168,7 +168,7 @@ class CCreatureAnim: public CShowableAnim
{
private:
//queue of animations waiting to be displayed
std::queue<ECreatureAnimType::Type> queue;
std::queue<ECreatureAnimType> queue;
//this function is used as callback if preview flag was set during construction
void loopPreview(bool warMachine);
@ -178,13 +178,13 @@ public:
void reset() override;
//add sequence to the end of queue
void addLast(ECreatureAnimType::Type newType);
void addLast(ECreatureAnimType newType);
void startPreview(bool warMachine);
//clear queue and set animation to this sequence
void clearAndSet(ECreatureAnimType::Type type);
void clearAndSet(ECreatureAnimType type);
CCreatureAnim(int x, int y, std::string name, ui8 flags = 0, ECreatureAnimType::Type = ECreatureAnimType::HOLDING);
CCreatureAnim(int x, int y, std::string name, ui8 flags = 0, ECreatureAnimType = ECreatureAnimType::HOLDING);
};