Nuclide
Software Development Kit for id Technology
sound.h
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
113.float maxspeed;
114.float flags;
115
116var logLevel_t autocvar_s_logLevel = LOGLEVEL_DEFAULT;
117void
118_SndLog(string functionName, string msg)
119{
120 if (autocvar_g_logTimestamps)
121 print(sprintf("^9%f ^xF50%s^7: %s\n", time, functionName, msg));
122 else
123 print(sprintf("^xF50%s^7: %s\n", functionName, msg));
124}
125
130#define SndLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndLog(__FUNC__, sprintf(__VA_ARGS__))
131
132void
133_SndEntLog(string className, string functionName, float edictNum, string warnMessage)
134{
135 if (autocvar_g_logTimestamps)
136 print(sprintf("^9%f ^xF50%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
137 else
138 print(sprintf("^xF50%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
139}
140
145#define SndEntLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
146
148var hashtable g_hashsounds;
149
152{
153 SNDFL_LOOPING,
154 SNDFL_NODUPS,
155 SNDFL_GLOBAL,
156 SNDFL_NOREVERB,
157 SNDFL_OMNI,
158 SNDFL_PRIVATE,
159 SNDFL_STEP,
160 SNDFL_FOLLOW,
161 SNDFL_ALERTS
162} soundFlag_t;
163
165typedef struct
166{
167 float dist_min;
168 float dist_max;
169 float offset;
170 float pitch_min;
171 float pitch_max;
172 float shakes;
173 float volume;
174 soundFlag_t flags;
175 int playc;
177 string samples;
178 string name;
179 string distshader;
181} snd_t;
182
184typedef struct
185{
186 string m_strSnd;
189} sound_t;
190
195
197void Sound_Init(void);
199void Sound_Shutdown(void);
201int Sound_Precache(string sndDef);
203void Sound_Play(entity targetEntity, int sndChannel, string sndDef);
205void Sound_PlayAt(vector worldPos, string sndDef);
206
207#ifdef CLIENT
209void Sound_PlayLocal(string shader);
211void Sound_Update(entity targetEntity, int sndChannel, int sndSample, float desiredVolume);
212
213int Sound_GetID(string sndDef);
214#else
216void Sound_Speak(entity targetEntity, string sentencesEntry);
217#endif
218
220void Sound_Stop(entity target, float chan);
221
222void Sound_DebugList();
223 // end of sounddefs
float flags
Definition: sound.h:114
var logLevel_t autocvar_s_logLevel
Definition: sound.h:116
void _SndLog(string functionName, string msg)
Definition: sound.h:118
int Sound_GetID(string sndDef)
Definition: sound.qc:780
void Sound_Update(entity targetEntity, int sndChannel, int sndSample, float desiredVolume)
Client-side only: Update the sound parameters on a given entity.
Definition: sound.qc:789
int Sound_Precache(string sndDef)
Force the precache of a soundDef file.
Definition: sound.qc:383
float maxspeed
Definition: sound.h:113
snd_t * g_sounds
Pointer to the global soundDef table.
Definition: sound.h:192
void Sound_Play(entity targetEntity, int sndChannel, string sndDef)
Play a soundDef on a given target entity.
Definition: sound.qc:577
var hashtable g_hashsounds
Global hash table for name > soundDef id lookup.
Definition: sound.h:148
void Sound_Stop(entity target, float chan)
Stops sounds on a given channel, on a target entity.
Definition: sound.qc:571
void Sound_PlayAt(vector worldPos, string sndDef)
Play a soundDef a a given location.
Definition: sound.qc:696
int g_sounds_count
Total amount of registered soundDef entries.
Definition: sound.h:194
void _SndEntLog(string className, string functionName, float edictNum, string warnMessage)
Definition: sound.h:133
void Sound_Shutdown(void)
Called by CSQC_Shutdown() and in theory, somewhere on the server.
Definition: sound.qc:39
void Sound_DebugList()
Called by listSoundDef.
Definition: sound.qc:937
void Sound_PlayLocal(string shader)
Client-side only: Play a sound locally, outside the game world.
Definition: sound.qc:754
void Sound_Init(void)
Called by the client inside CSQC_Init(), and on the server inside init().
Definition: sound.qc:52
typedef enumflags
Enumeration of valid sound flags.
Definition: sound.h:152
A soundDef aka 'sound shader' type.
Definition: sound.h:166
soundFlag_t flags
Sound flags that are applied to this soundDef.
Definition: sound.h:174
int playc
Number of plays.
Definition: sound.h:175
float dist_min
Minimum playback distance.
Definition: sound.h:167
int sample_count
Total amount of samples within this soundDef.
Definition: sound.h:176
float pitch_min
Minimum sound pitch.
Definition: sound.h:170
float offset
Sound sample offset.
Definition: sound.h:169
float pitch_max
Maximum sound pitch.
Definition: sound.h:171
float pointparticle
Definition: sound.h:180
float dist_max
Maximum playback distance.
Definition: sound.h:168
float shakes
Earthquake/Shake amplifier.
Definition: sound.h:172
string samples
Separated list of samples.
Definition: sound.h:177
string distshader
soundDef to play where this soundDef is not audible.
Definition: sound.h:179
float volume
Desired playback volume.
Definition: sound.h:173
string name
Name of the soundDef.
Definition: sound.h:178
A sound sample of a sentences.txt word sequence.
Definition: sound.h:185
string m_strSnd
Definition: sound.h:186
float m_flLength
Definition: sound.h:187
float m_flPitch
Definition: sound.h:188