]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/triggers.qc
Add strfree to reduce explicit use of strunzone/string_null
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / triggers.qc
index 6d8c5bb7efe55bafa60de6363a686e01da1aabfe..0957699b37ad4ef9594e33f930c95b26397030e9 100644 (file)
@@ -102,12 +102,8 @@ void trigger_common_write(entity this, bool withtarget)
                WriteVector(MSG_ENTITY, this.angles);
 
        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);
        WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
 }
 
@@ -120,29 +116,21 @@ void trigger_common_read(entity this, bool withtarget)
 
        if(withtarget)
        {
-               if(this.target) { strunzone(this.target); }
-               if(this.target2) { strunzone(this.target2); }
-               if(this.target3) { strunzone(this.target3); }
-               if(this.target4) { strunzone(this.target4); }
-               if(this.targetname) { strunzone(this.targetname); }
-               if(this.killtarget) { strunzone(this.killtarget); }
+               strfree(this.target);
+               strfree(this.target2);
+               strfree(this.target3);
+               strfree(this.target4);
+               strfree(this.targetname);
+               strfree(this.killtarget);
 
                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
+               this.target = ((targbits & BIT(0)) ? strzone(ReadString()) : string_null);
+               this.target2 = ((targbits & BIT(1)) ? strzone(ReadString()) : string_null);
+               this.target3 = ((targbits & BIT(2)) ? strzone(ReadString()) : string_null);
+               this.target4 = ((targbits & BIT(3)) ? strzone(ReadString()) : string_null);
+               this.targetname = ((targbits & BIT(4)) ? strzone(ReadString()) : string_null);
+               this.killtarget = ((targbits & BIT(5)) ? strzone(ReadString()) : string_null);
        }
 
        if(f & 4)
@@ -162,35 +150,20 @@ void trigger_common_read(entity this, bool withtarget)
                this.angles = '0 0 0';
 
        this.modelindex = ReadShort();
-       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();
        this.scale = ReadByte() / 16;
        setsize(this, this.mins, this.maxs);
 }
 
 void trigger_remove_generic(entity this)
 {
-       if(this.target) { strunzone(this.target); }
-       this.target = string_null;
-
-       if(this.target2) { strunzone(this.target2); }
-       this.target2 = string_null;
-
-       if(this.target3) { strunzone(this.target3); }
-       this.target3 = string_null;
-
-       if(this.target4) { strunzone(this.target4); }
-       this.target4 = string_null;
-
-       if(this.targetname) { strunzone(this.targetname); }
-       this.target = string_null;
-
-       if(this.killtarget) { strunzone(this.killtarget); }
-       this.killtarget = string_null;
+       strfree(this.target);
+       strfree(this.target2);
+       strfree(this.target3);
+       strfree(this.target4);
+       strfree(this.targetname);
+       strfree(this.killtarget);
 }
 #endif