[Orxonox-commit 1160] r5881 - in code/branches/core5/src: modules/pong orxonox/sound
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Oct 5 18:28:21 CEST 2009
Author: rgrieder
Date: 2009-10-05 18:28:21 +0200 (Mon, 05 Oct 2009)
New Revision: 5881
Modified:
code/branches/core5/src/modules/pong/PongBall.cc
code/branches/core5/src/modules/pong/PongBall.h
code/branches/core5/src/orxonox/sound/SoundManager.cc
Log:
Fixed sound problem in Pong by correcting the assumptions that you will always have sound.
Modified: code/branches/core5/src/modules/pong/PongBall.cc
===================================================================
--- code/branches/core5/src/modules/pong/PongBall.cc 2009-10-05 16:10:54 UTC (rev 5880)
+++ code/branches/core5/src/modules/pong/PongBall.cc 2009-10-05 16:28:21 UTC (rev 5881)
@@ -40,7 +40,11 @@
const float PongBall::MAX_REL_Z_VELOCITY = 1.5;
- PongBall::PongBall(BaseObject* creator) : MovableEntity(creator)
+ PongBall::PongBall(BaseObject* creator)
+ : MovableEntity(creator)
+ , sidesound_(NULL)
+ , batsound_(NULL)
+ , scoresound_(NULL)
{
RegisterObject(PongBall);
@@ -53,16 +57,29 @@
this->registerVariables();
- this->sidesound_ = new SoundBase(this);
- this->sidesound_->loadFile("sounds/pong_side.wav");
+ if (GameMode::playsSound())
+ {
+ this->sidesound_ = new SoundBase(this);
+ this->sidesound_->loadFile("sounds/pong_side.wav");
- this->batsound_ = new SoundBase(this);
- this->batsound_->loadFile("sounds/pong_bat.wav");
+ this->batsound_ = new SoundBase(this);
+ this->batsound_->loadFile("sounds/pong_bat.wav");
- this->scoresound_ = new SoundBase(this);
- this->scoresound_->loadFile("sounds/pong_score.wav");
+ this->scoresound_ = new SoundBase(this);
+ this->scoresound_->loadFile("sounds/pong_score.wav");
+ }
}
+ PongBall::~PongBall()
+ {
+ if (this->sidesound_)
+ delete this->sidesound_;
+ if (this->batsound_)
+ delete this->batsound_;
+ if (this->scoresound_)
+ delete this->scoresound_;
+ }
+
void PongBall::registerVariables()
{
registerVariable( this->fieldWidth_ );
@@ -86,7 +103,8 @@
if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
{
velocity.z = -velocity.z;
- this->sidesound_->play();
+ if (GameMode::playsSound())
+ this->sidesound_->play();
if (position.z > this->fieldHeight_ / 2)
position.z = this->fieldHeight_ / 2;
@@ -108,14 +126,16 @@
position.x = this->fieldWidth_ / 2;
velocity.x = -velocity.x;
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
- this->batsound_->play();
+ if (GameMode::playsSound())
+ this->batsound_->play();
}
else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
{
if (this->getGametype() && this->bat_[0])
{
this->getGametype()->playerScored(this->bat_[0]->getPlayer());
- this->scoresound_->play();
+ if (GameMode::playsSound())
+ this->scoresound_->play();
return;
}
}
@@ -128,13 +148,15 @@
position.x = -this->fieldWidth_ / 2;
velocity.x = -velocity.x;
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
- this->batsound_->play();
+ if (GameMode::playsSound())
+ this->batsound_->play();
}
else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
{
if (this->getGametype() && this->bat_[1])
{
- this->scoresound_->play();
+ if (GameMode::playsSound())
+ this->scoresound_->play();
this->getGametype()->playerScored(this->bat_[1]->getPlayer());
return;
}
@@ -156,7 +178,8 @@
if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
{
velocity.z = -velocity.z;
- this->sidesound_->play();
+ if (GameMode::playsSound())
+ this->sidesound_->play();
if (position.z > this->fieldHeight_ / 2)
position.z = this->fieldHeight_ / 2;
@@ -177,7 +200,8 @@
{
position.x = this->fieldWidth_ / 2;
velocity.x = -velocity.x;
- this->batsound_->play();
+ if (GameMode::playsSound())
+ this->batsound_->play();
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
}
}
@@ -188,7 +212,8 @@
{
position.x = -this->fieldWidth_ / 2;
velocity.x = -velocity.x;
- this->batsound_->play();
+ if (GameMode::playsSound())
+ this->batsound_->play();
velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
}
}
Modified: code/branches/core5/src/modules/pong/PongBall.h
===================================================================
--- code/branches/core5/src/modules/pong/PongBall.h 2009-10-05 16:10:54 UTC (rev 5880)
+++ code/branches/core5/src/modules/pong/PongBall.h 2009-10-05 16:28:21 UTC (rev 5881)
@@ -40,7 +40,7 @@
{
public:
PongBall(BaseObject* creator);
- virtual ~PongBall() {}
+ virtual ~PongBall();
virtual void tick(float dt);
Modified: code/branches/core5/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/core5/src/orxonox/sound/SoundManager.cc 2009-10-05 16:10:54 UTC (rev 5880)
+++ code/branches/core5/src/orxonox/sound/SoundManager.cc 2009-10-05 16:28:21 UTC (rev 5881)
@@ -72,7 +72,6 @@
COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
else
COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
- ThrowException(InitialisationFailed, "Just testing");
GameMode::setPlaysSound(true);
// Disarm guards
More information about the Orxonox-commit
mailing list