]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_main.c
md3 tag attachments (implemented but untested), also the capability to attach any...
[divverent/darkplaces.git] / cl_main.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // cl_main.c  -- client main loop
21
22 #include "quakedef.h"
23 #include "cl_collision.h"
24 #include "cl_video.h"
25 #include "image.h"
26
27 // we need to declare some mouse variables here, because the menu system
28 // references them even when on a unix system.
29
30 cvar_t cl_shownet = {0, "cl_shownet","0"};
31 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
32
33 cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
34 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
35
36 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
37 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
38 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
39
40 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
41 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
42 cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
43 cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
44
45 cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
46
47 cvar_t r_draweffects = {0, "r_draweffects", "1"};
48
49 cvar_t cl_explosions = {CVAR_SAVE, "cl_explosions", "1"};
50 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
51
52 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1"};
53 cvar_t cl_beams_relative = {CVAR_SAVE, "cl_beams_relative", "1"};
54 cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0"};
55
56 cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0"};
57
58 mempool_t *cl_refdef_mempool;
59 mempool_t *cl_entities_mempool;
60
61 client_static_t cls;
62 client_state_t  cl;
63
64 int cl_max_entities;
65 int cl_max_static_entities;
66 int cl_max_temp_entities;
67 int cl_max_effects;
68 int cl_max_beams;
69 int cl_max_dlights;
70 int cl_max_lightstyle;
71 int cl_max_brushmodel_entities;
72
73 entity_t *cl_entities;
74 qbyte *cl_entities_active;
75 entity_t *cl_static_entities;
76 entity_t *cl_temp_entities;
77 cl_effect_t *cl_effects;
78 beam_t *cl_beams;
79 dlight_t *cl_dlights;
80 lightstyle_t *cl_lightstyle;
81 entity_render_t **cl_brushmodel_entities;
82
83 int cl_num_entities;
84 int cl_num_static_entities;
85 int cl_num_temp_entities;
86 int cl_num_brushmodel_entities;
87
88 /*
89 =====================
90 CL_ClearState
91
92 =====================
93 */
94 void CL_ClearState(void)
95 {
96         int i;
97
98         if (!sv.active)
99                 Host_ClearMemory ();
100
101         Mem_EmptyPool(cl_entities_mempool);
102
103 // wipe the entire cl structure
104         memset (&cl, 0, sizeof(cl));
105
106         SZ_Clear (&cls.message);
107
108         cl_num_entities = 0;
109         cl_num_static_entities = 0;
110         cl_num_temp_entities = 0;
111         cl_num_brushmodel_entities = 0;
112
113         // tweak these if the game runs out
114         cl_max_entities = MAX_EDICTS;
115         cl_max_static_entities = 256;
116         cl_max_temp_entities = 512;
117         cl_max_effects = 256;
118         cl_max_beams = 24;
119         cl_max_dlights = MAX_DLIGHTS;
120         cl_max_lightstyle = MAX_LIGHTSTYLES;
121         cl_max_brushmodel_entities = MAX_EDICTS;
122
123         cl_entities = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(entity_t));
124         cl_entities_active = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(qbyte));
125         cl_static_entities = Mem_Alloc(cl_entities_mempool, cl_max_static_entities * sizeof(entity_t));
126         cl_temp_entities = Mem_Alloc(cl_entities_mempool, cl_max_temp_entities * sizeof(entity_t));
127         cl_effects = Mem_Alloc(cl_entities_mempool, cl_max_effects * sizeof(cl_effect_t));
128         cl_beams = Mem_Alloc(cl_entities_mempool, cl_max_beams * sizeof(beam_t));
129         cl_dlights = Mem_Alloc(cl_entities_mempool, cl_max_dlights * sizeof(dlight_t));
130         cl_lightstyle = Mem_Alloc(cl_entities_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
131         cl_brushmodel_entities = Mem_Alloc(cl_entities_mempool, cl_max_brushmodel_entities * sizeof(entity_render_t *));
132
133         CL_Screen_NewMap();
134
135         CL_Particles_Clear();
136
137         // LordHavoc: have to set up the baseline info for alpha and other stuff
138         for (i = 0;i < cl_max_entities;i++)
139         {
140                 ClearStateToDefault(&cl_entities[i].state_baseline);
141                 ClearStateToDefault(&cl_entities[i].state_previous);
142                 ClearStateToDefault(&cl_entities[i].state_current);
143         }
144
145         CL_CGVM_Clear();
146 }
147
148 /*
149 =====================
150 CL_Disconnect
151
152 Sends a disconnect message to the server
153 This is also called on Host_Error, so it shouldn't cause any errors
154 =====================
155 */
156 void CL_Disconnect(void)
157 {
158         if (cls.state == ca_dedicated)
159                 return;
160
161 // stop sounds (especially looping!)
162         S_StopAllSounds (true);
163
164         // clear contents blends
165         cl.cshifts[0].percent = 0;
166         cl.cshifts[1].percent = 0;
167         cl.cshifts[2].percent = 0;
168         cl.cshifts[3].percent = 0;
169
170         cl.worldmodel = NULL;
171
172         if (cls.demoplayback)
173                 CL_StopPlayback();
174         else if (cls.netcon)
175         {
176                 if (cls.demorecording)
177                         CL_Stop_f();
178
179                 Con_DPrintf("Sending clc_disconnect\n");
180                 SZ_Clear(&cls.message);
181                 MSG_WriteByte(&cls.message, clc_disconnect);
182                 NetConn_SendUnreliableMessage(cls.netcon, &cls.message);
183                 SZ_Clear(&cls.message);
184                 NetConn_Close(cls.netcon);
185                 cls.netcon = NULL;
186                 // if running a local server, shut it down
187                 if (sv.active)
188                 {
189                         // prevent this code from executing again during Host_ShutdownServer
190                         cls.state = ca_disconnected;
191                         Host_ShutdownServer(false);
192                 }
193         }
194         cls.state = ca_disconnected;
195
196         cls.demoplayback = cls.timedemo = false;
197         cls.signon = 0;
198 }
199
200 void CL_Disconnect_f(void)
201 {
202         CL_Disconnect ();
203         if (sv.active)
204                 Host_ShutdownServer (false);
205 }
206
207
208
209
210 /*
211 =====================
212 CL_EstablishConnection
213
214 Host should be either "local" or a net address
215 =====================
216 */
217 void CL_EstablishConnection(const char *host)
218 {
219         if (cls.state == ca_dedicated)
220                 return;
221
222         // clear menu's connect error message
223         m_return_reason[0] = 0;
224
225         // stop demo loop in case this fails
226         cls.demonum = -1;
227         CL_Disconnect();
228
229         if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
230         {
231                 cls.connect_trying = true;
232                 cls.connect_remainingtries = 3;
233                 cls.connect_nextsendtime = 0;
234                 if (sv.active)
235                 {
236                         NetConn_ClientFrame();
237                         NetConn_ServerFrame();
238                         NetConn_ClientFrame();
239                         NetConn_ServerFrame();
240                         NetConn_ClientFrame();
241                         NetConn_ServerFrame();
242                         NetConn_ClientFrame();
243                         NetConn_ServerFrame();
244                 }
245         }
246 }
247
248 /*
249 ==============
250 CL_PrintEntities_f
251 ==============
252 */
253 static void CL_PrintEntities_f(void)
254 {
255         entity_t *ent;
256         int i, j;
257         char name[32];
258
259         for (i = 0, ent = cl_entities;i < cl_num_entities;i++, ent++)
260         {
261                 if (!ent->state_current.active)
262                         continue;
263
264                 if (ent->render.model)
265                         strncpy(name, ent->render.model->name, 25);
266                 else
267                         strcpy(name, "--no model--");
268                 name[25] = 0;
269                 for (j = strlen(name);j < 25;j++)
270                         name[j] = ' ';
271                 Con_Printf ("%3i: %s:%04i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.origin[0], (int) ent->render.origin[1], (int) ent->render.origin[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
272         }
273 }
274
275 //static const vec3_t nomodelmins = {-16, -16, -16};
276 //static const vec3_t nomodelmaxs = {16, 16, 16};
277 void CL_BoundingBoxForEntity(entity_render_t *ent)
278 {
279         if (ent->model)
280         {
281                 //if (ent->angles[0] || ent->angles[2])
282                 if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
283                 {
284                         // pitch or roll
285                         ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
286                         ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
287                         ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
288                         ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
289                         ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
290                         ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
291                         //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
292                         //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
293                 }
294                 //else if (ent->angles[1])
295                 else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
296                 {
297                         // yaw
298                         ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
299                         ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
300                         ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
301                         ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
302                         ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
303                         ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
304                         //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
305                         //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
306                 }
307                 else
308                 {
309                         ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
310                         ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
311                         ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
312                         ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
313                         ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
314                         ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
315                         //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
316                         //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
317                 }
318         }
319         else
320         {
321                 ent->mins[0] = ent->matrix.m[0][3] - 16;
322                 ent->mins[1] = ent->matrix.m[1][3] - 16;
323                 ent->mins[2] = ent->matrix.m[2][3] - 16;
324                 ent->maxs[0] = ent->matrix.m[0][3] + 16;
325                 ent->maxs[1] = ent->matrix.m[1][3] + 16;
326                 ent->maxs[2] = ent->matrix.m[2][3] + 16;
327                 //VectorAdd(ent->origin, nomodelmins, ent->mins);
328                 //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
329         }
330 }
331
332 /*
333 ===============
334 CL_LerpPoint
335
336 Determines the fraction between the last two messages that the objects
337 should be put at.
338 ===============
339 */
340 static float CL_LerpPoint(void)
341 {
342         float f;
343
344         // dropped packet, or start of demo
345         if (cl.mtime[1] < cl.mtime[0] - 0.1)
346                 cl.mtime[1] = cl.mtime[0] - 0.1;
347
348         cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
349
350         // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
351         f = cl.mtime[0] - cl.mtime[1];
352         if (!f || cl_nolerp.integer || cls.timedemo || (sv.active && svs.maxclients == 1))
353         {
354                 cl.time = cl.mtime[0];
355                 return 1;
356         }
357
358         f = (cl.time - cl.mtime[1]) / f;
359         return bound(0, f, 1);
360 }
361
362 void CL_ClearTempEntities (void)
363 {
364         cl_num_temp_entities = 0;
365 }
366
367 entity_t *CL_NewTempEntity(void)
368 {
369         entity_t *ent;
370
371         if (r_refdef.numentities >= r_refdef.maxentities)
372                 return NULL;
373         if (cl_num_temp_entities >= cl_max_temp_entities)
374                 return NULL;
375         ent = &cl_temp_entities[cl_num_temp_entities++];
376         memset (ent, 0, sizeof(*ent));
377         r_refdef.entities[r_refdef.numentities++] = &ent->render;
378
379         ent->render.colormap = -1; // no special coloring
380         ent->render.scale = 1;
381         ent->render.alpha = 1;
382         return ent;
383 }
384
385 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
386 {
387         int i;
388         cl_effect_t *e;
389         if (!modelindex) // sanity check
390                 return;
391         for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
392         {
393                 if (e->active)
394                         continue;
395                 e->active = true;
396                 VectorCopy(org, e->origin);
397                 e->modelindex = modelindex;
398                 e->starttime = cl.time;
399                 e->startframe = startframe;
400                 e->endframe = startframe + framecount;
401                 e->framerate = framerate;
402
403                 e->frame = 0;
404                 e->frame1time = cl.time;
405                 e->frame2time = cl.time;
406                 break;
407         }
408 }
409
410 void CL_AllocDlight(entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
411 {
412         int i;
413         dlight_t *dl;
414
415         /*
416 // first look for an exact key match
417         if (ent)
418         {
419                 dl = cl_dlights;
420                 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
421                         if (dl->ent == ent)
422                                 goto dlightsetup;
423         }
424         */
425
426 // then look for anything else
427         dl = cl_dlights;
428         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
429                 if (!dl->radius)
430                         goto dlightsetup;
431
432         // unable to find one
433         return;
434
435 dlightsetup:
436         //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
437         memset (dl, 0, sizeof(*dl));
438         dl->ent = ent;
439         CL_FindNonSolidLocation(org, dl->origin, 6);
440         //VectorCopy(org, dl->origin);
441         dl->radius = radius;
442         dl->color[0] = red;
443         dl->color[1] = green;
444         dl->color[2] = blue;
445         dl->decay = decay;
446         if (lifetime)
447                 dl->die = cl.time + lifetime;
448         else
449                 dl->die = 0;
450 }
451
452 void CL_DecayLights(void)
453 {
454         int i;
455         dlight_t *dl;
456         float time;
457
458         time = cl.time - cl.oldtime;
459
460         dl = cl_dlights;
461         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
462         {
463                 if (!dl->radius)
464                         continue;
465                 if (dl->die < cl.time)
466                 {
467                         dl->radius = 0;
468                         continue;
469                 }
470
471                 dl->radius -= time*dl->decay;
472                 if (dl->radius < 0)
473                         dl->radius = 0;
474         }
475 }
476
477 extern qboolean Nehahrademcompatibility;
478 #define MAXVIEWMODELS 32
479 entity_t *viewmodels[MAXVIEWMODELS];
480 int numviewmodels;
481
482 matrix4x4_t viewmodelmatrix;
483
484 static int entitylinkframenumber;
485
486 static const vec3_t muzzleflashorigin = {18, 0, 0};
487
488 extern void V_DriftPitch(void);
489 extern void V_FadeViewFlashs(void);
490 extern void V_CalcViewBlend(void);
491
492 extern void V_CalcRefdef(void);
493 // note this is a recursive function, but it can never get in a runaway loop (because of the delayedlink flags)
494 void CL_LinkNetworkEntity(entity_t *e)
495 {
496         matrix4x4_t *matrix, blendmatrix, tempmatrix, matrix2;
497         int j, k, l, trailtype, temp;
498         float origin[3], angles[3], delta[3], lerp, dlightcolor[3], mins[3], maxs[3], v[3], v2[3], d;
499         entity_t *t;
500         model_t *model;
501         //entity_persistent_t *p = &e->persistent;
502         //entity_render_t *r = &e->render;
503         if (e->persistent.linkframe != entitylinkframenumber)
504         {
505                 e->persistent.linkframe = entitylinkframenumber;
506                 // skip inactive entities and world
507                 if (!e->state_current.active || e == cl_entities)
508                         return;
509                 if (e->render.flags & RENDER_VIEWMODEL)
510                 {
511                         if (cl.stats[STAT_HEALTH] <= 0 || !r_drawviewmodel.integer || chase_active.integer || envmap || (cl.items & IT_INVISIBILITY))
512                                 return;
513                         if (cl.viewentity)
514                                 CL_LinkNetworkEntity(cl_entities + cl.viewentity);
515                         matrix = &viewmodelmatrix;
516                         if (e == &cl.viewent && cl.viewentity >= 0 && cl.viewentity < MAX_EDICTS && cl_entities[cl.viewentity].state_current.active)
517                         {
518                                 e->state_current.alpha = cl_entities[cl.viewentity].state_current.alpha;
519                                 e->state_current.effects = EF_NOSHADOW | (cl_entities[cl.viewentity].state_current.effects & (EF_ADDITIVE | EF_REFLECTIVE | EF_FULLBRIGHT));
520                         }
521                 }
522                 else
523                 {
524                         t = cl_entities + e->state_current.tagentity;
525                         if (!t->state_current.active)
526                                 return;
527                         // note: this can link to world
528                         CL_LinkNetworkEntity(t);
529                         // make relative to the entity
530                         matrix = &t->render.matrix;
531                         // if a valid tagindex is used, make it relative to that tag instead
532                         if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model) && e->state_current.tagindex <= t->render.model->alias.aliasnum_tags)
533                         {
534                                 // blend the matrices
535                                 R_LerpAnimation(&t->render);
536                                 memset(&blendmatrix, 0, sizeof(blendmatrix));
537                                 for (j = 0;j < 4 && t->render.frameblend[j].lerp > 0;j++)
538                                 {
539                                         matrix = &t->render.model->alias.aliasdata_tags[t->render.frameblend[j].frame * t->render.model->alias.aliasnum_tags + (e->state_current.tagindex - 1)].matrix;
540                                         d = t->render.frameblend[j].lerp;
541                                         for (l = 0;l < 4;l++)
542                                                 for (k = 0;k < 4;k++)
543                                                         blendmatrix.m[l][k] += d * matrix->m[l][k];
544                                 }
545                                 // concat the tag matrices onto the entity matrix
546                                 Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
547                                 // use the constructed tag matrix
548                                 matrix = &tempmatrix;
549                         }
550                 }
551                 e->render.alpha = e->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
552                 e->render.scale = e->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
553                 e->render.flags = e->state_current.flags;
554                 if (e - cl_entities == cl.viewentity)
555                         e->render.flags |= RENDER_EXTERIORMODEL;
556                 e->render.effects = e->state_current.effects;
557                 if (e->state_current.flags & RENDER_COLORMAPPED)
558                         e->render.colormap = e->state_current.colormap;
559                 else if (cl.scores != NULL && e->state_current.colormap)
560                         e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it
561                 else
562                         e->render.colormap = -1; // no special coloring
563                 e->render.skinnum = e->state_current.skin;
564                 // set up the render matrix
565                 if (e->state_previous.active && e->state_current.modelindex == e->state_previous.modelindex)
566                 {
567                         // movement lerp
568                         if (e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
569                         {
570                                 // interpolate the origin and angles
571                                 VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin);
572                                 VectorSubtract(e->persistent.newangles, e->persistent.oldangles, delta);
573                                 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
574                                 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
575                                 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
576                                 VectorMA(e->persistent.oldangles, lerp, delta, angles);
577                         }
578                         else
579                         {
580                                 // no interpolation
581                                 VectorCopy(e->persistent.neworigin, origin);
582                                 VectorCopy(e->persistent.newangles, angles);
583                         }
584                         // animation lerp
585                         if (e->render.frame2 != e->state_current.frame)
586                         {
587                                 // begin a new frame lerp
588                                 e->render.frame1 = e->render.frame2;
589                                 e->render.frame1time = e->render.frame2time;
590                                 e->render.frame = e->render.frame2 = e->state_current.frame;
591                                 e->render.frame2time = cl.time;
592                                 e->render.framelerp = 0;
593                         }
594                         else
595                         {
596                                 // update frame lerp fraction
597                                 e->render.framelerp = e->render.frame2time > e->render.frame1time ? ((cl.time - e->render.frame2time) / (e->render.frame2time - e->render.frame1time)) : 1;
598                                 e->render.framelerp = bound(0, e->render.framelerp, 1);
599                         }
600                 }
601                 else
602                 {
603                         // no interpolation
604                         VectorCopy(e->persistent.neworigin, origin);
605                         VectorCopy(e->persistent.newangles, angles);
606                         e->render.frame = e->render.frame1 = e->render.frame2 = e->state_current.frame;
607                         e->render.frame1time = e->render.frame2time = cl.time;
608                         e->render.framelerp = 1;
609                 }
610
611                 e->render.model = cl.model_precache[e->state_current.modelindex];
612                 if (e->render.model)
613                 {
614                         Mod_CheckLoaded(e->render.model);
615                         if (e->render.model->type != mod_brush)
616                                 angles[0] = -angles[0];
617                         if (e->render.model->flags & EF_ROTATE)
618                         {
619                                 angles[1] = ANGLEMOD(100*cl.time);
620                                 if (cl_itembobheight.value)
621                                         origin[2] += (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
622                         }
623                 }
624
625                 // FIXME: e->render.scale should go away
626                 Matrix4x4_CreateFromQuakeEntity(&matrix2, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale);
627                 // concat the matrices to make the entity relative to its tag
628                 Matrix4x4_Concat(&e->render.matrix, matrix, &matrix2);
629                 // make the other useful stuff
630                 Matrix4x4_Invert_Simple(&e->render.inversematrix, &e->render.matrix);
631                 CL_BoundingBoxForEntity(&e->render);
632
633                 // handle effects now that we know where this entity is in the world...
634                 origin[0] = e->render.matrix.m[0][3];
635                 origin[1] = e->render.matrix.m[1][3];
636                 origin[2] = e->render.matrix.m[2][3];
637                 trailtype = -1;
638                 dlightcolor[0] = 0;
639                 dlightcolor[1] = 0;
640                 dlightcolor[2] = 0;
641                 // LordHavoc: if the entity has no effects, don't check each
642                 if (e->render.effects)
643                 {
644                         if (e->render.effects & EF_BRIGHTFIELD)
645                         {
646                                 if (gamemode == GAME_NEXUIZ)
647                                 {
648                                         dlightcolor[0] += 100.0f;
649                                         dlightcolor[1] += 200.0f;
650                                         dlightcolor[2] += 400.0f;
651                                         trailtype = 8;
652                                 }
653                                 else
654                                         CL_EntityParticles(e);
655                         }
656                         if (e->render.effects & EF_MUZZLEFLASH)
657                                 e->persistent.muzzleflash = 100.0f;
658                         if (e->render.effects & EF_DIMLIGHT)
659                         {
660                                 dlightcolor[0] += 200.0f;
661                                 dlightcolor[1] += 200.0f;
662                                 dlightcolor[2] += 200.0f;
663                         }
664                         if (e->render.effects & EF_BRIGHTLIGHT)
665                         {
666                                 dlightcolor[0] += 400.0f;
667                                 dlightcolor[1] += 400.0f;
668                                 dlightcolor[2] += 400.0f;
669                         }
670                         // LordHavoc: more effects
671                         if (e->render.effects & EF_RED) // red
672                         {
673                                 dlightcolor[0] += 200.0f;
674                                 dlightcolor[1] +=  20.0f;
675                                 dlightcolor[2] +=  20.0f;
676                         }
677                         if (e->render.effects & EF_BLUE) // blue
678                         {
679                                 dlightcolor[0] +=  20.0f;
680                                 dlightcolor[1] +=  20.0f;
681                                 dlightcolor[2] += 200.0f;
682                         }
683                         if (e->render.effects & EF_FLAME)
684                         {
685                                 mins[0] = origin[0] - 16.0f;
686                                 mins[1] = origin[1] - 16.0f;
687                                 mins[2] = origin[2] - 16.0f;
688                                 maxs[0] = origin[0] + 16.0f;
689                                 maxs[1] = origin[1] + 16.0f;
690                                 maxs[2] = origin[2] + 16.0f;
691                                 // how many flames to make
692                                 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
693                                 CL_FlameCube(mins, maxs, temp);
694                                 d = lhrandom(200, 250);
695                                 dlightcolor[0] += d * 1.0f;
696                                 dlightcolor[1] += d * 0.7f;
697                                 dlightcolor[2] += d * 0.3f;
698                         }
699                         if (e->render.effects & EF_STARDUST)
700                         {
701                                 mins[0] = origin[0] - 16.0f;
702                                 mins[1] = origin[1] - 16.0f;
703                                 mins[2] = origin[2] - 16.0f;
704                                 maxs[0] = origin[0] + 16.0f;
705                                 maxs[1] = origin[1] + 16.0f;
706                                 maxs[2] = origin[2] + 16.0f;
707                                 // how many particles to make
708                                 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
709                                 CL_Stardust(mins, maxs, temp);
710                                 d = 100;
711                                 dlightcolor[0] += d * 1.0f;
712                                 dlightcolor[1] += d * 0.7f;
713                                 dlightcolor[2] += d * 0.3f;
714                         }
715                 }
716                 // muzzleflash fades over time, and is offset a bit
717                 if (e->persistent.muzzleflash > 0)
718                 {
719                         Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
720                         CL_TraceLine(origin, v2, v, NULL, 0, true, NULL);
721                         CL_AllocDlight(NULL, v, e->persistent.muzzleflash, 1, 1, 1, 0, 0);
722                         e->persistent.muzzleflash -= cl.frametime * 1000;
723                 }
724                 // LordHavoc: if the model has no flags, don't check each
725                 if (e->render.model && e->render.model->flags)
726                 {
727                         if (e->render.model->flags & EF_GIB)
728                                 trailtype = 2;
729                         else if (e->render.model->flags & EF_ZOMGIB)
730                                 trailtype = 4;
731                         else if (e->render.model->flags & EF_TRACER)
732                         {
733                                 trailtype = 3;
734                                 dlightcolor[0] += 0x10;
735                                 dlightcolor[1] += 0x40;
736                                 dlightcolor[2] += 0x10;
737                         }
738                         else if (e->render.model->flags & EF_TRACER2)
739                         {
740                                 trailtype = 5;
741                                 dlightcolor[0] += 0x50;
742                                 dlightcolor[1] += 0x30;
743                                 dlightcolor[2] += 0x10;
744                         }
745                         else if (e->render.model->flags & EF_ROCKET)
746                         {
747                                 trailtype = 0;
748                                 dlightcolor[0] += 200.0f;
749                                 dlightcolor[1] += 160.0f;
750                                 dlightcolor[2] +=  80.0f;
751                         }
752                         else if (e->render.model->flags & EF_GRENADE)
753                         {
754                                 // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
755                                 trailtype = e->render.alpha == -1 ? 7 : 1;
756                         }
757                         else if (e->render.model->flags & EF_TRACER3)
758                         {
759                                 trailtype = 6;
760                                 dlightcolor[0] += 0x50;
761                                 dlightcolor[1] += 0x20;
762                                 dlightcolor[2] += 0x40;
763                         }
764                 }
765                 // LordHavoc: customizable glow
766                 if (e->state_current.glowsize)
767                 {
768                         // * 4 for the expansion from 0-255 to 0-1023 range,
769                         // / 255 to scale down byte colors
770                         VectorMA(dlightcolor, e->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[e->state_current.glowcolor], dlightcolor);
771                 }
772                 // make the dlight
773                 if ((dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL) && !e->state_current.tagentity)
774                 {
775                         VectorCopy(origin, v);
776                         // hack to make glowing player light shine on their gun
777                         if ((e - cl_entities) == cl.viewentity/* && !chase_active.integer*/)
778                                 v[2] += 30;
779                         CL_AllocDlight(&e->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
780                 }
781                 // trails need the previous frame
782                 if (e->state_previous.active && e->state_previous.modelindex == e->state_current.modelindex)
783                 {
784                         if (e->render.flags & RENDER_GLOWTRAIL)
785                                 CL_RocketTrail2(e->persistent.trail_origin, origin, e->state_current.glowcolor, e);
786                         else if (trailtype >= 0)
787                                 CL_RocketTrail(e->persistent.trail_origin, origin, trailtype, e);
788                 }
789                 VectorCopy(origin, e->persistent.trail_origin);
790                 // note: the cl.viewentity and intermission check is to hide player
791                 // shadow during intermission and during the Nehahra movie and
792                 // Nehahra cinematics
793                 if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE))
794                  && (e->render.alpha == 1)
795                  && !(e->render.flags & RENDER_VIEWMODEL)
796                  && ((e - cl_entities) != cl.viewentity || (!cl.intermission && !Nehahrademcompatibility && !cl_noplayershadow.integer)))
797                         e->render.flags |= RENDER_SHADOW;
798                 // as soon as player is known we can call V_CalcRefDef
799                 if ((e - cl_entities) == cl.viewentity)
800                         V_CalcRefdef();
801                 if (e->render.model && e->render.model->name[0] == '*' && e->render.model->type == mod_brush)
802                         cl_brushmodel_entities[cl_num_brushmodel_entities++] = &e->render;
803                 // don't show entities with no modelindex (note: this still shows
804                 // entities which have a modelindex that resolved to a NULL model)
805                 if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
806                         r_refdef.entities[r_refdef.numentities++] = &e->render;
807                 if (cl_num_entities < e->state_current.number + 1)
808                         cl_num_entities = e->state_current.number + 1;
809         }
810 }
811
812 void CL_RelinkWorld(void)
813 {
814         entity_t *ent = &cl_entities[0];
815         if (cl_num_entities < 1)
816                 cl_num_entities = 1;
817         cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
818         // FIXME: this should be done at load
819         Matrix4x4_CreateIdentity(&ent->render.matrix);
820         Matrix4x4_CreateIdentity(&ent->render.inversematrix);
821         CL_BoundingBoxForEntity(&ent->render);
822 }
823
824 static void CL_RelinkStaticEntities(void)
825 {
826         int i;
827         for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
828         {
829                 Mod_CheckLoaded(cl_static_entities[i].render.model);
830                 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
831         }
832 }
833
834 /*
835 ===============
836 CL_RelinkEntities
837 ===============
838 */
839 static void CL_RelinkNetworkEntities(void)
840 {
841         entity_t *ent;
842         int i;
843
844         ent = &cl.viewent;
845         ent->state_previous = ent->state_current;
846         ClearStateToDefault(&ent->state_current);
847         ent->state_current.time = cl.time;
848         ent->state_current.number = -1;
849         ent->state_current.active = true;
850         ent->state_current.modelindex = cl.stats[STAT_WEAPON];
851         ent->state_current.frame = cl.stats[STAT_WEAPONFRAME];
852         ent->state_current.flags = RENDER_VIEWMODEL;
853
854         // start on the entity after the world
855         entitylinkframenumber++;
856         for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
857         {
858                 if (cl_entities_active[i])
859                 {
860                         if (ent->state_current.active)
861                                 CL_LinkNetworkEntity(ent);
862                         else
863                                 cl_entities_active[i] = false;
864                 }
865         }
866         CL_LinkNetworkEntity(&cl.viewent);
867 }
868
869 static void CL_RelinkEffects(void)
870 {
871         int i, intframe;
872         cl_effect_t *e;
873         entity_t *ent;
874         float frame;
875
876         for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
877         {
878                 if (e->active)
879                 {
880                         frame = (cl.time - e->starttime) * e->framerate + e->startframe;
881                         intframe = frame;
882                         if (intframe < 0 || intframe >= e->endframe)
883                         {
884                                 memset(e, 0, sizeof(*e));
885                                 continue;
886                         }
887
888                         if (intframe != e->frame)
889                         {
890                                 e->frame = intframe;
891                                 e->frame1time = e->frame2time;
892                                 e->frame2time = cl.time;
893                         }
894
895                         // if we're drawing effects, get a new temp entity
896                         // (NewTempEntity adds it to the render entities list for us)
897                         if (r_draweffects.integer && (ent = CL_NewTempEntity()))
898                         {
899                                 // interpolation stuff
900                                 ent->render.frame1 = intframe;
901                                 ent->render.frame2 = intframe + 1;
902                                 if (ent->render.frame2 >= e->endframe)
903                                         ent->render.frame2 = -1; // disappear
904                                 ent->render.framelerp = frame - intframe;
905                                 ent->render.frame1time = e->frame1time;
906                                 ent->render.frame2time = e->frame2time;
907
908                                 // normal stuff
909                                 ent->render.model = cl.model_precache[e->modelindex];
910                                 ent->render.frame = ent->render.frame2;
911                                 ent->render.colormap = -1; // no special coloring
912                                 ent->render.alpha = 1;
913
914                                 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
915                                 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
916                                 CL_BoundingBoxForEntity(&ent->render);
917                         }
918                 }
919         }
920 }
921
922 void CL_RelinkBeams(void)
923 {
924         int i;
925         beam_t *b;
926         vec3_t dist, org;
927         float d;
928         entity_t *ent;
929         float yaw, pitch;
930         float forward;
931
932         for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
933         {
934                 if (!b->model || b->endtime < cl.time)
935                         continue;
936
937                 // if coming from the player, update the start position
938                 //if (b->entity == cl.viewentity)
939                 //      VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
940                 if (cl_beams_relative.integer && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
941                 {
942                         entity_state_t *p = &cl_entities[b->entity].state_previous;
943                         //entity_state_t *c = &cl_entities[b->entity].state_current;
944                         entity_render_t *r = &cl_entities[b->entity].render;
945                         matrix4x4_t matrix, imatrix;
946                         if (b->relativestartvalid == 2)
947                         {
948                                 // not really valid yet, we need to get the orientation now
949                                 // (ParseBeam flagged this because it is received before
950                                 //  entities are received, by now they have been received)
951                                 // note: because players create lightning in their think
952                                 // function (which occurs before movement), they actually
953                                 // have some lag in it's location, so compare to the
954                                 // previous player state, not the latest
955                                 if (b->entity == cl.viewentity)
956                                         Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
957                                 else
958                                         Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
959                                 Matrix4x4_Invert_Simple(&imatrix, &matrix);
960                                 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
961                                 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
962                                 b->relativestartvalid = 1;
963                         }
964                         else
965                         {
966                                 if (b->entity == cl.viewentity)
967                                         Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
968                                 else
969                                         Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
970                                 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
971                                 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
972                         }
973                 }
974
975                 if (b->lightning)
976                 {
977                         if (cl_beams_lightatend.integer)
978                                 CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
979                         if (cl_beams_polygons.integer)
980                                 continue;
981                 }
982
983                 // calculate pitch and yaw
984                 VectorSubtract (b->end, b->start, dist);
985
986                 if (dist[1] == 0 && dist[0] == 0)
987                 {
988                         yaw = 0;
989                         if (dist[2] > 0)
990                                 pitch = 90;
991                         else
992                                 pitch = 270;
993                 }
994                 else
995                 {
996                         yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
997                         if (yaw < 0)
998                                 yaw += 360;
999
1000                         forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
1001                         pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
1002                         if (pitch < 0)
1003                                 pitch += 360;
1004                 }
1005
1006                 // add new entities for the lightning
1007                 VectorCopy (b->start, org);
1008                 d = VectorNormalizeLength(dist);
1009                 while (d > 0)
1010                 {
1011                         ent = CL_NewTempEntity ();
1012                         if (!ent)
1013                                 return;
1014                         //VectorCopy (org, ent->render.origin);
1015                         ent->render.model = b->model;
1016                         ent->render.effects = EF_FULLBRIGHT;
1017                         //ent->render.angles[0] = pitch;
1018                         //ent->render.angles[1] = yaw;
1019                         //ent->render.angles[2] = rand()%360;
1020                         Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1021                         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1022                         CL_BoundingBoxForEntity(&ent->render);
1023                         VectorMA(org, 30, dist, org);
1024                         d -= 30;
1025                 }
1026         }
1027 }
1028
1029 void CL_LerpPlayer(float frac)
1030 {
1031         int i;
1032         float d;
1033
1034         cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
1035
1036         for (i = 0;i < 3;i++)
1037                 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1038
1039         if (cls.demoplayback)
1040         {
1041                 // interpolate the angles
1042                 for (i = 0;i < 3;i++)
1043                 {
1044                         d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1045                         if (d > 180)
1046                                 d -= 360;
1047                         else if (d < -180)
1048                                 d += 360;
1049                         cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1050                 }
1051         }
1052 }
1053
1054 /*
1055 ===============
1056 CL_ReadFromServer
1057
1058 Read all incoming data from the server
1059 ===============
1060 */
1061 int CL_ReadFromServer(void)
1062 {
1063         CL_ReadDemoMessage();
1064
1065         r_refdef.numentities = 0;
1066         cl_num_entities = 0;
1067         cl_num_brushmodel_entities = 0;
1068
1069         if (cls.state == ca_connected && cls.signon == SIGNONS)
1070         {
1071                 // prepare for a new frame
1072                 CL_LerpPlayer(CL_LerpPoint());
1073                 CL_DecayLights();
1074                 CL_ClearTempEntities();
1075                 V_DriftPitch();
1076                 V_FadeViewFlashs();
1077
1078                 // relink network entities (note: this sets up the view!)
1079                 CL_RelinkNetworkEntities();
1080
1081                 // move particles
1082                 CL_MoveParticles();
1083
1084                 // link stuff
1085                 CL_RelinkWorld();
1086                 CL_RelinkStaticEntities();
1087                 CL_RelinkBeams();
1088                 CL_RelinkEffects();
1089
1090                 // run cgame code (which can add more entities)
1091                 CL_CGVM_Frame();
1092
1093                 // update view blend
1094                 V_CalcViewBlend();
1095         }
1096
1097         return 0;
1098 }
1099
1100 /*
1101 =================
1102 CL_SendCmd
1103 =================
1104 */
1105 void CL_SendCmd(void)
1106 {
1107         usercmd_t cmd;
1108
1109         if (cls.signon == SIGNONS)
1110         {
1111                 // get basic movement from keyboard
1112                 CL_BaseMove(&cmd);
1113
1114                 // OS independent code
1115                 IN_PreMove();
1116
1117                 // allow mice or other external controllers to add to the move
1118                 IN_Move(&cmd);
1119
1120                 // OS independent code
1121                 IN_PostMove();
1122
1123                 // send the unreliable message
1124                 CL_SendMove(&cmd);
1125         }
1126
1127         if (cls.demoplayback)
1128         {
1129                 SZ_Clear(&cls.message);
1130                 return;
1131         }
1132
1133         // send the reliable message (forwarded commands) if there is one
1134         if (cls.message.cursize && NetConn_CanSendMessage(cls.netcon))
1135         {
1136                 if (developer.integer)
1137                 {
1138                         Con_Printf("CL_SendCmd: sending reliable message:\n");
1139                         SZ_HexDumpToConsole(&cls.message);
1140                 }
1141                 if (NetConn_SendReliableMessage(cls.netcon, &cls.message) == -1)
1142                         Host_Error("CL_WriteToServer: lost server connection");
1143                 SZ_Clear(&cls.message);
1144         }
1145 }
1146
1147 // LordHavoc: pausedemo command
1148 static void CL_PauseDemo_f (void)
1149 {
1150         cls.demopaused = !cls.demopaused;
1151         if (cls.demopaused)
1152                 Con_Printf("Demo paused\n");
1153         else
1154                 Con_Printf("Demo unpaused\n");
1155 }
1156
1157 /*
1158 ======================
1159 CL_Fog_f
1160 ======================
1161 */
1162 static void CL_Fog_f (void)
1163 {
1164         if (Cmd_Argc () == 1)
1165         {
1166                 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1167                 return;
1168         }
1169         fog_density = atof(Cmd_Argv(1));
1170         fog_red = atof(Cmd_Argv(2));
1171         fog_green = atof(Cmd_Argv(3));
1172         fog_blue = atof(Cmd_Argv(4));
1173 }
1174
1175 /*
1176 =================
1177 CL_Init
1178 =================
1179 */
1180 void CL_Init (void)
1181 {
1182         cl_entities_mempool = Mem_AllocPool("client entities");
1183         cl_refdef_mempool = Mem_AllocPool("refdef");
1184
1185         memset(&r_refdef, 0, sizeof(r_refdef));
1186         // max entities sent to renderer per frame
1187         r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1188         r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1189         // 256k drawqueue buffer
1190         r_refdef.maxdrawqueuesize = 256 * 1024;
1191         r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1192
1193         SZ_Alloc (&cls.message, 1024, "cls.message");
1194
1195         CL_InitInput ();
1196         CL_InitTEnts ();
1197
1198 //
1199 // register our commands
1200 //
1201         Cvar_RegisterVariable (&cl_upspeed);
1202         Cvar_RegisterVariable (&cl_forwardspeed);
1203         Cvar_RegisterVariable (&cl_backspeed);
1204         Cvar_RegisterVariable (&cl_sidespeed);
1205         Cvar_RegisterVariable (&cl_movespeedkey);
1206         Cvar_RegisterVariable (&cl_yawspeed);
1207         Cvar_RegisterVariable (&cl_pitchspeed);
1208         Cvar_RegisterVariable (&cl_anglespeedkey);
1209         Cvar_RegisterVariable (&cl_shownet);
1210         Cvar_RegisterVariable (&cl_nolerp);
1211         Cvar_RegisterVariable (&lookspring);
1212         Cvar_RegisterVariable (&lookstrafe);
1213         Cvar_RegisterVariable (&sensitivity);
1214         Cvar_RegisterVariable (&freelook);
1215
1216         Cvar_RegisterVariable (&m_pitch);
1217         Cvar_RegisterVariable (&m_yaw);
1218         Cvar_RegisterVariable (&m_forward);
1219         Cvar_RegisterVariable (&m_side);
1220
1221         Cvar_RegisterVariable (&cl_itembobspeed);
1222         Cvar_RegisterVariable (&cl_itembobheight);
1223
1224         Cmd_AddCommand ("entities", CL_PrintEntities_f);
1225         Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1226         Cmd_AddCommand ("record", CL_Record_f);
1227         Cmd_AddCommand ("stop", CL_Stop_f);
1228         Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1229         Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1230
1231         Cmd_AddCommand ("fog", CL_Fog_f);
1232
1233         // LordHavoc: added pausedemo
1234         Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1235
1236         Cvar_RegisterVariable(&r_draweffects);
1237         Cvar_RegisterVariable(&cl_explosions);
1238         Cvar_RegisterVariable(&cl_stainmaps);
1239         Cvar_RegisterVariable(&cl_beams_polygons);
1240         Cvar_RegisterVariable(&cl_beams_relative);
1241         Cvar_RegisterVariable(&cl_beams_lightatend);
1242         Cvar_RegisterVariable(&cl_noplayershadow);
1243
1244         CL_Parse_Init();
1245         CL_Particles_Init();
1246         CL_Screen_Init();
1247         CL_CGVM_Init();
1248
1249         CL_Video_Init();
1250 }
1251