Planeshift

soundmanager.h

Go to the documentation of this file.
00001 /*
00002 * soundmanager.h, Author: Andrea Rizzi <[email protected]>
00003 *
00004 * Copyright (C) 2001-2011 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef _SOUNDMANAGER_H_
00021 #define _SOUNDMANAGER_H_
00022 
00023 //====================================================================================
00024 // Crystal Space Includes
00025 //====================================================================================
00026 #include <iutil/comp.h>
00027 #include <iutil/eventh.h>
00028 
00029 //====================================================================================
00030 // Project Includes
00031 //====================================================================================
00032 #include <isoundmngr.h>
00033 
00034 //====================================================================================
00035 // Local Includes
00036 //====================================================================================
00037 #include "soundctrl.h"
00038 
00039 //------------------------------------------------------------------------------------
00040 // Forward Declarations
00041 //------------------------------------------------------------------------------------
00042 class SoundQueue;
00043 class csRandomGen;
00044 class InstrumentManager;
00045 class SoundSectorManager;
00046 class SoundSystemManager;
00047 
00048 
00053 class SoundManager: public scfImplementation3<SoundManager, iSoundManager, iComponent, iEventHandler>
00054 {
00055 public:
00056     // TODO this should be moved inside a ConfigManager
00057     static uint updateTime;                 
00058     static csRandomGen randomGen;           
00059 
00060     SoundManager(iBase* parent);
00061     virtual ~SoundManager();
00062 
00063     //From iComponent
00064     virtual bool Initialize(iObjectRegistry* objReg);
00065 
00066     //From iEventHandler
00067     virtual bool HandleEvent(iEvent &e);
00068     CS_EVENTHANDLER_NAMES("crystalspace.planeshift.sound")
00069     virtual const csHandlerID* GenericPrec(csRef<iEventHandlerRegistry> &ehr,
00070             csRef<iEventNameRegistry> &enr, csEventID id) const;
00071     virtual const csHandlerID* GenericSucc(csRef<iEventHandlerRegistry> &ehr,
00072             csRef<iEventNameRegistry> &enr, csEventID id) const { return 0; }
00073     CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS
00074 
00075     //From iSoundManager
00076     //Sectors managing
00077     virtual bool InitializeSectors();
00078     virtual bool LoadActiveSector(const char* sectorName);
00079     virtual bool ReloadSectors();
00080 
00081     //SoundControls and SoundQueue managing
00082     virtual iSoundControl* GetSndCtrl(SndCtrlID sndCtrlID);
00083     virtual bool AddSndQueue(int queueID, SndCtrlID sndCtrlID);
00084     virtual void RemoveSndQueue(int queueID);
00085     virtual bool PushQueueItem(int queueID, const char* fileName);
00086 
00087     //State
00088     virtual bool IsSoundActive(SndCtrlID sndCtrlID);
00089     virtual void SetCombatStance(int newCombatStance);
00090     virtual int GetCombatStance() const;
00091     virtual void SetPlayerMovement(csVector3 playerPosition, csVector3 playerVelocity);
00092     virtual csVector3 GetPosition() const;
00093     virtual void SetTimeOfDay(int newTimeOfDay);
00094     virtual void SetWeather(int newWeather);
00095     virtual void SetEntityState(int state, iMeshWrapper* mesh, const char* meshName, bool forceChange);
00096     virtual void AddObjectEntity(iMeshWrapper* mesh, const char* meshName);
00097     virtual void RemoveObjectEntity(iMeshWrapper* mesh, const char* meshName);
00098     virtual void UpdateObjectEntity(iMeshWrapper* mesh, const char* meshName);
00099 
00100 
00101     //Toggles
00102     virtual void SetLoopBGMToggle(bool toggle);
00103     virtual bool IsLoopBGMToggleOn();
00104     virtual void SetCombatMusicToggle(bool toggle);
00105     virtual bool IsCombatMusicToggleOn();
00106     virtual void SetListenerOnCameraToggle(bool toggle);
00107     virtual bool IsListenerOnCameraToggleOn();
00108     virtual void SetChatToggle(bool toggle);
00109     virtual bool IsChatToggleOn();
00110 
00111     //Play sounds
00112     virtual bool IsSoundValid(uint soundID) const;
00113     virtual uint PlaySound(const char* fileName, bool loop, SndCtrlID sndCtrlID);
00114     virtual uint PlaySound(const char* fileName, bool loop, SndCtrlID sndCtrlID, csVector3 pos, csVector3 dir, float minDist, float maxDist);
00115     virtual uint PlaySong(csRef<iDocument> musicalSheet, const char* instrument,
00116         SndCtrlID sndCtrlID, csVector3 pos, csVector3 dir);
00117     virtual bool StopSound(uint soundID);
00118     virtual bool SetSoundSource(uint soundID, csVector3 position);
00119 
00120     //Updating function
00121     virtual void Update();
00122     virtual void UpdateListener(iView* view);
00123     
00124 
00125 private:
00126     iObjectRegistry*            objectReg;         
00127     SoundSystemManager*         sndSysMgr;         
00128     InstrumentManager*          instrMgr;          
00129     SoundSectorManager*         sectorMgr;         
00130 
00131     csHash<SoundQueue*, int>    soundQueues;       
00132     bool                        listenerOnCamera;  
00133     bool                        chatToggle;        
00134 
00135     csTicks                     sndTime;           
00136     csTicks                     lastUpdateTime;    
00137 
00138     float                                               volumeDampPercent; 
00139     csArray<SndCtrlID>          dampenCtrls;       
00140 
00141     csEventID                   evSystemOpen;      
00142 
00148     void InitSoundSystem();
00149 
00150 };    
00151 
00152 #endif // __SOUNDMANAGER_H__