ScummVM API documentation
SoundEntity.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_SOUND_ENTITY_H
29 #define HPL_SOUND_ENTITY_H
30 
31 #include "hpl1/engine/scene/Entity3D.h"
32 #include "hpl1/engine/sound/SoundChannel.h"
33 
34 namespace hpl {
35 
36 class cSoundHandler;
37 class cSoundEntityData;
38 class cSoundEntityManager;
39 class cWorld3D;
40 class cSoundEntry;
41 
42 enum eSoundEntityType {
43  eSoundEntityType_Main,
44  eSoundEntityType_Start,
45  eSoundEntityType_Stop,
46  eSoundEntityType_LastEnum
47 };
48 
49 class cSoundEntity;
50 
52 public:
53  virtual ~cSoundEntityChannelCallback() = default;
54  void OnPriorityRelease();
55 
56  cSoundEntity *mpEntity;
57 };
58 
59 //----------------------------------------
60 
61 kSaveData_ChildClass(iEntity3D, cSoundEntity) {
62  kSaveData_ClassInit(cSoundEntity) public : tString msData;
63  bool mbStopped;
64  bool mbRemoveWhenOver;
65  bool mbStarted;
66  bool mbFadingOut;
67  float mfVolume;
68 
69  virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
70  virtual int GetSaveCreatePrio();
71 };
72 
73 //------------------------------------------
74 
76 public:
77  virtual ~iSoundEntityGlobalCallback() = default;
78  virtual void OnStart(cSoundEntity *apSoundEntity) = 0;
79 };
80 
83 
84 //------------------------------------------
85 
86 class cSoundEntity : public iEntity3D {
87  typedef iEntity3D super;
88  friend class cSoundEntityChannelCallback;
89 
90 public:
91  static void initGlobalCallbackList();
92  static void finalizeGlobalCallbackList();
93 
94  cSoundEntity(const tString &asName, cSoundEntityData *apData,
95  cSoundEntityManager *apSoundEntityManager,
96  cWorld3D *apWorld,
97  cSoundHandler *apSoundHandler, bool abRemoveWhenOver);
98  virtual ~cSoundEntity();
99 
100  void Play(bool abPlayStart = true);
101  void Stop(bool abPlayEnd = true);
102 
103  void FadeIn(float afSpeed);
104  void FadeOut(float afSpeed);
105 
106  bool IsStopped();
107  bool IsFadingOut();
108  float getFadingSpeed() { return _fadeSpeed; }
109  bool GetRemoveWhenOver();
110 
111  void SetVolume(float afX) { mfVolume = afX; }
112  float GetVolume() { return mfVolume; }
113 
114  iSoundChannel *GetSound(eSoundEntityType aType) { return mvSounds[aType]; }
115  cSoundEntry *GetSoundEntry(eSoundEntityType aType);
116 
117  // Entity implementation
118  void UpdateLogic(float afTimeStep);
119 
120  tString GetEntityType() { return "SoundEntity"; }
121 
122  cSoundEntityData *GetData() { return mpData; }
123 
124  static void AddGlobalCallback(iSoundEntityGlobalCallback *apCallback);
125  static void RemoveGlobalCallback(iSoundEntityGlobalCallback *apCallback);
126 
127  // SaveObject implementation
128  virtual iSaveData *CreateSaveData();
129  virtual void SaveToSaveData(iSaveData *apSaveData);
130  virtual void LoadFromSaveData(iSaveData *apSaveData);
131  virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
132 
133 private:
134  bool PlaySound(const tString &asName, bool abLoop, eSoundEntityType aType);
135 
136  float GetListenerSqrLength();
137 
138  cSoundEntityManager *mpSoundEntityManager;
139  cSoundHandler *mpSoundHandler;
140  cSoundEntityData *mpData;
141  cWorld3D *mpWorld;
142 
143  iSoundChannel *mvSounds[3];
144  // cSoundEntry *mvSoundEntries[3];
145  int mvSoundId[3];
146 
147  bool mbStopped;
148  bool mbRemoveWhenOver;
149 
150  bool mbOutOfRange;
151 
152  float mfIntervalCount;
153 
154  cSoundEntityChannelCallback *mpSoundCallback;
155 
156  bool mbStarted;
157 
158  bool mbFadingOut;
159 
160  bool mbLog;
161 
162  float mfVolume;
163 
164  bool mbPrioRemove;
165 
166  bool mbSkipStartEnd;
167 
168  float mfSleepCount;
169 
170  float _fadeSpeed;
171 
172  static tSoundEntityGlobalCallbackList *mlstGlobalCallbacks;
173 };
174 
175 } // namespace hpl
176 
177 #endif // HPL_SOUND_ENTITY_H
Definition: AI.h:36
Definition: Game.h:91
Definition: str.h:59
Definition: SoundEntity.h:51
Definition: SoundEntityData.h:36
Definition: SoundChannel.h:38
Definition: SoundEntityManager.h:39
Definition: list.h:44
Definition: SoundHandler.h:71
Definition: SaveGame.h:130
Definition: SoundEntity.h:75
Definition: World3D.h:179
Definition: SaveGame.h:111
Definition: SoundHandler.h:122
Definition: SoundChannel.h:46
Definition: Entity3D.h:81
Definition: list_intern.h:51
Definition: SoundEntity.h:86
Definition: SaveGame.h:183