[Orxonox-commit 1589] r6307 - in code/branches/presentation2/src: modules/weapons/weaponmodes orxonox/sound orxonox/weaponsystem
scheusso at orxonox.net
scheusso at orxonox.net
Wed Dec 9 22:09:27 CET 2009
Author: scheusso
Date: 2009-12-09 22:09:27 +0100 (Wed, 09 Dec 2009)
New Revision: 6307
Modified:
code/branches/presentation2/src/modules/weapons/weaponmodes/HsW01.cc
code/branches/presentation2/src/modules/weapons/weaponmodes/LightningGun.cc
code/branches/presentation2/src/modules/weapons/weaponmodes/RocketFire.cc
code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
code/branches/presentation2/src/orxonox/sound/AmbientSound.h
code/branches/presentation2/src/orxonox/sound/BaseSound.cc
code/branches/presentation2/src/orxonox/sound/BaseSound.h
code/branches/presentation2/src/orxonox/sound/WorldSound.cc
code/branches/presentation2/src/orxonox/sound/WorldSound.h
code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc
Log:
Approach to make sounds synchronisable (not yet working)
Modified: code/branches/presentation2/src/modules/weapons/weaponmodes/HsW01.cc
===================================================================
--- code/branches/presentation2/src/modules/weapons/weaponmodes/HsW01.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/modules/weapons/weaponmodes/HsW01.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -41,8 +41,6 @@
#include "worldentities/WorldEntity.h"
#include "worldentities/pawns/Pawn.h"
-#include "sound/WorldSound.h"
-
namespace orxonox
{
CreateFactory(HsW01);
Modified: code/branches/presentation2/src/modules/weapons/weaponmodes/LightningGun.cc
===================================================================
--- code/branches/presentation2/src/modules/weapons/weaponmodes/LightningGun.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/modules/weapons/weaponmodes/LightningGun.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -35,8 +35,6 @@
#include "weaponsystem/WeaponSystem.h"
#include "worldentities/pawns/Pawn.h"
-#include "sound/WorldSound.h"
-
namespace orxonox
{
CreateFactory(LightningGun);
Modified: code/branches/presentation2/src/modules/weapons/weaponmodes/RocketFire.cc
===================================================================
--- code/branches/presentation2/src/modules/weapons/weaponmodes/RocketFire.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/modules/weapons/weaponmodes/RocketFire.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -37,8 +37,6 @@
#include "weaponsystem/WeaponSystem.h"
#include "worldentities/pawns/Pawn.h"
-#include "sound/WorldSound.h"
-
namespace orxonox
{
CreateFactory(RocketFire);
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -41,17 +41,28 @@
CreateFactory(AmbientSound);
AmbientSound::AmbientSound(BaseObject* creator)
- : BaseObject(creator)
+ : BaseObject(creator), Synchronisable(creator)
{
RegisterObject(AmbientSound);
// Ambient sounds always fade in
this->setVolume(0);
+ this->registerVariables();
}
AmbientSound::~AmbientSound()
{
}
+
+ void AmbientSound::registerVariables()
+ {
+ registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
+// registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
+ registerVariable(ambientSource_, ObjectDirection::ToClient, new NetworkCallback<AmbientSound>(this, &AmbientSound::ambientSourceChanged));
+ registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
+ registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
+ registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
+ }
void AmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
Modified: code/branches/presentation2/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/AmbientSound.h 2009-12-09 21:09:27 UTC (rev 6307)
@@ -34,6 +34,7 @@
#include "core/BaseObject.h"
#include "sound/BaseSound.h"
+#include "network/synchronisable/Synchronisable.h"
namespace orxonox
{
@@ -42,7 +43,7 @@
* It server as main interface to the OpenAL library.
*
*/
- class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject
+ class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject, public Synchronisable
{
friend class SoundManager;
@@ -62,11 +63,14 @@
virtual void setAmbientSource(const std::string& source);
const std::string& getAmbientSource() const { return this->ambientSource_; }
+ inline void ambientSourceChanged(){ this->setAmbientSource(this->ambientSource_); }
private:
void doPlay();
void doStop();
void doPause();
+
+ void registerVariables();
std::string ambientSource_; //!< Analogous to source_, but mood independent
};
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -45,7 +45,7 @@
: audioSource_(0)
, bPooling_(false)
, volume_(1.0)
- , bLoop_(false)
+ , bLooping_(false)
, state_(Stopped)
, pitch_ (1.0)
{
@@ -150,7 +150,7 @@
void BaseSound::setLooping(bool val)
{
- this->bLoop_ = val;
+ this->bLooping_ = val;
if (GameMode::playsSound() && alIsSource(this->audioSource_))
alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
}
@@ -203,7 +203,7 @@
alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
if (ALuint error = alGetError())
{
- COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString << std::endl;
+ COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
return;
}
Modified: code/branches/presentation2/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/BaseSound.h 2009-12-09 21:09:27 UTC (rev 6307)
@@ -67,41 +67,44 @@
virtual void setSource(const std::string& source);
virtual const std::string& getSource() const { return this->source_; }
+ inline void sourceChanged(){ this->setSource(this->source_); }
void setVolume(float vol);
float getVolume() const { return this->volume_; }
+ inline void volumeChanged(){ this->setVolume(this->volume_); }
virtual float getVolumeGain();
void updateVolume(void);
- bool getLooping() const { return this->bLoop_; }
+ bool getLooping() const { return this->bLooping_; }
void setLooping(bool val);
+ inline void loopingChanged(){ this->setLooping(this->bLooping_); }
float getPitch() const { return this->pitch_; }
void setPitch(float pitch);
+ inline void pitchChanged(){ this->setPitch(this->pitch_); }
//ALuint getALAudioSource(void);
protected:
- ALint getSourceState() const;
-
- ALuint audioSource_;
- bool bPooling_;
- shared_ptr<SoundBuffer> soundBuffer_;
-
- private:
enum State
{
Stopped,
Playing,
Paused
};
+ ALint getSourceState() const;
+ ALuint audioSource_;
+ bool bPooling_;
+ shared_ptr<SoundBuffer> soundBuffer_;
std::string source_;
float volume_;
- bool bLoop_;
+ bool bLooping_;
State state_;
float pitch_;
+
+ private:
DataStreamPtr dataStream_;
};
}
Modified: code/branches/presentation2/src/orxonox/sound/WorldSound.cc
===================================================================
--- code/branches/presentation2/src/orxonox/sound/WorldSound.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/WorldSound.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -35,6 +35,7 @@
#include "core/EventIncludes.h"
#include "core/XMLPort.h"
#include "SoundManager.h"
+#include <core/ConsoleCommandCompilation.h>
namespace orxonox
{
@@ -46,11 +47,21 @@
RegisterObject(WorldSound);
// WorldSound buffers should be pooled when they're not used anymore
this->bPooling_ = true;
+ this->registerVariables();
}
WorldSound::~WorldSound()
{
}
+
+ void WorldSound::registerVariables()
+ {
+ registerVariable(volume_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::volumeChanged));
+ registerVariable(source_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::sourceChanged));
+ registerVariable(bLooping_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::loopingChanged));
+ registerVariable((int&)(BaseSound::state_), ObjectDirection::ToClient);
+ registerVariable(pitch_, ObjectDirection::ToClient, new NetworkCallback<BaseSound>(static_cast<BaseSound*>(this), &BaseSound::pitchChanged));
+ }
void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
Modified: code/branches/presentation2/src/orxonox/sound/WorldSound.h
===================================================================
--- code/branches/presentation2/src/orxonox/sound/WorldSound.h 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/sound/WorldSound.h 2009-12-09 21:09:27 UTC (rev 6307)
@@ -56,6 +56,7 @@
virtual void tick(float dt);
private:
+ void registerVariables();
};
}
Modified: code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc 2009-12-09 20:36:29 UTC (rev 6306)
+++ code/branches/presentation2/src/orxonox/weaponsystem/WeaponMode.cc 2009-12-09 21:09:27 UTC (rev 6307)
@@ -70,16 +70,22 @@
this->muzzlePosition_ = Vector3::ZERO;
this->muzzleOrientation_ = Quaternion::IDENTITY;
- this->defSndWpnFire_ = new WorldSound(this);
- this->defSndWpnFire_->setLooping(false);
- this->bSoundAttached_ = false;
+ if( GameMode::isMaster() )
+ {
+ this->defSndWpnFire_ = new WorldSound(this);
+ this->defSndWpnFire_->setLooping(false);
+ this->bSoundAttached_ = false;
+ }
+ else
+ this->defSndWpnFire_ = 0;
}
WeaponMode::~WeaponMode()
{
if(this->isInitialized())
{
- delete this->defSndWpnFire_;
+ if( this->defSndWpnFire_ )
+ delete this->defSndWpnFire_;
}
}
@@ -105,7 +111,7 @@
bool WeaponMode::fire(float* reloadTime)
{
(*reloadTime) = this->reloadTime_;
- if( !this->bSoundAttached_ )
+ if( !this->bSoundAttached_ && GameMode::isMaster() )
{
assert(this->getWeapon() && this->getWeapon()->getWeaponSlot());
this->getWeapon()->getWeaponSlot()->attach(this->defSndWpnFire_);
@@ -129,7 +135,7 @@
this->reloadTimer_.setInterval(reloadtime);
this->reloadTimer_.startTimer();
- if(!(this->defSndWpnFire_->isPlaying()))
+ if( this->defSndWpnFire_ && !(this->defSndWpnFire_->isPlaying()))
{
this->defSndWpnFire_->play();
}
@@ -221,7 +227,7 @@
void WeaponMode::reloaded()
{
- if(this->defSndWpnFire_->isPlaying())
+ if( this->defSndWpnFire_ && this->defSndWpnFire_->isPlaying())
{
this->defSndWpnFire_->stop();
}
@@ -256,11 +262,15 @@
void WeaponMode::setDefaultSound(const std::string& soundPath)
{
- this->defSndWpnFire_->setSource(soundPath);
+ if( this->defSndWpnFire_ )
+ this->defSndWpnFire_->setSource(soundPath);
}
const std::string& WeaponMode::getDefaultSound()
{
- return this->defSndWpnFire_->getSource();
+ if( this->defSndWpnFire_ )
+ return this->defSndWpnFire_->getSource();
+ else
+ return std::string();
}
}
More information about the Orxonox-commit
mailing list