From f2b9561cabb0f4239ff76e19d45d576d64be870c Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 8 Nov 2015 19:14:03 +1100 Subject: [PATCH] GlobalSound: clientside voice selection --- qcsrc/common/effects/qc/globalsound.qc | 128 ++++++++++++------------- qcsrc/common/effects/qc/globalsound.qh | 47 +++++---- qcsrc/server/autocvars.qh | 1 - qcsrc/server/cl_client.qc | 4 - qcsrc/server/miscfunctions.qc | 1 - 5 files changed, 91 insertions(+), 90 deletions(-) diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index b2b2e5f06..0e9242268 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -93,7 +93,8 @@ float r = ReadByte() / 255; int who = ReadByte(); entity e = findfloat(world, entnum, autocvar_cl_forceplayermodels ? player_currententnum : who); - string s = e.(ps.m_playersoundfld); // TODO: populate this field + UpdatePlayerSounds(e); + string s = e.(ps.m_playersoundfld); string sample = GlobalSound_sample(s, r); int chan = ReadByte(); float vol = ReadByte() / 255; @@ -153,70 +154,69 @@ } } - #ifdef SVQC + entity GetVoiceMessage(string type) + { + FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, LAMBDA(return it)); + return NULL; + } - entity GetVoiceMessage(string type) - { - FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, LAMBDA(return it)); - return NULL; - } + entity GetPlayerSound(string type) + { + FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == false, LAMBDA(return it)); + return NULL; + } - entity GetPlayerSound(string type) - { - FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == false, LAMBDA(return it)); - return NULL; - } + string allvoicesamples; + STATIC_INIT(allvoicesamples) + { + FOREACH(PlayerSounds, it.instanceOfVoiceMessage, LAMBDA( + allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr) + )); + allvoicesamples = strzone(substring(allvoicesamples, 1, -1)); + } - .string _GetPlayerSoundSampleField(string type, bool voice) - { - GetPlayerSoundSampleField_notFound = false; - entity e = voice ? GetVoiceMessage(type) : GetPlayerSound(type); - if (e) return e.m_playersoundfld; - GetPlayerSoundSampleField_notFound = true; - return playersound_taunt.m_playersoundfld; - } + .string _GetPlayerSoundSampleField(string type, bool voice) + { + GetPlayerSoundSampleField_notFound = false; + entity e = voice ? GetVoiceMessage(type) : GetPlayerSound(type); + if (e) return e.m_playersoundfld; + GetPlayerSoundSampleField_notFound = true; + return playersound_taunt.m_playersoundfld; + } - .string GetVoiceMessageSampleField(string type) - { - return _GetPlayerSoundSampleField(type, true); - } + .string GetVoiceMessageSampleField(string type) + { + return _GetPlayerSoundSampleField(type, true); + } - .string GetPlayerSoundSampleField(string type) + void PrecachePlayerSounds(string f) + { + int fh = fopen(f, FILE_READ); + if (fh < 0) { - return _GetPlayerSoundSampleField(type, false); + LOG_WARNINGF("Player sound file not found: %s\n", f); + return; } - - string allvoicesamples; - - void PrecachePlayerSounds(string f) + for (string s; (s = fgets(fh)); ) { - int fh = fopen(f, FILE_READ); - if (fh < 0) - { - LOG_WARNINGF("Player sound file not found: %s\n", f); - return; - } - for (string s; (s = fgets(fh)); ) + int n = tokenize_console(s); + if (n != 3) { - int n = tokenize_console(s); - if (n != 3) - { - if (n != 0) LOG_WARNINGF("Invalid sound info line: %s\n", s); - continue; - } - string file = argv(1); - string variants = argv(2); - PrecacheGlobalSound(strcat(file, " ", variants)); + if (n != 0) LOG_WARNINGF("Invalid sound info line: %s\n", s); + continue; } - fclose(fh); + string file = argv(1); + string variants = argv(2); + PrecacheGlobalSound(strcat(file, " ", variants)); + } + fclose(fh); + } - if (!allvoicesamples) - { - FOREACH(PlayerSounds, it.instanceOfVoiceMessage, LAMBDA( - allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr) - )); - allvoicesamples = strzone(substring(allvoicesamples, 1, -1)); - } + #ifdef CSQC + + .string GetPlayerSoundSampleField(string type) + { + return _GetPlayerSoundSampleField(type, false); } void ClearPlayerSounds(entity this) @@ -267,6 +267,8 @@ .int modelindex_for_playersound; .int skin_for_playersound; + bool autocvar_g_debug_defaultsounds; + void UpdatePlayerSounds(entity this) { if (this.modelindex == this.modelindex_for_playersound && this.skin == this.skin_for_playersound) return; @@ -274,24 +276,20 @@ this.skin_for_playersound = this.skin; ClearPlayerSounds(this); LoadPlayerSounds(this, "sound/player/default.sounds", true); - if (autocvar_g_debug_defaultsounds) return; - if (!LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) - LoadPlayerSounds(this, get_model_datafilename( - this.model, 0, - "sounds"), - true); + if (this.model == "null" || autocvar_g_debug_defaultsounds) return; + if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return; + LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true); } + #endif + + #ifdef SVQC + void _GlobalSound(entity gs, entity ps, string sample, int chan, int voicetype, bool fake) { SELFPARAM(); if (gs == NULL && ps == NULL && sample == "") return; float r = random(); - if (ps) // TODO: remove - { - sample = this.(ps.m_playersoundfld); - ps = NULL; - } if (sample != "") sample = GlobalSound_sample(sample, r); switch (voicetype) { diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index d120c0555..7f8fb77b1 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -18,7 +18,10 @@ REGISTRY(PlayerSounds, BITS(8) - 1) } REGISTER_REGISTRY(RegisterPlayerSounds) REGISTRY_SORT(PlayerSounds, 0) -STATIC_INIT(PlayerSounds_renumber) { FOREACH(PlayerSounds, true, LAMBDA(it.m_id = i)); } +STATIC_INIT(PlayerSounds_renumber) +{ + FOREACH(PlayerSounds, true, LAMBDA(it.m_id = i)); +} REGISTRY_CHECK(PlayerSounds) // TODO implement fall and falling @@ -90,7 +93,10 @@ REGISTRY(GlobalSounds, BITS(8) - 1) } REGISTER_REGISTRY(RegisterGlobalSounds) REGISTRY_SORT(GlobalSounds, 0) -STATIC_INIT(GlobalSounds_renumber) { FOREACH(GlobalSounds, true, LAMBDA(it.m_id = i)); } +STATIC_INIT(GlobalSounds_renumber) +{ + FOREACH(GlobalSounds, true, LAMBDA(it.m_id = i)); +} REGISTRY_CHECK(GlobalSounds) void PrecacheGlobalSound(string samplestring); PRECACHE(GlobalSounds) @@ -103,33 +109,36 @@ REGISTER_GLOBALSOUND(STEP_METAL, "misc/metalfootstep0 6") REGISTER_GLOBALSOUND(FALL, "misc/hitground 4") REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4") -#ifdef SVQC - - bool GetPlayerSoundSampleField_notFound; +bool GetPlayerSoundSampleField_notFound; +void PrecachePlayerSounds(string f); +#ifdef CSQC .string GetVoiceMessageSampleField(string type); .string GetPlayerSoundSampleField(string type); - void PrecachePlayerSounds(string f); void ClearPlayerSounds(entity this); float LoadPlayerSounds(entity this, string f, bool strict); void UpdatePlayerSounds(entity this); +#endif + +#ifdef SVQC + void _GlobalSound(entity gs, entity ps, string sample, float chan, float voicetype, bool fake); #define GlobalSound(def, chan, voicetype) _GlobalSound(def, NULL, string_null, chan, voicetype, false) #define GlobalSound_string(def, chan, voicetype) _GlobalSound(NULL, NULL, def, chan, voicetype, false) #define PlayerSound(def, chan, voicetype) _GlobalSound(NULL, def, string_null, chan, voicetype, false) #define VoiceMessage(def, msg) \ - do \ - { \ - entity VM = def; \ - int voicetype = VM.m_playersoundvt; \ - bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \ - int flood = Say(this, ownteam, world, msg, true); \ - bool fake; \ - if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \ - else if (flood > 0) fake = false; \ - else break; \ - _GlobalSound(NULL, VM, string_null, CH_VOICE, voicetype, fake); \ - } \ - while (0) + do \ + { \ + entity VM = def; \ + int voicetype = VM.m_playersoundvt; \ + bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \ + int flood = Say(this, ownteam, world, msg, true); \ + bool fake; \ + if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \ + else if (flood > 0) fake = false; \ + else break; \ + _GlobalSound(NULL, VM, string_null, CH_VOICE, voicetype, fake); \ + } \ + while (0) #endif diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 6cd7e2395..c271b65b4 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -437,7 +437,6 @@ bool autocvar_waypoint_benchmark; float autocvar_sv_gameplayfix_gravityunaffectedbyticrate; bool autocvar_sv_gameplayfix_upwardvelocityclearsongroundflag; float autocvar_g_trueaim_minrange; -bool autocvar_g_debug_defaultsounds; float autocvar_g_grab_range; int autocvar_g_max_info_autoscreenshot; bool autocvar_physics_ode; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 24a63d5aa..454ddc903 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -175,7 +175,6 @@ void setplayermodel(entity e, string modelname) precache_model(modelname); _setmodel(e, modelname); player_setupanimsformodel(); - UpdatePlayerSounds(e); } /* @@ -405,7 +404,6 @@ void FixPlayermodel(entity player) if(chmdl || oldskin != player.skin) // model or skin has changed { player.species = player_getspecies(player); // update species - UpdatePlayerSounds(player); // update skin sounds } if(!teamplay) @@ -1307,8 +1305,6 @@ void ClientDisconnect () if(self.weaponorder_byimpulse) strunzone(self.weaponorder_byimpulse); - ClearPlayerSounds(self); - if(self.personal) remove(self.personal); diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index d12a90377..ef399f566 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -703,7 +703,6 @@ void readplayerstartcvars() warmup_start_ammo_fuel = max(0, warmup_start_ammo_fuel); } -void PrecachePlayerSounds(string f); void precache_playermodel(string m) { float globhandle, i, n; -- 2.39.2