]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/sounds/sound.qh
Merge branch 'master' into terencehill/infomessages_panel_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / sounds / sound.qh
1 #ifndef SOUND_H
2 #define SOUND_H
3
4 // negative = SVQC autochannels
5 // positive = one per entity
6
7 const int CH_INFO = 0;
8 const int CH_WEAPON_A = -1;
9 const int CH_WEAPON_B = -1;
10 const int CH_WEAPON_SINGLE = 1;
11 const int CH_VOICE = -2;
12 // const int CH_VOICE_SINGLE = 2;
13 const int CH_TRIGGER = -3;
14 const int CH_TRIGGER_SINGLE = 3;
15 const int CH_SHOTS = -4;
16 const int CH_SHOTS_SINGLE = 4;
17 // const int CH_TUBA = -5;
18 const int CH_TUBA_SINGLE = 5;
19 const int CH_PAIN = -6;
20 const int CH_PAIN_SINGLE = 6;
21 const int CH_PLAYER = -7;
22 const int CH_PLAYER_SINGLE = 7;
23 // const int CH_BGM_SINGLE = -8;
24 const int CH_BGM_SINGLE = 8;
25 const int CH_AMBIENT = -9;
26 // const int CH_AMBIENT_SINGLE = 9;
27
28 const float ATTEN_NONE = 0;
29 const float ATTEN_MIN = 0.015625;
30 const float ATTEN_NORM = 0.5;
31 const float ATTEN_LARGE = 1;
32 const float ATTEN_IDLE = 2;
33 const float ATTEN_STATIC = 3;
34 const float ATTEN_MAX = 3.984375;
35
36 const float VOL_BASE = 0.7;
37 const float VOL_BASEVOICE = 1.0;
38 const float VOL_MUFFLED = 0.35;
39
40 // Play all sounds via sound7, for access to the extra channels.
41 // Otherwise, channels 8 to 15 would be blocked for a weird QW feature.
42 #ifdef SVQC
43         #define _sound(e, c, s, v, a) \
44                 MACRO_BEGIN \
45                 { \
46                         entity __e = e; \
47                         if (sound_allowed(MSG_BROADCAST, __e)) \
48                                 sound7(__e, c, s, v, a, 0, 0); \
49                 } MACRO_END
50 #else
51         #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0)
52 #endif
53 #define sound(e, c, s, v, a) _sound(e, c, Sound_fixpath(s), v, a)
54
55 /**
56  * because sound7 didn't have origin
57  *
58  * @param e sound owner
59  * @param o sound origin
60  * @param chan sound channel
61  * @param samp sound filename
62  * @param vol sound volume
63  * @param atten sound attenuation
64  * @param speed
65  * @param sf
66  */
67 #define sound8(e, o, chan, samp, vol, atten, speed, sf) \
68         MACRO_BEGIN \
69         { \
70                 entity __e; \
71                 int __chan = chan; \
72                 string __samp = samp; \
73                 bool auto = false; \
74                 if (__chan > 0) __e = e; \
75                 else \
76                 { \
77                         auto = true; \
78                         __chan = fabs(__chan); \
79                         entity tmp = __e = new(csqc_autochannel); \
80                         setthink(tmp, SUB_Remove); \
81                         tmp.nextthink = time + soundlength(__samp); \
82                 } \
83                 vector old_origin = __e.origin; \
84                 vector old_mins = __e.mins; \
85                 vector old_maxs = __e.maxs; \
86                 setorigin(__e, o); \
87                 setsize(__e, '0 0 0', '0 0 0'); \
88                 sound7(__e, __chan, __samp, vol, atten, speed, sf); \
89                 if (!auto) \
90                 { \
91                         setorigin(__e, old_origin); \
92                         setsize(__e, old_mins, old_maxs); \
93                 } \
94         } MACRO_END
95
96 CLASS(Sound, Object)
97         ATTRIB(Sound, m_id, int, 0)
98         ATTRIB(Sound, sound_str, string(), func_null)
99         CONSTRUCTOR(Sound, string() path)
100         {
101                 CONSTRUCT(Sound);
102                 this.sound_str = path;
103         }
104         #define Sound_fixpath(this) _Sound_fixpath((this).sound_str())
105         string _Sound_fixpath(string base)
106         {
107                 if (base == "") return string_null;
108 #ifdef SVQC
109                 return strcat(base, ".wav");  // let the client engine decide
110 #else
111                 #define extensions(x) \
112                         x(wav) \
113                         x(ogg) \
114                         x(flac) \
115                         /**/
116                 #define tryext(ext) { string s = strcat(base, "." #ext); if (fexists(strcat("sound/", s))) return s; }
117                 extensions(tryext);
118                 LOG_WARNINGF("Missing sound: \"%s\"\n", strcat("sound/", base));
119                 #undef tryext
120                 #undef extensions
121                 return string_null;
122 #endif
123         }
124         METHOD(Sound, sound_precache, void(Sound this))
125         {
126             TC(Sound, this);
127                 string s = Sound_fixpath(this);
128                 if (!s) return;
129                 profile(sprintf("precache_sound(\"%s\")\n", s));
130                 precache_sound(s);
131         }
132 ENDCLASS(Sound)
133
134 #endif