ScummVM API documentation
SoundHandler.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_SOUNDHANDLER_H
29 #define HPL_SOUNDHANDLER_H
30 
31 #include "common/list.h"
32 #include "hpl1/engine/math/MathTypes.h"
33 #include "hpl1/engine/physics/PhysicsWorld.h"
34 #include "hpl1/engine/system/SystemTypes.h"
35 
36 namespace hpl {
37 
38 class iLowLevelSound;
39 class iSoundChannel;
40 class cWorld3D;
41 
42 //----------------------------------------
43 
44 enum eSoundDest : unsigned int {
45  eSoundDest_World = eFlagBit_0,
46  eSoundDest_Gui = eFlagBit_1,
47  eSoundDest_All = eFlagBit_All
48 };
49 
50 //----------------------------------------
51 
53 public:
54  void Reset();
55  bool HasCollided() { return mbHasCollided; }
56 
57  bool BeforeIntersect(iPhysicsBody *pBody);
58  bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
59 
60 private:
61  bool mbHasCollided;
62  // int mlCount;
63 };
64 
65 //----------------------------------------
66 
70 
71 class cSoundEntry {
72 public:
73  cSoundEntry() : mfNormalVolume(1), mfNormalVolumeFadeDest(1),
74  mfNormalVolumeMul(1), mfNormalVolumeFadeSpeed(0), mbStream(false),
75  mlCount(0), mpSound(nullptr) {}
76 
77  void Update(float afTimeStep);
78 
79  tString msName;
80  iSoundChannel *mpSound;
81 
82  float mfNormalVolume;
83  float mfNormalVolumeMul;
84  float mfNormalVolumeFadeDest;
85  float mfNormalVolumeFadeSpeed;
86 
87  float mfNormalSpeed;
88 
89  bool mbFirstTime;
90 
91  float mfBlockMul;
92  float mfBlockFadeDest;
93  float mfBlockFadeSpeed;
94 
95  bool mbStream;
96 
97  long int mlCount;
98 
99  eSoundDest mEffectType;
100 };
101 
104 
106 
110 
111 //----------------------------------------
112 
114 typedef tPlayedSoundNumMap::iterator tPlayedSoundNumMapIt;
115 
116 //----------------------------------------
117 
118 class cResources;
119 
120 //----------------------------------------
121 
123 public:
124  cSoundHandler(iLowLevelSound *apLowLevelSound, cResources *apResources);
125  ~cSoundHandler();
126 
127  iSoundChannel *Play(const tString &asName, bool abLoop, float afVolume, const cVector3f &avPos,
128  float afMinDist, float afMaxDist, eSoundDest mType, bool abRelative, bool ab3D = false,
129  int alPriorityModifier = 0, eSoundDest aEffectType = eSoundDest_World);
130 
131  iSoundChannel *Play3D(const tString &asName, bool abLoop, float afVolume, const cVector3f &avPos,
132  float afMinDist, float afMaxDist, eSoundDest mType, bool abRelative, int alPriorityModifier = 0,
133  eSoundDest aEffectType = eSoundDest_World) {
134  return Play(asName, abLoop, afVolume, avPos, afMinDist, afMaxDist, mType, abRelative, true,
135  alPriorityModifier, aEffectType);
136  }
137 
138  iSoundChannel *PlayStream(const tString &asFileName, bool abLoop, float afVolume, bool ab3D = false,
139  eSoundDest aEffectType = eSoundDest_Gui);
140 
141  iSoundChannel *PlayGui(const tString &asName, bool abLoop, float afVolume, const cVector3f &avPos = cVector3f(0, 0, 1),
142  eSoundDest aEffectType = eSoundDest_Gui);
143 
144  void SetSilent(bool abX) { mbSilent = abX; }
145  bool GetSilent() { return mbSilent; }
146 
147  bool Stop(const tString &asName);
148  bool StopAllExcept(const tString &asName);
149 
150  void StopAll(tFlag mTypes);
151  void PauseAll(tFlag mTypes);
152  void ResumeAll(tFlag mTypes);
153 
154  bool IsPlaying(const tString &asName);
155 
156  bool IsValid(iSoundChannel *apChannel);
157  bool IsValidId(iSoundChannel *apChannel, int alId);
158 
159  void Update(float afTimeStep);
160 
161  void SetSpeed(float afSpeed, float afRate, tFlag mTypes);
162  void SetVolume(float afVolume, float afRate, tFlag mTypes);
163 
164  float GetVolume() { return mfVolume; }
165 
166  void SetWorld3D(cWorld3D *apWorld3D);
167 
168  cSoundEntry *GetEntryFromSound(iSoundChannel *apSound);
169 
170  iSoundChannel *CreateChannel(const tString &asName, int alPriority);
171 
172  tSoundEntryList *GetWorldEntryList();
173  tSoundEntryList *GetGuiEntryList();
174 
175 private:
176  iLowLevelSound *mpLowLevelSound;
177  cResources *mpResources;
178 
179  tSoundEntryList mlstGuiSounds;
180  tSoundEntryList mlstWorldSounds;
181 
182  bool mbSilent;
183 
184  float mfSpeed;
185  float mfNewSpeed;
186  float mfSpeedRate;
187  tFlag mAffectedBySpeed;
188 
189  float mfVolume;
190  float mfNewVolume;
191  float mfVolumeRate;
192  tFlag mAffectedByVolume;
193 
194  cWorld3D *mpWorld3D;
195 
196  cSoundRayCallback mSoundRayCallback;
197 
198  tPlayedSoundNumMap m_mapPlayedSound;
199 
200  cSoundEntry *GetEntry(const tString &asName);
201  bool UpdateEntry(cSoundEntry *apEntry, float afTimeStep, tFlag aTypes);
202  void UpdateDistanceVolume3D(cSoundEntry *apEntry, float afTimeStep, bool abFade, tFlag aTypes);
203 
204  int mlCount;
205  int mlIdCount;
206 };
207 
208 } // namespace hpl
209 
210 #endif // HPL_SOUNDHANDLER_H
Definition: AI.h:36
Definition: str.h:59
Definition: PhysicsWorld.h:92
Definition: PhysicsWorld.h:100
Definition: SoundHandler.h:71
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: SystemTypes.h:411
Definition: PhysicsBody.h:117
Definition: World3D.h:179
Definition: SoundHandler.h:122
Definition: SoundHandler.h:52
Definition: Resources.h:160
Definition: SoundChannel.h:46
Definition: LowLevelSound.h:45
Definition: list_intern.h:51