Use info strings for scoreboard names in nq.

Nukes a strcpy and a buffer, and is one step closer to merged client data.
This commit is contained in:
Bill Currie 2012-05-26 12:53:03 +09:00
parent bf751cafe0
commit 3fd279ea6c
5 changed files with 20 additions and 8 deletions

View file

@ -54,7 +54,8 @@ typedef struct usercmd_s
typedef struct typedef struct
{ {
char name[MAX_SCOREBOARDNAME]; struct info_s *info;
struct info_key_s *name;
float entertime; float entertime;
int frags; int frags;
int topcolor; int topcolor;

View file

@ -199,6 +199,13 @@ CL_ClearState (void)
if (cl.edicts) if (cl.edicts)
PL_Free (cl.edicts); PL_Free (cl.edicts);
if (cl.scores) {
int i;
for (i = 0; i < cl.maxclients; i++)
Info_Destroy (cl.scores[i].info);
}
// wipe the entire cl structure // wipe the entire cl structure
memset (&cl, 0, sizeof (cl)); memset (&cl, 0, sizeof (cl));
cl.chase = 1; cl.chase = 1;

View file

@ -365,6 +365,10 @@ CL_ParseServerInfo (void)
goto done; goto done;
} }
cl.scores = Hunk_AllocName (cl.maxclients * sizeof (*cl.scores), "scores"); cl.scores = Hunk_AllocName (cl.maxclients * sizeof (*cl.scores), "scores");
for (i = 0; i < cl.maxclients; i++) {
cl.scores[i].info = Info_ParseString ("name\\", 0, 0);
cl.scores[i].name = Info_Key (cl.scores[i].info, "name");
}
// parse gametype // parse gametype
cl.gametype = MSG_ReadByte (net_message); cl.gametype = MSG_ReadByte (net_message);
@ -1023,7 +1027,8 @@ CL_ParseServerMessage (void)
if (i >= cl.maxclients) if (i >= cl.maxclients)
Host_Error ("CL_ParseServerMessage: svc_updatename > " Host_Error ("CL_ParseServerMessage: svc_updatename > "
"MAX_SCOREBOARD"); "MAX_SCOREBOARD");
strcpy (cl.scores[i].name, MSG_ReadString (net_message)); Info_SetValueForKey (cl.scores[i].info, "name",
MSG_ReadString (net_message), 0);
break; break;
case svc_updatefrags: case svc_updatefrags:

View file

@ -522,7 +522,7 @@ Sbar_SortFrags (void)
// sort by frags // sort by frags
scoreboardlines = 0; scoreboardlines = 0;
for (i = 0; i < cl.maxclients; i++) { for (i = 0; i < cl.maxclients; i++) {
if (cl.scores[i].name[0]) { if (cl.scores[i].name->value[0]) {
fragsort[scoreboardlines] = i; fragsort[scoreboardlines] = i;
scoreboardlines++; scoreboardlines++;
} }
@ -592,7 +592,7 @@ draw_frags (view_t *view)
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
k = fragsort[i]; k = fragsort[i];
s = &cl.scores[k]; s = &cl.scores[k];
if (!s->name[0]) if (!s->name->value[0])
continue; continue;
// draw background // draw background
@ -1044,7 +1044,7 @@ Sbar_DeathmatchOverlay (view_t *view)
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
k = fragsort[i]; k = fragsort[i];
s = &cl.scores[k]; s = &cl.scores[k];
if (!s->name[0]) if (!s->name->value[0])
continue; continue;
// draw background // draw background
@ -1060,7 +1060,7 @@ Sbar_DeathmatchOverlay (view_t *view)
draw_character (view, x - 4, y, 12); draw_character (view, x - 4, y, 12);
// draw name // draw name
draw_string (view, x + 64, y, s->name); draw_string (view, x + 64, y, s->name->value);
y += 10; y += 10;
} }

View file

@ -67,6 +67,7 @@ typedef struct player_info_s
// scoreboard information // scoreboard information
struct info_key_s *name; struct info_key_s *name;
struct info_key_s *team;
float entertime; float entertime;
int frags; int frags;
int ping; int ping;
@ -76,10 +77,8 @@ typedef struct player_info_s
int topcolor; int topcolor;
int bottomcolor; int bottomcolor;
struct info_key_s *skinname; struct info_key_s *skinname;
struct info_key_s *team;
struct skin_s *skin; struct skin_s *skin;
int spectator; int spectator;
int stats[MAX_CL_STATS]; // health, etc int stats[MAX_CL_STATS]; // health, etc
int prevcount; int prevcount;