From ffa79eed01d63acd2b9ac589d266fcbe8d1501f6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 9 Jan 2012 16:22:39 +0900 Subject: [PATCH] Don't lie about the number of models. The renderer being told there were 2048 models when there were only ~160 was a bit of an unpleasant surprise :P --- nq/include/client.h | 2 ++ nq/source/cl_parse.c | 20 ++++++++-------- qw/include/client.h | 2 ++ qw/source/cl_demo.c | 4 ++-- qw/source/cl_parse.c | 54 ++++++++++++++++++++++---------------------- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/nq/include/client.h b/nq/include/client.h index 249c53fab..5690f92cc 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -219,6 +219,8 @@ typedef struct struct model_s *model_precache[MAX_MODELS]; struct sfx_s *sound_precache[MAX_SOUNDS]; + int nummodels; + int numsounds; struct plitem_s *edicts; struct plitem_s *worldspawn; diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index fdf5cf353..1876b2af6 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -315,7 +315,7 @@ map_ent (const char *mapname) static void CL_NewMap (const char *mapname) { - R_NewMap (cl.worldmodel, cl.model_precache, MAX_MODELS); + R_NewMap (cl.worldmodel, cl.model_precache, cl.nummodels); Con_NewMap (); Hunk_Check (); // make sure nothing is hurt Sbar_CenterPrint (0); @@ -338,7 +338,7 @@ CL_ParseServerInfo (void) char model_precache[MAX_MODELS][MAX_QPATH]; char sound_precache[MAX_SOUNDS][MAX_QPATH]; const char *str; - int nummodels, numsounds, i; + int i; Sys_MaskPrintf (SYS_DEV, "Serverinfo packet received.\n"); @@ -387,36 +387,36 @@ CL_ParseServerInfo (void) // precache models memset (cl.model_precache, 0, sizeof (cl.model_precache)); - for (nummodels = 1;; nummodels++) { + for (cl.nummodels = 1;; cl.nummodels++) { str = MSG_ReadString (net_message); if (!str[0]) break; - if (nummodels == MAX_MODELS) { + if (cl.nummodels >= MAX_MODELS) { Sys_Printf ("Server sent too many model precaches\n"); goto done; } - strcpy (model_precache[nummodels], str); + strcpy (model_precache[cl.nummodels], str); Mod_TouchModel (str); } // precache sounds memset (cl.sound_precache, 0, sizeof (cl.sound_precache)); - for (numsounds = 1;; numsounds++) { + for (cl.numsounds = 1;; cl.numsounds++) { str = MSG_ReadString (net_message); if (!str[0]) break; - if (numsounds == MAX_SOUNDS) { + if (cl.numsounds >= MAX_SOUNDS) { Sys_Printf ("Server sent too many sound precaches\n"); goto done; } - strcpy (sound_precache[numsounds], str); + strcpy (sound_precache[cl.numsounds], str); } // now we try to load everything else until a cache allocation fails if (model_precache[1]) map_cfg (model_precache[1], 0); - for (i = 1; i < nummodels; i++) { + for (i = 1; i < cl.nummodels; i++) { cl.model_precache[i] = Mod_ForName (model_precache[i], false); if (cl.model_precache[i] == NULL) { Sys_Printf ("Model %s not found\n", model_precache[i]); @@ -425,7 +425,7 @@ CL_ParseServerInfo (void) CL_KeepaliveMessage (); } - for (i = 1; i < numsounds; i++) { + for (i = 1; i < cl.numsounds; i++) { cl.sound_precache[i] = S_PrecacheSound (sound_precache[i]); CL_KeepaliveMessage (); } diff --git a/qw/include/client.h b/qw/include/client.h index ffaae3c54..e10db48f6 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -276,6 +276,8 @@ typedef struct struct model_s *model_precache[MAX_MODELS]; struct sfx_s *sound_precache[MAX_SOUNDS]; + int nummodels; + int numsounds; struct plitem_s *edicts; struct plitem_s *worldspawn; diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 5258932c0..39adb3637 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -755,10 +755,10 @@ CL_Record (const char *argv1, int track) for (ent = cl_static_entities; ent; ent = ent->unext) { MSG_WriteByte (&buf, svc_spawnstatic); - for (j = 1; j < MAX_MODELS; j++) + for (j = 1; j < cl.nummodels; j++) if (ent->model == cl.model_precache[j]) break; - if (j == MAX_MODELS) + if (j == cl.nummodels) MSG_WriteByte (&buf, 0); else MSG_WriteByte (&buf, j); diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 9368edea3..8a8f0dd55 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -302,7 +302,7 @@ CL_NewMap (const char *mapname) { cl_static_entities = 0; cl_static_tail = &cl_static_entities; - R_NewMap (cl.worldmodel, cl.model_precache, MAX_MODELS); + R_NewMap (cl.worldmodel, cl.model_precache, cl.nummodels); Team_NewMap (); Con_NewMap (); Hunk_Check (); // make sure nothing is hurt @@ -344,7 +344,7 @@ Model_NextDownload (void) if (cl.model_name[1]) map_cfg (cl.model_name[1], 0); - for (i = 1; i < MAX_MODELS; i++) { + for (i = 1; i < cl.nummodels; i++) { char *info_key = 0; if (!cl.model_name[i][0]) @@ -426,7 +426,7 @@ Sound_NextDownload (void) return; // started a download } - for (i = 1; i < MAX_SOUNDS; i++) { + for (i = 1; i < cl.numsounds; i++) { if (!cl.sound_name[i][0]) break; cl.sound_precache[i] = S_PrecacheSound (cl.sound_name[i]); @@ -855,21 +855,21 @@ static void CL_ParseSoundlist (void) { const char *str; - int numsounds, n; + int n; // precache sounds // memset (cl.sound_precache, 0, sizeof (cl.sound_precache)); - numsounds = MSG_ReadByte (net_message); + cl.numsounds = MSG_ReadByte (net_message); for (;;) { str = MSG_ReadString (net_message); if (!str[0]) break; - numsounds++; - if (numsounds == MAX_SOUNDS) + cl.numsounds++; + if (cl.numsounds >= MAX_SOUNDS) Host_Error ("Server sent too many sound_precache"); - strcpy (cl.sound_name[numsounds], str); + strcpy (cl.sound_name[cl.numsounds], str); } n = MSG_ReadByte (net_message); @@ -889,36 +889,36 @@ CL_ParseSoundlist (void) static void CL_ParseModellist (void) { - int nummodels, n; + int n; const char *str; // precache models and note certain default indexes - nummodels = MSG_ReadByte (net_message); + cl.nummodels = MSG_ReadByte (net_message); for (;;) { str = MSG_ReadString (net_message); if (!str[0]) break; - nummodels++; - if (nummodels == MAX_MODELS) + cl.nummodels++; + if (cl.nummodels >= MAX_MODELS) Host_Error ("Server sent too many model_precache"); - strcpy (cl.model_name[nummodels], str); + strcpy (cl.model_name[cl.nummodels], str); - if (!strcmp (cl.model_name[nummodels], "progs/spike.mdl")) - cl_spikeindex = nummodels; - else if (!strcmp (cl.model_name[nummodels], "progs/player.mdl")) - cl_playerindex = nummodels; - else if (!strcmp (cl.model_name[nummodels], "progs/flag.mdl")) - cl_flagindex = nummodels; + if (!strcmp (cl.model_name[cl.nummodels], "progs/spike.mdl")) + cl_spikeindex = cl.nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/player.mdl")) + cl_playerindex = cl.nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/flag.mdl")) + cl_flagindex = cl.nummodels; // for deadbodyfilter & gib filter - else if (!strcmp (cl.model_name[nummodels], "progs/h_player.mdl")) - cl_h_playerindex = nummodels; - else if (!strcmp (cl.model_name[nummodels], "progs/gib1.mdl")) - cl_gib1index = nummodels; - else if (!strcmp (cl.model_name[nummodels], "progs/gib2.mdl")) - cl_gib2index = nummodels; - else if (!strcmp (cl.model_name[nummodels], "progs/gib3.mdl")) - cl_gib3index = nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/h_player.mdl")) + cl_h_playerindex = cl.nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib1.mdl")) + cl_gib1index = cl.nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib2.mdl")) + cl_gib2index = cl.nummodels; + else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib3.mdl")) + cl_gib3index = cl.nummodels; } n = MSG_ReadByte (net_message);