]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add Read/WriteAngleVector macros to simplify the networking of angles
authorMario <mario.mario@y7mail.com>
Fri, 31 Jul 2020 10:48:34 +0000 (20:48 +1000)
committerMario <mario.mario@y7mail.com>
Fri, 31 Jul 2020 10:48:34 +0000 (20:48 +1000)
18 files changed:
qcsrc/common/effects/qc/modeleffects.qc
qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
qcsrc/common/mapobjects/func/plat.qc
qcsrc/common/mapobjects/func/train.qc
qcsrc/common/mapobjects/misc/laser.qc
qcsrc/common/mapobjects/misc/teleport_dest.qc
qcsrc/common/mapobjects/models.qc
qcsrc/common/mapobjects/trigger/jumppads.qc
qcsrc/common/mapobjects/trigger/viewloc.qc
qcsrc/common/t_items.qc
qcsrc/common/turrets/cl_turrets.qc
qcsrc/common/turrets/sv_turrets.qc
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/vehicles/vehicle/bumblebee.qc
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/wepent.qc
qcsrc/lib/net.qh

index 9849b5be73f8ebf3d1aef3ff5b1e61ec4dfea2d0..41eee445c61b9616a2e76444b0bb63431cdf5838 100644 (file)
@@ -30,15 +30,11 @@ bool modeleffect_SendEntity(entity this, entity to, int sf)
        }
        if(f & 2)
        {
-               WriteCoord(MSG_ENTITY, this.angles.x);
-               WriteCoord(MSG_ENTITY, this.angles.y);
-               WriteCoord(MSG_ENTITY, this.angles.z);
+               WriteAngleVector(MSG_ENTITY, this.angles);
        }
        if(f & 4)
        {
-               WriteCoord(MSG_ENTITY, this.avelocity.x);
-               WriteCoord(MSG_ENTITY, this.avelocity.y);
-               WriteCoord(MSG_ENTITY, this.avelocity.z);
+               WriteAngleVector(MSG_ENTITY, this.avelocity);
        }
        WriteShort(MSG_ENTITY, this.scale * 256.0);
        WriteShort(MSG_ENTITY, this.scale2 * 256.0);
@@ -128,15 +124,11 @@ NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew)
        }
        if(f & 2)
        {
-               e.angles_x = ReadAngle();
-               e.angles_y = ReadAngle();
-               e.angles_z = ReadAngle();
+               e.angles = ReadAngleVector();
        }
        if(f & 4)
        {
-               e.avelocity_x = ReadAngle();
-               e.avelocity_y = ReadAngle();
-               e.avelocity_z = ReadAngle();
+               e.avelocity = ReadAngleVector();
        }
        e.scale1 = ReadShort() / 256.0;
        e.scale2 = ReadShort() / 256.0;
index 66ae14db424dfb64a0f36124c3ca7ba1e686c72f..f0a0046d8dfc6059ff700da0d73afcad96bce4b1 100644 (file)
@@ -12,9 +12,7 @@ NET_HANDLE(ENT_ONSCAMERA, bool isnew)
        this.origin = ReadVector();
        setorigin(this, this.origin);
 
-       this.angles_x = ReadAngle();
-       this.angles_y = ReadAngle();
-       this.angles_z = ReadAngle();
+       this.angles = ReadAngleVector();
 
        this.drawmask  = MASK_NORMAL;
        setmodel(this, MDL_Null); // give it a size for clientcamera
index 1f3e43378c71919fce84baf73f2d26e2e59d4587..170845298ff1eb1e4a8891c5073d9c7a97d092bf 100644 (file)
@@ -39,9 +39,7 @@ bool clientcamera_send(entity this, entity to, int sf)
 
        WriteVector(MSG_ENTITY, this.origin);
 
-       WriteAngle(MSG_ENTITY, this.angles_x);
-       WriteAngle(MSG_ENTITY, this.angles_y);
-       WriteAngle(MSG_ENTITY, this.angles_z);
+       WriteAngleVector(MSG_ENTITY, this.angles);
 
        return true;
 }
@@ -876,6 +874,7 @@ void ons_camSetup(entity this)
 
        FOREACH_CLIENT(true, it.clientcamera = cam;);
 
+       // NOTE: engine networked
        WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
        WriteAngle(MSG_ALL, cam.angles_x);
        WriteAngle(MSG_ALL, cam.angles_y);
index 53dbed02fa42a50580b69efe7ef80143ba0b0f5e..64275a357aaa216e28a34c528da312aaabd441dc 100644 (file)
@@ -31,9 +31,7 @@ float plat_send(entity this, entity to, float sf)
 
                WriteVector(MSG_ENTITY, this.size);
 
-               WriteAngle(MSG_ENTITY, this.mangle_x);
-               WriteAngle(MSG_ENTITY, this.mangle_y);
-               WriteAngle(MSG_ENTITY, this.mangle_z);
+               WriteAngleVector(MSG_ENTITY, this.mangle);
 
                WriteShort(MSG_ENTITY, this.speed);
                WriteShort(MSG_ENTITY, this.height);
@@ -152,9 +150,7 @@ NET_HANDLE(ENT_CLIENT_PLAT, bool isnew)
 
                this.size = ReadVector();
 
-               this.mangle_x = ReadAngle();
-               this.mangle_y = ReadAngle();
-               this.mangle_z = ReadAngle();
+               this.mangle = ReadAngleVector();
 
                this.speed = ReadShort();
                this.height = ReadShort();
index 4e9c334562c97cc1bad305ccb2abf279a3d20fa4..4ee741d580b6ccfa18abfe502645f67f1aeb815e 100644 (file)
@@ -164,9 +164,7 @@ float train_send(entity this, entity to, float sf)
 
                WriteVector(MSG_ENTITY, this.view_ofs);
 
-               WriteAngle(MSG_ENTITY, this.mangle_x);
-               WriteAngle(MSG_ENTITY, this.mangle_y);
-               WriteAngle(MSG_ENTITY, this.mangle_z);
+               WriteAngleVector(MSG_ENTITY, this.mangle);
 
                WriteShort(MSG_ENTITY, this.speed);
                WriteShort(MSG_ENTITY, this.height);
@@ -303,9 +301,7 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
 
                this.view_ofs = ReadVector();
 
-               this.mangle_x = ReadAngle();
-               this.mangle_y = ReadAngle();
-               this.mangle_z = ReadAngle();
+               this.mangle = ReadAngleVector();
 
                this.speed = ReadShort();
                this.height = ReadShort();
index 812dce76beff338b65307631231a084e418a6c04..77435e938b405cf5b013b07b56283f12383bb68f 100644 (file)
@@ -161,8 +161,7 @@ bool laser_SendEntity(entity this, entity to, float sendflags)
                }
                else
                {
-                       WriteAngle(MSG_ENTITY, this.mangle_x);
-                       WriteAngle(MSG_ENTITY, this.mangle_y);
+                       WriteAngleVector2D(MSG_ENTITY, this.mangle);
                }
        }
        if(sendflags & SF_LASER_UPDATE_ACTIVE)
@@ -388,8 +387,7 @@ NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
                }
                else
                {
-                       this.angles_x = ReadAngle();
-                       this.angles_y = ReadAngle();
+                       this.angles = ReadAngleVector2D();
                }
        }
        if(sendflags & SF_LASER_UPDATE_ACTIVE)
index 7402726d436a3dd8c06a8e4be045e32c853ab623..6bf95f24f6dfa8b2ccaa5824c1ce1bb7da839722 100644 (file)
@@ -14,10 +14,7 @@ bool teleport_dest_send(entity this, entity to, int sendflags)
                WriteCoord(MSG_ENTITY, this.speed);
                WriteString(MSG_ENTITY, this.targetname);
                WriteVector(MSG_ENTITY, this.origin);
-
-               WriteAngle(MSG_ENTITY, this.mangle_x);
-               WriteAngle(MSG_ENTITY, this.mangle_y);
-               WriteAngle(MSG_ENTITY, this.mangle_z);
+               WriteAngleVector(MSG_ENTITY, this.mangle);
        }
 
        return true;
@@ -72,10 +69,7 @@ NET_HANDLE(ENT_CLIENT_TELEPORT_DEST, bool isnew)
                this.speed = ReadCoord();
                this.targetname = strzone(ReadString());
                this.origin = ReadVector();
-
-               this.mangle_x = ReadAngle();
-               this.mangle_y = ReadAngle();
-               this.mangle_z = ReadAngle();
+               this.mangle = ReadAngleVector();
 
                setorigin(this, this.origin);
 
index bcaca193f476981a9c76041126dc5891e1592e40..c70effedb2eb3e93b2472fe6d5cd118e4bdf966e 100644 (file)
@@ -109,11 +109,7 @@ bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
        if(sf & BIT(2))
        {
                if(sf & 0x10)
-               {
-                       WriteAngle(MSG_ENTITY, this.angles.x);
-                       WriteAngle(MSG_ENTITY, this.angles.y);
-                       WriteAngle(MSG_ENTITY, this.angles.z);
-               }
+                       WriteAngleVector(MSG_ENTITY, this.angles);
        }
 
        if(sf & BIT(3))
@@ -334,11 +330,7 @@ NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
        if(f & 4)
        {
                if(f & 0x10)
-               {
-                       this.angles_x = ReadAngle();
-                       this.angles_y = ReadAngle();
-                       this.angles_z = ReadAngle();
-               }
+                       this.angles = ReadAngleVector();
                else
                        this.angles = '0 0 0';
        }
index 5138419d1ada9546081f6ce63549bd14a389a74c..b016dde9a19287d7e8c9e77ede292ee22c69c6cb 100644 (file)
@@ -634,9 +634,7 @@ bool target_push_send(entity this, entity to, float sf)
        WriteString(MSG_ENTITY, this.targetname);
        WriteVector(MSG_ENTITY, this.origin);
 
-       WriteAngle(MSG_ENTITY, this.angles_x);
-       WriteAngle(MSG_ENTITY, this.angles_y);
-       WriteAngle(MSG_ENTITY, this.angles_z);
+       WriteAngleVector(MSG_ENTITY, this.angles);
 
        return true;
 }
@@ -726,9 +724,7 @@ NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
        this.targetname = strzone(ReadString());
        this.origin = ReadVector();
 
-       this.angles_x = ReadAngle();
-       this.angles_y = ReadAngle();
-       this.angles_z = ReadAngle();
+       this.angles = ReadAngleVector();
 
        return = true;
 
index ba5dcbe443ea4c26e955adfa68b9f997eb0f8d69..354d36cb765ccfe72cc780949de7ab7e44bd3629 100644 (file)
@@ -125,9 +125,7 @@ bool viewloc_send(entity this, entity to, int sf)
 
        WriteVector(MSG_ENTITY, this.origin);
 
-       WriteAngle(MSG_ENTITY, this.angles_x);
-       WriteAngle(MSG_ENTITY, this.angles_y);
-       WriteAngle(MSG_ENTITY, this.angles_z);
+       WriteAngleVector(MSG_ENTITY, this.angles);
 
        return true;
 }
@@ -200,9 +198,7 @@ NET_HANDLE(ENT_CLIENT_VIEWLOC, bool isnew)
        this.origin = ReadVector();
        setorigin(this, this.origin);
 
-       this.movedir_x = ReadAngle();
-       this.movedir_y = ReadAngle();
-       this.movedir_z = ReadAngle();
+       this.movedir = ReadAngleVector();
 
        return = true;
 
index ef2923b86932814247d70707de3466153b51145c..3b550f93e75be2e27f6b401c0225ca3448f250e3 100644 (file)
@@ -168,9 +168,7 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
 
     if(sf & ISF_ANGLES)
     {
-        this.angles_x = ReadAngle();
-        this.angles_y = ReadAngle();
-        this.angles_z = ReadAngle();
+        this.angles = ReadAngleVector();
     }
 
     if(sf & ISF_SIZE)
@@ -321,9 +319,7 @@ bool ItemSend(entity this, entity to, int sf)
 
        if(sf & ISF_ANGLES)
        {
-               WriteAngle(MSG_ENTITY, this.angles_x);
-               WriteAngle(MSG_ENTITY, this.angles_y);
-               WriteAngle(MSG_ENTITY, this.angles_z);
+               WriteAngleVector(MSG_ENTITY, this.angles);
        }
 
        // sets size on the client, unused on server
index df20e1ad2f2d8371638de205f191a458be3db41e..fca9f7f237c1936409298da55e5ea0becc87073b 100644 (file)
@@ -376,8 +376,7 @@ NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
                this.origin = ReadVector();
                setorigin(this, this.origin);
 
-               this.angles_x = ReadAngle();
-               this.angles_y = ReadAngle();
+               this.angles = ReadAngleVector2D();
 
                turret_construct(this, isnew);
                this.colormap = 1024;
index d8587b14a809954a433f033fe88e5e33245c49d8..ceaae8ad5c58c45e79f5089f29365ae5e0a20052 100644 (file)
@@ -320,7 +320,6 @@ void turrets_setframe(entity this, float _frame, float client_only)
 
 bool turret_send(entity this, entity to, float sf)
 {
-
        WriteHeader(MSG_ENTITY, ENT_CLIENT_TURRET);
        WriteByte(MSG_ENTITY, sf);
        if(sf & TNSF_SETUP)
@@ -329,8 +328,7 @@ bool turret_send(entity this, entity to, float sf)
 
                WriteVector(MSG_ENTITY, this.origin);
 
-               WriteAngle(MSG_ENTITY, this.angles_x);
-               WriteAngle(MSG_ENTITY, this.angles_y);
+               WriteAngleVector2D(MSG_ENTITY, this.angles);
        }
 
        if(sf & TNSF_ANG)
index 7273f5a642220820bd7007cd8720c7aad9f1c1ae..5d864b1b5382c7dfd6ce0d8e0ec428f6e7a47ec0 100644 (file)
@@ -839,6 +839,7 @@ void vehicles_exit(entity vehic, bool eject)
                        WriteByte (MSG_ONE, SVC_SETVIEWPORT);
                        WriteEntity( MSG_ONE, player);
 
+                       // NOTE: engine networked
                        WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
                        WriteAngle(MSG_ONE, 0);
                        WriteAngle(MSG_ONE, vehic.angles_y);
@@ -1081,6 +1082,7 @@ void vehicles_enter(entity pl, entity veh)
                WriteByte (MSG_ONE, SVC_SETVIEWPORT);
                WriteEntity(MSG_ONE, veh.vehicle_viewport);
 
+               // NOTE: engine networked
                WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
                if(veh.tur_head)
                {
index 224f96564e7a0fc7347decf2350fc268b8af92e6..0a8875b48df02cb9a74f7392883d9210d7d0fda5 100644 (file)
@@ -230,6 +230,7 @@ void bumblebee_gunner_exit(entity this, int _exitflag)
                WriteByte(MSG_ONE, SVC_SETVIEWPORT);
                WriteEntity(MSG_ONE, player);
 
+               // NOTE: engine networked
                WriteByte(MSG_ONE, SVC_SETVIEWANGLES);
                WriteAngle(MSG_ONE, 0);
                WriteAngle(MSG_ONE, vehic.angles.y);
@@ -340,6 +341,7 @@ bool bumblebee_gunner_enter(entity this, entity player)
                WriteByte(MSG_ONE,              SVC_SETVIEWPORT);
                WriteEntity(MSG_ONE,    gunner.vehicle_viewport);
 
+               // NOTE: engine networked
                WriteByte(MSG_ONE,              SVC_SETVIEWANGLES);
                WriteAngle(MSG_ONE,     gunner.angles_x + vehic.angles_x); // tilt
                WriteAngle(MSG_ONE,     gunner.angles_y + vehic.angles_y); // yaw
index 387bb910fdbab55ac6c4e308bd789e47c36f9083..5f79c8ccfa58d622c4607dc5129e73783399b103 100644 (file)
@@ -40,9 +40,7 @@ bool W_Arc_Beam_Send(entity this, entity to, int sf)
        }
        if(sf & ARC_SF_BEAMDIR) // beam direction
        {
-               WriteAngle(MSG_ENTITY, this.beam_dir.x);
-               WriteAngle(MSG_ENTITY, this.beam_dir.y);
-               WriteAngle(MSG_ENTITY, this.beam_dir.z);
+               WriteAngleVector(MSG_ENTITY, this.beam_dir);
        }
        if(sf & ARC_SF_BEAMTYPE) // beam type
        {
@@ -1274,9 +1272,7 @@ NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew)
 
        if(sf & ARC_SF_BEAMDIR) // beam direction
        {
-               this.angles_x = ReadAngle();
-               this.angles_y = ReadAngle();
-               this.angles_z = ReadAngle();
+               this.angles = ReadAngleVector();
        }
 
        if(sf & ARC_SF_BEAMTYPE) // beam type
index 5e78207d4a7986ea754e0a0dc692e96d86b391c1..3d751035b029f4b186c5af77ca8f3582bf558933 100644 (file)
@@ -36,10 +36,10 @@ MACRO_END
     \
     PROP(false, porto_v_angle_held, WEPENT_SET_NORMAL, \
        { WriteByte(chan, this.porto_v_angle_held); if(this.porto_v_angle_held) { \
-                WriteAngle(chan, this.owner.porto_v_angle.x); WriteAngle(chan, this.owner.porto_v_angle.y); \
+                WriteAngleVector2D(chan, this.owner.porto_v_angle); \
                } }, \
        { (viewmodels[this.m_wepent_slot]).angles_held_status = ReadByte(); if((viewmodels[this.m_wepent_slot]).angles_held_status) { \
-               (viewmodels[this.m_wepent_slot]).angles_held = vec2(ReadAngle(), ReadAngle()); } \
+               (viewmodels[this.m_wepent_slot]).angles_held = ReadAngleVector2D(); } \
                else { (viewmodels[this.m_wepent_slot]).angles_held = '0 0 0'; } }) \
     \
     PROP(false, tuba_instrument, WEPENT_SET_NORMAL, \
index 3cec9fd9ba8734a9ed1b9ff52014a05a5787e821..522b4ff2301f86b4e22f8c6d008e79a4f8103f83 100644 (file)
@@ -357,6 +357,8 @@ MACRO_END
                #define ReadFloat() ReadCoord()
                #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat())
                #define ReadVector2D() vec2(ReadFloat(), ReadFloat())
+               #define ReadAngleVector() vec3(ReadAngle(), ReadAngle(), ReadAngle())
+               #define ReadAngleVector2D() vec2(ReadAngle(), ReadAngle())
 
                int Readbits(int num)
                {
@@ -397,6 +399,8 @@ MACRO_END
                #define WriteFloat(to, f) WriteCoord(to, f)
                #define WriteVector(to, v) MACRO_BEGIN WriteFloat(to, v.x); WriteFloat(to, v.y); WriteFloat(to, v.z); MACRO_END
                #define WriteVector2D(to, v) MACRO_BEGIN WriteFloat(to, v.x); WriteFloat(to, v.y); MACRO_END
+               #define WriteAngleVector(to, v) MACRO_BEGIN WriteAngle(to, v.x); WriteAngle(to, v.y); WriteAngle(to, v.z); MACRO_END
+               #define WriteAngleVector2D(to, v) MACRO_BEGIN WriteAngle(to, v.x); WriteAngle(to, v.y); MACRO_END
 
                void Writebits(float dst, float val, int num)
                {