Nuclide
Software Development Kit for id Tech
sound.h
Go to the documentation of this file.
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
112.float maxspeed;
113.float flags;
114
116void
117_SndLog(string functionName, string msg)
118{
120 print(sprintf("^9%f ^xF50%s^7: %s\n", time, functionName, msg));
121 else
122 print(sprintf("^xF50%s^7: %s\n", functionName, msg));
123}
124
129#define SndLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndLog(__FUNC__, sprintf(__VA_ARGS__))
130
131void
132_SndEntLog(string className, string functionName, float edictNum, string warnMessage)
133{
135 print(sprintf("^9%f ^xF50%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
136 else
137 print(sprintf("^xF50%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
138}
139
144#define SndEntLog(...) if (autocvar_s_logLevel >= LOGLEVEL_DEBUG) _SndEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
145
147var hashtable g_hashsounds;
148
151{
152 SNDFL_LOOPING,
153 SNDFL_NODUPS,
154 SNDFL_GLOBAL,
155 SNDFL_NOREVERB,
156 SNDFL_OMNI,
157 SNDFL_PRIVATE,
158 SNDFL_STEP,
159 SNDFL_FOLLOW,
160 SNDFL_ALERTS
161} soundFlag_t;
162
164typedef struct
165{
166 float dist_min;
167 float dist_max;
168 float offset;
169 float pitch_min;
170 float pitch_max;
171 float shakes;
172 float volume;
173 soundFlag_t flags;
174 int playc;
176 string samples;
177 string name;
178 string distshader;
180} snd_t;
181
183typedef struct
184{
185 string m_strSnd;
188} sound_t;
189
194
196void Sound_Init(void);
198void Sound_Shutdown(void);
200int Sound_Precache(string sndDef);
202void Sound_Play(entity targetEntity, int sndChannel, string sndDef);
204void Sound_PlayAt(vector worldPos, string sndDef);
205
206#ifdef CLIENT
208void Sound_PlayLocal(string shader);
210void Sound_Update(entity targetEntity, int sndChannel, int sndSample, float desiredVolume);
211
212int Sound_GetID(string sndDef);
213#else
215void Sound_Speak(entity targetEntity, string sentencesEntry);
216#endif
217
219void Sound_Stop(entity target, int chan);
220
221void Sound_DebugList();
222 // end of sounddefs
#define LOGLEVEL_DEFAULT
Definition: global.h:27
logLevel_t
Definition: global.h:20
var bool autocvar_g_logTimestamps
Definition: global.h:17
float flags
Definition: sound.h:113
var logLevel_t autocvar_s_logLevel
Definition: sound.h:115
void _SndLog(string functionName, string msg)
Definition: sound.h:117
int Sound_GetID(string sndDef)
Definition: sound.qc:777
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:786
void Sound_Stop(entity target, int chan)
Stops sounds on a given channel, on a target entity.
Definition: sound.qc:568
int Sound_Precache(string sndDef)
Force the precache of a soundDef file.
Definition: sound.qc:380
float maxspeed
Definition: sound.h:112
snd_t * g_sounds
Pointer to the global soundDef table.
Definition: sound.h:191
void Sound_Play(entity targetEntity, int sndChannel, string sndDef)
Play a soundDef on a given target entity.
Definition: sound.qc:574
var hashtable g_hashsounds
Global hash table for name > soundDef id lookup.
Definition: sound.h:147
void Sound_PlayAt(vector worldPos, string sndDef)
Play a soundDef a a given location.
Definition: sound.qc:693
int g_sounds_count
Total amount of registered soundDef entries.
Definition: sound.h:193
void _SndEntLog(string className, string functionName, float edictNum, string warnMessage)
Definition: sound.h:132
void Sound_Shutdown(void)
Called by CSQC_Shutdown() and in theory, somewhere on the server.
Definition: sound.qc:37
void Sound_DebugList()
Called by listSoundDef.
Definition: sound.qc:934
void Sound_PlayLocal(string shader)
Client-side only: Play a sound locally, outside the game world.
Definition: sound.qc:751
void Sound_Init(void)
Called by the client inside CSQC_Init(), and on the server inside init().
Definition: sound.qc:50
typedef enumflags
Enumeration of valid sound flags.
Definition: sound.h:151
string target
Definition: defs.h:23
A soundDef aka 'sound shader' type.
Definition: sound.h:165
soundFlag_t flags
Sound flags that are applied to this soundDef.
Definition: sound.h:173
int playc
Number of plays.
Definition: sound.h:174
float dist_min
Minimum playback distance.
Definition: sound.h:166
int sample_count
Total amount of samples within this soundDef.
Definition: sound.h:175
float pitch_min
Minimum sound pitch.
Definition: sound.h:169
float offset
Sound sample offset.
Definition: sound.h:168
float pitch_max
Maximum sound pitch.
Definition: sound.h:170
float pointparticle
Definition: sound.h:179
float dist_max
Maximum playback distance.
Definition: sound.h:167
float shakes
Earthquake/Shake amplifier.
Definition: sound.h:171
string samples
Separated list of samples.
Definition: sound.h:176
string distshader
soundDef to play where this soundDef is not audible.
Definition: sound.h:178
float volume
Desired playback volume.
Definition: sound.h:172
string name
Name of the soundDef.
Definition: sound.h:177
A sound sample of a sentences.txt word sequence.
Definition: sound.h:184
string m_strSnd
Definition: sound.h:185
float m_flLength
Definition: sound.h:186
float m_flPitch
Definition: sound.h:187