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