]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/music.qc
Merge branch 'master' into terencehill/min_spec_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / music.qc
index 94c15c17a416b74eacf09f4a0380407800f790dd..7ec3351381b6265b0d24e4e16c02caa80d32fe2d 100644 (file)
@@ -1,7 +1,9 @@
+#include "music.qh"
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
     #include <common/constants.qh>
+    #include <common/net_linked.qh>
     #include <server/constants.qh>
     #include <server/defs.qh>
 #endif
@@ -11,6 +13,9 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC)
 
 #ifdef SVQC
 
+IntrusiveList g_targetmusic_list;
+STATIC_INIT(g_targetmusic_list) { g_targetmusic_list = IL_NEW(); }
+
 // values:
 //   volume
 //   noise
@@ -36,12 +41,13 @@ void target_music_reset(entity this)
 }
 void target_music_kill()
 {
-       FOREACH_ENTITY_CLASS("target_music", true, {
+       IL_EACH(g_targetmusic_list, true,
+       {
                it.volume = 0;
         if (it.targetname == "")
-            WITHSELF(it, target_music_sendto(it, MSG_ALL, 1));
+            target_music_sendto(it, MSG_ALL, 1);
         else
-            WITHSELF(it, target_music_sendto(it, MSG_ALL, 0));
+            target_music_sendto(it, MSG_ALL, 0);
        });
 }
 void target_music_use(entity this, entity actor, entity trigger)
@@ -64,6 +70,7 @@ spawnfunc(target_music)
        this.reset = target_music_reset;
        if(!this.volume)
                this.volume = 1;
+       IL_PUSH(g_targetmusic_list, this);
        if(this.targetname == "")
                target_music_sendto(this, MSG_INIT, 1);
        else
@@ -71,13 +78,13 @@ spawnfunc(target_music)
 }
 void TargetMusic_RestoreGame()
 {
-       for(entity e = world; (e = find(e, classname, "target_music")); )
+       IL_EACH(g_targetmusic_list, true,
        {
-               if(e.targetname == "")
-                       target_music_sendto(e, MSG_INIT, 1);
+               if(it.targetname == "")
+                       target_music_sendto(it, MSG_INIT, 1);
                else
-                       target_music_sendto(e, MSG_INIT, 0);
-       }
+                       target_music_sendto(it, MSG_INIT, 0);
+       });
 }
 // values:
 //   volume
@@ -96,28 +103,20 @@ bool trigger_music_SendEntity(entity this, entity to, float sf)
        WriteByte(MSG_ENTITY, sf);
        if(sf & 4)
        {
-               WriteCoord(MSG_ENTITY, this.origin.x);
-               WriteCoord(MSG_ENTITY, this.origin.y);
-               WriteCoord(MSG_ENTITY, this.origin.z);
+               WriteVector(MSG_ENTITY, this.origin);
        }
        if(sf & 1)
        {
                if(this.model != "null")
                {
                        WriteShort(MSG_ENTITY, this.modelindex);
-                       WriteCoord(MSG_ENTITY, this.mins.x);
-                       WriteCoord(MSG_ENTITY, this.mins.y);
-                       WriteCoord(MSG_ENTITY, this.mins.z);
-                       WriteCoord(MSG_ENTITY, this.maxs.x);
-                       WriteCoord(MSG_ENTITY, this.maxs.y);
-                       WriteCoord(MSG_ENTITY, this.maxs.z);
+                       WriteVector(MSG_ENTITY, this.mins);
+                       WriteVector(MSG_ENTITY, this.maxs);
                }
                else
                {
                        WriteShort(MSG_ENTITY, 0);
-                       WriteCoord(MSG_ENTITY, this.maxs.x);
-                       WriteCoord(MSG_ENTITY, this.maxs.y);
-                       WriteCoord(MSG_ENTITY, this.maxs.z);
+                       WriteVector(MSG_ENTITY, this.maxs);
                }
                WriteByte(MSG_ENTITY, this.volume * 255.0);
                WriteByte(MSG_ENTITY, this.fade_time * 16.0);
@@ -188,7 +187,7 @@ void TargetMusic_Advance()
                        it.lastvol = vol;
                }
        });
-       music_trigger = world;
+       music_trigger = NULL;
        bgmtime = (best) ? getsoundtime(best, CH_BGM_SINGLE) : gettime(GETTIME_CDTRACK);
 }
 
@@ -223,7 +222,7 @@ void Net_TargetMusic()
                _sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
                if(getsoundtime(e, CH_BGM_SINGLE) < 0)
                {
-                       LOG_TRACEF("Cannot initialize sound %s\n", e.noise);
+                       LOG_TRACEF("Cannot initialize sound %s", e.noise);
                        strunzone(e.noise);
                        e.noise = string_null;
                }
@@ -254,18 +253,18 @@ void Net_TargetMusic()
 
 void Ent_TriggerMusic_Think(entity this)
 {
-       if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
+       if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL))
        {
-               music_trigger = self;
+               music_trigger = this;
        }
-       self.nextthink = time;
+       this.nextthink = time;
 }
 
 void Ent_TriggerMusic_Remove(entity this)
 {
-       if(self.noise)
-               strunzone(self.noise);
-       self.noise = string_null;
+       if(this.noise)
+               strunzone(this.noise);
+       this.noise = string_null;
 }
 
 NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
@@ -273,28 +272,20 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
        int f = ReadByte();
        if(f & 4)
        {
-               this.origin_x = ReadCoord();
-               this.origin_y = ReadCoord();
-               this.origin_z = ReadCoord();
+               this.origin = ReadVector();
        }
        if(f & 1)
        {
                this.modelindex = ReadShort();
                if(this.modelindex)
                {
-                       this.mins_x = ReadCoord();
-                       this.mins_y = ReadCoord();
-                       this.mins_z = ReadCoord();
-                       this.maxs_x = ReadCoord();
-                       this.maxs_y = ReadCoord();
-                       this.maxs_z = ReadCoord();
+                       this.mins = ReadVector();
+                       this.maxs = ReadVector();
                }
                else
                {
                        this.mins    = '0 0 0';
-                       this.maxs_x = ReadCoord();
-                       this.maxs_y = ReadCoord();
-                       this.maxs_z = ReadCoord();
+                       this.maxs = ReadVector();
                }
 
                this.volume = ReadByte() / 255.0;
@@ -310,7 +301,7 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
                        _sound(this, CH_BGM_SINGLE, this.noise, 0, ATTEN_NONE);
                        if(getsoundtime(this, CH_BGM_SINGLE) < 0)
                        {
-                               LOG_TRACEF("Cannot initialize sound %s\n", this.noise);
+                               LOG_TRACEF("Cannot initialize sound %s", this.noise);
                                strunzone(this.noise);
                                this.noise = string_null;
                        }