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

Removed sound playback from PointEffectAnimation

This commit is contained in:
Ivan Savenko 2022-12-25 21:35:13 +02:00
parent 7e3cd7db51
commit 5b41ced427
6 changed files with 38 additions and 72 deletions

View File

@ -797,10 +797,11 @@ void CatapultAnimation::nextFrame()
explosionEmitted = true;
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack) + Point(225, 225) - Point(126, 105);
if(catapultDamage > 0)
owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", shotTarget));
else
owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLMISS", "CSGRCK.DEF", shotTarget));
std::string soundFilename = (catapultDamage > 0) ? "WALLHIT" : "WALLMISS";
std::string effectFilename = (catapultDamage > 0) ? "SGEXPL" : "CSGRCK";
CCS->soundh->playSound( soundFilename );
owner.stacksController->addNewAnim( new PointEffectAnimation(owner, effectFilename, shotTarget));
}
void CatapultAnimation::createProjectile(const Point & from, const Point & dest) const
@ -864,45 +865,42 @@ uint32_t CastAnimation::getAttackClimaxFrame() const
return maxFrames / 2;
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects):
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, int effects):
BattleAnimation(owner),
animation(std::make_shared<CAnimation>(animationName)),
soundName(soundName),
effectFlags(effects),
soundPlayed(false),
soundFinished(false),
effectFinished(false)
{
logAnim->debug("CPointEffectAnimation::init: effect %s", animationName);
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects):
PointEffectAnimation(owner, soundName, animationName, effects)
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<BattleHex> hex, int effects):
PointEffectAnimation(owner, animationName, effects)
{
battlehexes = hex;
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex, int effects):
PointEffectAnimation(owner, soundName, animationName, effects)
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex, int effects):
PointEffectAnimation(owner, animationName, effects)
{
assert(hex.isValid());
battlehexes.push_back(hex);
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos, int effects):
PointEffectAnimation(owner, soundName, animationName, effects)
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<Point> pos, int effects):
PointEffectAnimation(owner, animationName, effects)
{
positions = pos;
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, int effects):
PointEffectAnimation(owner, soundName, animationName, effects)
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos, int effects):
PointEffectAnimation(owner, animationName, effects)
{
positions.push_back(pos);
}
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects):
PointEffectAnimation(owner, soundName, animationName, effects)
PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects):
PointEffectAnimation(owner, animationName, effects)
{
assert(hex.isValid());
battlehexes.push_back(hex);
@ -969,10 +967,9 @@ bool PointEffectAnimation::init()
void PointEffectAnimation::nextFrame()
{
playSound();
playEffect();
if (soundFinished && effectFinished)
if (effectFinished)
{
//remove visual effect itself only if sound has finished as well - necessary for obstacles like force field
clearEffect();
@ -985,11 +982,6 @@ bool PointEffectAnimation::alignToBottom() const
return effectFlags & ALIGN_TO_BOTTOM;
}
bool PointEffectAnimation::waitForSound() const
{
return effectFlags & WAIT_FOR_SOUND;
}
bool PointEffectAnimation::forceOnTop() const
{
return effectFlags & FORCE_ON_TOP;
@ -1005,31 +997,6 @@ void PointEffectAnimation::onEffectFinished()
effectFinished = true;
}
void PointEffectAnimation::onSoundFinished()
{
soundFinished = true;
}
void PointEffectAnimation::playSound()
{
if (soundPlayed)
return;
soundPlayed = true;
if (soundName.empty())
{
onSoundFinished();
return;
}
int channel = CCS->soundh->playSound(soundName);
if (!waitForSound() || channel == -1)
onSoundFinished();
else
CCS->soundh->setCallback(channel, [&](){ onSoundFinished(); });
}
void PointEffectAnimation::playEffect()
{
if ( effectFinished )
@ -1063,7 +1030,6 @@ void PointEffectAnimation::clearEffect()
PointEffectAnimation::~PointEffectAnimation()
{
assert(effectFinished);
assert(soundFinished);
}
HeroCastAnimation::HeroCastAnimation(BattleInterface & owner, std::shared_ptr<BattleHero> hero, BattleHex dest, const CStack * defender, const CSpell * spell):

View File

@ -305,8 +305,6 @@ public:
class PointEffectAnimation : public BattleAnimation
{
std::string soundName;
bool soundPlayed;
bool soundFinished;
bool effectFinished;
int effectFlags;
@ -320,33 +318,29 @@ class PointEffectAnimation : public BattleAnimation
bool screenFill() const;
void onEffectFinished();
void onSoundFinished();
void clearEffect();
void playSound();
void playEffect();
public:
enum EEffectFlags
{
ALIGN_TO_BOTTOM = 1,
WAIT_FOR_SOUND = 2, // Unused, can be removed
FORCE_ON_TOP = 4,
SCREEN_FILL = 8,
FORCE_ON_TOP = 2,
SCREEN_FILL = 4,
};
/// Create animation with screen-wide effect
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, int effects = 0);
/// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos , int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos , int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos , int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<Point> pos , int effects = 0);
/// Create animation positioned at certain hex(es)
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex , int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex , int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<BattleHex> hex, int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects = 0);
PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects = 0);
~PointEffectAnimation();
bool init() override;

View File

@ -49,7 +49,9 @@ void BattleEffectsController::displayEffect(EBattleEffect effect, std::string so
std::string customAnim = graphics->battleACToDef[effectID][0];
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, soundFile, customAnim, destTile));
CCS->soundh->playSound( soundFile );
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, customAnim, destTile));
}
void BattleEffectsController::battleTriggerEffect(const BattleTriggerEffect & bte)

View File

@ -413,8 +413,8 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
bool side = sc->side;
executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){
stacksController->addNewAnim(new PointEffectAnimation(*this, "", side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero));
stacksController->addNewAnim(new PointEffectAnimation(*this, "", side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero));
stacksController->addNewAnim(new PointEffectAnimation(*this, side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero));
stacksController->addNewAnim(new PointEffectAnimation(*this, side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero));
});
}
}
@ -478,9 +478,9 @@ void BattleInterface::displaySpellAnimationQueue(const CSpell * spell, const CSp
flags |= PointEffectAnimation::SCREEN_FILL;
if (!destinationTile.isValid())
stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, flags));
stacksController->addNewAnim(new PointEffectAnimation(*this, animation.resourceName, flags));
else
stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, destinationTile, flags));
stacksController->addNewAnim(new PointEffectAnimation(*this, animation.resourceName, destinationTile, flags));
}
}
}

View File

@ -17,6 +17,8 @@
#include "BattleRenderer.h"
#include "CreatureAnimation.h"
#include "../CMusicHandler.h"
#include "../CGameInfo.h"
#include "../CPlayerInterface.h"
#include "../gui/CAnimation.h"
#include "../gui/Canvas.h"
@ -95,7 +97,8 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
//we assume here that effect graphics have the same size as the usual obstacle image
// -> if we know how to blit obstacle, let's blit the effect in the same place
Point whereTo = getObstaclePosition(first, *oi);
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, spellObstacle->appearSound, spellObstacle->appearAnimation, whereTo, oi->pos));
CCS->soundh->playSound( spellObstacle->appearSound );
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, spellObstacle->appearAnimation, whereTo, oi->pos));
//so when multiple obstacles are added, they show up one after another
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);

View File

@ -345,7 +345,8 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
for (auto attackInfo : ca.attackedParts)
positions.push_back(owner.stacksController->getStackPositionAtHex(attackInfo.destinationTile, nullptr) + Point(99, 120));
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", positions));
CCS->soundh->playSound( "WALLHIT" );
owner.stacksController->addNewAnim(new PointEffectAnimation(owner, "SGEXPL.DEF", positions));
}
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);