]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Limit what's sent for each trigger with a couple of bitflags
authorMario <mario@smbclan.net>
Mon, 12 Feb 2018 14:51:02 +0000 (00:51 +1000)
committerMario <mario@smbclan.net>
Mon, 12 Feb 2018 14:51:28 +0000 (00:51 +1000)
qcsrc/common/triggers/triggers.qc

index f6cb013d9e2df3d4ad8b4170ac8299148576a6c4..6d8c5bb7efe55bafa60de6363a686e01da1aabfe 100644 (file)
@@ -59,24 +59,47 @@ void trigger_common_write(entity this, bool withtarget)
                BITSET_ASSIGN(f, 1);
        if(this.origin != '0 0 0')
                BITSET_ASSIGN(f, 4);
+       if(this.movedir != '0 0 0')
+               BITSET_ASSIGN(f, 8);
+       if(this.angles != '0 0 0')
+               BITSET_ASSIGN(f, 16);
        WriteByte(MSG_ENTITY, f);
 
        if(withtarget)
        {
-               WriteString(MSG_ENTITY, this.target);
-               WriteString(MSG_ENTITY, this.target2);
-               WriteString(MSG_ENTITY, this.target3);
-               WriteString(MSG_ENTITY, this.target4);
-               WriteString(MSG_ENTITY, this.targetname);
-               WriteString(MSG_ENTITY, this.killtarget);
+               // probably some way to clean this up...
+               int targbits = 0;
+               if(this.target && this.target != "") targbits |= BIT(0);
+               if(this.target2 && this.target2 != "") targbits |= BIT(1);
+               if(this.target3 && this.target3 != "") targbits |= BIT(2);
+               if(this.target4 && this.target4 != "") targbits |= BIT(3);
+               if(this.targetname && this.targetname != "") targbits |= BIT(4);
+               if(this.killtarget && this.killtarget != "") targbits |= BIT(5);
+
+               WriteByte(MSG_ENTITY, targbits);
+
+               if(targbits & BIT(0))
+                       WriteString(MSG_ENTITY, this.target);
+               if(targbits & BIT(1))
+                       WriteString(MSG_ENTITY, this.target2);
+               if(targbits & BIT(2))
+                       WriteString(MSG_ENTITY, this.target3);
+               if(targbits & BIT(3))
+                       WriteString(MSG_ENTITY, this.target4);
+               if(targbits & BIT(4))
+                       WriteString(MSG_ENTITY, this.targetname);
+               if(targbits & BIT(5))
+                       WriteString(MSG_ENTITY, this.killtarget);
        }
 
        if(f & 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(f & 8)
+               WriteVector(MSG_ENTITY, this.movedir);
+
+       if(f & 16)
+               WriteVector(MSG_ENTITY, this.angles);
 
        WriteShort(MSG_ENTITY, this.modelindex);
        WriteCoord(MSG_ENTITY, this.mins.x);
@@ -86,14 +109,6 @@ void trigger_common_write(entity this, bool withtarget)
        WriteCoord(MSG_ENTITY, this.maxs.y);
        WriteCoord(MSG_ENTITY, this.maxs.z);
        WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
-
-       WriteCoord(MSG_ENTITY, this.movedir_x);
-       WriteCoord(MSG_ENTITY, this.movedir_y);
-       WriteCoord(MSG_ENTITY, this.movedir_z);
-
-       WriteCoord(MSG_ENTITY, this.angles_x);
-       WriteCoord(MSG_ENTITY, this.angles_y);
-       WriteCoord(MSG_ENTITY, this.angles_z);
 }
 
 #elif defined(CSQC)
@@ -106,29 +121,46 @@ void trigger_common_read(entity this, bool withtarget)
        if(withtarget)
        {
                if(this.target) { strunzone(this.target); }
-               this.target = strzone(ReadString());
                if(this.target2) { strunzone(this.target2); }
-               this.target2 = strzone(ReadString());
                if(this.target3) { strunzone(this.target3); }
-               this.target3 = strzone(ReadString());
                if(this.target4) { strunzone(this.target4); }
-               this.target4 = strzone(ReadString());
                if(this.targetname) { strunzone(this.targetname); }
-               this.targetname = strzone(ReadString());
                if(this.killtarget) { strunzone(this.killtarget); }
-               this.killtarget = strzone(ReadString());
+
+               int targbits = ReadByte();
+
+               #define X(xs,b) MACRO_BEGIN { \
+                       if(targbits & BIT(b)) \
+                               xs = strzone(ReadString()); \
+                       else \
+                               xs = string_null; \
+               } MACRO_END
+
+               X(this.target, 0);
+               X(this.target2, 1);
+               X(this.target3, 2);
+               X(this.target4, 3);
+               X(this.targetname, 4);
+               X(this.killtarget, 5);
+               #undef X
        }
 
        if(f & 4)
-       {
-               this.origin_x = ReadCoord();
-               this.origin_y = ReadCoord();
-               this.origin_z = ReadCoord();
-       }
+               this.origin = ReadVector();
        else
                this.origin = '0 0 0';
        setorigin(this, this.origin);
 
+       if(f & 8)
+               this.movedir = ReadVector();
+       else
+               this.movedir = '0 0 0';
+
+       if(f & 16)
+               this.angles = ReadVector();
+       else
+               this.angles = '0 0 0';
+
        this.modelindex = ReadShort();
        this.mins_x = ReadCoord();
        this.mins_y = ReadCoord();
@@ -138,14 +170,6 @@ void trigger_common_read(entity this, bool withtarget)
        this.maxs_z = ReadCoord();
        this.scale = ReadByte() / 16;
        setsize(this, this.mins, this.maxs);
-
-       this.movedir_x = ReadCoord();
-       this.movedir_y = ReadCoord();
-       this.movedir_z = ReadCoord();
-
-       this.angles_x = ReadCoord();
-       this.angles_y = ReadCoord();
-       this.angles_z = ReadCoord();
 }
 
 void trigger_remove_generic(entity this)