mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Removed sound playback from PointEffectAnimation
This commit is contained in:
		| @@ -797,10 +797,11 @@ void CatapultAnimation::nextFrame() | |||||||
| 	explosionEmitted = true; | 	explosionEmitted = true; | ||||||
| 	Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack) + Point(225, 225) - Point(126, 105); | 	Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack) + Point(225, 225) - Point(126, 105); | ||||||
|  |  | ||||||
| 	if(catapultDamage > 0) | 	std::string soundFilename  = (catapultDamage > 0) ? "WALLHIT" : "WALLMISS"; | ||||||
| 		owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", shotTarget)); | 	std::string effectFilename = (catapultDamage > 0) ? "SGEXPL" : "CSGRCK"; | ||||||
| 	else |  | ||||||
| 		owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLMISS", "CSGRCK.DEF", shotTarget)); | 	CCS->soundh->playSound( soundFilename ); | ||||||
|  | 	owner.stacksController->addNewAnim( new PointEffectAnimation(owner, effectFilename, shotTarget)); | ||||||
| } | } | ||||||
|  |  | ||||||
| void CatapultAnimation::createProjectile(const Point & from, const Point & dest) const | void CatapultAnimation::createProjectile(const Point & from, const Point & dest) const | ||||||
| @@ -864,45 +865,42 @@ uint32_t CastAnimation::getAttackClimaxFrame() const | |||||||
| 	return maxFrames / 2; | 	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), | 	BattleAnimation(owner), | ||||||
| 	animation(std::make_shared<CAnimation>(animationName)), | 	animation(std::make_shared<CAnimation>(animationName)), | ||||||
| 	soundName(soundName), |  | ||||||
| 	effectFlags(effects), | 	effectFlags(effects), | ||||||
| 	soundPlayed(false), |  | ||||||
| 	soundFinished(false), |  | ||||||
| 	effectFinished(false) | 	effectFinished(false) | ||||||
| { | { | ||||||
| 	logAnim->debug("CPointEffectAnimation::init: effect %s", animationName); | 	logAnim->debug("CPointEffectAnimation::init: effect %s", animationName); | ||||||
| } | } | ||||||
|  |  | ||||||
| PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects): | PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<BattleHex> hex, int effects): | ||||||
| 	PointEffectAnimation(owner, soundName, animationName, effects) | 	PointEffectAnimation(owner, animationName, effects) | ||||||
| { | { | ||||||
| 	battlehexes = hex; | 	battlehexes = hex; | ||||||
| } | } | ||||||
|  |  | ||||||
| PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex, int effects): | PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex, int effects): | ||||||
| 	PointEffectAnimation(owner, soundName, animationName, effects) | 	PointEffectAnimation(owner, animationName, effects) | ||||||
| { | { | ||||||
| 	assert(hex.isValid()); | 	assert(hex.isValid()); | ||||||
| 	battlehexes.push_back(hex); | 	battlehexes.push_back(hex); | ||||||
| } | } | ||||||
|  |  | ||||||
| PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos, int effects): | PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, std::vector<Point> pos, int effects): | ||||||
| 	PointEffectAnimation(owner, soundName, animationName, effects) | 	PointEffectAnimation(owner, animationName, effects) | ||||||
| { | { | ||||||
| 	positions = pos; | 	positions = pos; | ||||||
| } | } | ||||||
|  |  | ||||||
| PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, int effects): | PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos, int effects): | ||||||
| 	PointEffectAnimation(owner, soundName, animationName, effects) | 	PointEffectAnimation(owner, animationName, effects) | ||||||
| { | { | ||||||
| 	positions.push_back(pos); | 	positions.push_back(pos); | ||||||
| } | } | ||||||
|  |  | ||||||
| PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex,   int effects): | PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex,   int effects): | ||||||
| 	PointEffectAnimation(owner, soundName, animationName, effects) | 	PointEffectAnimation(owner, animationName, effects) | ||||||
| { | { | ||||||
| 	assert(hex.isValid()); | 	assert(hex.isValid()); | ||||||
| 	battlehexes.push_back(hex); | 	battlehexes.push_back(hex); | ||||||
| @@ -969,10 +967,9 @@ bool PointEffectAnimation::init() | |||||||
|  |  | ||||||
| void PointEffectAnimation::nextFrame() | void PointEffectAnimation::nextFrame() | ||||||
| { | { | ||||||
| 	playSound(); |  | ||||||
| 	playEffect(); | 	playEffect(); | ||||||
|  |  | ||||||
| 	if (soundFinished && effectFinished) | 	if (effectFinished) | ||||||
| 	{ | 	{ | ||||||
| 		//remove visual effect itself only if sound has finished as well - necessary for obstacles like force field | 		//remove visual effect itself only if sound has finished as well - necessary for obstacles like force field | ||||||
| 		clearEffect(); | 		clearEffect(); | ||||||
| @@ -985,11 +982,6 @@ bool PointEffectAnimation::alignToBottom() const | |||||||
| 	return effectFlags & ALIGN_TO_BOTTOM; | 	return effectFlags & ALIGN_TO_BOTTOM; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool PointEffectAnimation::waitForSound() const |  | ||||||
| { |  | ||||||
| 	return effectFlags & WAIT_FOR_SOUND; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| bool PointEffectAnimation::forceOnTop() const | bool PointEffectAnimation::forceOnTop() const | ||||||
| { | { | ||||||
| 	return effectFlags & FORCE_ON_TOP; | 	return effectFlags & FORCE_ON_TOP; | ||||||
| @@ -1005,31 +997,6 @@ void PointEffectAnimation::onEffectFinished() | |||||||
| 	effectFinished = true; | 	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() | void PointEffectAnimation::playEffect() | ||||||
| { | { | ||||||
| 	if ( effectFinished ) | 	if ( effectFinished ) | ||||||
| @@ -1063,7 +1030,6 @@ void PointEffectAnimation::clearEffect() | |||||||
| PointEffectAnimation::~PointEffectAnimation() | PointEffectAnimation::~PointEffectAnimation() | ||||||
| { | { | ||||||
| 	assert(effectFinished); | 	assert(effectFinished); | ||||||
| 	assert(soundFinished); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| HeroCastAnimation::HeroCastAnimation(BattleInterface & owner, std::shared_ptr<BattleHero> hero, BattleHex dest, const CStack * defender, const CSpell * spell): | HeroCastAnimation::HeroCastAnimation(BattleInterface & owner, std::shared_ptr<BattleHero> hero, BattleHex dest, const CStack * defender, const CSpell * spell): | ||||||
|   | |||||||
| @@ -305,8 +305,6 @@ public: | |||||||
| class PointEffectAnimation : public BattleAnimation | class PointEffectAnimation : public BattleAnimation | ||||||
| { | { | ||||||
| 	std::string soundName; | 	std::string soundName; | ||||||
| 	bool soundPlayed; |  | ||||||
| 	bool soundFinished; |  | ||||||
| 	bool effectFinished; | 	bool effectFinished; | ||||||
| 	int effectFlags; | 	int effectFlags; | ||||||
|  |  | ||||||
| @@ -320,33 +318,29 @@ class PointEffectAnimation : public BattleAnimation | |||||||
| 	bool screenFill() const; | 	bool screenFill() const; | ||||||
|  |  | ||||||
| 	void onEffectFinished(); | 	void onEffectFinished(); | ||||||
| 	void onSoundFinished(); |  | ||||||
| 	void clearEffect(); | 	void clearEffect(); | ||||||
|  |  | ||||||
| 	void playSound(); |  | ||||||
| 	void playEffect(); | 	void playEffect(); | ||||||
|  |  | ||||||
| public: | public: | ||||||
| 	enum EEffectFlags | 	enum EEffectFlags | ||||||
| 	{ | 	{ | ||||||
| 		ALIGN_TO_BOTTOM = 1, | 		ALIGN_TO_BOTTOM = 1, | ||||||
| 		WAIT_FOR_SOUND  = 2, // Unused, can be removed | 		FORCE_ON_TOP    = 2, | ||||||
| 		FORCE_ON_TOP    = 4, | 		SCREEN_FILL     = 4, | ||||||
| 		SCREEN_FILL     = 8, |  | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	/// Create animation with screen-wide effect | 	/// 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 | 	/// 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 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, std::vector<Point> pos    , int effects = 0); | ||||||
|  |  | ||||||
| 	/// Create animation positioned at certain hex(es) | 	/// 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 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, 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(); | 	 ~PointEffectAnimation(); | ||||||
|  |  | ||||||
| 	bool init() override; | 	bool init() override; | ||||||
|   | |||||||
| @@ -49,7 +49,9 @@ void BattleEffectsController::displayEffect(EBattleEffect effect, std::string so | |||||||
|  |  | ||||||
| 	std::string customAnim = graphics->battleACToDef[effectID][0]; | 	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) | void BattleEffectsController::battleTriggerEffect(const BattleTriggerEffect & bte) | ||||||
|   | |||||||
| @@ -413,8 +413,8 @@ void BattleInterface::spellCast(const BattleSpellCast * sc) | |||||||
| 		bool side = sc->side; | 		bool side = sc->side; | ||||||
|  |  | ||||||
| 		executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){ | 		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_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_B.DEF" : "SP07_A.DEF", rightHero)); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -478,9 +478,9 @@ void BattleInterface::displaySpellAnimationQueue(const CSpell * spell, const CSp | |||||||
| 				flags |= PointEffectAnimation::SCREEN_FILL; | 				flags |= PointEffectAnimation::SCREEN_FILL; | ||||||
|  |  | ||||||
| 			if (!destinationTile.isValid()) | 			if (!destinationTile.isValid()) | ||||||
| 				stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, flags)); | 				stacksController->addNewAnim(new PointEffectAnimation(*this, animation.resourceName, flags)); | ||||||
| 			else | 			else | ||||||
| 				stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, destinationTile, flags)); | 				stacksController->addNewAnim(new PointEffectAnimation(*this, animation.resourceName, destinationTile, flags)); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -17,6 +17,8 @@ | |||||||
| #include "BattleRenderer.h" | #include "BattleRenderer.h" | ||||||
| #include "CreatureAnimation.h" | #include "CreatureAnimation.h" | ||||||
|  |  | ||||||
|  | #include "../CMusicHandler.h" | ||||||
|  | #include "../CGameInfo.h" | ||||||
| #include "../CPlayerInterface.h" | #include "../CPlayerInterface.h" | ||||||
| #include "../gui/CAnimation.h" | #include "../gui/CAnimation.h" | ||||||
| #include "../gui/Canvas.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 | 		//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 | 		// -> if we know how to blit obstacle, let's blit the effect in the same place | ||||||
| 		Point whereTo = getObstaclePosition(first, *oi); | 		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 | 		//so when multiple obstacles are added, they show up one after another | ||||||
| 		owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); | 		owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); | ||||||
|   | |||||||
| @@ -345,7 +345,8 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca) | |||||||
| 		for (auto attackInfo : ca.attackedParts) | 		for (auto attackInfo : ca.attackedParts) | ||||||
| 			positions.push_back(owner.stacksController->getStackPositionAtHex(attackInfo.destinationTile, nullptr) + Point(99, 120)); | 			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); | 	owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user