]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
optimized SV_WriteClientdataToMessage by caching weaponmodelindex in client structure...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 26 Oct 2005 02:09:48 +0000 (02:09 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 26 Oct 2005 02:09:48 +0000 (02:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5769 d7cf8633-e32d-0410-b094-e92efae38249

server.h
sv_main.c

index a64f43c6cbe1111bca15a53950162535cc8f88f3..bbe93156aa84bc2e87867c37d8d17de3a963bc74 100644 (file)
--- a/server.h
+++ b/server.h
@@ -163,6 +163,10 @@ typedef struct client_s
        // latest received clc_ackframe (used to detect packet loss)
        int latestframenum;
 
+       // cache weaponmodel name lookups
+       char weaponmodel[MAX_QPATH];
+       int weaponmodelindex;
+
        entityframe_database_t *entitydatabase;
        entityframe4_database_t *entitydatabase4;
        entityframe5_database_t *entitydatabase5;
@@ -316,6 +320,7 @@ void SV_BroadcastPrint(const char *msg);
 void SV_BroadcastPrintf(const char *fmt, ...);
 
 void SV_Physics (void);
+void SV_Physics_ClientEntity (prvm_edict_t *ent);
 
 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
 qboolean SV_CheckBottom (prvm_edict_t *ent);
index 73ddd1ef3b8ed7e14b8eb2a48be9f6723fdd9f57..47897a61f6c6d0d6a90e2904d0a92fcb84be1b12 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -930,7 +930,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        prvm_eval_t     *val;
        vec3_t  punchvector;
        qbyte   viewzoom;
-       int             weaponmodelindex;
+       const char *s;
 
 //
 // send a damage message
@@ -974,7 +974,14 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        if ((val = PRVM_GETEDICTFIELDVALUE(ent, eval_punchvector)))
                VectorCopy(val->vector, punchvector);
 
-       weaponmodelindex = SV_ModelIndex(PRVM_GetString(ent->fields.server->weaponmodel), 1);
+       // FIXME: cache weapon model name and index in client struct to save time
+       // (this search can be almost 1% of cpu time!)
+       s = PRVM_GetString(ent->fields.server->weaponmodel);
+       if (strcmp(s, client->weaponmodel))
+       {
+               strlcpy(client->weaponmodel, s, sizeof(client->weaponmodel));
+               client->weaponmodelindex = SV_ModelIndex(s, 1);
+       }
 
        viewzoom = 255;
        if ((val = PRVM_GETEDICTFIELDVALUE(ent, eval_viewzoom)))
@@ -1007,7 +1014,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
        stats[STAT_ITEMS] = items;
        stats[STAT_WEAPONFRAME] = ent->fields.server->weaponframe;
        stats[STAT_ARMOR] = ent->fields.server->armorvalue;
-       stats[STAT_WEAPON] = weaponmodelindex;
+       stats[STAT_WEAPON] = client->weaponmodelindex;
        stats[STAT_HEALTH] = ent->fields.server->health;
        stats[STAT_AMMO] = ent->fields.server->currentammo;
        stats[STAT_SHELLS] = ent->fields.server->ammo_shells;