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