Xonotic
globalsound.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define REGISTER_GLOBALSOUND(id, str)
 
#define REGISTER_PLAYERSOUND(id)
 
#define REGISTER_VOICEMSG(id, vt, listed)
 

Functions

void ClearPlayerSounds (entity this)
 
string GetPlayerSoundSampleField (string type)
 
entity GetVoiceMessage (string type)
 
string GetVoiceMessageSampleField (string type)
 
float GlobalSound_pitch (float _pitch)
 
string GlobalSound_sample (string pair, float r)
 
float LoadPlayerSounds (entity this, string f, bool strict)
 
 PRECACHE (GlobalSounds)
 
void PrecacheGlobalSound (string samplestring)
 
void PrecachePlayerSounds (string f)
 
 REPLICATE_INIT (float, cvar_cl_autotaunt)
 
 REPLICATE_INIT (int, cvar_cl_voice_directional)
 
 REPLICATE_INIT (float, cvar_cl_voice_directional_taunt_attenuation)
 
 STATIC_INIT (PlayerSounds_renumber)
 
 STATIC_INIT (GlobalSounds_renumber)
 
 STATIC_INIT (allvoicesamples)
 
void UpdatePlayerSounds (entity this)
 

Variables

string allvoicesamples
 
bool GetPlayerSoundSampleField_notFound
 
bool instanceOfVoiceMessage
 
string m_globalsoundstr
 
string m_playersoundfld
 
string m_playersoundstr
 
int m_playersoundvt
 
const int VOICETYPE_AUTOTAUNT = 14
 
const int VOICETYPE_LASTATTACKER = 12
 
const int VOICETYPE_LASTATTACKER_ONLY = 13
 
const int VOICETYPE_PLAYERSOUND = 10
 
const int VOICETYPE_TAUNT = 15
 
const int VOICETYPE_TEAMRADIO = 11
 

Macro Definition Documentation

◆ REGISTER_GLOBALSOUND

#define REGISTER_GLOBALSOUND (   id,
  str 
)
Value:
REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
{ \
this.m_globalsoundstr = str; \
}
#define REGISTER(...)
Register a new entity with a registry.
Definition: registry.qh:87
int m_id
Definition: effect.qh:19
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62

Definition at line 98 of file globalsound.qh.

Referenced by PRECACHE().

◆ REGISTER_PLAYERSOUND

#define REGISTER_PLAYERSOUND (   id)
Value:
.string _playersound_##id; \
REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
{ \
this.m_playersoundstr = #id; \
this.m_playersoundfld = _playersound_##id; \
}
int m_id
Definition: effect.qh:19
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62

Definition at line 24 of file globalsound.qh.

Referenced by STATIC_INIT().

◆ REGISTER_VOICEMSG

#define REGISTER_VOICEMSG (   id,
  vt,
  listed 
)
Value:
.string _playersound_##id; \
REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
{ \
this.instanceOfVoiceMessage = listed; \
this.m_playersoundstr = #id; \
this.m_playersoundfld = _playersound_##id; \
this.m_playersoundvt = vt; \
}
int m_id
Definition: effect.qh:19
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62

Definition at line 54 of file globalsound.qh.

Function Documentation

◆ ClearPlayerSounds()

void ClearPlayerSounds ( entity  this)

Definition at line 252 of file globalsound.qc.

References FOREACH, and strfree.

Referenced by UpdatePlayerSounds().

253  {
254  FOREACH(PlayerSounds, true, {
255  .string fld = it.m_playersoundfld;
256  if (this.(fld))
257  {
258  strfree(this.(fld));
259  }
260  });
261  }
#define strfree(this)
Definition: string.qh:56
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GetPlayerSoundSampleField()

string GetPlayerSoundSampleField ( string  type)

Definition at line 247 of file globalsound.qc.

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

248  {
249  return _GetPlayerSoundSampleField(type, false);
250  }
string _GetPlayerSoundSampleField(string type, bool voice)
Definition: globalsound.qc:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetVoiceMessage()

entity GetVoiceMessage ( string  type)

Definition at line 196 of file globalsound.qc.

References FOREACH, and NULL.

Referenced by _GetPlayerSoundSampleField(), and ClientCommand_voice().

197  {
198  FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it);
199  return NULL;
200  }
#define NULL
Definition: post.qh:17
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the caller graph for this function:

◆ GetVoiceMessageSampleField()

string GetVoiceMessageSampleField ( string  type)

Definition at line 217 of file globalsound.qc.

References _GetPlayerSoundSampleField().

Referenced by LoadPlayerSounds().

218  {
219  return _GetPlayerSoundSampleField(type, true);
220  }
string _GetPlayerSoundSampleField(string type, bool voice)
Definition: globalsound.qc:208
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GlobalSound_pitch()

float GlobalSound_pitch ( float  _pitch)

Definition at line 164 of file globalsound.qc.

Referenced by UpdatePlayerSounds().

165  {
166  // customizable gradient function that crosses (0,a), (c,1) and asymptotically approaches b
167  float a = 1.5; // max pitch
168  float b = 0.75; // min pitch
169  float c = 100; // standard pitch (scale * 100)
170  float d = _pitch;
171  float pitch_shift = (b*d*(a-1) + a*c*(1-b)) / (d*(a-1) + c*(1-b));
172 
173  return pitch_shift * 100;
174  }
+ Here is the caller graph for this function:

◆ GlobalSound_sample()

string GlobalSound_sample ( string  pair,
float  r 
)

Definition at line 150 of file globalsound.qc.

References car(), cdr(), floor(), and stof().

Referenced by Monster_Sound(), and UpdatePlayerSounds().

151  {
152  int n;
153  {
154  string s = cdr(pair);
155  if (s) n = stof(s);
156  else n = 0;
157  }
158  string sample = car(pair);
159  if (n > 0) sample = sprintf("%s%d.wav", sample, floor(r * n + 1)); // randomization
160  else sample = sprintf("%s.wav", sample);
161  return sample;
162  }
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadPlayerSounds()

float LoadPlayerSounds ( entity  this,
string  f,
bool  strict 
)

Definition at line 263 of file globalsound.qc.

References argv(), fclose(), fgets(), FILE_READ, fopen(), GetPlayerSoundSampleField(), GetPlayerSoundSampleField_notFound, GetVoiceMessageSampleField(), LOG_TRACEF, LOG_WARNF, strcat(), strcpy, and tokenize_console.

Referenced by UpdatePlayerSounds().

264  {
265  int fh = fopen(f, FILE_READ);
266  if (fh < 0)
267  {
268  if (strict) LOG_WARNF("Player sound file not found: %s", f);
269  return false;
270  }
271  for (string s; (s = fgets(fh)); )
272  {
273  int n = tokenize_console(s);
274  if (n != 3)
275  {
276  if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
277  continue;
278  }
279  string key = argv(0);
280  var.string field = GetPlayerSoundSampleField(key);
283  {
284  LOG_TRACEF("Invalid sound info field in player sound file '%s': %s", f, key);
285  continue;
286  }
287  string file = argv(1);
288  string variants = argv(2);
289  strcpy(this.(field), strcat(file, " ", variants));
290  }
291  fclose(fh);
292  return true;
293  }
const float FILE_READ
Definition: csprogsdefs.qc:231
#define strcpy(this, s)
Definition: string.qh:49
#define LOG_WARNF(...)
Definition: log.qh:67
string GetPlayerSoundSampleField(string type)
Definition: globalsound.qc:247
string GetVoiceMessageSampleField(string type)
Definition: globalsound.qc:217
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
bool GetPlayerSoundSampleField_notFound
Definition: globalsound.qh:123
#define LOG_TRACEF(...)
Definition: log.qh:82
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PRECACHE()

PRECACHE ( GlobalSounds  )

Definition at line 113 of file globalsound.qh.

References FOREACH, PrecacheGlobalSound(), and REGISTER_GLOBALSOUND.

114 {
115  FOREACH(GlobalSounds, true, PrecacheGlobalSound(it.m_globalsoundstr));
116 }
void PrecacheGlobalSound(string samplestring)
Definition: globalsound.qc:176
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ PrecacheGlobalSound()

void PrecacheGlobalSound ( string  samplestring)

Definition at line 176 of file globalsound.qc.

References car(), cdr(), precache_sound(), and stof().

Referenced by Monster_Sound_Precache(), PRECACHE(), PrecachePlayerSounds(), and STATIC_INIT().

177  {
178  int n;
179  {
180  string s = cdr(sample);
181  if (s) n = stof(s);
182  else n = 0;
183  }
184  sample = car(sample);
185  if (n > 0)
186  {
187  for (int i = 1; i <= n; ++i)
188  precache_sound(sprintf("%s%d.wav", sample, i));
189  }
190  else
191  {
192  precache_sound(sprintf("%s.wav", sample));
193  }
194  }
ERASEABLE string cdr(string s)
returns all but first word
Definition: string.qh:249
ERASEABLE string car(string s)
returns first word
Definition: string.qh:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrecachePlayerSounds()

void PrecachePlayerSounds ( string  f)

Definition at line 222 of file globalsound.qc.

References argv(), fclose(), fgets(), FILE_READ, fopen(), LOG_WARNF, PrecacheGlobalSound(), strcat(), and tokenize_console.

Referenced by PRECACHE(), and precache_playermodel().

223  {
224  int fh = fopen(f, FILE_READ);
225  if (fh < 0)
226  {
227  LOG_WARNF("Player sound file not found: %s", f);
228  return;
229  }
230  for (string s; (s = fgets(fh)); )
231  {
232  int n = tokenize_console(s);
233  if (n != 3)
234  {
235  if (n != 0) LOG_WARNF("Invalid sound info line: %s", s);
236  continue;
237  }
238  string file = argv(1);
239  string variants = argv(2);
240  PrecacheGlobalSound(strcat(file, " ", variants));
241  }
242  fclose(fh);
243  }
const float FILE_READ
Definition: csprogsdefs.qc:231
#define LOG_WARNF(...)
Definition: log.qh:67
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void PrecacheGlobalSound(string sample)
Definition: globalsound.qc:176
#define tokenize_console
Definition: dpextensions.qh:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REPLICATE_INIT() [1/3]

REPLICATE_INIT ( float  ,
cvar_cl_autotaunt   
)

Referenced by STATIC_INIT().

+ Here is the caller graph for this function:

◆ REPLICATE_INIT() [2/3]

REPLICATE_INIT ( int  ,
cvar_cl_voice_directional   
)

◆ REPLICATE_INIT() [3/3]

REPLICATE_INIT ( float  ,
cvar_cl_voice_directional_taunt_attenuation   
)

◆ STATIC_INIT() [1/3]

STATIC_INIT ( PlayerSounds_renumber  )

Definition at line 35 of file globalsound.qh.

References FOREACH, REGISTER_PLAYERSOUND, and REGISTRY_CHECK.

36 {
37  FOREACH(PlayerSounds, true, it.m_id = i);
38 }
#define FOREACH(list, cond, body)
Definition: iter.qh:19

◆ STATIC_INIT() [2/3]

STATIC_INIT ( GlobalSounds_renumber  )

Definition at line 107 of file globalsound.qh.

References FOREACH, PrecacheGlobalSound(), and REGISTRY_CHECK.

108 {
109  FOREACH(GlobalSounds, true, it.m_id = i);
110 }
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ STATIC_INIT() [3/3]

STATIC_INIT ( allvoicesamples  )

Definition at line 160 of file globalsound.qh.

References FOREACH, strcat(), strzone(), and substring().

161 {
162  FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr));
164 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string allvoicesamples
Definition: globalsound.qh:159
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

◆ UpdatePlayerSounds()

void UpdatePlayerSounds ( entity  this)

Definition at line 300 of file globalsound.qc.

References ANIMACTION_TAUNT, animdecide_setaction(), ATTEN_MIN, ATTEN_NONE, ATTEN_NORM, backtrace, classname, ClearPlayerSounds(), CS_CVAR, entity(), FOREACH_CLIENT, get_model_datafilename(), GlobalSound_pitch(), GlobalSound_sample(), IS_DEAD, IS_PLAYER, IS_REAL_CLIENT, LoadPlayerSounds(), model, model_for_playersound, MSG_ALL, MSG_BROADCAST, msg_entity, MSG_ONE, NULL, pusher, random(), SAME_TEAM, scale, skin, skin_for_playersound, strcpy, VOICETYPE_AUTOTAUNT, VOICETYPE_LASTATTACKER, VOICETYPE_LASTATTACKER_ONLY, VOICETYPE_PLAYERSOUND, VOICETYPE_TAUNT, VOICETYPE_TEAMRADIO, VOL_BASE, and X.

Referenced by FixPlayermodel(), and setplayermodel().

301  {
302  if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return;
303  strcpy(this.model_for_playersound, this.model);
304  this.skin_for_playersound = this.skin;
305  ClearPlayerSounds(this);
306  LoadPlayerSounds(this, "sound/player/default.sounds", true);
307  if (this.model == "null"
308  #ifdef SVQC
309  && autocvar_g_debug_globalsounds
310  #endif
311  ) return;
312  if (autocvar_g_debug_defaultsounds) return;
313  if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return;
314  LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true);
315  }
string get_model_datafilename(string m, float sk, string fil)
Definition: util.qc:1245
skin
Definition: ent_cs.qc:143
int skin_for_playersound
Definition: globalsound.qc:296
string model
Definition: csprogsdefs.qc:108
#define strcpy(this, s)
Definition: string.qh:49
bool LoadPlayerSounds(entity this, string f, bool strict)
Definition: globalsound.qc:263
void ClearPlayerSounds(entity this)
Definition: globalsound.qc:252
bool autocvar_g_debug_defaultsounds
Definition: globalsound.qc:298
string model_for_playersound
Definition: globalsound.qc:295
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ allvoicesamples

string allvoicesamples

Definition at line 159 of file globalsound.qh.

Referenced by ClientCommand_voice().

◆ GetPlayerSoundSampleField_notFound

bool GetPlayerSoundSampleField_notFound

Definition at line 123 of file globalsound.qh.

Referenced by _GetPlayerSoundSampleField(), and LoadPlayerSounds().

◆ instanceOfVoiceMessage

bool instanceOfVoiceMessage

Definition at line 52 of file globalsound.qh.

◆ m_globalsoundstr

string m_globalsoundstr

Definition at line 96 of file globalsound.qh.

◆ m_playersoundfld

string m_playersoundfld

Definition at line 17 of file globalsound.qh.

◆ m_playersoundstr

string m_playersoundstr

Definition at line 16 of file globalsound.qh.

◆ m_playersoundvt

int m_playersoundvt

Definition at line 53 of file globalsound.qh.

◆ VOICETYPE_AUTOTAUNT

const int VOICETYPE_AUTOTAUNT = 14

Definition at line 68 of file globalsound.qh.

Referenced by PlayerPreThink(), and UpdatePlayerSounds().

◆ VOICETYPE_LASTATTACKER

const int VOICETYPE_LASTATTACKER = 12

Definition at line 66 of file globalsound.qh.

Referenced by UpdatePlayerSounds().

◆ VOICETYPE_LASTATTACKER_ONLY

const int VOICETYPE_LASTATTACKER_ONLY = 13

Definition at line 67 of file globalsound.qh.

Referenced by PlayerPreThink(), and UpdatePlayerSounds().

◆ VOICETYPE_PLAYERSOUND

const int VOICETYPE_PLAYERSOUND = 10

◆ VOICETYPE_TAUNT

const int VOICETYPE_TAUNT = 15

Definition at line 69 of file globalsound.qh.

Referenced by UpdatePlayerSounds().

◆ VOICETYPE_TEAMRADIO

const int VOICETYPE_TEAMRADIO = 11

Definition at line 65 of file globalsound.qh.

Referenced by UpdatePlayerSounds().