]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
GlobalSound: clientside voice selection
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 8 Nov 2015 08:14:03 +0000 (19:14 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 8 Nov 2015 08:14:03 +0000 (19:14 +1100)
qcsrc/common/effects/qc/globalsound.qc
qcsrc/common/effects/qc/globalsound.qh
qcsrc/server/autocvars.qh
qcsrc/server/cl_client.qc
qcsrc/server/miscfunctions.qc

index b2b2e5f06ac3bbe57a719d84339b3c2788fd462b..0e924226880bfeed75d483f0661df6f6952865ce 100644 (file)
@@ -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;
                }
        }
 
-       #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)
                .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;
                        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)
                        {
index d120c05554efad8af193ec5cb698729679e33004..7f8fb77b1462c76d37c0ddea478cc4775d83314e 100644 (file)
@@ -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
 
index 6cd7e2395a2acd17b62a8862691e62c7d52e6298..c271b65b49523721b47972de15f7a6caf9e6b8de 100644 (file)
@@ -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;
index 24a63d5aab0e8823b07b5fec3eb73dba70528d7c..454ddc9030e6a0d6ad6475ce959bc11dba5c0974 100644 (file)
@@ -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);
 
index d12a903778571195c13999e904daa605330ba24d..ef399f5666c8ba40402748670d2de6d000ab6482 100644 (file)
@@ -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;