DP_SV_PING_PACKETLOSS: expose packet loss to server QC
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Dec 2009 08:48:36 +0000 (08:48 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Dec 2009 08:48:36 +0000 (08:48 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9638 d7cf8633-e32d-0410-b094-e92efae38249

progsvm.h
prvm_edict.c
prvm_exec.c
sv_user.c
svvm_cmds.c

index 2dd9e0f..5136c4c 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -212,6 +212,8 @@ typedef struct prvm_prog_fieldoffsets_s
        int nodrawtoclient; // ssqc
        int pflags; // ssqc
        int ping; // ssqc
+       int packetloss; // ssqc
+       int movementloss; // ssqc
        int pitch_speed; // ssqc / csqc
        int playermodel; // ssqc
        int playerskin; // ssqc
index 8b4ddf0..828ebcf 100644 (file)
@@ -1609,6 +1609,8 @@ void PRVM_FindOffsets(void)
        prog->fieldoffsets.nodrawtoclient                 = PRVM_ED_FindFieldOffset("nodrawtoclient");
        prog->fieldoffsets.pflags                         = PRVM_ED_FindFieldOffset("pflags");
        prog->fieldoffsets.ping                           = PRVM_ED_FindFieldOffset("ping");
+       prog->fieldoffsets.packetloss                     = PRVM_ED_FindFieldOffset("ping_packetloss");
+       prog->fieldoffsets.movementloss                   = PRVM_ED_FindFieldOffset("ping_movementloss");
        prog->fieldoffsets.pitch_speed                    = PRVM_ED_FindFieldOffset("pitch_speed");
        prog->fieldoffsets.playermodel                    = PRVM_ED_FindFieldOffset("playermodel");
        prog->fieldoffsets.playerskin                     = PRVM_ED_FindFieldOffset("playerskin");
index f32ff3f..9713022 100644 (file)
@@ -212,7 +212,7 @@ void PRVM_PrintFunctionStatements (const char *name)
                        endstatement = prog->functions[i].first_statement;
 
        // now print the range of statements
-       Con_Printf("%s progs: disassembly of function %s (statements %i-%i):\n", PRVM_NAME, name, firststatement, endstatement);
+       Con_Printf("%s progs: disassembly of function %s (statements %i-%i, locals %i-%i):\n", PRVM_NAME, name, firststatement, endstatement, func->parm_start, func->parm_start + func->locals - 1);
        for (i = firststatement;i < endstatement;i++)
        {
                PRVM_PrintStatement(prog->statements + i);
index 2ca62d7..dfa9bb2 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -696,6 +696,7 @@ void SV_ApplyClientMove (void)
 {
        prvm_eval_t *val;
        usercmd_t *move = &host_client->cmd;
+       int j, movementloss, packetloss;
 
        if (!move->receivetime)
                return;
@@ -714,6 +715,18 @@ void SV_ApplyClientMove (void)
                host_client->edict->fields.server->impulse = move->impulse;
        // only send the impulse to qc once
        move->impulse = 0;
+
+       movementloss = packetloss = 0;
+       if(host_client->netconnection)
+       {
+               for (j = 0;j < NETGRAPH_PACKETS;j++)
+                       if (host_client->netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
+                               packetloss++;
+               for (j = 0;j < NETGRAPH_PACKETS;j++)
+                       if (host_client->movement_count[j] < 0)
+                               movementloss++;
+       }
+
        VectorCopy(move->viewangles, host_client->edict->fields.server->v_angle);
        if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button3))) val->_float = ((move->buttons >> 2) & 1);
        if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.button4))) val->_float = ((move->buttons >> 3) & 1);
@@ -738,6 +751,8 @@ void SV_ApplyClientMove (void)
        if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_trace_endpos))) VectorCopy(move->cursor_impact, val->vector);
        if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.cursor_trace_ent))) val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM(move->cursor_entitynumber));
        if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ping))) val->_float = host_client->ping * 1000.0;
+       if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.packetloss))) val->_float = packetloss / (float) NETGRAPH_PACKETS;
+       if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.movementloss))) val->_float = movementloss / (float) NETGRAPH_PACKETS;
 }
 
 void SV_FrameLost(int framenum)
index e0e5dc3..a7819b0 100644 (file)
@@ -148,6 +148,7 @@ char *vm_sv_extensions =
 "DP_SV_ONENTITYNOSPAWNFUNCTION "
 "DP_SV_ONENTITYPREPOSTSPAWNFUNCTION "
 "DP_SV_PING "
+"DP_SV_PING_PACKETLOSS "
 "DP_SV_PLAYERPHYSICS "
 "DP_SV_POINTPARTICLES "
 "DP_SV_POINTSOUND "