From: havoc Date: Wed, 26 Oct 2005 02:09:48 +0000 (+0000) Subject: optimized SV_WriteClientdataToMessage by caching weaponmodelindex in client structure... X-Git-Tag: xonotic-v0.1.0preview~4515 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=28518d468abf40ed92227387e69ccb5b534e4afb;p=xonotic%2Fdarkplaces.git optimized SV_WriteClientdataToMessage by caching weaponmodelindex in client structure, saving 1% cpu time in masque.bsp git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5769 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/server.h b/server.h index a64f43c6..bbe93156 100644 --- 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); diff --git a/sv_main.c b/sv_main.c index 73ddd1ef..47897a61 100644 --- 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;