[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src sound.cpp
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src sound.cpp |
Date: |
Tue, 08 Feb 2005 16:38:42 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/02/08 21:38:42
Modified files:
src : sound.cpp
Log message:
Fix bug with user sound files when zipios is activated. And
sanitize/optimize the code along the way.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sound.cpp.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
Patches:
Index: wesnoth/src/sound.cpp
diff -u wesnoth/src/sound.cpp:1.27 wesnoth/src/sound.cpp:1.28
--- wesnoth/src/sound.cpp:1.27 Sat Jan 8 13:57:23 2005
+++ wesnoth/src/sound.cpp Tue Feb 8 21:38:41 2005
@@ -1,4 +1,4 @@
-/* $Id: sound.cpp,v 1.27 2005/01/08 13:57:23 ydirson Exp $ */
+/* $Id: sound.cpp,v 1.28 2005/02/08 21:38:41 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -132,41 +132,33 @@
if(!mix_ok || sound_off)
return;
- std::map<std::string,Mix_Chunk*>::const_iterator itor =
sound_cache.find(file);
- if(itor == sound_cache.end()) {
+ // the insertion will fail if there is already an element in the cache
+ std::pair< std::map< std::string, Mix_Chunk * >::iterator, bool >
+ it = sound_cache.insert(std::make_pair(file, (Mix_Chunk *)0));
+ Mix_Chunk *&cache = it.first->second;
+ if (it.second) {
+ std::string const &filename =
get_binary_file_location("sounds", file);
+ if (!filename.empty()) {
#ifdef USE_ZIPIOS
- std::string s = read_file("sounds/" + file);
- if (s.empty()) {
- return;
- }
-
- SDL_RWops* ops = SDL_RWFromMem((void*)s.c_str(), s.size());
- Mix_Chunk* const sfx = Mix_LoadWAV_RW(ops,0);
- if(sfx == NULL) {
- std::cerr << "Could not load sound file '" << file <<
"': "
- << SDL_GetError() << "\n";
- return;
- }
+ std::string const &s = read_file(filename);
+ if (!s.empty()) {
+ SDL_RWops* ops =
SDL_RWFromMem((void*)s.c_str(), s.size());
+ cache = Mix_LoadWAV_RW(ops,0);
+ }
#else
- const std::string& filename =
get_binary_file_location("sounds",file);
-
- if(filename.empty()) {
- return;
+ cache = Mix_LoadWAV(filename.c_str());
+#endif
}
- Mix_Chunk* const sfx = Mix_LoadWAV(filename.c_str());
- if(sfx == NULL) {
+ if (cache == NULL) {
std::cerr << "Could not load sound file '" << filename
<< "': "
<< SDL_GetError() << "\n";
return;
}
-#endif
-
- itor =
sound_cache.insert(std::pair<std::string,Mix_Chunk*>(file,sfx)).first;
}
//play on the first available channel
- const int res = Mix_PlayChannel(-1,itor->second,0);
+ const int res = Mix_PlayChannel(-1, cache, 0);
if(res < 0) {
std::cerr << "error playing sound effect: " << SDL_GetError()
<< "\n";
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src sound.cpp,
Guillaume Melquiond <=