Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2009, 10:14:08 PM (15 years ago)
Author:
rgrieder
Message:

Fixed a major sound issue: The state gets reset to 'Stopped' when the sound has finished playing (unless in loop mode of course).

Location:
code/branches/presentation2/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/modules/weapons/projectiles/Rocket.cc

    r6381 r6383  
    115115        {
    116116            if (GameMode::isMaster() && this->player_)
    117             {
    118117                this->player_->stopTemporaryControl();
    119             }
     118
    120119            if ( this->defSndWpnEngine_ )
    121             {
    122                 if ( this->defSndWpnEngine_->isPlaying() )
    123                     this->defSndWpnEngine_->stop();
    124120                this->defSndWpnEngine_->destroy();
    125             }
     121
    126122            if ( this->defSndWpnLaunch_ )
    127             {
    128                 if ( this->defSndWpnLaunch_->isPlaying())
    129                     this->defSndWpnLaunch_->stop();
    130123                this->defSndWpnLaunch_->destroy();
    131             }
    132124        }
    133125    }
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6382 r6383  
    7777            if (!alIsSource(this->audioSource_))
    7878            {
    79                 this->audioSource_ = SoundManager::getInstance().getSoundSource();
     79                this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
    8080                if (!alIsSource(this->audioSource_))
    8181                    return;
  • code/branches/presentation2/src/orxonox/sound/SoundManager.cc

    r6378 r6383  
    145145        alGenSources(1, &source);
    146146        if (!alGetError() && alIsSource(source))
    147             this->soundSources_.push_back(source);
     147            this->availableSoundSources_.push_back(source);
    148148        else
    149149            ThrowException(InitialisationFailed, "Sound Error: Could not even create a single source");
     
    153153        while (alIsSource(source) && !alGetError() && count <= this->maxSources_)
    154154        {
    155             this->soundSources_.push_back(source);
     155            this->availableSoundSources_.push_back(source);
    156156            alGenSources(1, &source);
    157157            ++count;
     
    195195    {
    196196        this->processCrossFading(time.getDeltaTime());
     197
     198        // Check whether a sound object has stopped playing
     199        for (unsigned int i = 0; i < this->usedSoundSources_.size(); ++i)
     200        {
     201            ALint state;
     202            alGetSourcei(this->usedSoundSources_[i].first, AL_SOURCE_STATE, &state);
     203            if (state == AL_STOPPED)
     204            {
     205                this->usedSoundSources_[i].second->stop();
     206                --i;
     207            }
     208        }
    197209    }
    198210
     
    536548    }
    537549
    538     ALuint SoundManager::getSoundSource()
    539     {
    540         if (!this->soundSources_.empty())
    541         {
    542             ALuint source = this->soundSources_.back();
    543             this->soundSources_.pop_back();
     550    ALuint SoundManager::getSoundSource(BaseSound* object)
     551    {
     552        if (!this->availableSoundSources_.empty())
     553        {
     554            ALuint source = this->availableSoundSources_.back();
     555            this->availableSoundSources_.pop_back();
     556            this->usedSoundSources_.push_back(std::make_pair(source, object));
    544557            return source;
    545558        }
     
    556569    {
    557570#ifndef NDEBUG
    558         for (std::vector<ALuint>::const_iterator it = this->soundSources_.begin(); it != this->soundSources_.end(); ++it)
     571        for (std::vector<ALuint>::const_iterator it = this->availableSoundSources_.begin(); it != this->availableSoundSources_.end(); ++it)
    559572            assert((*it) != source);
    560573#endif
    561         this->soundSources_.push_back(source);
     574        this->availableSoundSources_.push_back(source);
     575        for (std::vector<std::pair<ALuint, BaseSound*> >::iterator it = this->usedSoundSources_.begin();
     576            it != this->usedSoundSources_.end(); ++it)
     577        {
     578            if (it->first == source)
     579            {
     580                this->usedSoundSources_.erase(it);
     581                break;
     582            }
     583        }
    562584    }
    563585}
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6370 r6383  
    102102        void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
    103103
    104         ALuint getSoundSource();
     104        ALuint getSoundSource(BaseSound* object);
    105105        void releaseSoundSource(ALuint source);
    106106
     
    147147        // Sound source related
    148148        unsigned int maxSources_;
    149         std::vector<ALuint> soundSources_;
     149        std::vector<ALuint> availableSoundSources_;
     150        std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_;
    150151
    151152        static SoundManager* singletonPtr_s;
Note: See TracChangeset for help on using the changeset viewer.