Преглед изворни кода

- fixed crash on hovering indestructible walls
- fix for music player (no music after end of battle)

Ivan Savenko пре 13 година
родитељ
комит
4d4f72292e
3 измењених фајлова са 15 додато и 14 уклоњено
  1. 1 1
      client/BattleInterface/CBattleInterface.cpp
  2. 12 11
      client/CMusicHandler.cpp
  3. 2 2
      client/CMusicHandler.h

+ 1 - 1
client/BattleInterface/CBattleInterface.cpp

@@ -1515,7 +1515,7 @@ bool CBattleInterface::isCatapultAttackable(BattleHex hex) const
 		return false;
 
 	int wallUnder = curInt->cb->battleHexToWallPart(hex);
-	if(wallUnder == -1)
+	if(wallUnder < 0) //invalid or indestructible
 		return false;
 
 	return curInt->cb->battleGetWallState(wallUnder) < EWallState::DESTROYED;

+ 12 - 11
client/CMusicHandler.cpp

@@ -426,11 +426,7 @@ void CMusicHandler::queueNext(MusicEntry *queued)
 
 	next.reset(queued);
 
-	if (current.get() != NULL)
-	{
-		current->stop(1000);
-	}
-	else
+	if (current.get() == nullptr || !current->stop(1000))
 	{
 		current.reset(next.release());
 		current->play();
@@ -480,7 +476,7 @@ void CMusicHandler::musicFinishedCallback(void)
 MusicEntry::MusicEntry(CMusicHandler *owner, std::string setName, std::string musicURI, bool looped):
 	owner(owner),
 	music(nullptr),
-	looped(looped),
+	loop(looped ? -1 : 1),
     setName(setName)
 {
 	if (!musicURI.empty())
@@ -521,7 +517,7 @@ void MusicEntry::load(std::string musicURI)
 
 bool MusicEntry::play()
 {
-	if (!looped && music) //already played once - return
+	if (!(loop--) && music) //already played once - return
 		return false;
 
 	if (!setName.empty())
@@ -542,11 +538,16 @@ bool MusicEntry::play()
 	return true;
 }
 
-void MusicEntry::stop(int fade_ms)
+bool MusicEntry::stop(int fade_ms)
 {
-	tlog5<<"Stoping music file "<<currentName<<"\n";
-	looped = false;
-	Mix_FadeOutMusic(fade_ms);
+	if (Mix_PlayingMusic())
+	{
+		tlog5<<"Stoping music file "<<currentName<<"\n";
+		loop = 0;
+		Mix_FadeOutMusic(fade_ms);
+		return true;
+	}
+	return false;
 }
 
 bool MusicEntry::isSet(std::string set)

+ 2 - 2
client/CMusicHandler.h

@@ -112,7 +112,7 @@ class MusicEntry
 {
 	CMusicHandler *owner;
 	Mix_Music *music;
-	bool looped;
+	int loop; // -1 = indefinite
 	//if not null - set from which music will be randomly selected
 	std::string setName;
 	std::string currentName;
@@ -128,7 +128,7 @@ public:
 	~MusicEntry();
 
 	bool play();
-	void stop(int fade_ms=0);
+	bool stop(int fade_ms=0);
 };
 
 class CMusicHandler: public CAudioBase