]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
shot origin compression out the window
authordrjaska <drjaska83@gmail.com>
Wed, 8 Nov 2023 03:01:07 +0000 (05:01 +0200)
committerdrjaska <drjaska83@gmail.com>
Wed, 8 Nov 2023 03:01:07 +0000 (05:01 +0200)
12 files changed:
qcsrc/client/hud/crosshair.qc
qcsrc/client/main.qc
qcsrc/common/stats.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/weapon/arc.qc
qcsrc/common/weapons/weapon/devastator.qc
qcsrc/server/client.qc
qcsrc/server/damage.qc
qcsrc/server/impulse.qc
qcsrc/server/weapons/tracing.qc

index 229a6024084df01cbabefa97a02de385a558a86a..4159787f8fa7a3c7fd1c0bb446b793f6ce425854 100644 (file)
@@ -122,7 +122,7 @@ float TrueAimCheck(entity wepent)
 
        vector traceorigin = entcs_receiver(player_localentnum - 1).origin + (eZ * STAT(VIEWHEIGHT));
 
-       vecs = decompressShotOrigin(STAT(SHOTORG));
+       vecs = STAT(SHOTORG);
 
        traceline(traceorigin, traceorigin + view_forward * max_shot_distance, mv, ta);
        trueaimpoint = trace_endpos;
@@ -133,10 +133,7 @@ float TrueAimCheck(entity wepent)
        if(vdist((trueaimpoint - traceorigin), <, g_trueaim_minrange))
                trueaimpoint = traceorigin + view_forward * g_trueaim_minrange;
 
-       if(vecs.x > 0)
-               vecs.y = -vecs.y;
-       else
-               vecs = '0 0 0';
+       vecs.y = -vecs.y;
 
        dv = view_right * vecs.y + view_up * vecs.z;
        w_shotorg = traceorigin + dv;
index 58d497aab77b176a9ef60b951762e60d7eecac95..941ab54301dbeaccd4c3740af4d57a8093d5fc5b 100644 (file)
@@ -1097,14 +1097,14 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
 {
        nb_pb_period = ReadByte() / 32; //Accuracy of 1/32th
 
-       hook_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
-       hook_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
-       hook_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
-       hook_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
-       arc_shotorigin[0] = decompressShotOrigin(ReadInt24_t());
-       arc_shotorigin[1] = decompressShotOrigin(ReadInt24_t());
-       arc_shotorigin[2] = decompressShotOrigin(ReadInt24_t());
-       arc_shotorigin[3] = decompressShotOrigin(ReadInt24_t());
+       hook_shotorigin[0] = ReadVector();
+       hook_shotorigin[1] = ReadVector();
+       hook_shotorigin[2] = ReadVector();
+       hook_shotorigin[3] = ReadVector();
+       arc_shotorigin[0]  = ReadVector();
+       arc_shotorigin[1]  = ReadVector();
+       arc_shotorigin[2]  = ReadVector();
+       arc_shotorigin[3]  = ReadVector();
 
        strcpy(forcefog, ReadString());
 
index b7be1425c02c535c3354e91a9edc9af2613c8177..ed4dbf30cf0cf068068f3760a2e06967673a62aa 100644 (file)
@@ -94,8 +94,7 @@ REGISTER_STAT(GAMESTARTTIME, float, game_starttime)
 /** arc heat in [0,1] */
 REGISTER_STAT(PRESSED_KEYS, int)
 REGISTER_STAT(FUEL, int)
-/** compressShotOrigin */
-REGISTER_STAT(SHOTORG, int)
+REGISTER_STAT(SHOTORG, vector)
 REGISTER_STAT(LEADLIMIT, float, autocvar_leadlimit)
 REGISTER_STAT(LEADLIMIT_AND_FRAGLIMIT, float, autocvar_leadlimit_and_fraglimit)
 
index df54e3536b10acdf149037ddacc8b6c4c133da12..21f0b13de237b628de5350d54f2fb2b5f55bfbbb 100644 (file)
@@ -1184,37 +1184,6 @@ vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_styl
        return myvel + spd * mydir;
 }
 
-float compressShotOrigin(vector v)
-{
-       float rx = rint(v.x * 2);
-       float ry = rint(v.y * 4) + 128;
-       float rz = rint(v.z * 4) + 128;
-       if(rx > 255 || rx < 0)
-       {
-               LOG_DEBUG("shot origin ", vtos(v), " x out of bounds\n");
-               rx = bound(0, rx, 255);
-       }
-       if(ry > 255 || ry < 0)
-       {
-               LOG_DEBUG("shot origin ", vtos(v), " y out of bounds\n");
-               ry = bound(0, ry, 255);
-       }
-       if(rz > 255 || rz < 0)
-       {
-               LOG_DEBUG("shot origin ", vtos(v), " z out of bounds\n");
-               rz = bound(0, rz, 255);
-       }
-       return rx * 0x10000 + ry * 0x100 + rz;
-}
-vector decompressShotOrigin(int f)
-{
-       vector v;
-       v.x = ((f & 0xFF0000) / 0x10000) / 2;
-       v.y = ((f & 0xFF00) / 0x100 - 128) / 4;
-       v.z = ((f & 0xFF) - 128) / 4;
-       return v;
-}
-
 #ifdef GAMEQC
 vector healtharmor_maxdamage(float h, float a, float armorblock, int deathtype)
 {
index 01933cb348323b7090b7b889c85ae2271d55e094..2add42e2d9dd5bdd0b07ff45172071c0526254bb 100644 (file)
@@ -148,9 +148,6 @@ float isGametypeInFilter(entity gt, float tp, float ts, string pattern);
 vector solve_shotdirection(vector myorg, vector myvel, vector eorg, vector evel, float spd, float newton_style);
 vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_style, float mi, float ma);
 
-float compressShotOrigin(vector v);
-vector decompressShotOrigin(float f);
-
 #ifdef SVQC
 string rankings_reply, ladder_reply, lsmaps_reply, maplist_reply, monsterlist_reply; // cached replies
 string records_reply[10];
index effa087e65c57ce2efabc3d2a5d9ad54622d7c74..d1b83592f9d2709c4d69916e4f7c61570bb87acb 100644 (file)
@@ -512,25 +512,20 @@ void CL_WeaponEntity_SetModel(entity this, string name, bool _anim)
        this.view_ofs = '0 0 0';
        this.movedir_aligned = this.movedir;
 
-       if (this.movedir.x >= 0)
-       {
-               //int algn = STAT(GUNALIGN, this.owner);
-               int algn = W_GunAlign(this, STAT(GUNALIGN, this.owner));
-       #ifdef SVQC
-               this.m_gunalign = algn;
-       #endif
-               vector v = this.movedir;
-               this.movedir = shotorg_adjust(v, false, false, algn);
-               this.movedir_aligned = shotorg_adjust(v, false, true, algn);
-               this.view_ofs = this.movedir_aligned - v;
-       }
-       int compressed_shotorg = compressShotOrigin(this.movedir);
-       // make them match perfectly
+       //int algn = STAT(GUNALIGN, this.owner);
+       int algn = W_GunAlign(this, STAT(GUNALIGN, this.owner));
+#ifdef SVQC
+       this.m_gunalign = algn;
+#endif
+       vector v = this.movedir;
+       this.movedir = shotorg_adjust(v, false, false, algn);
+       this.movedir_aligned = shotorg_adjust(v, false, true, algn);
+       this.view_ofs = this.movedir_aligned - v;
+
 #ifdef SVQC
        // null during init
-       if (this.owner) STAT(SHOTORG, this.owner) = compressed_shotorg;
+       if (this.owner) STAT(SHOTORG, this.owner) = this.movedir;
 #endif
-       this.movedir = decompressShotOrigin(compressed_shotorg);
 
 #ifdef SVQC
        this.spawnorigin += this.view_ofs;  // offset the casings origin by the same amount
@@ -786,8 +781,7 @@ NET_HANDLE(w_muzzleflash, bool isNew)
                rlplayer = csqcplayer; // fall back to the global
 
        vector md = wepent.movedir_aligned;
-       vector vecs = ((md.x > 0) ? md : '0 0 0');
-       vector dv = forward * vecs.x + right * -vecs.y + up * vecs.z;
+       vector dv = forward * md.x + right * -md.y + up * md.z;
        vector org = rlplayer.origin + rlplayer.view_ofs + dv;
 
        pointparticles(thiswep.m_muzzleeffect, org, forward * 1000, 1);
index 43d7a03a400dae69ba74e6e6858435ad9ad113fe..5bacdc35e6e705e43963627cea2b5365ed226ff4 100644 (file)
@@ -564,8 +564,7 @@ void Arc_Smoke(Weapon thiswep, entity actor, .entity weaponentity, int fire)
        makevectors(actor.v_angle);
        w_shotdir = v_forward;
        vector md = actor.(weaponentity).movedir;
-       vector vecs = ((md.x > 0) ? md : '0 0 0');
-       vector dv = v_forward * vecs.x + v_right * -vecs.y + v_up * vecs.z;
+       vector dv = v_forward * md.x + v_right * -md.y + v_up * md.z;
        w_shotorg = actor.origin + actor.view_ofs + dv;
        //W_SetupShot_Range(actor,weaponentity,false,0,SND_Null,0,0,0,thiswep.m_id);
 
index 6f428dc6c413430cb52440659da1c3a5eac6e6b5..593d1bce102053f980a62f8b302dc825d2f22263 100644 (file)
@@ -237,9 +237,8 @@ void W_Devastator_Think(entity this)
                                f = 1;
 
                        vector md = this.realowner.(weaponentity).movedir;
-                       vector vecs = ((md.x > 0) ? md : '0 0 0');
 
-                       vector dv = v_right * -vecs.y + v_up * vecs.z;
+                       vector dv = v_right * -md.y + v_up * md.z;
 
                        if(!W_DualWielding(this.realowner))
                                dv = '0 0 0'; // don't override!
index 00063bba214fae3ba064a144ec18bf2983db2eae..85ca746cab8df9a84aaac3eccc2a0e5eb9b4c1de 100644 (file)
@@ -873,14 +873,14 @@ void ClientInit_misc(entity this)
        int channel = MSG_ONE;
        WriteHeader(channel, ENT_CLIENT_INIT);
        WriteByte(channel, g_nexball_meter_period * 32);
-       WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[0]));
-       WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[1]));
-       WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[2]));
-       WriteInt24_t(channel, compressShotOrigin(hook_shotorigin[3]));
-       WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[0]));
-       WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[1]));
-       WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[2]));
-       WriteInt24_t(channel, compressShotOrigin(arc_shotorigin[3]));
+       WriteVector(channel, hook_shotorigin[0]);
+       WriteVector(channel, hook_shotorigin[1]);
+       WriteVector(channel, hook_shotorigin[2]);
+       WriteVector(channel, hook_shotorigin[3]);
+       WriteVector(channel, arc_shotorigin[0]);
+       WriteVector(channel, arc_shotorigin[1]);
+       WriteVector(channel, arc_shotorigin[2]);
+       WriteVector(channel, arc_shotorigin[3]);
 
        if(autocvar_sv_foginterval && world.fog != "")
                WriteString(channel, world.fog);
index 2e84cac3af71e089bbb921e3e59b03539983c8d3..d30ed8fc846f390abf16f87b7f4c782c1d411b1a 100644 (file)
@@ -961,8 +961,7 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
                                                #if 0
                                                        // code stolen from W_SetupShot_Dir_ProjectileSize_Range()
                                                        vector md = targ.(weaponentity).movedir;
-                                                       vector vecs = ((md.x > 0) ? md : '0 0 0');
-                                                       vector dv = v_right * -vecs.y + v_up * vecs.z;
+                                                       vector dv = v_right * -md.y + v_up * md.z;
                                                        vector mi = '0 0 0', ma = '0 0 0';
 
                                                        if(IS_CLIENT(targ)) // no antilag for non-clients!
@@ -977,8 +976,8 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in
 
                                                        center.z = trace_endpos.z;
                                                #else
-                                                       // very cheap way but it skips movedir.x > 0 checks and move into solid checks which is fine most of the time for now AFAIK
-                                                       // this should only really be an issue with absurd g_shootfromfixedorigin custom values like "-1 0 9001"
+                                                       // very cheap way but it skips move into solid checks which is fine most of the time for now AFAIK
+                                                       // this should only really be an issue with absurd g_shootfromfixedorigin custom values like "0 0 9001"
                                                        center.z = center.z + targ.(weaponentity).movedir.z;
                                                #endif
                                                }
index be66fe968c2b6a2eadc8ac35b8390805ad519289..b9f9d7766f200a270d8471f6731db4170af9f4c2 100644 (file)
@@ -340,8 +340,7 @@ IMPULSE(weapon_drop)
        {
                .entity weaponentity = weaponentities[slot];
                vector md = this.(weaponentity).movedir;
-               vector vecs = ((md.x > 0) ? md : '0 0 0');
-               vector dv = v_right * -vecs.y;
+               vector dv = v_right * -md.y;
                if(!is_dualwielding)
                        dv = '0 0 0'; // don't override!
                W_ThrowWeapon(this, weaponentity, W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), dv, true);
index dbd3d5b27e6573b4d4125ff653daf3c3ff51f6e3..3e3db211548729c0cf2fb4c5f4e7ca485c83a64f 100644 (file)
@@ -69,11 +69,12 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, .entity weaponentity, vect
        if(IS_PLAYER(ent))
                W_HitPlotAnalysis(ent, wep, forward, right, up);
 
-       vector md = ent.(weaponentity).movedir;
-       vector vecs = ((md.x > 0) ? md : '0 0 0');
-
-       vector dv = right * -vecs.y + up * vecs.z;
+       vector md = ent.(weaponentity).movedir; // read shot origin offset, like g_shootfromcenter
+       //print(sprintf("offset of %s: %v\n\n", ent.(weaponentity).m_weapon.netname, md));
+       vector dv = right * -md.y + up * md.z;
        w_shotorg = ent.origin + ent.view_ofs;
+
+       // move the shotorg sideways and vertically as much as requested if possible
        if(antilag)
        {
                if(CS(ent).antilag_debug)
@@ -89,13 +90,14 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, .entity weaponentity, vect
        if(antilag)
        {
                if(CS(ent).antilag_debug)
-                       tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + forward * (vecs.x + nudge), MOVE_NORMAL, ent, CS(ent).antilag_debug);
+                       tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + forward * (md.x + nudge), MOVE_NORMAL, ent, CS(ent).antilag_debug);
                else
-                       tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + forward * (vecs.x + nudge), MOVE_NORMAL, ent, ANTILAG_LATENCY(ent));
+                       tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + forward * (md.x + nudge), MOVE_NORMAL, ent, ANTILAG_LATENCY(ent));
        }
        else
-               tracebox(w_shotorg, mi, ma, w_shotorg + forward * (vecs.x + nudge), MOVE_NORMAL, ent);
+               tracebox(w_shotorg, mi, ma, w_shotorg + forward * (md.x + nudge), MOVE_NORMAL, ent);
        w_shotorg = trace_endpos - forward * nudge;
+
        // calculate the shotdir from the chosen shotorg
        if(W_DualWielding(ent))
                w_shotdir = s_forward;