[Orxonox-commit 325] r2950 - in branches/sound: cmake src/orxonox src/orxonox/objects src/sound
erwin at orxonox.net
erwin at orxonox.net
Mon May 4 15:40:08 CEST 2009
Author: erwin
Date: 2009-05-04 15:40:08 +0200 (Mon, 04 May 2009)
New Revision: 2950
Added:
branches/sound/src/sound/CMakeLists.txt
Removed:
branches/sound/src/sound/copyheader
Modified:
branches/sound/cmake/LibraryConfig.cmake
branches/sound/src/orxonox/CMakeLists.txt
branches/sound/src/orxonox/objects/Level.cc
branches/sound/src/orxonox/objects/Level.h
branches/sound/src/sound/SoundBase.cc
branches/sound/src/sound/SoundBase.h
branches/sound/src/sound/SoundManager.cc
branches/sound/src/sound/SoundManager.h
Log:
ambient sound loading for levels
Modified: branches/sound/cmake/LibraryConfig.cmake
===================================================================
--- branches/sound/cmake/LibraryConfig.cmake 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/cmake/LibraryConfig.cmake 2009-05-04 13:40:08 UTC (rev 2950)
@@ -110,8 +110,8 @@
FIND_PACKAGE(OGRE 1.4 EXACT REQUIRED)
FIND_PACKAGE(ENet 1.1 REQUIRED)
-FIND_PACKAGE(Ogg REQUIRED)
-FIND_PACKAGE(Vorbis REQUIRED)
+#FIND_PACKAGE(Ogg REQUIRED)
+#FIND_PACKAGE(Vorbis REQUIRED)
FIND_PACKAGE(ALUT REQUIRED)
FIND_PACKAGE(ZLIB REQUIRED)
IF(WIN32)
Modified: branches/sound/src/orxonox/CMakeLists.txt
===================================================================
--- branches/sound/src/orxonox/CMakeLists.txt 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/orxonox/CMakeLists.txt 2009-05-04 13:40:08 UTC (rev 2950)
@@ -57,7 +57,7 @@
util
core
network
- #audio
+ sound
)
ORXONOX_INSTALL(orxonox)
Modified: branches/sound/src/orxonox/objects/Level.cc
===================================================================
--- branches/sound/src/orxonox/objects/Level.cc 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/orxonox/objects/Level.cc 2009-05-04 13:40:08 UTC (rev 2950)
@@ -76,6 +76,8 @@
XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
+
+ XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode);
XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
}
@@ -147,6 +149,22 @@
return 0;
}
+ void Level::loadAmbientSound(const std::string& filename)
+ {
+ if(filename == "") return;
+ else
+ {
+ if(this->ambientsound_ == NULL)
+ {
+ this->ambientsound_ = new SoundBase();
+ this->sndmgr_.addSound(this->ambientsound_);
+ }
+
+ this->ambientsound_->loadFile(filename);
+ this->ambientsound_->play();
+ }
+ }
+
void Level::playerEntered(PlayerInfo* player)
{
COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl;
Modified: branches/sound/src/orxonox/objects/Level.h
===================================================================
--- branches/sound/src/orxonox/objects/Level.h 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/orxonox/objects/Level.h 2009-05-04 13:40:08 UTC (rev 2950)
@@ -32,6 +32,8 @@
#include "OrxonoxPrereqs.h"
#include "network/synchronisable/Synchronisable.h"
+#include "sound/SoundBase.h"
+#include "sound/SoundManager.h"
#include "core/BaseObject.h"
namespace orxonox
@@ -50,6 +52,8 @@
inline const std::string& getDescription() const
{ return this->description_; }
+ void loadAmbientSound(const std::string& filename);
+
void playerEntered(PlayerInfo* player);
void playerLeft(PlayerInfo* player);
@@ -68,6 +72,8 @@
std::string xmlfilename_;
XMLFile* xmlfile_;
std::list<BaseObject*> objects_;
+ SoundManager sndmgr_;
+ SoundBase* ambientsound_;
};
}
Added: branches/sound/src/sound/CMakeLists.txt
===================================================================
--- branches/sound/src/sound/CMakeLists.txt (rev 0)
+++ branches/sound/src/sound/CMakeLists.txt 2009-05-04 13:40:08 UTC (rev 2950)
@@ -0,0 +1,41 @@
+ #
+ # ORXONOX - the hottest 3D action shooter ever to exist
+ # > www.orxonox.net <
+ #
+ # This program is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU General Public License
+ # as published by the Free Software Foundation; either version 2
+ # of the License, or (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License along
+ # with this program; if not, write to the Free Software Foundation,
+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ #
+
+SET_SOURCE_FILES(SOUND_FILES
+ SoundManager.h
+ SoundBase.h
+
+ SoundManager.cc
+ SoundBase.cc
+)
+GENERATE_SOURCE_GROUPS(${SOUND_FILES})
+
+
+ADD_LIBRARY(sound SHARED ${SOUND_FILES})
+TARGET_LINK_LIBRARIES(sound
+ ${OPENAL_LIBRARY}
+ ${ALUT_LIBRARY}
+ #${VORBISFILE_LIBRARY}
+ #${VORBIS_LIBRARY}
+ #${OGG_LIBRARY}
+ core
+ util
+)
+
+ORXONOX_INSTALL(sound)
\ No newline at end of file
Modified: branches/sound/src/sound/SoundBase.cc
===================================================================
--- branches/sound/src/sound/SoundBase.cc 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/sound/SoundBase.cc 2009-05-04 13:40:08 UTC (rev 2950)
@@ -33,14 +33,17 @@
namespace orxonox
{
+ SoundBase::SoundBase()
+ {
+ this->source_ = 0;
+ this->buffer_ = 0;
+ this->entity_ = NULL;
+ }
SoundBase::SoundBase(WorldEntity* entity)
{
this->source_ = 0;
this->buffer_ = 0;
this->entity_ = entity;
-
- if(SoundBase::soundmanager_s == NULL)
- SoundBase::soundmanager_s = SoundManager::instance();
}
void SoundBase::attachToEntity(WorldEntity* entity)
@@ -50,7 +53,7 @@
}
void SoundBase::update() {
- if(alIsSource(this->source_)) {
+ if(this->entity_ != NULL && alIsSource(this->source_)) {
Vector3 pos = this->entity_->getPosition();
alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
ALenum error = alGetError();
@@ -98,31 +101,35 @@
if(alIsSource(this->source_)) {
return getSourceState() == AL_PLAYING;
}
+ return false;
}
bool SoundBase::isPaused() {
if(alIsSource(this->source_)) {
return getSourceState() == AL_PAUSED;
}
+ return true;
}
bool SoundBase::isStopped() {
if(alIsSource(this->source_)) {
return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
}
+ return true;
}
bool SoundBase::loadFile(std::string filename) {
+ COUT(3) << "OpenAL ALUT: loading file " << filename << std::endl;
this->buffer_ = alutCreateBufferFromFile(filename.c_str());
if(this->buffer_ == AL_NONE) {
- COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError());
+ COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
return false;
}
alGenSources(1, &this->source_);
alSourcei(this->source_, AL_BUFFER, this->buffer_);
if(alGetError() != AL_NO_ERROR) {
- COUT(2) << "OpenAL: Error loading sample file";
+ COUT(2) << "OpenAL: Error loading sample file" << std::endl;
return false;
}
return true;
Modified: branches/sound/src/sound/SoundBase.h
===================================================================
--- branches/sound/src/sound/SoundBase.h 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/sound/SoundBase.h 2009-05-04 13:40:08 UTC (rev 2950)
@@ -44,8 +44,8 @@
class SoundBase
{
public:
+ SoundBase();
SoundBase(WorldEntity* entity);
- ~SoundBase();
void attachToEntity(WorldEntity* entity);
void update();
@@ -64,8 +64,6 @@
ALuint buffer_;
WorldEntity* entity_;
- static SoundManager* soundmanager_s;
-
ALint getSourceState();
}; // class SoundBase
} // namepsace orxonox
Modified: branches/sound/src/sound/SoundManager.cc
===================================================================
--- branches/sound/src/sound/SoundManager.cc 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/sound/SoundManager.cc 2009-05-04 13:40:08 UTC (rev 2950)
@@ -37,28 +37,16 @@
namespace orxonox
{
/**
- * Static function to get the singleton instance of SoundManager.
- *
- * @return The singleton instance
- */
- SoundManager* SoundManager::instance()
- {
- if(SoundManager::singleton_ == NULL)
- {
- SoundManager::singleton_ = new SoundManager();
- }
-
- return SoundManager::singleton_;
- }
-
- /**
* Default constructor
*/
SoundManager::SoundManager()
{
if(!alutInit(NULL,NULL)) {
- COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError());
+ COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
}
+
+ COUT(4) << "OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
+ COUT(4) << "OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
}
/**
@@ -97,6 +85,7 @@
{
// update listener position
Camera* camera = CameraManager::getInstance().getActiveCamera();
+ if(camera == NULL) return;
Vector3 pos = camera->getPosition();
alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
ALenum error = alGetError();
Modified: branches/sound/src/sound/SoundManager.h
===================================================================
--- branches/sound/src/sound/SoundManager.h 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/sound/SoundManager.h 2009-05-04 13:40:08 UTC (rev 2950)
@@ -45,17 +45,13 @@
class SoundManager : public Tickable
{
public:
- static SoundManager* instance();
-
+ SoundManager();
void addSound(SoundBase* sound);
void removeSound(SoundBase* sound);
-
+
virtual void tick(float dt);
private:
- SoundManager(); // private constructor -> singleton
- static SoundManager* singleton_;
-
std::list<SoundBase*> soundlist_;
}; // class SoundManager
Deleted: branches/sound/src/sound/copyheader
===================================================================
--- branches/sound/src/sound/copyheader 2009-05-02 14:19:43 UTC (rev 2949)
+++ branches/sound/src/sound/copyheader 2009-05-04 13:40:08 UTC (rev 2950)
@@ -1,28 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Erwin 'vaiursch' Herrsche
- * Co-authors:
- * ...
- *
- */
-
More information about the Orxonox-commit
mailing list