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
This commit is contained in:
Bill Currie 2012-01-09 16:22:39 +09:00
parent 12fd6bd390
commit ffa79eed01
5 changed files with 43 additions and 39 deletions

View file

@ -219,6 +219,8 @@ typedef struct
struct model_s *model_precache[MAX_MODELS]; struct model_s *model_precache[MAX_MODELS];
struct sfx_s *sound_precache[MAX_SOUNDS]; struct sfx_s *sound_precache[MAX_SOUNDS];
int nummodels;
int numsounds;
struct plitem_s *edicts; struct plitem_s *edicts;
struct plitem_s *worldspawn; struct plitem_s *worldspawn;

View file

@ -315,7 +315,7 @@ map_ent (const char *mapname)
static void static void
CL_NewMap (const char *mapname) 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 (); Con_NewMap ();
Hunk_Check (); // make sure nothing is hurt Hunk_Check (); // make sure nothing is hurt
Sbar_CenterPrint (0); Sbar_CenterPrint (0);
@ -338,7 +338,7 @@ CL_ParseServerInfo (void)
char model_precache[MAX_MODELS][MAX_QPATH]; char model_precache[MAX_MODELS][MAX_QPATH];
char sound_precache[MAX_SOUNDS][MAX_QPATH]; char sound_precache[MAX_SOUNDS][MAX_QPATH];
const char *str; const char *str;
int nummodels, numsounds, i; int i;
Sys_MaskPrintf (SYS_DEV, "Serverinfo packet received.\n"); Sys_MaskPrintf (SYS_DEV, "Serverinfo packet received.\n");
@ -387,36 +387,36 @@ CL_ParseServerInfo (void)
// precache models // precache models
memset (cl.model_precache, 0, sizeof (cl.model_precache)); memset (cl.model_precache, 0, sizeof (cl.model_precache));
for (nummodels = 1;; nummodels++) { for (cl.nummodels = 1;; cl.nummodels++) {
str = MSG_ReadString (net_message); str = MSG_ReadString (net_message);
if (!str[0]) if (!str[0])
break; break;
if (nummodels == MAX_MODELS) { if (cl.nummodels >= MAX_MODELS) {
Sys_Printf ("Server sent too many model precaches\n"); Sys_Printf ("Server sent too many model precaches\n");
goto done; goto done;
} }
strcpy (model_precache[nummodels], str); strcpy (model_precache[cl.nummodels], str);
Mod_TouchModel (str); Mod_TouchModel (str);
} }
// precache sounds // precache sounds
memset (cl.sound_precache, 0, sizeof (cl.sound_precache)); memset (cl.sound_precache, 0, sizeof (cl.sound_precache));
for (numsounds = 1;; numsounds++) { for (cl.numsounds = 1;; cl.numsounds++) {
str = MSG_ReadString (net_message); str = MSG_ReadString (net_message);
if (!str[0]) if (!str[0])
break; break;
if (numsounds == MAX_SOUNDS) { if (cl.numsounds >= MAX_SOUNDS) {
Sys_Printf ("Server sent too many sound precaches\n"); Sys_Printf ("Server sent too many sound precaches\n");
goto done; 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 // now we try to load everything else until a cache allocation fails
if (model_precache[1]) if (model_precache[1])
map_cfg (model_precache[1], 0); 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); cl.model_precache[i] = Mod_ForName (model_precache[i], false);
if (cl.model_precache[i] == NULL) { if (cl.model_precache[i] == NULL) {
Sys_Printf ("Model %s not found\n", model_precache[i]); Sys_Printf ("Model %s not found\n", model_precache[i]);
@ -425,7 +425,7 @@ CL_ParseServerInfo (void)
CL_KeepaliveMessage (); 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.sound_precache[i] = S_PrecacheSound (sound_precache[i]);
CL_KeepaliveMessage (); CL_KeepaliveMessage ();
} }

View file

@ -276,6 +276,8 @@ typedef struct
struct model_s *model_precache[MAX_MODELS]; struct model_s *model_precache[MAX_MODELS];
struct sfx_s *sound_precache[MAX_SOUNDS]; struct sfx_s *sound_precache[MAX_SOUNDS];
int nummodels;
int numsounds;
struct plitem_s *edicts; struct plitem_s *edicts;
struct plitem_s *worldspawn; struct plitem_s *worldspawn;

View file

@ -755,10 +755,10 @@ CL_Record (const char *argv1, int track)
for (ent = cl_static_entities; ent; ent = ent->unext) { for (ent = cl_static_entities; ent; ent = ent->unext) {
MSG_WriteByte (&buf, svc_spawnstatic); 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]) if (ent->model == cl.model_precache[j])
break; break;
if (j == MAX_MODELS) if (j == cl.nummodels)
MSG_WriteByte (&buf, 0); MSG_WriteByte (&buf, 0);
else else
MSG_WriteByte (&buf, j); MSG_WriteByte (&buf, j);

View file

@ -302,7 +302,7 @@ CL_NewMap (const char *mapname)
{ {
cl_static_entities = 0; cl_static_entities = 0;
cl_static_tail = &cl_static_entities; 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 (); Team_NewMap ();
Con_NewMap (); Con_NewMap ();
Hunk_Check (); // make sure nothing is hurt Hunk_Check (); // make sure nothing is hurt
@ -344,7 +344,7 @@ Model_NextDownload (void)
if (cl.model_name[1]) if (cl.model_name[1])
map_cfg (cl.model_name[1], 0); 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; char *info_key = 0;
if (!cl.model_name[i][0]) if (!cl.model_name[i][0])
@ -426,7 +426,7 @@ Sound_NextDownload (void)
return; // started a download return; // started a download
} }
for (i = 1; i < MAX_SOUNDS; i++) { for (i = 1; i < cl.numsounds; i++) {
if (!cl.sound_name[i][0]) if (!cl.sound_name[i][0])
break; break;
cl.sound_precache[i] = S_PrecacheSound (cl.sound_name[i]); cl.sound_precache[i] = S_PrecacheSound (cl.sound_name[i]);
@ -855,21 +855,21 @@ static void
CL_ParseSoundlist (void) CL_ParseSoundlist (void)
{ {
const char *str; const char *str;
int numsounds, n; int n;
// precache sounds // precache sounds
// memset (cl.sound_precache, 0, sizeof (cl.sound_precache)); // memset (cl.sound_precache, 0, sizeof (cl.sound_precache));
numsounds = MSG_ReadByte (net_message); cl.numsounds = MSG_ReadByte (net_message);
for (;;) { for (;;) {
str = MSG_ReadString (net_message); str = MSG_ReadString (net_message);
if (!str[0]) if (!str[0])
break; break;
numsounds++; cl.numsounds++;
if (numsounds == MAX_SOUNDS) if (cl.numsounds >= MAX_SOUNDS)
Host_Error ("Server sent too many sound_precache"); 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); n = MSG_ReadByte (net_message);
@ -889,36 +889,36 @@ CL_ParseSoundlist (void)
static void static void
CL_ParseModellist (void) CL_ParseModellist (void)
{ {
int nummodels, n; int n;
const char *str; const char *str;
// precache models and note certain default indexes // precache models and note certain default indexes
nummodels = MSG_ReadByte (net_message); cl.nummodels = MSG_ReadByte (net_message);
for (;;) { for (;;) {
str = MSG_ReadString (net_message); str = MSG_ReadString (net_message);
if (!str[0]) if (!str[0])
break; break;
nummodels++; cl.nummodels++;
if (nummodels == MAX_MODELS) if (cl.nummodels >= MAX_MODELS)
Host_Error ("Server sent too many model_precache"); 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")) if (!strcmp (cl.model_name[cl.nummodels], "progs/spike.mdl"))
cl_spikeindex = nummodels; cl_spikeindex = cl.nummodels;
else if (!strcmp (cl.model_name[nummodels], "progs/player.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/player.mdl"))
cl_playerindex = nummodels; cl_playerindex = cl.nummodels;
else if (!strcmp (cl.model_name[nummodels], "progs/flag.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/flag.mdl"))
cl_flagindex = nummodels; cl_flagindex = cl.nummodels;
// for deadbodyfilter & gib filter // for deadbodyfilter & gib filter
else if (!strcmp (cl.model_name[nummodels], "progs/h_player.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/h_player.mdl"))
cl_h_playerindex = nummodels; cl_h_playerindex = cl.nummodels;
else if (!strcmp (cl.model_name[nummodels], "progs/gib1.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib1.mdl"))
cl_gib1index = nummodels; cl_gib1index = cl.nummodels;
else if (!strcmp (cl.model_name[nummodels], "progs/gib2.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib2.mdl"))
cl_gib2index = nummodels; cl_gib2index = cl.nummodels;
else if (!strcmp (cl.model_name[nummodels], "progs/gib3.mdl")) else if (!strcmp (cl.model_name[cl.nummodels], "progs/gib3.mdl"))
cl_gib3index = nummodels; cl_gib3index = cl.nummodels;
} }
n = MSG_ReadByte (net_message); n = MSG_ReadByte (net_message);