]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_main.c
some whitespace changes
[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 cvar_t  cl_pmodel = {"_cl_pmodel", "0", true};
31
32 cvar_t  cl_shownet = {"cl_shownet","0"};        // can be 0, 1, or 2
33 cvar_t  cl_nolerp = {"cl_nolerp","0"};
34
35 cvar_t  lookspring = {"lookspring","0", true};
36 cvar_t  lookstrafe = {"lookstrafe","0", true};
37 cvar_t  sensitivity = {"sensitivity","3", true};
38
39 cvar_t  m_pitch = {"m_pitch","0.022", true};
40 cvar_t  m_yaw = {"m_yaw","0.022", true};
41 cvar_t  m_forward = {"m_forward","1", true};
42 cvar_t  m_side = {"m_side","0.8", true};
43
44 cvar_t freelook = {"freelook", "1", true};
45
46 cvar_t demo_nehahra = {"demo_nehahra", "0"};
47
48 client_static_t cls;
49 client_state_t  cl;
50 // FIXME: put these on hunk?
51 entity_t                cl_entities[MAX_EDICTS];
52 entity_t                cl_static_entities[MAX_STATIC_ENTITIES];
53 lightstyle_t    cl_lightstyle[MAX_LIGHTSTYLES];
54 dlight_t                cl_dlights[MAX_DLIGHTS];
55
56 int                             cl_numvisedicts;
57 entity_t                *cl_visedicts[MAX_VISEDICTS];
58
59 /*
60 =====================
61 CL_ClearState
62
63 =====================
64 */
65 void CL_ClearState (void)
66 {
67         int                     i;
68
69         if (!sv.active)
70                 Host_ClearMemory ();
71
72 // wipe the entire cl structure
73         memset (&cl, 0, sizeof(cl));
74
75         SZ_Clear (&cls.message);
76
77 // clear other arrays   
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                 ClearStateToDefault(&cl_entities[i].state_baseline);
87                 ClearStateToDefault(&cl_entities[i].state_previous);
88                 ClearStateToDefault(&cl_entities[i].state_current);
89         }
90 }
91
92 /*
93 =====================
94 CL_Disconnect
95
96 Sends a disconnect message to the server
97 This is also called on Host_Error, so it shouldn't cause any errors
98 =====================
99 */
100 void CL_Disconnect (void)
101 {
102 // stop sounds (especially looping!)
103         S_StopAllSounds (true);
104
105         // clear contents blends
106         cl.cshifts[0].percent = 0;
107         cl.cshifts[1].percent = 0;
108         cl.cshifts[2].percent = 0;
109         cl.cshifts[3].percent = 0;
110
111 // if running a local server, shut it down
112         if (cls.demoplayback)
113                 CL_StopPlayback ();
114         else if (cls.state == ca_connected)
115         {
116                 if (cls.demorecording)
117                         CL_Stop_f ();
118
119                 Con_DPrintf ("Sending clc_disconnect\n");
120                 SZ_Clear (&cls.message);
121                 MSG_WriteByte (&cls.message, clc_disconnect);
122                 NET_SendUnreliableMessage (cls.netcon, &cls.message);
123                 SZ_Clear (&cls.message);
124                 NET_Close (cls.netcon);
125
126                 cls.state = ca_disconnected;
127                 if (sv.active)
128                         Host_ShutdownServer(false);
129         }
130
131         cls.demoplayback = cls.timedemo = false;
132         cls.signon = 0;
133 }
134
135 void CL_Disconnect_f (void)
136 {
137         CL_Disconnect ();
138         if (sv.active)
139                 Host_ShutdownServer (false);
140 }
141
142
143
144
145 /*
146 =====================
147 CL_EstablishConnection
148
149 Host should be either "local" or a net address to be passed on
150 =====================
151 */
152 void CL_EstablishConnection (char *host)
153 {
154         if (cls.state == ca_dedicated)
155                 return;
156
157         if (cls.demoplayback)
158                 return;
159
160         CL_Disconnect ();
161
162         cls.netcon = NET_Connect (host);
163         if (!cls.netcon)
164                 Host_Error ("CL_Connect: connect failed\n");
165         Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
166         
167         cls.demonum = -1;                       // not in the demo loop now
168         cls.state = ca_connected;
169         cls.signon = 0;                         // need all the signon messages before playing
170 }
171
172 /*
173 =====================
174 CL_SignonReply
175
176 An svc_signonnum has been received, perform a client side setup
177 =====================
178 */
179 void CL_SignonReply (void)
180 {
181         char    str[8192];
182
183 Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
184
185         switch (cls.signon)
186         {
187         case 1:
188                 MSG_WriteByte (&cls.message, clc_stringcmd);
189                 MSG_WriteString (&cls.message, "prespawn");
190                 break;
191                 
192         case 2:
193                 MSG_WriteByte (&cls.message, clc_stringcmd);
194                 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
195
196                 MSG_WriteByte (&cls.message, clc_stringcmd);
197                 MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
198         
199                 if (cl_pmodel.value)
200                 {
201                         MSG_WriteByte (&cls.message, clc_stringcmd);
202                         MSG_WriteString (&cls.message, va("pmodel %f\n", cl_pmodel.value));
203                 }
204
205                 MSG_WriteByte (&cls.message, clc_stringcmd);
206                 sprintf (str, "spawn %s", cls.spawnparms);
207                 MSG_WriteString (&cls.message, str);
208                 break;
209                 
210         case 3: 
211                 MSG_WriteByte (&cls.message, clc_stringcmd);
212                 MSG_WriteString (&cls.message, "begin");
213                 Cache_Report ();                // print remaining memory
214                 break;
215                 
216         case 4:
217 //              SCR_EndLoadingPlaque ();                // allow normal screen updates
218                 Con_ClearNotify();
219                 break;
220         }
221 }
222
223 /*
224 =====================
225 CL_NextDemo
226
227 Called to play the next demo in the demo loop
228 =====================
229 */
230 void CL_NextDemo (void)
231 {
232         char    str[1024];
233
234         if (cls.demonum == -1)
235                 return;         // don't play demos
236
237 //      SCR_BeginLoadingPlaque ();
238
239         if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
240         {
241                 cls.demonum = 0;
242                 if (!cls.demos[cls.demonum][0])
243                 {
244                         Con_Printf ("No demos listed with startdemos\n");
245                         cls.demonum = -1;
246                         return;
247                 }
248         }
249
250         sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
251         Cbuf_InsertText (str);
252         cls.demonum++;
253 }
254
255 /*
256 ==============
257 CL_PrintEntities_f
258 ==============
259 */
260 void CL_PrintEntities_f (void)
261 {
262         entity_t        *ent;
263         int                     i;
264         
265         for (i = 0, ent = cl_entities;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
266         {
267                 Con_Printf ("%3i:", i);
268                 if (!ent->render.model)
269                 {
270                         Con_Printf ("EMPTY\n");
271                         continue;
272                 }
273                 Con_Printf ("%s:%2i  (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n", ent->render.model->name, ent->render.frame, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2]);
274         }
275 }
276
277
278 /*
279 ===============
280 CL_AllocDlight
281
282 ===============
283 */
284 void CL_AllocDlight (entity_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
285 {
286         int             i;
287         dlight_t        *dl;
288
289 // first look for an exact key match
290         if (ent)
291         {
292                 dl = cl_dlights;
293                 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
294                         if (dl->ent == ent)
295                                 goto dlightsetup;
296         }
297
298 // then look for anything else
299         dl = cl_dlights;
300         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
301                 if (!dl->radius)
302                         goto dlightsetup;
303
304         // unable to find one
305         return;
306
307 dlightsetup:
308         memset (dl, 0, sizeof(*dl));
309         dl->ent = ent;
310         VectorCopy(org, dl->origin);
311         dl->radius = radius;
312         dl->color[0] = red;
313         dl->color[1] = green;
314         dl->color[2] = blue;
315         dl->decay = decay;
316         dl->die = cl.time + lifetime;
317 }
318
319
320 /*
321 ===============
322 CL_DecayLights
323
324 ===============
325 */
326 void CL_DecayLights (void)
327 {
328         int                     i;
329         dlight_t        *dl;
330         float           time;
331         
332         time = cl.time - cl.oldtime;
333
334         c_dlights = 0;
335         dl = cl_dlights;
336         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
337         {
338                 if (!dl->radius)
339                         continue;
340                 if (dl->die < cl.time)
341                 {
342                         dl->radius = 0;
343                         continue;
344                 }
345
346                 c_dlights++; // count every dlight in use
347
348                 dl->radius -= time*dl->decay;
349                 if (dl->radius < 0)
350                         dl->radius = 0;
351         }
352 }
353
354
355 /*
356 ===============
357 CL_LerpPoint
358
359 Determines the fraction between the last two messages that the objects
360 should be put at.
361 ===============
362 */
363 float   CL_LerpPoint (void)
364 {
365         float   f, frac;
366
367         f = cl.mtime[0] - cl.mtime[1];
368
369         // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
370         if (!f || cl_nolerp.value || cls.timedemo || (sv.active && svs.maxclients == 1))
371         {
372                 cl.time = cl.mtime[0];
373                 return 1;
374         }
375                 
376         if (f > 0.1)
377         {       // dropped packet, or start of demo
378                 cl.mtime[1] = cl.mtime[0] - 0.1;
379                 f = 0.1;
380         }
381         frac = (cl.time - cl.mtime[1]) / f;
382 //      Con_Printf ("frac: %f\n",frac);
383         if (frac < 0)
384         {
385                 if (frac < -0.01)
386                 {
387                         cl.time = cl.mtime[1];
388 //                      Con_Printf ("low frac\n");
389                 }
390                 frac = 0;
391         }
392         else if (frac > 1)
393         {
394                 if (frac > 1.01)
395                 {
396                         cl.time = cl.mtime[0];
397 //                      Con_Printf ("high frac\n");
398                 }
399                 frac = 1;
400         }
401                 
402         return frac;
403 }
404
405 float CL_EntityLerpPoint (entity_t *ent)
406 {
407         float   f;
408
409         if (cl_nolerp.value || cls.timedemo || (sv.active && svs.maxclients == 1))
410                 return 1;
411
412         f = ent->state_current.time - ent->state_previous.time;
413 //      Con_Printf(" %g-%g=%g", ent->state_current.time, ent->state_previous.time, f);
414
415         if (f <= 0)
416                 return 1;
417         if (f >= 0.1)
418                 f = 0.1;
419
420 //      Con_Printf(" %g-%g/%g=%f", cl.time, ent->state_previous.time, f, (cl.time - ent->state_previous.time) / f);
421         f = (cl.time - ent->state_previous.time) / f;
422         return bound(0, f, 1);
423 }
424
425 void CL_RelinkStaticEntities()
426 {
427         entity_t *ent, *endent;
428         if (cl.num_statics > MAX_VISEDICTS)
429                 Host_Error("CL_RelinkStaticEntities: cl.num_statics > MAX_VISEDICTS??\n");
430
431         ent = cl_static_entities;
432         endent = ent + cl.num_statics;
433         for (;ent < endent;ent++)
434                 cl_visedicts[cl_numvisedicts++] = ent;
435 }
436
437 /*
438 ===============
439 CL_RelinkEntities
440 ===============
441 */
442 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
443 void CL_RelinkEntities (void)
444 {
445         entity_t        *ent;
446         int                     i, j;
447         float           frac, f, d, bobjrotate/*, bobjoffset*/, dlightradius;
448         vec3_t          oldorg, delta, dlightcolor;
449
450 // determine partial update time        
451         frac = CL_LerpPoint ();
452
453         cl_numvisedicts = 0;
454
455         CL_RelinkStaticEntities();
456
457 //
458 // interpolate player info
459 //
460         for (i = 0;i < 3;i++)
461                 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
462
463         if (cls.demoplayback)
464         {
465         // interpolate the angles       
466                 for (j = 0;j < 3;j++)
467                 {
468                         d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
469                         if (d > 180)
470                                 d -= 360;
471                         else if (d < -180)
472                                 d += 360;
473                         cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
474                 }
475         }
476         
477         bobjrotate = ANGLEMOD(100*cl.time);
478 //      bobjoffset = cos(180 * cl.time * M_PI / 180) * 4.0f + 4.0f;
479         
480 // start on the entity after the world
481         for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
482         {
483                 // if the object wasn't included in the latest packet, remove it
484                 if (!ent->state_current.active)
485                         continue;
486
487                 VectorCopy (ent->render.origin, oldorg);
488
489                 if (!ent->state_previous.active)
490                 {
491                         // only one state available
492                         VectorCopy (ent->state_current.origin, ent->render.origin);
493                         VectorCopy (ent->state_current.angles, ent->render.angles);
494 //                      Con_Printf(" %i", i);
495                 }
496                 else
497                 {
498                         // if the delta is large, assume a teleport and don't lerp
499                         f = CL_EntityLerpPoint(ent);
500                         if (f < 1)
501                         {
502                                 for (j = 0;j < 3;j++)
503                                 {
504                                         delta[j] = ent->state_current.origin[j] - ent->state_previous.origin[j];
505                                         // LordHavoc: increased lerp tolerance from 100 to 200
506                                         if (delta[j] > 200 || delta[j] < -200)
507                                                 f = 1;
508                                 }
509                         }
510                         if (f >= 1)
511                         {
512                                 // no interpolation
513                                 VectorCopy (ent->state_current.origin, ent->render.origin);
514                                 VectorCopy (ent->state_current.angles, ent->render.angles);
515                         }
516                         else
517                         {
518                                 // interpolate the origin and angles
519                                 for (j = 0;j < 3;j++)
520                                 {
521                                         ent->render.origin[j] = ent->state_previous.origin[j] + f*delta[j];
522
523                                         d = ent->state_current.angles[j] - ent->state_previous.angles[j];
524                                         if (d > 180)
525                                                 d -= 360;
526                                         else if (d < -180)
527                                                 d += 360;
528                                         ent->render.angles[j] = ent->state_previous.angles[j] + f*d;
529                                 }
530                         }
531                 }
532
533                 ent->render.flags = ent->state_current.flags;
534                 ent->render.effects = ent->state_current.effects;
535                 ent->render.model = cl.model_precache[ent->state_current.modelindex];
536                 ent->render.frame = ent->state_current.frame;
537                 if (cl.scores == NULL || !ent->state_current.colormap)
538                         ent->render.colormap = -1; // no special coloring
539                 else
540                         ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
541                 ent->render.skinnum = ent->state_current.skin;
542                 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
543                 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
544                 ent->render.glowsize = ent->state_current.glowsize * 4.0f; // FIXME: interpolate?
545                 ent->render.glowcolor = ent->state_current.glowcolor;
546                 ent->render.colormod[0] = (float) ((ent->state_current.colormod >> 5) & 7) * (1.0f / 7.0f);
547                 ent->render.colormod[1] = (float) ((ent->state_current.colormod >> 2) & 7) * (1.0f / 7.0f);
548                 ent->render.colormod[2] = (float) (ent->state_current.colormod & 3) * (1.0f / 3.0f);
549
550                 dlightradius = 0;
551                 dlightcolor[0] = 0;
552                 dlightcolor[1] = 0;
553                 dlightcolor[2] = 0;
554
555                 // LordHavoc: if the entity has no effects, don't check each
556                 if (ent->render.effects)
557                 {
558                         if (ent->render.effects & EF_BRIGHTFIELD)
559                                 R_EntityParticles (ent);
560                         if (ent->render.effects & EF_MUZZLEFLASH)
561                         {
562                                 vec3_t v;
563
564                                 AngleVectors (ent->render.angles, v, NULL, NULL);
565
566                                 v[0] = v[0] * 18 + ent->render.origin[0];
567                                 v[1] = v[1] * 18 + ent->render.origin[1];
568                                 v[2] = v[2] * 18 + ent->render.origin[2] + 16;
569
570                                 CL_AllocDlight (NULL, v, 100, 1, 1, 1, 0, 0.1);
571                         }
572                         if (ent->render.effects & EF_DIMLIGHT)
573                         {
574                                 dlightcolor[0] += 200.0f;
575                                 dlightcolor[1] += 200.0f;
576                                 dlightcolor[2] += 200.0f;
577                         }
578                         if (ent->render.effects & EF_BRIGHTLIGHT)
579                         {
580                                 dlightcolor[0] += 400.0f;
581                                 dlightcolor[1] += 400.0f;
582                                 dlightcolor[2] += 400.0f;
583                         }
584                         // LordHavoc: added EF_RED and EF_BLUE
585                         if (ent->render.effects & EF_RED) // red
586                         {
587                                 dlightcolor[0] += 200.0f;
588                                 dlightcolor[1] +=  20.0f;
589                                 dlightcolor[2] +=  20.0f;
590                         }
591                         if (ent->render.effects & EF_BLUE) // blue
592                         {
593                                 dlightcolor[0] +=  20.0f;
594                                 dlightcolor[1] +=  20.0f;
595                                 dlightcolor[2] += 200.0f;
596                         }
597                         else if (ent->render.effects & EF_FLAME)
598                         {
599                                 if (ent->render.model)
600                                 {
601                                         vec3_t mins, maxs;
602                                         int temp;
603                                         VectorAdd(ent->render.origin, ent->render.model->mins, mins);
604                                         VectorAdd(ent->render.origin, ent->render.model->maxs, maxs);
605                                         // how many flames to make
606                                         temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
607                                         R_FlameCube(mins, maxs, temp);
608                                 }
609                                 d = lhrandom(200, 250);
610                                 dlightcolor[0] += d * 1.0f;
611                                 dlightcolor[1] += d * 0.7f;
612                                 dlightcolor[2] += d * 0.3f;
613                         }
614                 }
615
616                 // LordHavoc: if the model has no flags, don't check each
617                 if (ent->render.model && ent->render.model->flags)
618                 {
619                         if (ent->render.model->flags & EF_ROTATE)
620                         {
621                                 ent->render.angles[1] = bobjrotate;
622 //                              ent->render.origin[2] += bobjoffset;
623                         }
624                         // only do trails if present in the previous frame as well
625                         if (ent->state_previous.active)
626                         {
627                                 if (ent->render.model->flags & EF_GIB)
628                                         R_RocketTrail (oldorg, ent->render.origin, 2, ent);
629                                 else if (ent->render.model->flags & EF_ZOMGIB)
630                                         R_RocketTrail (oldorg, ent->render.origin, 4, ent);
631                                 else if (ent->render.model->flags & EF_TRACER)
632                                         R_RocketTrail (oldorg, ent->render.origin, 3, ent);
633                                 else if (ent->render.model->flags & EF_TRACER2)
634                                         R_RocketTrail (oldorg, ent->render.origin, 5, ent);
635                                 else if (ent->render.model->flags & EF_ROCKET)
636                                 {
637                                         R_RocketTrail (oldorg, ent->render.origin, 0, ent);
638                                         dlightcolor[0] += 200.0f;
639                                         dlightcolor[1] += 160.0f;
640                                         dlightcolor[2] +=  80.0f;
641                                 }
642                                 else if (ent->render.model->flags & EF_GRENADE)
643                                 {
644                                         if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility
645                                                 R_RocketTrail (oldorg, ent->render.origin, 7, ent);
646                                         else
647                                                 R_RocketTrail (oldorg, ent->render.origin, 1, ent);
648                                 }
649                                 else if (ent->render.model->flags & EF_TRACER3)
650                                         R_RocketTrail (oldorg, ent->render.origin, 6, ent);
651                         }
652                 }
653                 // LordHavoc: customizable glow
654                 if (ent->render.glowsize)
655                 {
656                         byte *tempcolor = (byte *)&d_8to24table[ent->render.glowcolor];
657                         dlightcolor[0] += ent->render.glowsize * tempcolor[0] * (1.0f / 255.0f);
658                         dlightcolor[1] += ent->render.glowsize * tempcolor[1] * (1.0f / 255.0f);
659                         dlightcolor[2] += ent->render.glowsize * tempcolor[2] * (1.0f / 255.0f);
660                 }
661                 // LordHavoc: customizable trail
662                 if (ent->render.flags & RENDER_GLOWTRAIL)
663                         R_RocketTrail2 (oldorg, ent->render.origin, ent->render.glowcolor, ent);
664
665                 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
666                 {
667                         dlightradius = VectorLength(dlightcolor);
668                         d = 1.0f / dlightradius;
669                         CL_AllocDlight (ent, ent->render.origin, dlightradius, dlightcolor[0] * d, dlightcolor[1] * d, dlightcolor[2] * d, 0, 0);
670                 }
671
672                 if (!chase_active.value && ((i == cl.viewentity) || (ent->render.flags & RENDER_EXTERIORMODEL)))
673                         continue;
674
675                 if (ent->render.model == NULL)
676                         continue;
677                 if (ent->render.effects & EF_NODRAW)
678                         continue;
679                 if (cl_numvisedicts < MAX_VISEDICTS)
680                         cl_visedicts[cl_numvisedicts++] = ent;
681         }
682 //      Con_Printf("\n");
683 }
684
685
686 // used by cl_shownet
687 int netshown;
688
689 /*
690 ===============
691 CL_ReadFromServer
692
693 Read all incoming data from the server
694 ===============
695 */
696 int CL_ReadFromServer (void)
697 {
698         int             ret;
699
700         cl.oldtime = cl.time;
701         cl.time += cl.frametime;
702         
703         netshown = false;
704         do
705         {
706                 ret = CL_GetMessage ();
707                 if (ret == -1)
708                         Host_Error ("CL_ReadFromServer: lost server connection");
709                 if (!ret)
710                         break;
711                 
712                 cl.last_received_message = realtime;
713                 CL_ParseServerMessage ();
714         } while (ret && cls.state == ca_connected);
715         
716         if (netshown)
717                 Con_Printf ("\n");
718
719         CL_RelinkEntities ();
720         CL_UpdateTEnts ();
721         CL_DoEffects ();
722
723 //
724 // bring the links up to date
725 //
726         return 0;
727 }
728
729 /*
730 =================
731 CL_SendCmd
732 =================
733 */
734 void CL_SendCmd (void)
735 {
736         usercmd_t               cmd;
737
738         if (cls.state != ca_connected)
739                 return;
740
741         if (cls.signon == SIGNONS)
742         {
743         // get basic movement from keyboard
744                 CL_BaseMove (&cmd);
745         
746         // allow mice or other external controllers to add to the move
747                 IN_Move (&cmd);
748         
749         // send the unreliable message
750                 CL_SendMove (&cmd);
751         }
752
753         if (cls.demoplayback)
754         {
755                 SZ_Clear (&cls.message);
756                 return;
757         }
758         
759 // send the reliable message
760         if (!cls.message.cursize)
761                 return;         // no message at all
762         
763         if (!NET_CanSendMessage (cls.netcon))
764         {
765                 Con_DPrintf ("CL_WriteToServer: can't send\n");
766                 return;
767         }
768
769         if (NET_SendMessage (cls.netcon, &cls.message) == -1)
770                 Host_Error ("CL_WriteToServer: lost server connection");
771
772         SZ_Clear (&cls.message);
773 }
774
775 // LordHavoc: pausedemo command
776 void CL_PauseDemo_f (void)
777 {
778         cls.demopaused = !cls.demopaused;
779         if (cls.demopaused)
780                 Con_Printf("Demo paused\n");
781         else
782                 Con_Printf("Demo unpaused\n");
783 }
784
785 /*
786 ======================
787 CL_PModel_f
788 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
789 ======================
790 */
791 void CL_PModel_f (void)
792 {
793         int i;
794         eval_t *val;
795
796         if (Cmd_Argc () == 1)
797         {
798                 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
799                 return;
800         }
801         i = atoi(Cmd_Argv(1));
802
803         if (cmd_source == src_command)
804         {
805                 if (cl_pmodel.value == i)
806                         return;
807                 Cvar_SetValue ("_cl_pmodel", i);
808                 if (cls.state == ca_connected)
809                         Cmd_ForwardToServer ();
810                 return;
811         }
812
813         host_client->pmodel = i;
814         if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
815                 val->_float = i;
816 }
817
818 /*
819 ======================
820 CL_Fog_f
821 ======================
822 */
823 void CL_Fog_f (void)
824 {
825         if (Cmd_Argc () == 1)
826         {
827                 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
828                 return;
829         }
830         fog_density = atof(Cmd_Argv(1));
831         fog_red = atof(Cmd_Argv(2));
832         fog_green = atof(Cmd_Argv(3));
833         fog_blue = atof(Cmd_Argv(4));
834 }
835
836 /*
837 =================
838 CL_Init
839 =================
840 */
841 void CL_Init (void)
842 {       
843         SZ_Alloc (&cls.message, 1024);
844
845         CL_InitInput ();
846         CL_InitTEnts ();
847         
848 //
849 // register our commands
850 //
851         Cvar_RegisterVariable (&cl_name);
852         Cvar_RegisterVariable (&cl_color);
853         Cvar_RegisterVariable (&cl_pmodel);
854         Cvar_RegisterVariable (&cl_upspeed);
855         Cvar_RegisterVariable (&cl_forwardspeed);
856         Cvar_RegisterVariable (&cl_backspeed);
857         Cvar_RegisterVariable (&cl_sidespeed);
858         Cvar_RegisterVariable (&cl_movespeedkey);
859         Cvar_RegisterVariable (&cl_yawspeed);
860         Cvar_RegisterVariable (&cl_pitchspeed);
861         Cvar_RegisterVariable (&cl_anglespeedkey);
862         Cvar_RegisterVariable (&cl_shownet);
863         Cvar_RegisterVariable (&cl_nolerp);
864         Cvar_RegisterVariable (&lookspring);
865         Cvar_RegisterVariable (&lookstrafe);
866         Cvar_RegisterVariable (&sensitivity);
867         Cvar_RegisterVariable (&freelook);
868
869         Cvar_RegisterVariable (&m_pitch);
870         Cvar_RegisterVariable (&m_yaw);
871         Cvar_RegisterVariable (&m_forward);
872         Cvar_RegisterVariable (&m_side);
873
874 //      Cvar_RegisterVariable (&cl_autofire);
875         
876         Cmd_AddCommand ("entities", CL_PrintEntities_f);
877         Cmd_AddCommand ("bitprofile", CL_BitProfile_f);
878         Cmd_AddCommand ("disconnect", CL_Disconnect_f);
879         Cmd_AddCommand ("record", CL_Record_f);
880         Cmd_AddCommand ("stop", CL_Stop_f);
881         Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
882         Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
883
884         Cmd_AddCommand ("fog", CL_Fog_f);
885
886         // LordHavoc: added pausedemo
887         Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
888         // LordHavoc: added pmodel command (like name, etc, only intended for Nehahra)
889         Cmd_AddCommand ("pmodel", CL_PModel_f);
890         // LordHavoc: added demo_nehahra cvar
891         Cvar_RegisterVariable (&demo_nehahra);
892         if (nehahra)
893                 Cvar_SetValue("demo_nehahra", 1);
894 }
895