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
8#include <engine/shared/jobs.h>
9#include <engine/sound.h>
10
11#include <game/client/component.h>
12
13class CSoundLoading : public IJob
14{
15 CGameClient *m_pGameClient;
16 bool m_Render;
17
18public:
19 CSoundLoading(CGameClient *pGameClient, bool Render);
20 void Run() override;
21};
22
23class CSounds : public CComponent
24{
25 enum
26 {
27 QUEUE_SIZE = 32,
28 };
29 class CQueueEntry
30 {
31 public:
32 int m_Channel;
33 int m_SetId;
34 };
35 CQueueEntry m_aQueue[QUEUE_SIZE];
36 int m_QueuePos;
37 int64_t m_QueueWaitTime;
38 std::shared_ptr<CSoundLoading> m_pSoundJob;
39 bool m_WaitForSoundJob;
40
41 void UpdateChannels();
42 int GetSampleId(int SetId);
43
44 float m_GuiSoundVolume = -1.0f;
45 float m_GameSoundVolume = -1.0f;
46 float m_MapSoundVolume = -1.0f;
47 float m_BackgroundMusicVolume = -1.0f;
48
49public:
50 // sound channels
51 enum
52 {
53 CHN_GUI = 0,
54 CHN_MUSIC,
55 CHN_WORLD,
56 CHN_GLOBAL,
57 CHN_MAPSOUND,
58 };
59
60 int Sizeof() const override { return sizeof(*this); }
61 void OnInit() override;
62 void OnReset() override;
63 void OnStateChange(int NewState, int OldState) override;
64 void OnRender() override;
65
66 void ClearQueue();
67 void Enqueue(int Channel, int SetId);
68 void Play(int Channel, int SetId, float Volume);
69 void PlayAt(int Channel, int SetId, float Volume, vec2 Position);
70 void PlayAndRecord(int Channel, int SetId, float Volume, vec2 Position);
71 void Stop(int SetId);
72 bool IsPlaying(int SetId);
73
74 ISound::CVoiceHandle PlaySample(int Channel, int SampleId, int Flags, float Volume);
75 ISound::CVoiceHandle PlaySampleAt(int Channel, int SampleId, int Flags, float Volume, vec2 Position);
76};
77
78#endif
79