| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "ResSoundPack.h" |
| 10 |
|
| 11 |
#include "Path.h" |
| 12 |
#include "OptionAgent.h" |
| 13 |
|
| 14 |
//----------------------------------------------------------------- |
| 15 |
void |
| 16 |
ResSoundPack::unloadRes(Mix_Chunk *res) |
| 17 |
{ |
| 18 |
Mix_FreeChunk(res); |
| 19 |
} |
| 20 |
//----------------------------------------------------------------- |
| 21 |
/** |
| 22 |
* Load unshared sound from file. |
| 23 |
* @return sound or NULL |
| 24 |
*/ |
| 25 |
Mix_Chunk * |
| 26 |
ResSoundPack::loadSound(const Path &file) |
| 27 |
{ |
| 28 |
Mix_Chunk *chunk = NULL; |
| 29 |
//TODO: ask SoundAgent to load this sound |
| 30 |
if (OptionAgent::agent()->getAsBool("sound", true)) { |
| 31 |
chunk = Mix_LoadWAV(file.getNative().c_str()); |
| 32 |
if (NULL == chunk) { |
| 33 |
LOG_WARNING(ExInfo("cannot load sound") |
| 34 |
.addInfo("path", file.getNative()) |
| 35 |
.addInfo("MixError", Mix_GetError())); |
| 36 |
} |
| 37 |
} |
| 38 |
return chunk; |
| 39 |
} |
| 40 |
//----------------------------------------------------------------- |
| 41 |
/** |
| 42 |
* Store sound under this name. |
| 43 |
* Nothing is stored when sound cannot be loaded. |
| 44 |
*/ |
| 45 |
void |
| 46 |
ResSoundPack::addSound(const std::string &name, const Path &file) |
| 47 |
{ |
| 48 |
Mix_Chunk *chunk = loadSound(file); |
| 49 |
if (chunk) { |
| 50 |
addRes(name, chunk); |
| 51 |
} |
| 52 |
} |
| 53 |
|