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