Quake II RTX doxygen  1.0 dev
precache.c File Reference
#include "client.h"
#include "client/sound/vorbis.h"

Go to the source code of this file.

Functions

void CL_ParsePlayerSkin (char *name, char *model, char *skin, const char *s)
 
void CL_LoadClientinfo (clientinfo_t *ci, const char *s)
 
void CL_RegisterSounds (void)
 
void CL_RegisterBspModels (void)
 
void CL_RegisterVWepModels (void)
 
void CL_SetSky (void)
 
void CL_PrepRefresh (void)
 
void CL_UpdateConfigstring (int index)
 

Function Documentation

◆ CL_LoadClientinfo()

void CL_LoadClientinfo ( clientinfo_t ci,
const char *  s 
)

Definition at line 104 of file precache.c.

105 {
106  int i;
107  char model_name[MAX_QPATH];
108  char skin_name[MAX_QPATH];
109  char model_filename[MAX_QPATH];
110  char skin_filename[MAX_QPATH];
111  char weapon_filename[MAX_QPATH];
112  char icon_filename[MAX_QPATH];
113 
114  CL_ParsePlayerSkin(ci->name, model_name, skin_name, s);
115 
116  // model file
117  Q_concat(model_filename, sizeof(model_filename),
118  "players/", model_name, "/tris.md2", NULL);
119  ci->model = R_RegisterModel(model_filename);
120  if (!ci->model && Q_stricmp(model_name, "male")) {
121  strcpy(model_name, "male");
122  strcpy(model_filename, "players/male/tris.md2");
123  ci->model = R_RegisterModel(model_filename);
124  }
125 
126  // skin file
127  Q_concat(skin_filename, sizeof(skin_filename),
128  "players/", model_name, "/", skin_name, ".pcx", NULL);
129  ci->skin = R_RegisterSkin(skin_filename);
130 
131  // if we don't have the skin and the model was female,
132  // see if athena skin exists
133  if (!ci->skin && !Q_stricmp(model_name, "female")) {
134  strcpy(skin_name, "athena");
135  strcpy(skin_filename, "players/female/athena.pcx");
136  ci->skin = R_RegisterSkin(skin_filename);
137  }
138 
139  // if we don't have the skin and the model wasn't male,
140  // see if the male has it (this is for CTF's skins)
141  if (!ci->skin && Q_stricmp(model_name, "male")) {
142  // change model to male
143  strcpy(model_name, "male");
144  strcpy(model_filename, "players/male/tris.md2");
145  ci->model = R_RegisterModel(model_filename);
146 
147  // see if the skin exists for the male model
148  Q_concat(skin_filename, sizeof(skin_filename),
149  "players/male/", skin_name, ".pcx", NULL);
150  ci->skin = R_RegisterSkin(skin_filename);
151  }
152 
153  // if we still don't have a skin, it means that the male model
154  // didn't have it, so default to grunt
155  if (!ci->skin) {
156  // see if the skin exists for the male model
157  strcpy(skin_name, "grunt");
158  strcpy(skin_filename, "players/male/grunt.pcx");
159  ci->skin = R_RegisterSkin(skin_filename);
160  }
161 
162  // weapon file
163  for (i = 0; i < cl.numWeaponModels; i++) {
164  Q_concat(weapon_filename, sizeof(weapon_filename),
165  "players/", model_name, "/", cl.weaponModels[i], NULL);
166  ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
167  if (!ci->weaponmodel[i] && !Q_stricmp(model_name, "cyborg")) {
168  // try male
169  Q_concat(weapon_filename, sizeof(weapon_filename),
170  "players/male/", cl.weaponModels[i], NULL);
171  ci->weaponmodel[i] = R_RegisterModel(weapon_filename);
172  }
173  }
174 
175  // icon file
176  Q_concat(icon_filename, sizeof(icon_filename),
177  "/players/", model_name, "/", skin_name, "_i.pcx", NULL);
178  ci->icon = R_RegisterPic2(icon_filename);
179 
180  strcpy(ci->model_name, model_name);
181  strcpy(ci->skin_name, skin_name);
182 
183  // base info should be at least partially valid
184  if (ci == &cl.baseclientinfo)
185  return;
186 
187  // must have loaded all data types to be valid
188  if (!ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0]) {
189  ci->skin = 0;
190  ci->icon = 0;
191  ci->model = 0;
192  ci->weaponmodel[0] = 0;
193  ci->model_name[0] = 0;
194  ci->skin_name[0] = 0;
195  }
196 }

Referenced by cl_noskins_changed(), CL_PrepRefresh(), CL_Skins_f(), and CL_UpdateConfigstring().

◆ CL_ParsePlayerSkin()

void CL_ParsePlayerSkin ( char *  name,
char *  model,
char *  skin,
const char *  s 
)

Definition at line 35 of file precache.c.

36 {
37  size_t len;
38  char *t;
39 
40  // configstring parsing guarantees that playerskins can never
41  // overflow, but still check the length to be entirely fool-proof
42  len = strlen(s);
43  if (len >= MAX_QPATH) {
44  Com_Error(ERR_DROP, "%s: oversize playerskin", __func__);
45  }
46 
47  // isolate the player's name
48  t = strchr(s, '\\');
49  if (t) {
50  len = t - s;
51  strcpy(model, t + 1);
52  } else {
53  len = 0;
54  strcpy(model, s);
55  }
56 
57  // copy the player's name
58  if (name) {
59  memcpy(name, s, len);
60  name[len] = 0;
61  }
62 
63  // isolate the model name
64  t = strchr(model, '/');
65  if (!t)
66  t = strchr(model, '\\');
67  if (!t)
68  goto default_model;
69  *t = 0;
70 
71  // isolate the skin name
72  strcpy(skin, t + 1);
73 
74  // fix empty model to male
75  if (t == model)
76  strcpy(model, "male");
77 
78  // apply restrictions on skins
79  if (cl_noskins->integer == 2 || !COM_IsPath(skin))
80  goto default_skin;
81 
82  if (cl_noskins->integer || !COM_IsPath(model))
83  goto default_model;
84 
85  return;
86 
87 default_skin:
88  if (!Q_stricmp(model, "female")) {
89  strcpy(model, "female");
90  strcpy(skin, "athena");
91  } else {
92 default_model:
93  strcpy(model, "male");
94  strcpy(skin, "grunt");
95  }
96 }

Referenced by check_player(), and CL_LoadClientinfo().

◆ CL_PrepRefresh()

void CL_PrepRefresh ( void  )

Definition at line 333 of file precache.c.

334 {
335  int i;
336  char *name;
337 
338  if (!cls.ref_initialized)
339  return;
340  if (!cl.mapname[0])
341  return; // no map loaded
342 
343  // register models, pics, and skins
345 
347 
349 
350 #if CL_RTX_SHADERBALLS
351  cvar_shaderballs = Cvar_Get("cl_shaderballs", "0", 0);
352  if (cvar_shaderballs->integer && vid_rtx->integer)
353  {
354  cl_dev_shaderballs = R_RegisterModel("develop/objects/ShaderBallArray/ShaderBallArray16.MD3");
355  if (cl_dev_shaderballs)
356  Com_Printf("Loaded the ShaderBalls model\n");
357  else
358  Com_WPrintf("Failed to load the ShaderBalls model\n");
359  }
360  else
361  cl_dev_shaderballs = -1;
362 #endif
363 
364  for (i = 2; i < MAX_MODELS; i++) {
365  name = cl.configstrings[CS_MODELS + i];
366  if (!name[0]) {
367  break;
368  }
369  if (name[0] == '#') {
370  continue;
371  }
372  cl.model_draw[i] = R_RegisterModel(name);
373  }
374 
376  for (i = 1; i < MAX_IMAGES; i++) {
377  name = cl.configstrings[CS_IMAGES + i];
378  if (!name[0]) {
379  break;
380  }
381  cl.image_precache[i] = R_RegisterPic2(name);
382  }
383 
385  for (i = 0; i < MAX_CLIENTS; i++) {
386  name = cl.configstrings[CS_PLAYERSKINS + i];
387  if (!name[0]) {
388  continue;
389  }
390  CL_LoadClientinfo(&cl.clientinfo[i], name);
391  }
392 
393  CL_LoadClientinfo(&cl.baseclientinfo, "unnamed\\male/grunt");
394 
395  // set sky textures and speed
396  CL_SetSky();
397 
398  // the renderer can now free unneeded stuff
400 
401  // clear any lines of console text
403 
405 
406  int cdtrack = atoi(cl.configstrings[CS_CDTRACK]);
407  OGG_PlayTrack(cdtrack);
408 }

Referenced by CL_Begin(), CL_Precache_f(), CL_RestartFilesystem(), and CL_RestartRefresh().

◆ CL_RegisterBspModels()

void CL_RegisterBspModels ( void  )

Definition at line 226 of file precache.c.

227 {
228  qerror_t ret;
229  char *name;
230  int i;
231 
232  ret = BSP_Load(cl.configstrings[CS_MODELS + 1], &cl.bsp);
233  if (cl.bsp == NULL) {
234  Com_Error(ERR_DROP, "Couldn't load %s: %s",
235  cl.configstrings[CS_MODELS + 1], Q_ErrorString(ret));
236  }
237 
238 #if USE_MAPCHECKSUM
239  if (cl.bsp->checksum != atoi(cl.configstrings[CS_MAPCHECKSUM])) {
240  if (cls.demo.playback) {
241  Com_WPrintf("Local map version differs from demo: %i != %s\n",
242  cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
243  } else {
244  Com_Error(ERR_DROP, "Local map version differs from server: %i != %s",
245  cl.bsp->checksum, cl.configstrings[CS_MAPCHECKSUM]);
246  }
247  }
248 #endif
249 
250  for (i = 1; i < MAX_MODELS; i++) {
251  name = cl.configstrings[CS_MODELS + i];
252  if (!name[0]) {
253  break;
254  }
255  if (name[0] == '*')
256  cl.model_clip[i] = BSP_InlineModel(cl.bsp, name);
257  else
258  cl.model_clip[i] = NULL;
259  }
260 }

Referenced by CL_Precache_f(), and CL_RequestNextDownload().

◆ CL_RegisterSounds()

void CL_RegisterSounds ( void  )

Definition at line 203 of file precache.c.

204 {
205  int i;
206  char *s;
207 
210  for (i = 1; i < MAX_SOUNDS; i++) {
211  s = cl.configstrings[CS_SOUNDS + i];
212  if (!s[0])
213  break;
215  }
217 }

Referenced by CL_Begin(), CL_Precache_f(), CL_RestartFilesystem(), and CL_RestartSound_f().

◆ CL_RegisterVWepModels()

void CL_RegisterVWepModels ( void  )

Definition at line 269 of file precache.c.

270 {
271  int i;
272  char *name;
273 
274  cl.numWeaponModels = 1;
275  strcpy(cl.weaponModels[0], "weapon.md2");
276 
277  // only default model when vwep is off
278  if (!cl_vwep->integer) {
279  return;
280  }
281 
282  for (i = 2; i < MAX_MODELS; i++) {
283  name = cl.configstrings[CS_MODELS + i];
284  if (!name[0]) {
285  break;
286  }
287  if (name[0] != '#') {
288  continue;
289  }
290 
291  // special player weapon model
292  strcpy(cl.weaponModels[cl.numWeaponModels++], name + 1);
293 
295  break;
296  }
297  }
298 }

Referenced by CL_Precache_f(), CL_Skins_f(), and cl_vwep_changed().

◆ CL_SetSky()

void CL_SetSky ( void  )

Definition at line 306 of file precache.c.

307 {
308  float rotate;
309  vec3_t axis;
310 
311  rotate = atof(cl.configstrings[CS_SKYROTATE]);
312  if (sscanf(cl.configstrings[CS_SKYAXIS], "%f %f %f",
313  &axis[0], &axis[1], &axis[2]) != 3) {
314  Com_DPrintf("Couldn't parse CS_SKYAXIS\n");
315  VectorClear(axis);
316  }
317 
318  R_SetSky(cl.configstrings[CS_SKY], rotate, axis);
319 }

Referenced by CL_PrepRefresh(), gl_drawsky_changed(), and SCR_Sky_f().

◆ CL_UpdateConfigstring()

void CL_UpdateConfigstring ( int  index)

Definition at line 417 of file precache.c.

418 {
419  const char *s = cl.configstrings[index];
420 
421  if (index == CS_MAXCLIENTS) {
422  cl.maxclients = atoi(s);
423  return;
424  }
425 
426  if (index == CS_AIRACCEL) {
427  if (cl.pmp.qwmode)
428  cl.pmp.airaccelerate = qtrue;
429  else
430  cl.pmp.airaccelerate = atoi(s) ? qtrue : qfalse;
431  return;
432  }
433 
434  if (index == CS_MODELS + 1) {
435  size_t len = strlen(s);
436 
437  if (len <= 9) {
438  Com_Error(ERR_DROP, "%s: bad world model: %s", __func__, s);
439  }
440  memcpy(cl.mapname, s + 5, len - 9); // skip "maps/"
441  cl.mapname[len - 9] = 0; // cut off ".bsp"
442  return;
443  }
444 
445 #if USE_LIGHTSTYLES
446  if (index >= CS_LIGHTS && index < CS_LIGHTS + MAX_LIGHTSTYLES) {
447  CL_SetLightStyle(index - CS_LIGHTS, s);
448  return;
449  }
450 #endif
451 
452  if (cls.state < ca_precached) {
453  return;
454  }
455 
456  if (index >= CS_MODELS + 2 && index < CS_MODELS + MAX_MODELS) {
457  int i = index - CS_MODELS;
458 
459  cl.model_draw[i] = R_RegisterModel(s);
460  if (*s == '*')
462  else
463  cl.model_clip[i] = NULL;
464  return;
465  }
466 
467  if (index >= CS_SOUNDS && index < CS_SOUNDS + MAX_SOUNDS) {
468  cl.sound_precache[index - CS_SOUNDS] = S_RegisterSound(s);
469  return;
470  }
471 
472  if (index >= CS_IMAGES && index < CS_IMAGES + MAX_IMAGES) {
473  cl.image_precache[index - CS_IMAGES] = R_RegisterPic2(s);
474  return;
475  }
476 
477  if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS) {
478  CL_LoadClientinfo(&cl.clientinfo[index - CS_PLAYERSKINS], s);
479  return;
480  }
481 }

Referenced by CL_ParseConfigstring(), and CL_Seek_f().

client_state_s::bsp
bsp_t * bsp
Definition: client.h:300
R_EndRegistration
void(* R_EndRegistration)(void)
Definition: refresh.c:407
client_state_s::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:289
CL_SetSky
void CL_SetSky(void)
Definition: precache.c:306
client_state_s::image_precache
qhandle_t image_precache[MAX_IMAGES]
Definition: client.h:306
client_static_s::playback
qhandle_t playback
Definition: client.h:453
R_SetSky
void(* R_SetSky)(const char *name, float rotate, vec3_t axis)
Definition: refresh.c:406
client_static_s::demo
struct client_static_s::@3 demo
client_state_s::model_clip
mmodel_t * model_clip[MAX_MODELS]
Definition: client.h:303
S_RegisterSound
qhandle_t S_RegisterSound(const char *name)
Definition: main.c:391
COM_IsPath
qboolean COM_IsPath(const char *s)
Definition: shared.c:348
CL_ParsePlayerSkin
void CL_ParsePlayerSkin(char *name, char *model, char *skin, const char *s)
Definition: precache.c:35
client_state_s::numWeaponModels
int numWeaponModels
Definition: client.h:312
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
Q_ErrorString
const char * Q_ErrorString(qerror_t error)
Definition: error.c:51
SCR_UpdateScreen
void SCR_UpdateScreen(void)
Definition: screen.c:2142
LOAD_IMAGES
@ LOAD_IMAGES
Definition: client.h:610
client_static_s::state
connstate_t state
Definition: client.h:375
CL_RegisterTEntModels
void CL_RegisterTEntModels(void)
Definition: tent.c:100
client_static_s::ref_initialized
qboolean ref_initialized
Definition: client.h:380
CL_RegisterTEntSounds
void CL_RegisterTEntSounds(void)
Definition: tent.c:64
client_state_s::weaponModels
char weaponModels[MAX_CLIENTWEAPONMODELS][MAX_QPATH]
Definition: client.h:311
BSP_InlineModel
mmodel_t * BSP_InlineModel(bsp_t *bsp, const char *name)
Definition: bsp.c:1459
client_state_s::sound_precache
qhandle_t sound_precache[MAX_SOUNDS]
Definition: client.h:305
cl_noskins
cvar_t * cl_noskins
Definition: main.c:25
clientinfo_s::name
char name[MAX_QPATH]
Definition: client.h:113
clientinfo_s::model
qhandle_t model
Definition: client.h:118
ca_precached
@ ca_precached
Definition: client.h:339
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
R_RegisterModel
qhandle_t R_RegisterModel(const char *name)
Definition: models.c:305
clientinfo_s::icon
qhandle_t icon
Definition: client.h:115
client_state_s::model_draw
qhandle_t model_draw[MAX_MODELS]
Definition: client.h:302
clientinfo_s::weaponmodel
qhandle_t weaponmodel[MAX_CLIENTWEAPONMODELS]
Definition: client.h:119
clientinfo_s::model_name
char model_name[MAX_QPATH]
Definition: client.h:116
client_state_s::baseclientinfo
clientinfo_t baseclientinfo
Definition: client.h:309
client_state_s::clientinfo
clientinfo_t clientinfo[MAX_CLIENTS]
Definition: client.h:308
client_state_s::mapname
char mapname[MAX_QPATH]
Definition: client.h:290
OGG_PlayTrack
void OGG_PlayTrack(int trackNo)
Definition: ogg.c:323
cl
client_state_t cl
Definition: main.c:99
cl_vwep
cvar_t * cl_vwep
Definition: main.c:72
cls
client_static_t cls
Definition: main.c:98
MAX_CLIENTWEAPONMODELS
#define MAX_CLIENTWEAPONMODELS
Definition: client.h:110
S_EndRegistration
void S_EndRegistration(void)
Definition: main.c:522
R_BeginRegistration
void(* R_BeginRegistration)(const char *map)
Definition: refresh.c:405
clientinfo_s::skin_name
char skin_name[MAX_QPATH]
Definition: client.h:117
LOAD_CLIENTS
@ LOAD_CLIENTS
Definition: client.h:611
LOAD_MODELS
@ LOAD_MODELS
Definition: client.h:609
CL_LoadClientinfo
void CL_LoadClientinfo(clientinfo_t *ci, const char *s)
Definition: precache.c:104
BSP_Load
qerror_t BSP_Load(const char *name, bsp_t **bsp_p)
Definition: bsp.c:1087
CL_LoadState
void CL_LoadState(load_state_t state)
Definition: console.c:541
Q_concat
size_t Q_concat(char *dest, size_t size,...)
Definition: shared.c:758
vid_rtx
cvar_t * vid_rtx
Definition: refresh.c:30
Con_ClearNotify_f
void Con_ClearNotify_f(void)
Definition: console.c:276
client_state_s::maxclients
int maxclients
Definition: client.h:279
S_BeginRegistration
void S_BeginRegistration(void)
Definition: main.c:379
clientinfo_s::skin
qhandle_t skin
Definition: client.h:114
client_state_s::pmp
pmoveParams_t pmp
Definition: client.h:280