Planeshift
soundmanager.h
Go to the documentation of this file.
1 /*
2 * soundmanager.h, Author: Andrea Rizzi <88whacko@gmail.com>
3 *
4 * Copyright (C) 2001-2011 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef _SOUNDMANAGER_H_
21 #define _SOUNDMANAGER_H_
22 
23 //====================================================================================
24 // Crystal Space Includes
25 //====================================================================================
26 #include <iutil/comp.h>
27 #include <iutil/eventh.h>
28 
29 //====================================================================================
30 // Project Includes
31 //====================================================================================
32 #include <isoundmngr.h>
33 
34 //====================================================================================
35 // Local Includes
36 //====================================================================================
37 #include "soundctrl.h"
38 
39 //------------------------------------------------------------------------------------
40 // Forward Declarations
41 //------------------------------------------------------------------------------------
42 class SoundQueue;
43 class csRandomGen;
44 class InstrumentManager;
45 class SoundSectorManager;
46 class SoundSystemManager;
47 
48 
53 class SoundManager: public scfImplementation3<SoundManager, iSoundManager, iComponent, iEventHandler>
54 {
55 public:
56  // TODO this should be moved inside a ConfigManager
57  static uint updateTime;
58  static csRandomGen randomGen;
59 
60  SoundManager(iBase* parent);
61  virtual ~SoundManager();
62 
63  //From iComponent
64  virtual bool Initialize(iObjectRegistry* objReg);
65 
66  //From iEventHandler
67  virtual bool HandleEvent(iEvent &e);
68  CS_EVENTHANDLER_NAMES("crystalspace.planeshift.sound")
69  virtual const csHandlerID* GenericPrec(csRef<iEventHandlerRegistry> &ehr,
70  csRef<iEventNameRegistry> &enr, csEventID id) const;
71  virtual const csHandlerID* GenericSucc(csRef<iEventHandlerRegistry> &ehr,
72  csRef<iEventNameRegistry> &enr, csEventID id) const { return 0; }
73  CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS
74 
75  //From iSoundManager
76  //Sectors managing
77  virtual bool InitializeSectors();
78  virtual bool LoadActiveSector(const char* sectorName);
79  virtual bool ReloadSectors();
80 
81  //SoundControls and SoundQueue managing
82  virtual iSoundControl* GetSndCtrl(SndCtrlID sndCtrlID);
83  virtual bool AddSndQueue(int queueID, SndCtrlID sndCtrlID);
84  virtual void RemoveSndQueue(int queueID);
85  virtual bool PushQueueItem(int queueID, const char* fileName);
86 
87  //State
88  virtual bool IsSoundActive(SndCtrlID sndCtrlID);
89  virtual void SetCombatStance(int newCombatStance);
90  virtual int GetCombatStance() const;
91  virtual void SetPlayerMovement(csVector3 playerPosition, csVector3 playerVelocity);
92  virtual csVector3 GetPosition() const;
93  virtual void SetTimeOfDay(int newTimeOfDay);
94  virtual void SetWeather(int newWeather);
95  virtual void SetEntityState(int state, iMeshWrapper* mesh, const char* meshName, bool forceChange);
96  virtual void AddObjectEntity(iMeshWrapper* mesh, const char* meshName);
97  virtual void RemoveObjectEntity(iMeshWrapper* mesh, const char* meshName);
98  virtual void UpdateObjectEntity(iMeshWrapper* mesh, const char* meshName);
99 
100 
101  //Toggles
102  virtual void SetLoopBGMToggle(bool toggle);
103  virtual bool IsLoopBGMToggleOn();
104  virtual void SetCombatMusicToggle(bool toggle);
105  virtual bool IsCombatMusicToggleOn();
106  virtual void SetListenerOnCameraToggle(bool toggle);
107  virtual bool IsListenerOnCameraToggleOn();
108  virtual void SetChatToggle(bool toggle);
109  virtual bool IsChatToggleOn();
110 
111  //Play sounds
112  virtual bool IsSoundValid(uint soundID) const;
113  virtual uint PlaySound(const char* fileName, bool loop, SndCtrlID sndCtrlID);
114  virtual uint PlaySound(const char* fileName, bool loop, SndCtrlID sndCtrlID, csVector3 pos, csVector3 dir, float minDist, float maxDist);
115  virtual uint PlaySong(csRef<iDocument> musicalSheet, const char* instrument,
116  SndCtrlID sndCtrlID, csVector3 pos, csVector3 dir);
117  virtual bool StopSound(uint soundID);
118  virtual bool SetSoundSource(uint soundID, csVector3 position);
119 
120  //Updating function
121  virtual void Update();
122  virtual void UpdateListener(iView* view);
123 
124 
125 private:
126  iObjectRegistry* objectReg;
127  SoundSystemManager* sndSysMgr;
128  InstrumentManager* instrMgr;
129  SoundSectorManager* sectorMgr;
130 
131  csHash<SoundQueue*, int> soundQueues;
132  bool listenerOnCamera;
133  bool chatToggle;
134 
135  csTicks sndTime;
136  csTicks lastUpdateTime;
137 
138  float volumeDampPercent;
139  csArray<SndCtrlID> dampenCtrls;
140 
141  csEventID evSystemOpen;
142 
148  void InitSoundSystem();
149 
150 };
151 
152 #endif // __SOUNDMANAGER_H__
This class keeps and manage the musical instruments.
virtual ~SoundManager()
virtual void SetEntityState(int state, iMeshWrapper *mesh, const char *meshName, bool forceChange)
virtual void RemoveObjectEntity(iMeshWrapper *mesh, const char *meshName)
Used to put Sounds in a Queue and play them in the order they have been added.
Definition: queue.h:61
virtual bool Initialize(iObjectRegistry *objReg)
virtual bool PushQueueItem(int queueID, const char *fileName)
SoundManager(iBase *parent)
virtual bool HandleEvent(iEvent &e)
virtual bool IsLoopBGMToggleOn()
virtual void RemoveSndQueue(int queueID)
virtual bool IsCombatMusicToggleOn()
virtual void SetCombatMusicToggle(bool toggle)
csRef< iEventNameRegistry > csEventID id const
Definition: soundmanager.h:70
Implement iSoundManager.
Definition: soundmanager.h:53
virtual CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS bool InitializeSectors()
virtual bool IsSoundValid(uint soundID) const
This class handles every sound defined in a sector.
Definition: sectormngr.h:52
virtual void AddObjectEntity(iMeshWrapper *mesh, const char *meshName)
CS_EVENTHANDLER_NAMES("crystalspace.planeshift.sound") virtual const csHandlerID *GenericPrec(csRef< iEventHandlerRegistry > &ehr
virtual bool IsChatToggleOn()
virtual void SetWeather(int newWeather)
csRef< iEventNameRegistry > & enr
Definition: soundmanager.h:70
virtual bool IsListenerOnCameraToggleOn()
virtual void SetLoopBGMToggle(bool toggle)
virtual bool StopSound(uint soundID)
static csRandomGen randomGen
random number generator.
Definition: soundmanager.h:58
virtual uint PlaySound(const char *fileName, bool loop, SndCtrlID sndCtrlID)
virtual bool LoadActiveSector(const char *sectorName)
virtual void SetCombatStance(int newCombatStance)
virtual uint PlaySong(csRef< iDocument > musicalSheet, const char *instrument, SndCtrlID sndCtrlID, csVector3 pos, csVector3 dir)
virtual void Update()
virtual bool ReloadSectors()
virtual int GetCombatStance() const
virtual bool SetSoundSource(uint soundID, csVector3 position)
virtual void UpdateListener(iView *view)
virtual void SetTimeOfDay(int newTimeOfDay)
virtual void SetChatToggle(bool toggle)
virtual csVector3 GetPosition() const
virtual void SetListenerOnCameraToggle(bool toggle)
This Manager Object is used to play all sounds.
Definition: manager.h:62
virtual void SetPlayerMovement(csVector3 playerPosition, csVector3 playerVelocity)
static uint updateTime
update throttle in milliseconds.
Definition: soundmanager.h:57
virtual bool AddSndQueue(int queueID, SndCtrlID sndCtrlID)
virtual bool IsSoundActive(SndCtrlID sndCtrlID)
virtual void UpdateObjectEntity(iMeshWrapper *mesh, const char *meshName)
virtual const csHandlerID * GenericSucc(csRef< iEventHandlerRegistry > &ehr, csRef< iEventNameRegistry > &enr, csEventID id) const
Definition: soundmanager.h:71
virtual iSoundControl * GetSndCtrl(SndCtrlID sndCtrlID)