Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2009, 10:09:27 PM (15 years ago)
Author:
scheusso
Message:

Approach to make sounds synchronisable (not yet working)

Location:
code/branches/presentation2/src/orxonox
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.cc

    r6203 r6307  
    4242
    4343    AmbientSound::AmbientSound(BaseObject* creator)
    44         : BaseObject(creator)
     44        : BaseObject(creator), Synchronisable(creator)
    4545    {
    4646        RegisterObject(AmbientSound);
     
    4848        // Ambient sounds always fade in
    4949        this->setVolume(0);
     50        this->registerVariables();
    5051    }
    5152
    5253    AmbientSound::~AmbientSound()
    5354    {
     55    }
     56   
     57    void AmbientSound::registerVariables()
     58    {
     59        registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
     60//         registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
     61        registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
     62        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
     63        registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
     64        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
    5465    }
    5566
  • code/branches/presentation2/src/orxonox/sound/AmbientSound.h

    r6186 r6307  
    3535#include "core/BaseObject.h"
    3636#include "sound/BaseSound.h"
     37#include "network/synchronisable/Synchronisable.h"
    3738
    3839namespace orxonox
     
    4344     *
    4445     */
    45     class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject
     46    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable
    4647    {
    4748        friend class SoundManager;
     
    6364        virtual void setAmbientSource(const std::string& source);
    6465        const std::string& getAmbientSource() const { return this->ambientSource_; }
     66        inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
    6567
    6668    private:
     
    6870        void doStop();
    6971        void doPause();
     72       
     73        void registerVariables();
    7074
    7175        std::string ambientSource_; //!< Analogous to source_, but mood independent
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6285 r6307  
    4646        , bPooling_(false)
    4747        , volume_(1.0)
    48         , bLoop_(false)
     48        , bLooping_(false)
    4949        , state_(Stopped)
    5050        , pitch_ (1.0)
     
    151151    void BaseSound::setLooping(bool val)
    152152    {
    153         this->bLoop_ = val;
     153        this->bLooping_ = val;
    154154        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    155155            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
     
    204204        if (ALuint error = alGetError())
    205205        {
    206             COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString << std::endl;
     206            COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
    207207            return;
    208208        }
  • code/branches/presentation2/src/orxonox/sound/BaseSound.h

    r6255 r6307  
    6868        virtual void setSource(const std::string& source);
    6969        virtual const std::string& getSource() const { return this->source_; }
     70        inline void sourceChanged(){ this->setSource(this->source_); }
    7071
    7172        void setVolume(float vol);
    7273        float getVolume() const { return this->volume_; }
     74        inline void volumeChanged(){ this->setVolume(this->volume_); }
    7375       
    7476        virtual float getVolumeGain();
    7577        void updateVolume(void);
    7678
    77         bool getLooping() const   { return this->bLoop_; }
     79        bool getLooping() const   { return this->bLooping_; }
    7880        void setLooping(bool val);
     81        inline void loopingChanged(){ this->setLooping(this->bLooping_); }
    7982
    8083        float getPitch() const   { return this->pitch_; }
    8184        void setPitch(float pitch);
     85        inline void pitchChanged(){ this->setPitch(this->pitch_); }
    8286
    8387        //ALuint getALAudioSource(void);
    8488
    8589    protected:
    86         ALint getSourceState() const;
    87 
    88         ALuint          audioSource_;
    89         bool            bPooling_;
    90         shared_ptr<SoundBuffer> soundBuffer_;
    91 
    92     private:
    9390        enum State
    9491        {
     
    9794            Paused
    9895        };
     96        ALint getSourceState() const;
    9997
     98        ALuint          audioSource_;
     99        bool            bPooling_;
     100        shared_ptr<SoundBuffer> soundBuffer_;
    100101        std::string     source_;
    101102        float           volume_;
    102         bool            bLoop_;
     103        bool            bLooping_;
    103104        State           state_;
    104105        float           pitch_;
     106
     107    private:
    105108        DataStreamPtr   dataStream_;
    106109    };
  • code/branches/presentation2/src/orxonox/sound/WorldSound.cc

    r6269 r6307  
    3636#include "core/XMLPort.h"
    3737#include "SoundManager.h"
     38#include <core/ConsoleCommandCompilation.h>
    3839
    3940namespace orxonox
     
    4748        // WorldSound buffers should be pooled when they're not used anymore
    4849        this->bPooling_ = true;
     50        this->registerVariables();
    4951    }
    5052
    5153    WorldSound::~WorldSound()
    5254    {
     55    }
     56   
     57    void WorldSound::registerVariables()
     58    {
     59        registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
     60        registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
     61        registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
     62        registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
     63        registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
    5364    }
    5465
  • code/branches/presentation2/src/orxonox/sound/WorldSound.h

    r6186 r6307  
    5757
    5858    private:
     59        void registerVariables();
    5960    };
    6061}
  • code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc

    r6265 r6307  
    7171        this->muzzleOrientation_ = Quaternion::IDENTITY;
    7272
    73         this->defSndWpnFire_ = new WorldSound(this);
    74         this->defSndWpnFire_->setLooping(false);
    75         this->bSoundAttached_ = false;
     73        if( GameMode::isMaster() )
     74        {
     75            this->defSndWpnFire_ = new WorldSound(this);
     76            this->defSndWpnFire_->setLooping(false);
     77            this->bSoundAttached_ = false;
     78        }
     79        else
     80            this->defSndWpnFire_ = 0;
    7681    }
    7782
     
    8085        if(this->isInitialized())
    8186        {
    82             delete this->defSndWpnFire_;
     87            if( this->defSndWpnFire_ )
     88                delete this->defSndWpnFire_;
    8389        }
    8490    }
     
    106112    {
    107113        (*reloadTime) = this->reloadTime_;
    108         if( !this->bSoundAttached_ )
     114        if( !this->bSoundAttached_ && GameMode::isMaster() )
    109115        {
    110116            assert(this->getWeapon() && this->getWeapon()->getWeaponSlot());
     
    130136            this->reloadTimer_.startTimer();
    131137
    132             if(!(this->defSndWpnFire_->isPlaying()))
     138            if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying()))
    133139            {
    134140                this->defSndWpnFire_->play();
     
    222228    void WeaponMode::reloaded()
    223229    {
    224         if(this->defSndWpnFire_->isPlaying())
     230        if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying())
    225231        {
    226232            this->defSndWpnFire_->stop();
     
    257263    void WeaponMode::setDefaultSound(const std::string& soundPath)
    258264    {
    259         this->defSndWpnFire_->setSource(soundPath);
     265        if( this->defSndWpnFire_ )
     266            this->defSndWpnFire_->setSource(soundPath);
    260267    }
    261268
    262269    const std::string& WeaponMode::getDefaultSound()
    263270    {
    264         return this->defSndWpnFire_->getSource();
     271        if( this->defSndWpnFire_ )
     272            return this->defSndWpnFire_->getSource();
     273        else
     274            return std::string();
    265275    }
    266276}
Note: See TracChangeset for help on using the changeset viewer.