cache some info strings (team and skin from client user info) and values

(no_pogo_stick and teamplay from server info) to cut down on the calls to
Info_ValueForKey (from over 550k to 23.5k in spam2.qwd).
This commit is contained in:
Bill Currie 2001-11-04 19:06:50 +00:00
parent a2ed608ee7
commit 7c5c53774f
6 changed files with 61 additions and 41 deletions

View file

@ -87,6 +87,8 @@ typedef struct player_info_s
// skin information // skin information
int topcolor; int topcolor;
int bottomcolor; int bottomcolor;
struct info_key_s *skinname;
struct info_key_s *team;
int _topcolor; int _topcolor;
int _bottomcolor; int _bottomcolor;
@ -258,8 +260,10 @@ typedef struct
float stdver; float stdver;
// serverinfo mirrors // serverinfo mirrors
int watervis;
int chase; int chase;
int no_pogo_stick;
int teamplay;
int watervis;
// refresh related state // refresh related state
struct model_s *worldmodel; // cl_entitites[0].model struct model_s *worldmodel; // cl_entitites[0].model

View file

@ -597,6 +597,12 @@ CL_FullServerinfo_f (void)
if ((p = Info_ValueForKey (cl.serverinfo, "chase")) && *p) { if ((p = Info_ValueForKey (cl.serverinfo, "chase")) && *p) {
cl.chase = atof (p); cl.chase = atof (p);
} }
if ((p = Info_ValueForKey (cl.serverinfo, "no_pogo_stick")) && *p) {
cl.no_pogo_stick = atof (p);
}
if ((p = Info_ValueForKey (cl.serverinfo, "teamplay")) && *p) {
cl.teamplay = atof (p);
}
if ((p = Info_ValueForKey (cl.serverinfo, "watervis")) && *p) { if ((p = Info_ValueForKey (cl.serverinfo, "watervis")) && *p) {
cl.watervis = atof (p); cl.watervis = atof (p);
} }
@ -1469,7 +1475,7 @@ Host_Frame (float time)
// fetch results from server // fetch results from server
CL_ReadPackets (); CL_ReadPackets ();
if (atoi (Info_ValueForKey (cl.serverinfo, "no_pogo_stick"))) if (cl.no_pogo_stick)
Cvar_Set (no_pogo_stick, "1"); Cvar_Set (no_pogo_stick, "1");
// send intentions now // send intentions now

View file

@ -47,6 +47,7 @@ static const char rcsid[] =
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/console.h" #include "QF/console.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/hash.h"
#include "QF/msg.h" #include "QF/msg.h"
#include "QF/screen.h" #include "QF/screen.h"
#include "QF/sound.h" #include "QF/sound.h"
@ -1002,12 +1003,25 @@ CL_ParseClientdata (void)
void void
CL_ProcessUserInfo (int slot, player_info_t *player) CL_ProcessUserInfo (int slot, player_info_t *player)
{ {
char skin[512];
const char *s;
s = Info_ValueForKey (player->userinfo, "skin");
COM_StripExtension (s, skin); // FIXME buffer overflow
if (!strequal (s, skin))
Info_SetValueForKey (player->userinfo, "skin", skin, 1);
strncpy (player->name, Info_ValueForKey (player->userinfo, "name"), strncpy (player->name, Info_ValueForKey (player->userinfo, "name"),
sizeof (player->name) - 1); sizeof (player->name) - 1);
player->_topcolor = player->_bottomcolor = -1; player->_topcolor = player->_bottomcolor = -1;
player->topcolor = atoi (Info_ValueForKey (player->userinfo, "topcolor")); player->topcolor = atoi (Info_ValueForKey (player->userinfo, "topcolor"));
player->bottomcolor = player->bottomcolor =
atoi (Info_ValueForKey (player->userinfo, "bottomcolor")); atoi (Info_ValueForKey (player->userinfo, "bottomcolor"));
while (!(player->team = Hash_Find (player->userinfo->tab, "team")))
Info_SetValueForKey (player->userinfo, "team", "", 1);
while (!(player->skinname = Hash_Find (player->userinfo->tab, "skin")))
Info_SetValueForKey (player->userinfo, "skin", "", 1);
if (Info_ValueForKey (player->userinfo, "*spectator")[0]) if (Info_ValueForKey (player->userinfo, "*spectator")[0])
player->spectator = true; player->spectator = true;
else else

View file

@ -177,13 +177,22 @@ CL_Skin_Init (void)
"pants will match"); "pants will match");
} }
static void
skin_f (cvar_t *var)
{
char *s = Hunk_TempAlloc (strlen (var->string) + 1);
COM_StripExtension (var->string, s);
Cvar_Set (var, s);
Cvar_Info (var);
}
void void
CL_Skin_Init_Cvars (void) CL_Skin_Init_Cvars (void)
{ {
Skin_Init_Cvars (); Skin_Init_Cvars ();
noskins = Cvar_Get ("noskins", "0", CVAR_NONE, NULL, //XXX FIXME noskins = Cvar_Get ("noskins", "0", CVAR_NONE, NULL, //XXX FIXME
"set to 1 to not download new skins"); "set to 1 to not download new skins");
skin = Cvar_Get ("skin", "", CVAR_ARCHIVE | CVAR_USERINFO, Cvar_Info, skin = Cvar_Get ("skin", "", CVAR_ARCHIVE | CVAR_USERINFO, skin_f,
"Players skin"); "Players skin");
topcolor = Cvar_Get ("topcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO, topcolor = Cvar_Get ("topcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO,
Cvar_Info, "Players color on top"); Cvar_Info, "Players color on top");
@ -194,7 +203,6 @@ CL_Skin_Init_Cvars (void)
void void
CL_NewTranslation (int slot, skin_t *skin) CL_NewTranslation (int slot, skin_t *skin)
{ {
char s[512];
player_info_t *player; player_info_t *player;
if (slot > MAX_CLIENTS) if (slot > MAX_CLIENTS)
@ -204,16 +212,13 @@ CL_NewTranslation (int slot, skin_t *skin)
if (!player->name[0]) if (!player->name[0])
return; return;
strcpy (s, Info_ValueForKey (player->userinfo, "skin")); if (player->skin && !strequal (player->skinname->value, player->skin->name))
COM_StripExtension (s, s);
if (player->skin && !strequal (s, player->skin->name))
player->skin = NULL; player->skin = NULL;
if (player->_topcolor != player->topcolor || if (player->_topcolor != player->topcolor ||
player->_bottomcolor != player->bottomcolor || !player->skin) { player->_bottomcolor != player->bottomcolor || !player->skin) {
player->_topcolor = player->topcolor; player->_topcolor = player->topcolor;
player->_bottomcolor = player->bottomcolor; player->_bottomcolor = player->bottomcolor;
Skin_Set_Translate (player->topcolor, player->bottomcolor, Skin_Set_Translate (player->topcolor, player->bottomcolor,
player->translations); player->translations);
if (!player->skin) if (!player->skin)

View file

@ -388,14 +388,13 @@ void
Sbar_SortTeams (void) Sbar_SortTeams (void)
{ {
char t[16 + 1]; char t[16 + 1];
int teamplay, i, j, k; int i, j, k;
player_info_t *s; player_info_t *s;
// request new ping times every two second // request new ping times every two second
scoreboardteams = 0; scoreboardteams = 0;
teamplay = atoi (Info_ValueForKey (cl.serverinfo, "teamplay")); if (!cl.teamplay)
if (!teamplay)
return; return;
// sort the teams // sort the teams
@ -412,7 +411,7 @@ Sbar_SortTeams (void)
// find his team in the list // find his team in the list
t[16] = 0; t[16] = 0;
strncpy (t, Info_ValueForKey (s->userinfo, "team"), 16); strncpy (t, s->team->value, 16);
if (!t || !t[0]) if (!t || !t[0])
continue; // not on team continue; // not on team
for (j = 0; j < scoreboardteams; j++) for (j = 0; j < scoreboardteams; j++)
@ -751,8 +750,8 @@ Sbar_Draw (int swap)
// main screen deathmatch rankings // main screen deathmatch rankings
// if we're dead show team scores in team games // if we're dead show team scores in team games
if (cl.stats[STAT_HEALTH] <= 0 && !cl.spectator) if (cl.stats[STAT_HEALTH] <= 0 && !cl.spectator)
if (atoi (Info_ValueForKey (cl.serverinfo, "teamplay")) > 0 && if (cl.teamplay > 0 && !sb_showscores)
!sb_showscores) Sbar_TeamOverlay (); Sbar_TeamOverlay ();
else else
Sbar_DeathmatchOverlay (0); Sbar_DeathmatchOverlay (0);
else if (sb_showscores) else if (sb_showscores)
@ -805,14 +804,12 @@ void
Sbar_TeamOverlay (void) Sbar_TeamOverlay (void)
{ {
char num[12], team[5]; char num[12], team[5];
int pavg, plow, phigh, teamplay, i, k, l, x, y; int pavg, plow, phigh, i, k, l, x, y;
qpic_t *pic; qpic_t *pic;
team_t *tm; team_t *tm;
// request new ping times every two second // request new ping times every two second
teamplay = atoi (Info_ValueForKey (cl.serverinfo, "teamplay")); if (!cl.teamplay) {
if (!teamplay) {
Sbar_DeathmatchOverlay (0); Sbar_DeathmatchOverlay (0);
return; return;
} }
@ -873,8 +870,7 @@ Sbar_TeamOverlay (void)
snprintf (num, sizeof (num), "%5i", tm->players); snprintf (num, sizeof (num), "%5i", tm->players);
Draw_String (x + 104 + 88, y, num); Draw_String (x + 104 + 88, y, num);
if (!strncmp (Info_ValueForKey (cl.players[cl.playernum].userinfo, if (strnequal (cl.players[cl.playernum].team->value, tm->team, 16)) {
"team"), tm->team, 16)) {
Draw_Character (x + 104 - 8, y, 16); Draw_Character (x + 104 - 8, y, 16);
Draw_Character (x + 104 + 32, y, 17); Draw_Character (x + 104 + 32, y, 17);
} }
@ -894,7 +890,7 @@ void
Sbar_DeathmatchOverlay (int start) Sbar_DeathmatchOverlay (int start)
{ {
char num[12], team[5]; char num[12], team[5];
int minutes, teamplay, total, top, bottom, f, i, k, l, p, x, y; int minutes, total, top, bottom, f, i, k, l, p, x, y;
int skip = 10; int skip = 10;
player_info_t *s; player_info_t *s;
qpic_t *pic; qpic_t *pic;
@ -913,8 +909,6 @@ Sbar_DeathmatchOverlay (int start)
SZ_Print (&cls.netchan.message, "pings"); SZ_Print (&cls.netchan.message, "pings");
} }
teamplay = atoi (Info_ValueForKey (cl.serverinfo, "teamplay"));
scr_copyeverything = 1; scr_copyeverything = 1;
scr_fullupdate = 0; scr_fullupdate = 0;
@ -932,7 +926,7 @@ Sbar_DeathmatchOverlay (int start)
y = start; y = start;
else else
y = 24; y = 24;
if (teamplay) { if (cl.teamplay) {
x = 4; x = 4;
// 0 40 64 104 152 192 // 0 40 64 104 152 192
if (cl_showscoresuid->int_val == 0) if (cl_showscoresuid->int_val == 0)
@ -988,7 +982,7 @@ Sbar_DeathmatchOverlay (int start)
if (s->spectator) { if (s->spectator) {
Draw_String (x + 40, y, "(spectator)"); Draw_String (x + 40, y, "(spectator)");
// draw name // draw name
if (teamplay) if (cl.teamplay)
Draw_String (x + 152 + 40, y, s->name); Draw_String (x + 152 + 40, y, s->name);
else else
Draw_String (x + 152, y, s->name); Draw_String (x + 152, y, s->name);
@ -1030,13 +1024,13 @@ Sbar_DeathmatchOverlay (int start)
Draw_Character (x + 136, y, 17); Draw_Character (x + 136, y, 17);
} }
// team // team
if (teamplay) { if (cl.teamplay) {
team[4] = 0; team[4] = 0;
strncpy (team, Info_ValueForKey (s->userinfo, "team"), 4); strncpy (team, s->team->value, 4);
Draw_String (x + 152, y, team); Draw_String (x + 152, y, team);
} }
// draw name // draw name
if (teamplay) if (cl.teamplay)
Draw_String (x + 152 + 40, y, s->name); Draw_String (x + 152 + 40, y, s->name);
else else
Draw_String (x + 152, y, s->name); Draw_String (x + 152, y, s->name);
@ -1058,7 +1052,7 @@ Sbar_DeathmatchOverlay (int start)
void void
Sbar_MiniDeathmatchOverlay (void) Sbar_MiniDeathmatchOverlay (void)
{ {
int numlines, teamplay, top, bottom, f, i, k, x, y; int numlines, top, bottom, f, i, k, x, y;
char name[16 + 1], num[12], team[5]; char name[16 + 1], num[12], team[5];
player_info_t *s; player_info_t *s;
team_t *tm; team_t *tm;
@ -1066,8 +1060,6 @@ Sbar_MiniDeathmatchOverlay (void)
if (vid.width < 512 || !sb_lines) if (vid.width < 512 || !sb_lines)
return; // not enuff room return; // not enuff room
teamplay = atoi (Info_ValueForKey (cl.serverinfo, "teamplay"));
scr_copyeverything = 1; scr_copyeverything = 1;
scr_fullupdate = 0; scr_fullupdate = 0;
@ -1131,15 +1123,15 @@ Sbar_MiniDeathmatchOverlay (void)
Draw_Character (x + 32, y, 17); Draw_Character (x + 32, y, 17);
} }
// team // team
if (teamplay) { if (cl.teamplay) {
team[4] = 0; team[4] = 0;
strncpy (team, Info_ValueForKey (s->userinfo, "team"), 4); strncpy (team, s->team->value, 4);
Draw_String (x + 48, y, team); Draw_String (x + 48, y, s->team->value);
} }
// draw name // draw name
name[16] = 0; name[16] = 0;
strncpy (name, s->name, 16); strncpy (name, s->name, 16);
if (teamplay) if (cl.teamplay)
Draw_String (x + 48 + 40, y, name); Draw_String (x + 48 + 40, y, name);
else else
Draw_String (x + 48, y, name); Draw_String (x + 48, y, name);
@ -1147,7 +1139,7 @@ Sbar_MiniDeathmatchOverlay (void)
} }
// draw teams if room // draw teams if room
if (vid.width < 640 || !teamplay) if (vid.width < 640 || !cl.teamplay)
return; return;
// draw separator // draw separator
@ -1172,8 +1164,7 @@ Sbar_MiniDeathmatchOverlay (void)
snprintf (num, sizeof (num), "%5i", tm->frags); snprintf (num, sizeof (num), "%5i", tm->frags);
Draw_String (x + 40, y, num); Draw_String (x + 40, y, num);
if (!strncmp (Info_ValueForKey (cl.players[cl.playernum].userinfo, if (strnequal (cl.players[cl.playernum].team->value, tm->team, 16)) {
"team"), tm->team, 16)) {
Draw_Character (x - 8, y, 16); Draw_Character (x - 8, y, 16);
Draw_Character (x + 32, y, 17); Draw_Character (x + 32, y, 17);
} }
@ -1189,8 +1180,8 @@ Sbar_IntermissionOverlay (void)
scr_copyeverything = 1; scr_copyeverything = 1;
scr_fullupdate = 0; scr_fullupdate = 0;
if (atoi (Info_ValueForKey (cl.serverinfo, "teamplay")) > 0 if (cl.teamplay > 0 && !sb_showscores)
&& !sb_showscores) Sbar_TeamOverlay (); Sbar_TeamOverlay ();
else else
Sbar_DeathmatchOverlay (0); Sbar_DeathmatchOverlay (0);
} }

View file

@ -91,7 +91,7 @@ Skin_Find (player_info_t *sc)
if (allskins[0]) { if (allskins[0]) {
strncpy (name, allskins, sizeof (name)); strncpy (name, allskins, sizeof (name));
} else { } else {
if ((s = Info_ValueForKey (sc->userinfo, "skin")) && s[0]) if ((s = sc->skinname->value) && s[0])
strncpy (name, s, sizeof (name)); strncpy (name, s, sizeof (name));
else else
strncpy (name, baseskin->string, sizeof (name)); strncpy (name, baseskin->string, sizeof (name));