#include <iostream>
#include <stdexcept>
#include <sstream>
+#include <physfs.h>
#include "audio/sound_manager.h"
#include "audio/musicref.h"
+#include "physfs/physfs_sdl.h"
#include "moving_object.h"
#include "resources.h"
std::cerr << "Sound '" << name << "' not found.\n";
return -1;
}
- return Mix_PlayChannel(-1, chunk, loops);
+ int chan=Mix_PlayChannel(-1, chunk, loops);
+ Mix_Volume(chan,MIX_MAX_VOLUME);
+ return chan;
}
-void
+int
SoundManager::play_sound(const std::string& sound, const MovingObject* object,
const Vector& pos)
{
// TODO keep track of the object later and move the sound along with the
// object.
- play_sound(sound, object->get_pos(), pos);
+ return play_sound(sound, object->get_pos(), pos);
}
-void
+int
SoundManager::play_sound(const std::string& sound, const Vector& pos,
const Vector& pos2)
{
if(!audio_device || !m_sound_enabled)
- return;
+ return -1;
Mix_Chunk* chunk = preload_sound(sound);
if(chunk == 0) {
std::cerr << "Sound '" << sound << "' not found.\n";
- return;
+ return -1;
}
// TODO make sure this formula is good
= pos2.x- pos.x;
int loud = int(255.0/float(1600) * fabsf(distance));
if(loud > 255)
- return;
+ return -1;
int chan = Mix_PlayChannel(-1, chunk, 0);
if(chan < 0)
- return;
+ return -1;
+ Mix_Volume(chan,MIX_MAX_VOLUME);
Mix_SetDistance(chan, loud);
// very bad way to do this...
Mix_SetPanning(chan, 230, 24);
else if(distance < -100)
Mix_SetPanning(chan, 24, 230);
+ return chan;
}
MusicRef
}
bool
-SoundManager::exists_music(const std::string& file)
+SoundManager::exists_music(const std::string& filename)
{
if(!audio_device)
return true;
// song already loaded?
- std::map<std::string, MusicResource>::iterator i = musics.find(file);
+ std::map<std::string, MusicResource>::iterator i = musics.find(filename);
if(i != musics.end()) {
return true;
}
-
- Mix_Music* song = Mix_LoadMUS(file.c_str());
+
+ const char* dir = PHYSFS_getRealDir(filename.c_str());
+ if(dir == 0)
+ return false;
+ Mix_Music* song = Mix_LoadMUS( (std::string(dir) + "/" + filename).c_str() );
if(song == 0)
return false;
// insert into music list
std::pair<std::map<std::string, MusicResource>::iterator, bool> result =
musics.insert(
- std::make_pair<std::string, MusicResource> (file, MusicResource()));
+ std::make_pair<std::string, MusicResource> (filename, MusicResource()));
MusicResource& resource = result.first->second;
resource.manager = this;
resource.music = song;
std::string filename = "sounds/";
filename += name;
filename += ".wav";
- filename = get_resource_filename(filename);
- Mix_Chunk* chunk = Mix_LoadWAV(filename.c_str());
+ Mix_Chunk* chunk = Mix_LoadWAV_RW(get_physfs_SDLRWops(filename), true);
if(chunk != 0) {
sounds.insert(std::make_pair(name, chunk));
}