From 3fd279ea6cad8f743e5311e75173b5b379b012d1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 26 May 2012 12:53:03 +0900 Subject: [PATCH] Use info strings for scoreboard names in nq. Nukes a strcpy and a buffer, and is one step closer to merged client data. --- nq/include/client.h | 3 ++- nq/source/cl_main.c | 7 +++++++ nq/source/cl_parse.c | 7 ++++++- nq/source/sbar.c | 8 ++++---- qw/include/client.h | 3 +-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/nq/include/client.h b/nq/include/client.h index 11efad0d2..a25a77279 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -54,7 +54,8 @@ typedef struct usercmd_s typedef struct { - char name[MAX_SCOREBOARDNAME]; + struct info_s *info; + struct info_key_s *name; float entertime; int frags; int topcolor; diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index 553dbe12e..a4de17d10 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -199,6 +199,13 @@ CL_ClearState (void) if (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 memset (&cl, 0, sizeof (cl)); cl.chase = 1; diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index 0efd4a861..fed31b3e1 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -365,6 +365,10 @@ CL_ParseServerInfo (void) goto done; } 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 cl.gametype = MSG_ReadByte (net_message); @@ -1023,7 +1027,8 @@ CL_ParseServerMessage (void) if (i >= cl.maxclients) Host_Error ("CL_ParseServerMessage: svc_updatename > " "MAX_SCOREBOARD"); - strcpy (cl.scores[i].name, MSG_ReadString (net_message)); + Info_SetValueForKey (cl.scores[i].info, "name", + MSG_ReadString (net_message), 0); break; case svc_updatefrags: diff --git a/nq/source/sbar.c b/nq/source/sbar.c index 1ca3b0ae6..da2f11e25 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -522,7 +522,7 @@ Sbar_SortFrags (void) // sort by frags scoreboardlines = 0; for (i = 0; i < cl.maxclients; i++) { - if (cl.scores[i].name[0]) { + if (cl.scores[i].name->value[0]) { fragsort[scoreboardlines] = i; scoreboardlines++; } @@ -592,7 +592,7 @@ draw_frags (view_t *view) for (i = 0; i < l; i++) { k = fragsort[i]; s = &cl.scores[k]; - if (!s->name[0]) + if (!s->name->value[0]) continue; // draw background @@ -1044,7 +1044,7 @@ Sbar_DeathmatchOverlay (view_t *view) for (i = 0; i < l; i++) { k = fragsort[i]; s = &cl.scores[k]; - if (!s->name[0]) + if (!s->name->value[0]) continue; // draw background @@ -1060,7 +1060,7 @@ Sbar_DeathmatchOverlay (view_t *view) draw_character (view, x - 4, y, 12); // draw name - draw_string (view, x + 64, y, s->name); + draw_string (view, x + 64, y, s->name->value); y += 10; } diff --git a/qw/include/client.h b/qw/include/client.h index 41418e68f..7ec5942de 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -67,6 +67,7 @@ typedef struct player_info_s // scoreboard information struct info_key_s *name; + struct info_key_s *team; float entertime; int frags; int ping; @@ -76,10 +77,8 @@ typedef struct player_info_s int topcolor; int bottomcolor; struct info_key_s *skinname; - struct info_key_s *team; struct skin_s *skin; - int spectator; int stats[MAX_CL_STATS]; // health, etc int prevcount;