Planeshift

manager.h

Go to the documentation of this file.
00001 /*
00002  * manager.h
00003  *
00004  * Copyright (C) 2001-2010 Atomic Blue ([email protected], http://www.planeshift.it)
00005  *
00006  * Credits : Saul Leite <[email protected]>
00007  *           Mathias 'AgY' Voeroes <[email protected]>
00008  *           and all past and present planeshift coders
00009  *
00010  * This program is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License
00012  * as published by the Free Software Foundation (version 2 of the License.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021  *
00022  */
00023 
00024 #ifndef _SOUND_MANAGER_H_
00025 #define _SOUND_MANAGER_H_
00026 
00027 
00028 //====================================================================================
00029 // Crystal Space Includes
00030 //====================================================================================
00031 #include <cssysdef.h>
00032 #include <iutil/objreg.h>
00033 #include <csgeom/vector3.h>
00034 #include <csutil/hash.h>
00035 #include <iutil/timer.h>
00036 #include <csutil/timer.h>
00037 #include <csutil/randomgen.h>
00038 
00039 //====================================================================================
00040 // Project Includes
00041 //====================================================================================
00042 #include "util/singleton.h"
00043 
00044 //------------------------------------------------------------------------------------
00045 // Forward Declarations
00046 //------------------------------------------------------------------------------------
00047 class SoundSystem;
00048 class SoundDataCache;
00049 class SoundHandle;
00050 class SoundControl;
00051 
00052 enum
00053 {
00054     LOOP        = true,
00055     DONT_LOOP   = false
00056 };
00057 
00058 
00059 #define VOLUME_ZERO 0.0f
00060 #define VOLUME_MIN  0.0f
00061 #define VOLUME_NORM 1.0f
00062 #define VOLUME_MAX  2.0f
00063 
00064 #define DEFAULT_SNDSYS_UPDATE_TIME 100
00065 #define DEFAULT_SPEED_OF_SOUND 331
00066 #define DEFAULT_DOPPLER_FACTOR 0.0
00067 #define DEFAULT_SOUNDLIB_PATH "/planeshift/art/soundlib.xml"
00068 
00080 class SoundSystemManager: public Singleton<SoundSystemManager>
00081 {
00082 public:
00083     bool                   Initialised;       
00084     SoundControl*          mainSndCtrl;
00085     csRef<iEventTimer>     eventTimer;        
00086 
00090     SoundSystemManager();
00091 
00098     ~SoundSystemManager();
00099 
00107     bool Initialize(iObjectRegistry* objectReg);
00108 
00113     bool IsHandleValid(uint handleID) const;
00114 
00119     void UpdateSound();
00120 
00133     bool Play2DSound(const char* name, bool loop, size_t loopstart,
00134                      size_t loopend, float volume_preset,
00135                      SoundControl* &sndCtrl, SoundHandle* &handle);
00136 
00154     bool Play3DSound(const char* name, bool loop, size_t loopstart,
00155                      size_t loopend, float volume_preset,
00156                      SoundControl* &sndCtrl, csVector3 pos, csVector3 dir,
00157                      float mindist, float maxdist, float rad, int type3d,
00158                      SoundHandle* &handle, bool dopplerEffect = true);
00159 
00165     bool StopSound(uint handleID);
00166 
00173     bool SetSoundSource(uint handleID, csVector3 position);
00174 
00179     void SetPlayerPosition(csVector3& pos);
00180 
00185     csVector3& GetPlayerPosition();
00186 
00191     void SetPlayerVelocity(csVector3 vel);
00192 
00199     void UpdateListener(csVector3 v, csVector3 f, csVector3 t);
00200 
00205     csVector3 GetListenerPos() const;
00206 
00212     void Update();
00213 
00220     SoundControl* AddSoundControl(uint sndCtrlID);
00221     void RemoveSoundControl(uint sndCtrlID);
00222     SoundControl* GetSoundControl(uint sndCtrlID) const;
00223 
00224     SoundSystem* GetSoundSystem() const { return soundSystem; }
00225     SoundDataCache* GetSoundDataCache() const { return soundDataCache; }
00226 
00227 private:
00228     SoundSystem*                   soundSystem;
00229     SoundDataCache*                soundDataCache;
00230     csHash<SoundHandle*, uint>     soundHandles;       
00231     csHash<SoundControl*, uint>    soundControllers;   
00232 
00233     uint                           updateTime;         
00234     csTicks                        SndTime;            
00235     csTicks                        LastUpdateTime;     
00236 
00237     csVector3                      playerPosition;     
00238     csVector3                      playerVelocity;     
00239 
00240     uint                           speedOfSound;       
00241     float                          dopplerFactor;      
00242 
00247     uint FindHandleID();
00248 
00254     void RemoveHandle(uint handleID);
00255 
00263     void ChangePlayRate(SoundHandle* handle);
00264 
00279     bool InitSoundHandle(const char* name, bool loop, size_t loopstart,
00280                      size_t loopend, float volume_preset, int type3d,
00281                      SoundControl* &sndCtrl, SoundHandle* &handle, bool dopplerEffect);
00282 };
00283 
00284 #endif /*_SOUND_MANAGER_H_*/