]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/sounds/sounds.qh
6b6a8a1ad7d84a5851639c03e94f90e94a735a15
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / sounds / sounds.qh
1 #ifndef SOUNDS_H
2 #define SOUNDS_H
3
4 #define SND(id) (SND_##id.sound_str())
5
6 void RegisterSounds();
7 const int MAX_SOUNDS = 128;
8 entity SOUNDS[MAX_SOUNDS], SOUNDS_first, SOUNDS_last;
9 int SOUNDS_COUNT;
10
11 CLASS(Sound, Object)
12     ATTRIB(Sound, m_id, int, 0)
13     ATTRIB(Sound, sound_str, string(), func_null)
14     CONSTRUCTOR(Sound, string() path)
15     {
16         CONSTRUCT(Sound);
17         this.sound_str = path;
18     }
19     METHOD(Sound, sound_precache, void(entity this)) {
20         string s = this.sound_str();
21         if (s && s != "" && !fexists(strcat("sound/", s))) {
22             LOG_WARNINGF("Missing sound: \"%s\"\n", s);
23             return;
24         }
25         LOG_TRACEF("precache_sound(\"%s\")\n", s);
26         precache_sound(s);
27     }
28 ENDCLASS(Sound)
29
30 #define SOUND(name, path) \
31     string SND_##name##_get() { return path; } \
32     REGISTER(RegisterSounds, SND, SOUNDS, SOUNDS_COUNT, name, m_id, NEW(Sound, SND_##name##_get))
33 REGISTER_REGISTRY(RegisterSounds)
34
35 STATIC_INIT(RegisterSounds_precache) {
36     FOREACH(SOUNDS, true, LAMBDA({
37         it.sound_precache(it);
38     }));
39 }
40
41 SOUND(Null, "misc/null.wav");
42 #include "sounds.inc"
43
44 #endif