]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/globalsound.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / globalsound.qc
index 413df981fda771b968c9fbcc1ae28336954451c7..d895d75c6857bb853ac37a99597d0254edf41ca2 100644 (file)
@@ -1,12 +1,12 @@
 #include "globalsound.qh"
 
-#include "../common/ent_cs.qh"
+#include <common/ent_cs.qh>
 
 #ifdef IMPLEMENTATION
-       #include "../../animdecide.qh"
+       #include <common/animdecide.qh>
 
        #ifdef SVQC
-               #include "../../../server/cl_player.qh"
+               #include <server/cl_player.qh>
        #endif
 
        REGISTER_NET_TEMP(globalsound)
                 */
                void globalsound(int channel, entity from, entity gs, float r, int chan, float vol, float atten)
                {
+                       assert(IS_PLAYER(from), eprint(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
                        WriteHeader(channel, globalsound);
                        WriteByte(channel, gs.m_id);
                        WriteByte(channel, r * 255);
                        WriteByte(channel, etof(from));
-                       WriteByte(channel, fabs(chan));
+                       WriteByte(channel, chan);
                        WriteByte(channel, floor(vol * 255));
                        WriteByte(channel, floor(atten * 64));
+                       entcs_force_origin(from);
                        vector o = from.origin + 0.5 * (from.mins + from.maxs);
                        WriteCoord(channel, o.x);
                        WriteCoord(channel, o.y);
                */
                void playersound(int channel, entity from, entity ps, float r, int chan, float vol, float atten)
                {
+                       assert(IS_PLAYER(from), eprint(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
                        WriteHeader(channel, playersound);
                        WriteByte(channel, ps.m_id);
                        WriteByte(channel, r * 255);
                        WriteByte(channel, etof(from));
-                       WriteByte(channel, fabs(chan));
+                       WriteByte(channel, chan);
                        WriteByte(channel, floor(vol * 255));
                        WriteByte(channel, floor(atten * 64));
                        entcs_force_origin(from);
                        float r = ReadByte() / 255;
                        string sample = GlobalSound_sample(gs.m_globalsoundstr, r);
                        int who = ReadByte();
-                       int chan = ReadByte();
+                       entity e = entcs_receiver(who - 1);
+                       int chan = ReadSByte();
                        float vol = ReadByte() / 255;
                        float atten = ReadByte() / 64;
                        vector o;
                        o.x = ReadCoord();
                        o.y = ReadCoord();
                        o.z = ReadCoord();
-                       if (who == player_currententnum)
+                       // TODO: is this really what we want to be doing? Footsteps that follow the player at head height?
+                       if (who == player_currententnum) e = findfloat(world, entnum, who);  // play at camera position for full volume
+                       else if (e) e.origin = o;
+                       if (e)
                        {
-                               // client knows better, play at current position to unlag
-                               entity e = findfloat(world, entnum, who);
                                sound7(e, chan, sample, vol, atten, 0, 0);
                        }
                        else
                        {
-                               entity e = new(globalsound);
-                               e.origin = o;
+                               // Can this happen?
+                               LOG_WARNINGF("Missing entcs data for player %d\n", who);
                                sound8(e, o, chan, sample, vol, atten, 0, 0);
-                               remove(e);  // debug with: e.think = SUB_Remove; e.nextthink = time + 1;
                        }
                        return true;
                }
                        entity ps = PlayerSounds_from(ReadByte());
                        float r = ReadByte() / 255;
                        int who = ReadByte();
-                       entity e = entcs_receiver[who - 1];
+                       entity e = entcs_receiver(who - 1);
                        UpdatePlayerSounds(e);
                        string s = e.(ps.m_playersoundfld);
                        string sample = GlobalSound_sample(s, r);
-                       int chan = ReadByte();
+                       int chan = ReadSByte();
                        float vol = ReadByte() / 255;
                        float atten = ReadByte() / 64;
                        vector o;
                        o.x = ReadCoord();
                        o.y = ReadCoord();
                        o.z = ReadCoord();
+                       if (who == player_currententnum) e = findfloat(world, entnum, who);  // play at camera position for full volume
+                       else if (e) e.origin = o;
                        if (e)
                        {
                                // TODO: for non-visible players, origin should probably continue to be updated as long as the sound is playing
-                               e.origin = o;
                                sound7(e, chan, sample, vol, atten, 0, 0);
                        }
                        else
                        {
-                           LOG_WARNINGF("Missing entcs data for player %i\n", e);
-                // Can this happen?
-                               entity e = new(playersound);
-                               e.origin = o;
+                               // Can this happen?
+                               LOG_WARNINGF("Missing entcs data for player %d\n", who);
                                sound8(e, o, chan, sample, vol, atten, 0, 0);
-                               remove(e);  // debug with: e.think = SUB_Remove; e.nextthink = time + 1;
                        }
                        return true;
                }
 
        #ifdef SVQC
 
-               void _GlobalSound(entity gs, entity ps, string sample, int chan, int voicetype, bool fake)
+               bool autocvar_g_debug_globalsounds;
+
+               void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, int voicetype, bool fake)
                {
-                       SELFPARAM();
                        if (gs == NULL && ps == NULL && sample == "") return;
                        float r = random();
                        if (sample != "") sample = GlobalSound_sample(sample, r);
                                case VOICETYPE_TEAMRADIO:
                                {
                                        #define X() \
-                                               do \
+                                               MACRO_BEGIN \
                                                { \
                                                        float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \
                                                        if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASEVOICE, atten); \
                                                        else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \
                                                        else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \
-                                               } \
-                                               while (0)
+                                               } MACRO_END
 
                                        if (fake) { msg_entity = this; X(); }
                                        else
                                        {
-                                               FOR_EACH_REALCLIENT(msg_entity)
-                                               {
-                                                       if (!teamplay || msg_entity.team == this.team) X();
-                                               }
+                                               FOREACH_CLIENT(IS_REAL_CLIENT(it) && (!teamplay || msg_entity.team == this.team), LAMBDA(
+                                                       msg_entity = it;
+                                                       X();
+                                               ));
                                        }
                #undef X
                                        break;
                                case VOICETYPE_TAUNT:
                                {
                                        if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) { break; }else {}
-                                       else if (IS_PLAYER(this) && this.deadflag == DEAD_NO) animdecide_setaction(this, ANIMACTION_TAUNT,
+                                       else if (IS_PLAYER(this) && !IS_DEAD(this)) animdecide_setaction(this, ANIMACTION_TAUNT,
                                                        true);
                                        if (!sv_taunt) break;
                                        if (autocvar_sv_gentle) break;
                                        float tauntrand = 0;
                                        if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random();
                                        #define X() \
-                                               do \
+                                               MACRO_BEGIN \
                                                { \
                                                        if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) \
                                                        { \
                                                                else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \
                                                                else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \
                                                        } \
-                                               } \
-                                               while (0)
+                                               } MACRO_END
                                        if (fake)
                                        {
                                                msg_entity = this;
                                        }
                                        else
                                        {
-                                               FOR_EACH_REALCLIENT(msg_entity)
-                                               {
+                                               FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+                                                       msg_entity = it;
                                                        X();
-                                               }
+                                               ));
                                        }
                #undef X
                                        break;
                                        }
                                        else
                                        {
-                                               if (gs) globalsound(MSG_ALL, this, gs, r, chan, VOL_BASE, ATTEN_NORM);
+                                               if (gs)
+                                               {
+                                                       if(autocvar_g_debug_globalsounds)
+                                                               globalsound(MSG_ALL, this, gs, r, chan, VOL_BASE, ATTEN_NORM);
+                                                       else
+                                                               _sound(this, chan, GlobalSound_sample(gs.m_globalsoundstr, r), VOL_BASE, ATTEN_NORM);
+                                               }
                                                else if (ps) playersound(MSG_ALL, this, ps, r, chan, VOL_BASE, ATTEN_NORM);
                                                else _sound(this, chan, sample, VOL_BASE, ATTEN_NORM);
                                        }