Bläddra i källkod

Minor refactoring

Ivan Savenko 2 år sedan
förälder
incheckning
2864a04bda

+ 5 - 7
client/battle/BattleAnimationClasses.cpp

@@ -354,9 +354,9 @@ bool MovementAnimation::init()
 		myAnim->setType(ECreatureAnimType::MOVING);
 	}
 
-	if (owner.moveSoundHander == -1)
+	if (moveSoundHander == -1)
 	{
-		owner.moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
+		moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
 	}
 
 	Point begPosition = owner.stacksController->getStackPositionAtHex(prevHex, stack);
@@ -416,11 +416,8 @@ MovementAnimation::~MovementAnimation()
 {
 	assert(stack);
 
-	if(owner.moveSoundHander != -1)
-	{
-		CCS->soundh->stopSound(owner.moveSoundHander);
-		owner.moveSoundHander = -1;
-	}
+	if(moveSoundHander != -1)
+		CCS->soundh->stopSound(moveSoundHander);
 }
 
 MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *stack, std::vector<BattleHex> _destTiles, int _distance)
@@ -430,6 +427,7 @@ MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *stac
 	  begX(0), begY(0),
 	  distanceX(0), distanceY(0),
 	  progressPerSecond(0.0),
+	  moveSoundHander(-1),
 	  progress(0.0)
 {
 	logAnim->debug("Created MovementAnimation for %s", stack->getName());

+ 2 - 0
client/battle/BattleAnimationClasses.h

@@ -141,6 +141,8 @@ protected:
 class MovementAnimation : public StackMoveAnimation
 {
 private:
+	int moveSoundHander; // sound handler used when moving a unit
+
 	std::vector<BattleHex> destTiles; //full path, includes already passed hexes
 	ui32 curentMoveIndex; // index of nextHex in destTiles
 

+ 14 - 1
client/battle/BattleInterface.cpp

@@ -54,7 +54,6 @@ BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *
 	, attackerInt(att)
 	, defenderInt(defen)
 	, curInt(att)
-	, moveSoundHander(-1)
 {
 	if(spectatorInt)
 	{
@@ -528,6 +527,20 @@ void BattleInterface::activateStack()
 	GH.fakeMouseMove();
 }
 
+bool BattleInterface::openingPlaying()
+{
+	return battleIntroSoundChannel != -1;
+}
+
+void BattleInterface::openingAbort()
+{
+	if (!openingPlaying())
+		return;
+
+	// stop playing sound, causing SDL to call sound finished callback
+	CCS->soundh->stopSound(battleIntroSoundChannel);
+}
+
 bool BattleInterface::makingTurn() const
 {
 	return stacksController->getActiveStack() != nullptr;

+ 6 - 5
client/battle/BattleInterface.h

@@ -111,6 +111,9 @@ class BattleInterface
 	/// defender interface, not null if attacker is human in our vcmiclient
 	std::shared_ptr<CPlayerInterface> defenderInt;
 
+	/// ID of channel on which battle opening sound is playing, or -1 if none
+	int battleIntroSoundChannel;
+
 	void playIntroSoundAndUnlockInterface();
 	void onIntroSoundPlayed();
 public:
@@ -118,9 +121,6 @@ public:
 	const CCreatureSet *army1;
 	const CCreatureSet *army2;
 
-	/// ID of channel on which battle opening sound is playing, or -1 if none
-	int battleIntroSoundChannel;
-
 	std::shared_ptr<BattleWindow> windowObject;
 	std::shared_ptr<BattleConsole> console;
 
@@ -145,9 +145,10 @@ public:
 
 	static CondSh<BattleAction *> givenCommand; //data != nullptr if we have i.e. moved current unit
 
-	bool makingTurn() const;
+	bool openingPlaying();
+	void openingAbort();
 
-	int moveSoundHander; // sound handler used when moving a unit
+	bool makingTurn() const;
 
 	BattleInterface(const CCreatureSet *army1, const CCreatureSet *army2, const CGHeroInstance *hero1, const CGHeroInstance *hero2, std::shared_ptr<CPlayerInterface> att, std::shared_ptr<CPlayerInterface> defen, std::shared_ptr<CPlayerInterface> spectatorInt = nullptr);
 	~BattleInterface();

+ 2 - 2
client/battle/BattleWindow.cpp

@@ -179,9 +179,9 @@ void BattleWindow::deactivate()
 
 void BattleWindow::keyPressed(const SDL_Keycode & key)
 {
-	if(owner.battleIntroSoundChannel != -1)
+	if (owner.openingPlaying())
 	{
-		CCS->soundh->stopSound(owner.battleIntroSoundChannel);
+		owner.openingAbort();
 		return;
 	}