Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sound.qh
Go to the documentation of this file.
1#pragma once
2
3// negative = SVQC autochannels
4// positive = one per entity
5
6const int CH_INFO = 0;
7const int CH_WEAPON_A = -1;
8const int CH_WEAPON_B = -1;
9const int CH_WEAPON_SINGLE = 1;
10const int CH_VOICE = -2;
11// const int CH_VOICE_SINGLE = 2;
12const int CH_TRIGGER = -3;
13const int CH_TRIGGER_SINGLE = 3;
14const int CH_SHOTS = -4;
15const int CH_SHOTS_SINGLE = 4;
16// const int CH_TUBA = -5;
17const int CH_TUBA_SINGLE = 5;
18const int CH_PAIN = -6;
19const int CH_PAIN_SINGLE = 6;
20const int CH_PLAYER = -7;
21const int CH_PLAYER_SINGLE = 7;
22// const int CH_BGM_SINGLE = -8;
23const int CH_BGM_SINGLE = 8;
24const int CH_AMBIENT = -9;
25const int CH_AMBIENT_SINGLE = 9;
26
27const float ATTEN_NONE = 0;
28const float ATTEN_MIN = 0.015625;
29const float ATTEN_LOW = 0.2;
30const float ATTEN_NORM = 0.5;
31const float ATTEN_LARGE = 1;
32const float ATTEN_IDLE = 2;
33const float ATTEN_STATIC = 3;
34const float ATTEN_MAX = 3.984375;
35
36const float VOL_BASE = 0.7;
37const float VOL_BASEVOICE = 1.0;
38const 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 entity __e = e; \
46 if (sound_allowed(MSG_BROADCAST, __e)) \
47 sound7(__e, c, s, v, a, 0, 0); \
48 MACRO_END
49#else
50 #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0)
51#endif
52#define sound(e, c, s, v, a) _sound(e, c, Sound_fixpath(s), v, a)
53
66#define sound8(e, o, chan, samp, vol, atten, speed, sf) \
67 MACRO_BEGIN \
68 entity __e; \
69 int __chan = chan; \
70 string __samp = samp; \
71 bool auto = false; \
72 if (__chan > 0) __e = e; \
73 else \
74 { \
75 auto = true; \
76 __chan = fabs(__chan); \
77 entity tmp = __e = new(csqc_autochannel); \
78 setthink(tmp, SUB_Remove); \
79 tmp.nextthink = time + soundlength(__samp); \
80 } \
81 vector old_origin = __e.origin; \
82 vector old_mins = __e.mins; \
83 vector old_maxs = __e.maxs; \
84 setorigin(__e, o); \
85 setsize(__e, '0 0 0', '0 0 0'); \
86 sound7(__e, __chan, __samp, vol, atten, speed, sf); \
87 if (!auto) \
88 { \
89 setorigin(__e, old_origin); \
90 setsize(__e, old_mins, old_maxs); \
91 } \
92 MACRO_END
93
94string _Sound_fixpath(string base)
95{
96 if (base == "") return string_null;
97#ifdef SVQC
98 return strcat(base, ".wav"); // let the client engine decide
99#else
100#define extensions(x) \
101 x(wav) \
102 x(ogg) \
103 x(flac) \
104 /**/
105#define tryext(ext) { \
106 string s = strcat(base, "." #ext); \
107 if (fexists(strcat("sound/", s))) { \
108 return s; \
109 } \
110 }
112 LOG_WARNF("Missing sound: \"%s\"", strcat("sound/", base));
113#undef tryext
114#undef extensions
115 return string_null;
116#endif
117}
118
120 ATTRIB(Sound, m_id, int, 0);
121 ATTRIB(Sound, sound_str, string());
122 ATTRIB(Sound, sound_str_, string);
123 CONSTRUCTOR(Sound, string() path)
124 {
126 this.sound_str = path;
127 }
129 {
130 TC(Sound, this);
131 string s = _Sound_fixpath(this.sound_str());
132 if (!s) return;
133 //profile(sprintf("precache_sound(\"%s\")", s));
135 strcpy(this.sound_str_, s);
136 }
138
141#define Sound_fixpath(this) ( \
142 _Sound_fixpath_this = (this), \
143 _Sound_fixpath_cached = _Sound_fixpath_this.sound_str_, \
144 _Sound_fixpath_cached ? _Sound_fixpath_cached : _Sound_fixpath(_Sound_fixpath_this.sound_str()) \
145)
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
ATTRIB(Sound, sound_str, string())
Sound(string() path)
Definition sound.qh:123
int m_id
Definition sound.qh:120
virtual void sound_precache()
Definition sound.qh:128
#define tryext(ext)
#define extensions(x)
#define TC(T, sym)
Definition _all.inc:82
#define LOG_WARNF(...)
Definition log.qh:62
string precache_sound(string sample)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define CLASS(...)
Definition oo.qh:145
#define ENDCLASS(cname)
Definition oo.qh:281
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define CONSTRUCTOR(cname,...)
Definition oo.qh:213
#define CONSTRUCT(cname,...)
Definition oo.qh:123
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASEVOICE
Definition sound.qh:37
const int CH_PAIN
Definition sound.qh:18
const int CH_TRIGGER_SINGLE
Definition sound.qh:13
const int CH_WEAPON_SINGLE
Definition sound.qh:9
const int CH_PLAYER_SINGLE
Definition sound.qh:21
const float VOL_BASE
Definition sound.qh:36
const int CH_PAIN_SINGLE
Definition sound.qh:19
const int CH_SHOTS
Definition sound.qh:14
const int CH_INFO
Definition sound.qh:6
const int CH_WEAPON_A
Definition sound.qh:7
entity _Sound_fixpath_this
Definition sound.qh:139
const int CH_AMBIENT
Definition sound.qh:24
const float ATTEN_MAX
Definition sound.qh:34
const int CH_SHOTS_SINGLE
Definition sound.qh:15
const int CH_VOICE
Definition sound.qh:10
const float ATTEN_MIN
Definition sound.qh:28
const float ATTEN_NONE
Definition sound.qh:27
const int CH_AMBIENT_SINGLE
Definition sound.qh:25
const float ATTEN_LOW
Definition sound.qh:29
const float VOL_MUFFLED
Definition sound.qh:38
const int CH_TUBA_SINGLE
Definition sound.qh:17
const float ATTEN_NORM
Definition sound.qh:30
string _Sound_fixpath(string base)
Definition sound.qh:94
const int CH_BGM_SINGLE
Definition sound.qh:23
const float ATTEN_IDLE
Definition sound.qh:32
const int CH_WEAPON_B
Definition sound.qh:8
const float ATTEN_STATIC
Definition sound.qh:33
const float ATTEN_LARGE
Definition sound.qh:31
const int CH_PLAYER
Definition sound.qh:20
string _Sound_fixpath_cached
Definition sound.qh:140
#define strcpy(this, s)
Definition string.qh:52