Make sure SoundHandle's are inited

svn-id: r17194
This commit is contained in:
Max Horn 2005-03-22 18:29:02 +00:00
parent a2ac6c9796
commit 61d0e3f02c
2 changed files with 21 additions and 14 deletions

View File

@ -166,7 +166,7 @@ void SoundMixer::insertChannel(SoundHandle *handle, Channel *chan) {
}
_channels[index] = chan;
chan->_handle = index + (_handleSeed * NUM_CHANNELS);
chan->_handle._val = index + (_handleSeed * NUM_CHANNELS);
_handleSeed++;
if (handle) {
*handle = chan->_handle;
@ -288,8 +288,8 @@ void SoundMixer::stopHandle(SoundHandle handle) {
Common::StackLock lock(_mutex);
// Simply ignore stop requests for handles of sounds that already terminated
const int index = handle % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle != handle)
const int index = handle._val % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle._val != handle._val)
return;
delete _channels[index];
@ -299,8 +299,8 @@ void SoundMixer::stopHandle(SoundHandle handle) {
void SoundMixer::setChannelVolume(SoundHandle handle, byte volume) {
Common::StackLock lock(_mutex);
const int index = handle % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle != handle)
const int index = handle._val % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle._val != handle._val)
return;
_channels[index]->setVolume(volume);
@ -309,8 +309,8 @@ void SoundMixer::setChannelVolume(SoundHandle handle, byte volume) {
void SoundMixer::setChannelBalance(SoundHandle handle, int8 balance) {
Common::StackLock lock(_mutex);
const int index = handle % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle != handle)
const int index = handle._val % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle._val != handle._val)
return;
_channels[index]->setBalance(balance);
@ -327,8 +327,8 @@ uint32 SoundMixer::getSoundElapsedTimeOfSoundID(int id) {
uint32 SoundMixer::getSoundElapsedTime(SoundHandle handle) {
Common::StackLock lock(_mutex);
const int index = handle % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle != handle)
const int index = handle._val % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle._val != handle._val)
return 0;
return _channels[index]->getElapsedTime();
@ -352,8 +352,8 @@ void SoundMixer::pauseHandle(SoundHandle handle, bool paused) {
Common::StackLock lock(_mutex);
// Simply ignore pause/unpause requests for handles of sound that alreayd terminated
const int index = handle % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle != handle)
const int index = handle._val % NUM_CHANNELS;
if (!_channels[index] || _channels[index]->_handle._val != handle._val)
return;
_channels[index]->pause(paused);
@ -368,8 +368,8 @@ bool SoundMixer::isSoundIDActive(int id) {
}
bool SoundMixer::isSoundHandleActive(SoundHandle handle) {
const int index = handle % NUM_CHANNELS;
return _channels[index] && _channels[index]->_handle == handle;
const int index = handle._val % NUM_CHANNELS;
return _channels[index] && _channels[index]->_handle._val == handle._val;
}
bool SoundMixer::hasActiveChannelOfType(SoundType type) {

View File

@ -33,7 +33,14 @@ class Channel;
class File;
class OSystem;
typedef uint32 SoundHandle;
class SoundHandle {
friend class Channel;
friend class SoundMixer;
uint32 _val;
public:
inline SoundHandle() : _val(0xFFFFFFFF) {}
};
class SoundMixer {
public: