Initial revision
[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
24 // we need to declare some mouse variables here, because the menu system
25 // references them even when on a unix system.
26
27 // these two are not intended to be set directly
28 cvar_t  cl_name = {"_cl_name", "player", true};
29 cvar_t  cl_color = {"_cl_color", "0", true};
30
31 cvar_t  cl_shownet = {"cl_shownet","0"};        // can be 0, 1, or 2
32 cvar_t  cl_nolerp = {"cl_nolerp","0"};
33
34 cvar_t  maxfps = {"maxfps", "100"};
35
36 cvar_t  lookspring = {"lookspring","0", true};
37 cvar_t  lookstrafe = {"lookstrafe","0", true};
38 cvar_t  sensitivity = {"sensitivity","3", true};
39
40 cvar_t  m_pitch = {"m_pitch","0.022", true};
41 cvar_t  m_yaw = {"m_yaw","0.022", true};
42 cvar_t  m_forward = {"m_forward","1", true};
43 cvar_t  m_side = {"m_side","0.8", true};
44
45
46 client_static_t cls;
47 client_state_t  cl;
48 // FIXME: put these on hunk?
49 efrag_t                 cl_efrags[MAX_EFRAGS];
50 entity_t                cl_entities[MAX_EDICTS];
51 entity_t                cl_static_entities[MAX_STATIC_ENTITIES];
52 lightstyle_t    cl_lightstyle[MAX_LIGHTSTYLES];
53 dlight_t                cl_dlights[MAX_DLIGHTS];
54
55 int                             cl_numvisedicts;
56 entity_t                *cl_visedicts[MAX_VISEDICTS];
57
58 /*
59 =====================
60 CL_ClearState
61
62 =====================
63 */
64 void CL_ClearState (void)
65 {
66         int                     i;
67
68         if (!sv.active)
69                 Host_ClearMemory ();
70
71 // wipe the entire cl structure
72         memset (&cl, 0, sizeof(cl));
73
74         SZ_Clear (&cls.message);
75
76 // clear other arrays   
77         memset (cl_efrags, 0, sizeof(cl_efrags));
78         memset (cl_entities, 0, sizeof(cl_entities));
79         memset (cl_dlights, 0, sizeof(cl_dlights));
80         memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
81         memset (cl_temp_entities, 0, sizeof(cl_temp_entities));
82         memset (cl_beams, 0, sizeof(cl_beams));
83         // LordHavoc: have to set up the baseline info for alpha and other stuff
84         for (i = 0;i < MAX_EDICTS;i++)
85         {
86                 cl_entities[i].baseline.alpha = 255;
87                 cl_entities[i].baseline.scale = 16;
88                 cl_entities[i].baseline.glowsize = 0;
89                 cl_entities[i].baseline.glowcolor = 254;
90                 cl_entities[i].baseline.colormod = 255;
91         }
92
93 //
94 // allocate the efrags and chain together into a free list
95 //
96         cl.free_efrags = cl_efrags;
97         for (i=0 ; i<MAX_EFRAGS-1 ; i++)
98                 cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
99         cl.free_efrags[i].entnext = NULL;
100 }
101
102 /*
103 =====================
104 CL_Disconnect
105
106 Sends a disconnect message to the server
107 This is also called on Host_Error, so it shouldn't cause any errors
108 =====================
109 */
110 void CL_Disconnect (void)
111 {
112 // stop sounds (especially looping!)
113         S_StopAllSounds (true);
114         
115 // bring the console down and fade the colors back to normal
116 //      SCR_BringDownConsole ();
117
118 // if running a local server, shut it down
119         if (cls.demoplayback)
120                 CL_StopPlayback ();
121         else if (cls.state == ca_connected)
122         {
123                 if (cls.demorecording)
124                         CL_Stop_f ();
125
126                 Con_DPrintf ("Sending clc_disconnect\n");
127                 SZ_Clear (&cls.message);
128                 MSG_WriteByte (&cls.message, clc_disconnect);
129                 NET_SendUnreliableMessage (cls.netcon, &cls.message);
130                 SZ_Clear (&cls.message);
131                 NET_Close (cls.netcon);
132
133                 cls.state = ca_disconnected;
134                 if (sv.active)
135                         Host_ShutdownServer(false);
136         }
137
138         cls.demoplayback = cls.timedemo = false;
139         cls.signon = 0;
140 }
141
142 void CL_Disconnect_f (void)
143 {
144         CL_Disconnect ();
145         if (sv.active)
146                 Host_ShutdownServer (false);
147 }
148
149
150
151
152 /*
153 =====================
154 CL_EstablishConnection
155
156 Host should be either "local" or a net address to be passed on
157 =====================
158 */
159 void CL_EstablishConnection (char *host)
160 {
161         if (cls.state == ca_dedicated)
162                 return;
163
164         if (cls.demoplayback)
165                 return;
166
167         CL_Disconnect ();
168
169         cls.netcon = NET_Connect (host);
170         if (!cls.netcon)
171                 Host_Error ("CL_Connect: connect failed\n");
172         Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
173         
174         cls.demonum = -1;                       // not in the demo loop now
175         cls.state = ca_connected;
176         cls.signon = 0;                         // need all the signon messages before playing
177 }
178
179 extern int numgltextures;
180 extern int texels;
181
182 /*
183 =====================
184 CL_SignonReply
185
186 An svc_signonnum has been received, perform a client side setup
187 =====================
188 */
189 void CL_SignonReply (void)
190 {
191         char    str[8192];
192
193 Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
194
195         switch (cls.signon)
196         {
197         case 1:
198                 MSG_WriteByte (&cls.message, clc_stringcmd);
199                 MSG_WriteString (&cls.message, "prespawn");
200                 break;
201                 
202         case 2:         
203                 MSG_WriteByte (&cls.message, clc_stringcmd);
204                 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
205         
206                 MSG_WriteByte (&cls.message, clc_stringcmd);
207                 MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
208         
209                 MSG_WriteByte (&cls.message, clc_stringcmd);
210                 sprintf (str, "spawn %s", cls.spawnparms);
211                 MSG_WriteString (&cls.message, str);
212                 break;
213                 
214         case 3: 
215                 MSG_WriteByte (&cls.message, clc_stringcmd);
216                 MSG_WriteString (&cls.message, "begin");
217                 Cache_Report ();                // print remaining memory
218                 break;
219                 
220         case 4:
221                 SCR_EndLoadingPlaque ();                // allow normal screen updates
222                 // LordHavoc: debugging purposes
223                 Con_DPrintf("GLQuake texture slots in use: %i : %i : %i texels\n", texture_extension_number, numgltextures, texels);
224                 break;
225         }
226 }
227
228 /*
229 =====================
230 CL_NextDemo
231
232 Called to play the next demo in the demo loop
233 =====================
234 */
235 void CL_NextDemo (void)
236 {
237         char    str[1024];
238
239         if (cls.demonum == -1)
240                 return;         // don't play demos
241
242         SCR_BeginLoadingPlaque ();
243
244         if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
245         {
246                 cls.demonum = 0;
247                 if (!cls.demos[cls.demonum][0])
248                 {
249                         Con_Printf ("No demos listed with startdemos\n");
250                         cls.demonum = -1;
251                         return;
252                 }
253         }
254
255         sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
256         Cbuf_InsertText (str);
257         cls.demonum++;
258 }
259
260 /*
261 ==============
262 CL_PrintEntities_f
263 ==============
264 */
265 void CL_PrintEntities_f (void)
266 {
267         entity_t        *ent;
268         int                     i;
269         
270         for (i=0,ent=cl_entities ; i<cl.num_entities ; i++,ent++)
271         {
272                 Con_Printf ("%3i:",i);
273                 if (!ent->model)
274                 {
275                         Con_Printf ("EMPTY\n");
276                         continue;
277                 }
278                 Con_Printf ("%s:%2i  (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n"
279                 ,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]);
280         }
281 }
282
283
284 /*
285 ===============
286 SetPal
287
288 Debugging tool, just flashes the screen
289 ===============
290 */
291 void SetPal (int i)
292 {
293 #if 0
294         static int old;
295         byte    pal[768];
296         int             c;
297         
298         if (i == old)
299                 return;
300         old = i;
301
302         if (i==0)
303                 VID_SetPalette (host_basepal);
304         else if (i==1)
305         {
306                 for (c=0 ; c<768 ; c+=3)
307                 {
308                         pal[c] = 0;
309                         pal[c+1] = 255;
310                         pal[c+2] = 0;
311                 }
312                 VID_SetPalette (pal);
313         }
314         else
315         {
316                 for (c=0 ; c<768 ; c+=3)
317                 {
318                         pal[c] = 0;
319                         pal[c+1] = 0;
320                         pal[c+2] = 255;
321                 }
322                 VID_SetPalette (pal);
323         }
324 #endif
325 }
326
327 /*
328 ===============
329 CL_AllocDlight
330
331 ===============
332 */
333 dlight_t *CL_AllocDlight (int key)
334 {
335         int             i;
336         dlight_t        *dl;
337
338 // first look for an exact key match
339         if (key)
340         {
341                 dl = cl_dlights;
342                 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
343                 {
344                         if (dl->key == key)
345                         {
346                                 memset (dl, 0, sizeof(*dl));
347                                 dl->key = key;
348                                 return dl;
349                         }
350                 }
351         }
352
353 // then look for anything else
354         dl = cl_dlights;
355         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
356         {
357                 if (dl->die < cl.time)
358                 {
359                         memset (dl, 0, sizeof(*dl));
360                         dl->key = key;
361                         return dl;
362                 }
363         }
364
365         dl = &cl_dlights[0];
366         memset (dl, 0, sizeof(*dl));
367         dl->key = key;
368         return dl;
369 }
370
371
372 /*
373 ===============
374 CL_DecayLights
375
376 ===============
377 */
378 void CL_DecayLights (void)
379 {
380         int                     i;
381         dlight_t        *dl;
382         float           time;
383         
384         time = cl.time - cl.oldtime;
385
386         dl = cl_dlights;
387         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
388         {
389                 if (dl->die < cl.time || !dl->radius)
390                         continue;
391                 
392                 dl->radius -= time*dl->decay;
393                 if (dl->radius < 0)
394                         dl->radius = 0;
395         }
396 }
397
398
399 /*
400 ===============
401 CL_LerpPoint
402
403 Determines the fraction between the last two messages that the objects
404 should be put at.
405 ===============
406 */
407 float   CL_LerpPoint (void)
408 {
409         float   f, frac;
410
411         f = cl.mtime[0] - cl.mtime[1];
412         
413         if (!f || cl_nolerp.value || cls.timedemo || sv.active)
414         {
415                 cl.time = cl.mtime[0];
416                 return 1;
417         }
418                 
419         if (f > 0.1)
420         {       // dropped packet, or start of demo
421                 cl.mtime[1] = cl.mtime[0] - 0.1;
422                 f = 0.1;
423         }
424         frac = (cl.time - cl.mtime[1]) / f;
425 //Con_Printf ("frac: %f\n",frac);
426         if (frac < 0)
427         {
428                 if (frac < -0.01)
429                 {
430 SetPal(1);
431                         cl.time = cl.mtime[1];
432 //                              Con_Printf ("low frac\n");
433                 }
434                 frac = 0;
435         }
436         else if (frac > 1)
437         {
438                 if (frac > 1.01)
439                 {
440 SetPal(2);
441                         cl.time = cl.mtime[0];
442 //                              Con_Printf ("high frac\n");
443                 }
444                 frac = 1;
445         }
446         else
447                 SetPal(0);
448                 
449         return frac;
450 }
451
452
453 /*
454 ===============
455 CL_RelinkEntities
456 ===============
457 */
458 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
459 void CL_RelinkEntities (void)
460 {
461         entity_t        *ent;
462         int                     i, j;
463         float           frac, f, d;
464         vec3_t          delta;
465         float           bobjrotate;
466         vec3_t          oldorg;
467         dlight_t        *dl;
468         byte            *tempcolor;
469
470 // determine partial update time        
471         frac = CL_LerpPoint ();
472
473         cl_numvisedicts = 0;
474
475 //
476 // interpolate player info
477 //
478         for (i=0 ; i<3 ; i++)
479                 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
480
481         if (cls.demoplayback)
482         {
483         // interpolate the angles       
484                 for (j=0 ; j<3 ; j++)
485                 {
486                         d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
487                         if (d > 180)
488                                 d -= 360;
489                         else if (d < -180)
490                                 d += 360;
491                         cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
492                 }
493         }
494         
495         bobjrotate = anglemod(100*cl.time);
496         
497 // start on the entity after the world
498         for (i=1,ent=cl_entities+1 ; i<cl.num_entities ; i++,ent++)
499         {
500                 if (!ent->model)
501                 {       // empty slot
502                         if (ent->forcelink)
503                                 R_RemoveEfrags (ent);   // just became empty
504                         continue;
505                 }
506
507 // if the object wasn't included in the last packet, remove it
508                 if (ent->msgtime != cl.mtime[0])
509                 {
510                         ent->model = NULL;
511                         continue;
512                 }
513
514                 VectorCopy (ent->origin, oldorg);
515
516                 if (ent->forcelink)
517                 {       // the entity was not updated in the last message
518                         // so move to the final spot
519                         VectorCopy (ent->msg_origins[0], ent->origin);
520                         VectorCopy (ent->msg_angles[0], ent->angles);
521                 }
522                 else
523                 {       // if the delta is large, assume a teleport and don't lerp
524                         f = frac;
525                         for (j=0 ; j<3 ; j++)
526                         {
527                                 delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j];
528                                 // LordHavoc: increased lerp tolerance from 100 to 200
529                                 if (delta[j] > 200 || delta[j] < -200)
530                                         f = 1;          // assume a teleportation, not a motion
531                         }
532
533                 // interpolate the origin and angles
534                         for (j=0 ; j<3 ; j++)
535                         {
536                                 ent->origin[j] = ent->msg_origins[1][j] + f*delta[j];
537
538                                 d = ent->msg_angles[0][j] - ent->msg_angles[1][j];
539                                 if (d > 180)
540                                         d -= 360;
541                                 else if (d < -180)
542                                         d += 360;
543                                 ent->angles[j] = ent->msg_angles[1][j] + f*d;
544                         }
545                         
546                 }
547
548                 if (ent->effects & EF_BRIGHTFIELD)
549                         R_EntityParticles (ent);
550                 if (ent->effects & EF_MUZZLEFLASH)
551                 {
552                         vec3_t          fv, rv, uv;
553
554                         dl = CL_AllocDlight (i);
555                         VectorCopy (ent->origin,  dl->origin);
556                         dl->origin[2] += 16;
557                         AngleVectors (ent->angles, fv, rv, uv);
558                          
559                         VectorMA (dl->origin, 18, fv, dl->origin);
560                         dl->radius = 200 + (rand()&31);
561                         dl->minlight = 32;
562                         dl->die = cl.time + 0.1;
563                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
564                 }
565                 if (ent->effects & EF_BRIGHTLIGHT)
566                 {                       
567                         dl = CL_AllocDlight (i);
568                         VectorCopy (ent->origin,  dl->origin);
569                         dl->origin[2] += 16;
570                         dl->radius = 400 + (rand()&31);
571                         dl->die = cl.time + 0.001;
572                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
573                 }
574                 if (ent->effects & EF_DIMLIGHT)
575                 {                       
576                         dl = CL_AllocDlight (i);
577                         VectorCopy (ent->origin,  dl->origin);
578                         dl->radius = 200 + (rand()&31);
579                         dl->die = cl.time + 0.001;
580                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
581                 }
582                 // LordHavoc: added EF_RED and EF_BLUE
583                 if (ent->effects & EF_RED) // red
584                 {                       
585                         if (ent->effects & EF_BLUE) // magenta
586                         {
587                                 dl = CL_AllocDlight (i);
588                                 VectorCopy (ent->origin,  dl->origin);
589                                 dl->radius = 200 + (rand()&31);
590                                 dl->die = cl.time + 0.001;
591                                 dl->color[0] = 0.7;dl->color[1] = 0.07;dl->color[2] = 0.7;
592                         }
593                         else // red
594                         {
595                                 dl = CL_AllocDlight (i);
596                                 VectorCopy (ent->origin,  dl->origin);
597                                 dl->radius = 200 + (rand()&31);
598                                 dl->die = cl.time + 0.001;
599                                 dl->color[0] = 0.8;dl->color[1] = 0.05;dl->color[2] = 0.05;
600                         }
601                 }
602                 else if (ent->effects & EF_BLUE) // blue
603                 {
604                         dl = CL_AllocDlight (i);
605                         VectorCopy (ent->origin,  dl->origin);
606                         dl->radius = 200 + (rand()&31);
607                         dl->die = cl.time + 0.001;
608                         dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
609                 }
610
611                 if (ent->model->flags) // LordHavoc: if the model has no flags, don't check each
612                 {
613                 // rotate binary objects locally
614                         if (ent->model->flags & EF_ROTATE)
615                                 ent->angles[1] = bobjrotate;
616                         if (ent->model->flags & EF_GIB)
617                                 R_RocketTrail (oldorg, ent->origin, 2, ent);
618                         else if (ent->model->flags & EF_ZOMGIB)
619                                 R_RocketTrail (oldorg, ent->origin, 4, ent);
620                         else if (ent->model->flags & EF_TRACER)
621                                 R_RocketTrail (oldorg, ent->origin, 3, ent);
622                         else if (ent->model->flags & EF_TRACER2)
623                                 R_RocketTrail (oldorg, ent->origin, 5, ent);
624                         else if (ent->model->flags & EF_ROCKET)
625                         {
626                                 R_RocketTrail (oldorg, ent->origin, 0, ent);
627                                 dl = CL_AllocDlight (i);
628                                 VectorCopy (ent->origin, dl->origin);
629                                 dl->radius = 200;
630                                 dl->die = cl.time + 0.001;
631                                 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
632                         }
633                         else if (ent->model->flags & EF_GRENADE)
634                         {
635                                 if (ent->alpha == -1) // LordHavoc: Nehahra dem compatibility
636                                         R_RocketTrail (oldorg, ent->origin, 7, ent);
637                                 else
638                                         R_RocketTrail (oldorg, ent->origin, 1, ent);
639                         }
640                         else if (ent->model->flags & EF_TRACER3)
641                                 R_RocketTrail (oldorg, ent->origin, 6, ent);
642                 }
643                 if (ent->glowsize) // LordHavoc: customizable glow
644                 {
645                         dl = CL_AllocDlight (i);
646                         VectorCopy (ent->origin, dl->origin);
647                         dl->dark = ent->glowsize < 0; // darklight
648                         dl->radius = ent->glowsize;
649                         if (dl->dark)
650                         {
651                                 if (ent->glowtrail) // LordHavoc: all darklights leave black trails
652                                         R_RocketTrail2 (oldorg, ent->origin, 0, ent);
653                                 dl->radius = -ent->glowsize;
654                         }
655                         else if (ent->glowtrail) // LordHavoc: customizable glow and trail
656                                 R_RocketTrail2 (oldorg, ent->origin, ent->glowcolor, ent);
657                         dl->die = cl.time + 0.001;
658                         tempcolor = (byte *)&d_8to24table[ent->glowcolor];
659                         dl->color[0] = tempcolor[0]*(1.0/255.0);dl->color[1] = tempcolor[1]*(1.0/255.0);dl->color[2] = tempcolor[2]*(1.0/255.0);
660                 }
661                 else if (ent->glowtrail) // LordHavoc: customizable glow and trail
662                         R_RocketTrail2 (oldorg, ent->origin, ent->glowcolor, ent);
663
664                 ent->forcelink = false;
665
666                 if (i == cl.viewentity && !chase_active.value)
667                         continue;
668
669 // LordHavoc: enabled EF_NODRAW
670                 if (!ent->model || ent->effects & EF_NODRAW)
671                         continue;
672                 if (cl_numvisedicts < MAX_VISEDICTS)
673                 {
674                         cl_visedicts[cl_numvisedicts] = ent;
675                         cl_numvisedicts++;
676                 }
677         }
678
679 }
680
681
682 /*
683 ===============
684 CL_ReadFromServer
685
686 Read all incoming data from the server
687 ===============
688 */
689 int CL_ReadFromServer (void)
690 {
691         int             ret;
692
693         cl.oldtime = cl.time;
694         cl.time += host_frametime;
695         
696         do
697         {
698                 ret = CL_GetMessage ();
699                 if (ret == -1)
700                         Host_Error ("CL_ReadFromServer: lost server connection");
701                 if (!ret)
702                         break;
703                 
704                 cl.last_received_message = realtime;
705                 CL_ParseServerMessage ();
706         } while (ret && cls.state == ca_connected);
707         
708         if (cl_shownet.value)
709                 Con_Printf ("\n");
710
711         CL_RelinkEntities ();
712         CL_UpdateTEnts ();
713
714 //
715 // bring the links up to date
716 //
717         return 0;
718 }
719
720 /*
721 =================
722 CL_SendCmd
723 =================
724 */
725 void CL_SendCmd (void)
726 {
727         usercmd_t               cmd;
728
729         if (cls.state != ca_connected)
730                 return;
731
732         if (cls.signon == SIGNONS)
733         {
734         // get basic movement from keyboard
735                 CL_BaseMove (&cmd);
736         
737         // allow mice or other external controllers to add to the move
738                 IN_Move (&cmd);
739         
740         // send the unreliable message
741                 CL_SendMove (&cmd);
742         
743         }
744
745         if (cls.demoplayback)
746         {
747                 SZ_Clear (&cls.message);
748                 return;
749         }
750         
751 // send the reliable message
752         if (!cls.message.cursize)
753                 return;         // no message at all
754         
755         if (!NET_CanSendMessage (cls.netcon))
756         {
757                 Con_DPrintf ("CL_WriteToServer: can't send\n");
758                 return;
759         }
760
761         if (NET_SendMessage (cls.netcon, &cls.message) == -1)
762                 Host_Error ("CL_WriteToServer: lost server connection");
763
764         SZ_Clear (&cls.message);
765 }
766
767 // LordHavoc: pausedemo command
768 void CL_PauseDemo_f (void)
769 {
770         cls.demopaused = !cls.demopaused;
771         if (cls.demopaused)
772                 Con_Printf("Demo paused\n");
773         else
774                 Con_Printf("Demo unpaused\n");
775 }
776
777 cvar_t demo_nehahra = {"demo_nehahra", "0"};
778
779 /*
780 =================
781 CL_Init
782 =================
783 */
784 void CL_Init (void)
785 {       
786         SZ_Alloc (&cls.message, 1024);
787
788         CL_InitInput ();
789         CL_InitTEnts ();
790         
791 //
792 // register our commands
793 //
794         Cvar_RegisterVariable (&cl_name);
795         Cvar_RegisterVariable (&cl_color);
796         Cvar_RegisterVariable (&cl_upspeed);
797         Cvar_RegisterVariable (&cl_forwardspeed);
798         Cvar_RegisterVariable (&cl_backspeed);
799         Cvar_RegisterVariable (&cl_sidespeed);
800         Cvar_RegisterVariable (&cl_movespeedkey);
801         Cvar_RegisterVariable (&cl_yawspeed);
802         Cvar_RegisterVariable (&cl_pitchspeed);
803         Cvar_RegisterVariable (&cl_anglespeedkey);
804         Cvar_RegisterVariable (&cl_shownet);
805         Cvar_RegisterVariable (&cl_nolerp);
806         Cvar_RegisterVariable (&maxfps);
807         Cvar_RegisterVariable (&lookspring);
808         Cvar_RegisterVariable (&lookstrafe);
809         Cvar_RegisterVariable (&sensitivity);
810
811         Cvar_RegisterVariable (&m_pitch);
812         Cvar_RegisterVariable (&m_yaw);
813         Cvar_RegisterVariable (&m_forward);
814         Cvar_RegisterVariable (&m_side);
815
816 //      Cvar_RegisterVariable (&cl_autofire);
817         
818         Cmd_AddCommand ("entities", CL_PrintEntities_f);
819         Cmd_AddCommand ("disconnect", CL_Disconnect_f);
820         Cmd_AddCommand ("record", CL_Record_f);
821         Cmd_AddCommand ("stop", CL_Stop_f);
822         Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
823         Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
824
825         // LordHavoc: added pausedemo
826         Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
827         // LordHavoc: added demo_nehahra cvar
828         Cvar_RegisterVariable (&demo_nehahra);
829         if (nehahra)
830                 Cvar_SetValue("demo_nehahra", 1);
831 }
832