Browse Source

* Reinstated music player. Added terrain music. To MSVC users: you need the recently uploaded libraries pack for this to work! [ http://download.vcmi.eu/msvc-pack.7z ]
* Not crash on empty (or 1-byte) lod file. (Case in SoD+WoG installations, where h3ab*.lod are dummies.

Michał W. Urbańczyk 14 năm trước cách đây
mục cha
commit
a043bfa44a
4 tập tin đã thay đổi với 18 bổ sung4 xóa
  1. 3 3
      client/CMT.cpp
  2. 9 1
      client/CMusicHandler.cpp
  3. 1 0
      client/CMusicHandler.h
  4. 5 0
      lib/CLodHandler.cpp

+ 3 - 3
client/CMT.cpp

@@ -137,8 +137,8 @@ void init()
 	CCS->soundh->init();
 	CCS->soundh->setVolume(GDefaultOptions.soundVolume);
 	CCS->musich = new CMusicHandler;
-	//CGI->musich->init();
-	//CGI->musich->setVolume(GDefaultOptions.musicVolume);
+	CCS->musich->init();
+	CCS->musich->setVolume(GDefaultOptions.musicVolume);
 	tlog0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
 	tlog0<<"Initializing screen and sound handling: "<<tmh.getDif()<<std::endl;
 
@@ -278,7 +278,7 @@ int main(int argc, char** argv)
 
 	if(!vm.count("battle"))
 	{
-		CCS->musich->playMusic(musicBase::mainMenu, -1);
+		//CCS->musich->playMusic(musicBase::mainMenu, -1);
 		GH.curInt = new CGPreGame; //will set CGP pointer to itself
 	}
 	else

+ 9 - 1
client/CMusicHandler.cpp

@@ -316,6 +316,10 @@ CMusicHandler::CMusicHandler(): currentMusic(NULL), nextMusic(NULL)
 	              musicBase::necroTown,      musicBase::dungeonTown,
 				  musicBase::strongHoldTown, musicBase::fortressTown,
 	              musicBase::elemTown;
+
+	terrainMusics += musicBase::dirt, musicBase::sand, musicBase::grass,
+		musicBase::snow, musicBase::swamp, musicBase::rough,
+		musicBase::underground, musicBase::lava,musicBase::water;
 }
 
 void CMusicHandler::init()
@@ -441,7 +445,11 @@ Mix_Music * CMusicHandler::LoadMUS(const char *file)
 	Mix_Music *ret = Mix_LoadMUS(file);
 	if(!ret) //load music and check for error
 		tlog1 << "Unable to load music file (" << file <<"). Error: " << Mix_GetError() << std::endl;
-	
+
+#ifdef _WIN32
+	//The assertion will fail if old MSVC libraries pack .dll is used
+	assert(Mix_GetMusicType(ret) == MUS_MP3_MAD);
+#endif
 	return ret;
 }
 

+ 1 - 0
client/CMusicHandler.h

@@ -121,6 +121,7 @@ public:
 	std::map<musicBase::musicID, std::string> musics;
 	std::vector<musicBase::musicID> battleMusics;
 	std::vector<musicBase::musicID> townMusics;
+	std::vector<musicBase::musicID> terrainMusics;
 
 	void playMusic(musicBase::musicID musicID, int loop=1);
 	void playMusicFromSet(std::vector<musicBase::musicID> &music_vec, int loop=1);

+ 5 - 0
lib/CLodHandler.cpp

@@ -280,6 +280,11 @@ void CLodHandler::init(const std::string lodFile, const std::string dirName)
 	totalFiles = SDL_SwapLE32(temp);
 
 	LOD.seekg(0x5c, std::ios::beg);
+	if(!LOD)
+	{
+		tlog2 << lodFile << " doesn't store anything!\n";
+		return;
+	}
 
 	struct LodEntry *lodEntries = new struct LodEntry[totalFiles];
 	LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles);