From 16158e434fb304de8c5f08a929c36826e9f48657 Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 23 Apr 2011 16:09:23 +0000 Subject: [PATCH] Make per-material sounds always positional git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8428 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/audio/sfx_buffer.hpp | 14 ++++++++------ src/audio/sfx_manager.cpp | 31 ++++++++++++++++--------------- src/audio/sfx_manager.hpp | 4 ++-- src/graphics/material.cpp | 8 +++++++- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/audio/sfx_buffer.hpp b/src/audio/sfx_buffer.hpp index 38ea5d908..7d6dd0436 100644 --- a/src/audio/sfx_buffer.hpp +++ b/src/audio/sfx_buffer.hpp @@ -85,16 +85,18 @@ public: void unload(); /** \return whether this buffer was loaded from disk */ - bool isLoaded() const { return m_loaded; } + bool isLoaded() const { return m_loaded; } /** Only returns a valid buffer if isLoaded() returned true */ - ALuint getBuffer() const { return m_buffer; } - - bool isPositional() const { return m_positional; } - float getRolloff() const { return m_rolloff; } - float getGain() const { return m_gain; } + ALuint getBuffer() const { return m_buffer; } + bool isPositional() const { return m_positional; } + float getRolloff() const { return m_rolloff; } + float getGain() const { return m_gain; } std::string getFileName() const { return m_file; } + + void setPositional(bool positional) { m_positional = positional; } + }; diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 035c19dbb..ceef50d62 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -178,11 +178,11 @@ void SFXManager::loadSfx() * \return whether loading this sound effect was successful */ -bool SFXManager::addSingleSfx(const std::string &sfx_name, - const std::string &sfx_file, - bool positional, - float rolloff, - float gain) +SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name, + const std::string &sfx_file, + bool positional, + float rolloff, + float gain) { SFXBuffer* buffer = new SFXBuffer(sfx_file, positional, rolloff, gain); @@ -193,22 +193,23 @@ bool SFXManager::addSingleSfx(const std::string &sfx_name, { // Keep the buffer even if SFX is disabled, in case // SFX is enabled back later - return false; + return NULL; } if (UserConfigParams::m_verbosity>=5) printf("Loading SFX %s\n", sfx_file.c_str()); - return buffer->load(); + if (buffer->load()) return buffer; + return NULL; } // addSingleSFX //---------------------------------------------------------------------------- /** Loads a single sfx from the XML specification. * \param node The XML node with the data for this sfx. */ -void SFXManager::loadSingleSfx(const XMLNode* node, - const std::string &path) +SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node, + const std::string &path) { std::string filename; @@ -216,7 +217,7 @@ void SFXManager::loadSingleSfx(const XMLNode* node, { fprintf(stderr, "/!\\ The 'filename' attribute is mandatory in the SFX XML file!\n"); - return; + return NULL; } std::string sfx_name = StringUtils::removeExtension(filename); @@ -233,7 +234,7 @@ void SFXManager::loadSingleSfx(const XMLNode* node, fprintf(stderr, "There is already a sfx named '%s' installed - new one is ignored.\n", sfx_name.c_str()); - return; + return NULL; } // Only use the filename if no full path is specified. This is used @@ -243,10 +244,10 @@ void SFXManager::loadSingleSfx(const XMLNode* node, SFXBuffer tmpbuffer(full_path, node); - addSingleSfx(sfx_name, full_path, - tmpbuffer.isPositional(), - tmpbuffer.getRolloff(), - tmpbuffer.getGain()); + return addSingleSfx(sfx_name, full_path, + tmpbuffer.isPositional(), + tmpbuffer.getRolloff(), + tmpbuffer.getGain()); } // loadSingleSfx diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index e6185fe51..e96a1a1cc 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -100,9 +100,9 @@ public: SFXManager(); virtual ~SFXManager(); bool sfxAllowed(); - void loadSingleSfx(const XMLNode* node, + SFXBuffer* loadSingleSfx(const XMLNode* node, const std::string &path=std::string("")); - bool addSingleSfx(const std::string &sfx_name, + SFXBuffer* addSingleSfx(const std::string &sfx_name, const std::string &filename, bool positional, float rolloff, diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index 8a631190c..3528efa8e 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -23,6 +23,7 @@ #include #include "audio/sfx_base.hpp" +#include "audio/sfx_buffer.hpp" #include "config/user_config.hpp" #include "config/stk_config.hpp" #include "graphics/irr_driver.hpp" @@ -312,7 +313,12 @@ void Material::initCustomSFX(const XMLNode *sfx) // The directory for the track was added to the model search path // so just misuse the getModelFile function const std::string full_path = file_manager->getModelFile(filename); - sfx_manager->loadSingleSfx(sfx, full_path); + SFXBuffer* buffer = sfx_manager->loadSingleSfx(sfx, full_path); + + if (buffer != NULL) + { + buffer->setPositional(true); + } } } // initCustomSFX