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