# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

background_sound_manager.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_BACKGROUND_SOUND_MANAGER_H
00027 #define NL_BACKGROUND_SOUND_MANAGER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "background_sound.h"
00031 #include <vector>
00032 #include <set>
00033 
00034 
00035 namespace NLLIGO
00036 {
00037         class CPrimRegion;
00038 }
00039 
00040 namespace NLSOUND {
00041 
00042 
00043 class CListenerUser;
00044 class IPlayable;
00045 class IBoundingShape;
00046 
00048 const uint32    BACKGROUND_LAYER = 3;   // 3 layer
00049 
00050 
00074 class CBackgroundSoundManager
00075 {
00076 public:
00079         void            loadSoundsFromRegion(const NLLIGO::CPrimRegion &region);
00082         void            loadEffecsFromRegion(const NLLIGO::CPrimRegion &region);
00085         void            loadSamplesFromRegion(const NLLIGO::CPrimRegion &region);
00086 
00092         void            load (const std::string &continent);
00093 
00096         void            unload ();
00097 
00099         void            play();
00101         void            stop();
00102 
00104         void            setListenerPosition (const NLMISC::CVector &listenerPosition);
00105 
00107         void            updateBackgroundStatus();
00108 
00109         // Call this function evenly to update the stuffs
00110 //      void            update ();
00111 
00113         const std::vector<NLMISC::CVector> &getZone(uint32 zone, bool *isPath = 0);
00114 
00116         NLMISC::CVector getZoneSourcePos(uint32 zone);
00117 
00119         const UAudioMixer::TBackgroundFlags &getBackgroundFlags();
00121         void            setBackgroundFlags(const UAudioMixer::TBackgroundFlags &backgroundFlags);
00122 
00123 private:
00124 
00125         // CAudioMixerUser will call private constructor and destructor, so, it is our friend ;)
00126         friend class CAudioMixerUser;
00127 
00129         CBackgroundSoundManager();
00131         virtual                                 ~CBackgroundSoundManager();
00132 
00134         void addSound(const std::string &soundName, const std::vector<NLLIGO::CPrimVector> &points, bool isPath);
00135 
00137         template <class CharType>
00138                 std::vector<std::basic_string<CharType> >       split(const std::basic_string<CharType> &str, CharType splitTag)
00139         {
00140                 std::vector<std::basic_string<CharType> >       splitted;
00141                 std::basic_string<CharType>::size_type pos = 0, nextPos = 0, size = 0;
00142 
00143                 while ((nextPos = str.find(splitTag, nextPos)) != std::basic_string<CharType>::npos)
00144                 {
00145                         size = nextPos - pos;
00146                         if (size > 0)
00147                                 splitted.push_back(std::basic_string<CharType>(str, pos, nextPos - pos));
00148                         // skip the tag
00149                         nextPos += 1;
00150                         pos = nextPos;
00151                 }
00152                 // is there a last part ?
00153                 size = nextPos - pos;
00154                 if (pos != str.size())
00155                         splitted.push_back(std::basic_string<CharType>(str, pos, str.size() - pos));
00156 
00157                 return splitted;
00158         }
00159 
00160 
00162         bool                                    _Playing;
00163 
00165         UAudioMixer::TBackgroundFlags _BackgroundFlags;
00166 
00168         NLMISC::CVector                 _LastPosition;
00169 
00171         //\name Samples banks related thinks
00172 
00174         struct TBanksData
00175         {
00177                 std::vector<std::string>                Banks;
00179                 NLMISC::CVector         MinBox;
00181                 NLMISC::CVector         MaxBox;
00183                 std::vector<NLMISC::CVector>    Points;
00184         };
00186         std::vector<TBanksData>         _Banks;
00188         std::set<std::string>           _LoadedBanks;
00190 
00191 
00193         //\name Sounds related thinks
00195         struct TSoundData
00196         {
00198                 std::string                     SoundName;
00200                 CSound                          *Sound;
00202                 USource                         *Source;
00203 
00205                 NLMISC::CVector         MinBox;
00207                 NLMISC::CVector         MaxBox;
00209                 float                           Surface;
00211                 float                           MaxDist;
00213                 bool                            IsPath;
00215                 std::vector<NLMISC::CVector>    Points;
00217                 bool                            Selected;
00218         };
00220         std::vector<TSoundData>         _Layers[BACKGROUND_LAYER];
00221         // utility structure for audio mixing computation (see cpp)
00222         struct TSoundStatus
00223         {
00225                 TSoundData                      &SoundData;
00227                 NLMISC::CVector         Position;
00231                 float                           Gain;
00233                 float                           Distance;
00235                 TSoundStatus(TSoundData &sd, NLMISC::CVector position, float gain, float distance)
00236                         : SoundData(sd), Position(position), Gain(gain), Distance(distance)
00237                 {}
00238         };
00240 };
00241 
00242 
00243 } // NLSOUND
00244 
00245 
00246 #endif // NL_BACKGROUND_SOUND_MANAGER_H
00247 
00248 /* End of background_sound_manager.h */