]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/sounds/sounds.qh
c9838b2f6a0dabb8243fe78265a9da6665e263e6
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / sounds / sounds.qh
1 #ifndef SOUNDS_H
2 #define SOUNDS_H
3
4 #include "../teams.qh"
5
6 // Play all sounds via sound7, for access to the extra channels.
7 // Otherwise, channels 8 to 15 would be blocked for a weird QW feature.
8 #ifdef SVQC
9     #define _sound(e, c, s, v, a) do { \
10         entity __e = e; \
11         if (!sound_allowed(MSG_BROADCAST, __e)) break; \
12         sound7(__e, c, s, v, a, 0, 0); \
13     } while (0)
14 #else
15     #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0)
16 #endif
17 #define sound(e, c, s, v, a) _sound(e, c, s.sound_str(), v, a)
18 // Used in places where a string is required
19 #define SND(id) (SND_##id.sound_str())
20
21 void RegisterSounds();
22 const int MAX_SOUNDS = 128;
23 entity SOUNDS[MAX_SOUNDS], SOUNDS_first, SOUNDS_last;
24 int SOUNDS_COUNT;
25
26 CLASS(Sound, Object)
27     ATTRIB(Sound, m_id, int, 0)
28     ATTRIB(Sound, sound_str, string(), func_null)
29     CONSTRUCTOR(Sound, string() path)
30     {
31         CONSTRUCT(Sound);
32         this.sound_str = path;
33     }
34     METHOD(Sound, sound_precache, void(entity this)) {
35         string s = this.sound_str();
36         if (s && s != "" && !fexists(strcat("sound/", s))) {
37             LOG_WARNINGF("Missing sound: \"%s\"\n", s);
38             return;
39         }
40         LOG_TRACEF("precache_sound(\"%s\")\n", s);
41         precache_sound(s);
42     }
43 ENDCLASS(Sound)
44
45 #define SOUND(name, path) \
46     string SND_##name##_get() { return path; } \
47     REGISTER(RegisterSounds, SND, SOUNDS, SOUNDS_COUNT, name, m_id, NEW(Sound, SND_##name##_get))
48 REGISTER_REGISTRY(RegisterSounds)
49
50 STATIC_INIT(RegisterSounds_precache) {
51     FOREACH(SOUNDS, true, LAMBDA({
52         it.sound_precache(it);
53     }));
54 }
55
56 SOUND(Null, "misc/null.wav");
57 #include "sounds.inc"
58
59 #endif