1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Handles the sound bank and plays effects */
19 
20 #ifndef INC_C4SoundSystem
21 #define INC_C4SoundSystem
22 
23 #include "c4group/C4Group.h"
24 #include "platform/C4SoundModifiers.h"
25 
26 const int32_t
27 	C4MaxSoundName=100,
28 	C4MaxSoundInstances=20,
29 	C4NearSoundRadius=50,
30 	C4AudibilityRadius=700;
31 
32 const int32_t SoundUnloadTime=60, SoundMaxUnloadSize=100000;
33 
34 class C4SoundInstance;
35 class C4SoundEffect;
36 class C4SoundModifier;
37 
38 class C4SoundSystem
39 {
40 public:
41 	C4SoundSystem();
42 	~C4SoundSystem();
43 	void Clear();
44 	void Execute();
45 	int32_t LoadEffects(C4Group &hGroup, const char *namespace_prefix, bool group_is_root);
46 	C4SoundInstance *NewEffect(const char *szSound, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = nullptr, int32_t iCustomFalloffDistance = 0, int32_t iPitch = 0, C4SoundModifier *modifier = nullptr);
47 	C4SoundInstance *FindInstance(const char *szSound, C4Object *pObj);
48 	C4SoundInstance *GetFirstInstance() const;
49 	C4SoundInstance *GetNextInstance(C4SoundInstance *prev) const;
50 	bool Init();
51 	void ClearPointers(C4Object *pObj);
GetFirstSound()52 	C4SoundEffect *GetFirstSound() const { return FirstSound; }
53 
54 	C4SoundModifierList Modifiers;
55 protected:
56 	C4Group SoundFile;
57 	C4SoundEffect *FirstSound{nullptr}; // TODO: Add a hash map for sound lookup. Also add a global list for all running sound instances.
58 	void ClearEffects();
59 	C4SoundEffect* GetEffect(const char *szSound);
60 	int32_t RemoveEffect(const char *szFilename);
61 };
62 
63 C4SoundInstance *StartSoundEffect(const char *szSndName, bool fLoop = false, int32_t iVolume = 100, C4Object *pObj = nullptr, int32_t iCustomFalloffDistance = 0, int32_t iPitch = 0, C4SoundModifier *modifier = nullptr);
64 C4SoundInstance *StartSoundEffectAt(const char *szSndName, int32_t iX, int32_t iY, int32_t iVolume = 100, int32_t iCustomFallofDistance = 0, int32_t iPitch = 0, C4SoundModifier *modifier = nullptr);
65 C4SoundInstance *GetSoundInstance(const char *szSndName, C4Object *pObj);
66 void StopSoundEffect(const char *szSndName, C4Object *pObj);
67 void SoundLevel(const char *szSndName, C4Object *pObj, int32_t iLevel);
68 void SoundPan(const char *szSndName, C4Object *pObj, int32_t iPan);
69 void SoundPitch(const char *szSndName, C4Object *pObj, int32_t iPitch);
70 void SoundUpdate(C4SoundInstance *inst, int32_t iLevel, int32_t iPitch);
71 
72 #endif
73