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