1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_COMPONENTS_SOUNDS_H
4#define GAME_CLIENT_COMPONENTS_SOUNDS_H
5
6#include <base/vmath.h>
7#include <engine/shared/jobs.h>
8#include <engine/sound.h>
9#include <game/client/component.h>
10
11class CSoundLoading : public IJob
12{
13 CGameClient *m_pGameClient;
14 bool m_Render;
15
16public:
17 CSoundLoading(CGameClient *pGameClient, bool Render);
18 void Run() override;
19};
20
21class CSounds : public CComponent
22{
23 enum
24 {
25 QUEUE_SIZE = 32,
26 };
27 struct QueueEntry
28 {
29 int m_Channel;
30 int m_SetId;
31 } m_aQueue[QUEUE_SIZE];
32 int m_QueuePos;
33 int64_t m_QueueWaitTime;
34 std::shared_ptr<CSoundLoading> m_pSoundJob;
35 bool m_WaitForSoundJob;
36
37 int GetSampleId(int SetId);
38
39 float m_GuiSoundVolume;
40 float m_GameSoundVolume;
41 float m_MapSoundVolume;
42 float m_BackgroundMusicVolume;
43
44public:
45 // sound channels
46 enum
47 {
48 CHN_GUI = 0,
49 CHN_MUSIC,
50 CHN_WORLD,
51 CHN_GLOBAL,
52 CHN_MAPSOUND,
53 };
54
55 virtual int Sizeof() const override { return sizeof(*this); }
56 virtual void OnInit() override;
57 virtual void OnReset() override;
58 virtual void OnStateChange(int NewState, int OldState) override;
59 virtual void OnRender() override;
60
61 void ClearQueue();
62 void Enqueue(int Channel, int SetId);
63 void Play(int Channel, int SetId, float Vol);
64 void PlayAt(int Channel, int SetId, float Vol, vec2 Pos);
65 void PlayAndRecord(int Channel, int SetId, float Vol, vec2 Pos);
66 void Stop(int SetId);
67 bool IsPlaying(int SetId);
68
69 ISound::CVoiceHandle PlaySample(int Channel, int SampleId, float Vol, int Flags = 0);
70 ISound::CVoiceHandle PlaySampleAt(int Channel, int SampleId, float Vol, vec2 Pos, int Flags = 0);
71};
72
73#endif
74