2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // cl_main.c -- client main loop
24 // we need to declare some mouse variables here, because the menu system
25 // references them even when on a unix system.
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"};
32 cvar_t cl_shownet = {0, "cl_shownet","0"};
33 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
35 cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
36 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
38 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
39 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
40 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
42 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
43 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
44 cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
45 cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
47 cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
49 cvar_t cl_draweffects = {0, "cl_draweffects", "1"};
51 mempool_t *cl_scores_mempool;
52 mempool_t *cl_refdef_mempool;
56 // FIXME: put these on hunk?
57 entity_t cl_entities[MAX_EDICTS];
58 entity_t cl_static_entities[MAX_STATIC_ENTITIES];
59 lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
61 typedef struct effect_s
70 // these are for interpolation
77 #define MAX_EFFECTS 256
79 static cl_effect_t cl_effect[MAX_EFFECTS];
88 void CL_ClearState (void)
95 Mem_EmptyPool(cl_scores_mempool);
97 // wipe the entire cl structure
98 memset (&cl, 0, sizeof(cl));
100 SZ_Clear (&cls.message);
102 // clear other arrays
103 memset(cl_entities, 0, sizeof(cl_entities));
104 memset(cl_lightstyle, 0, sizeof(cl_lightstyle));
105 memset(cl_temp_entities, 0, sizeof(cl_temp_entities));
106 memset(cl_beams, 0, sizeof(cl_beams));
107 memset(cl_dlights, 0, sizeof(cl_dlights));
108 memset(cl_effect, 0, sizeof(cl_effect));
110 CL_Particles_Clear();
111 // LordHavoc: have to set up the baseline info for alpha and other stuff
112 for (i = 0;i < MAX_EDICTS;i++)
114 ClearStateToDefault(&cl_entities[i].state_baseline);
115 ClearStateToDefault(&cl_entities[i].state_previous);
116 ClearStateToDefault(&cl_entities[i].state_current);
122 void CL_LerpUpdate(entity_t *e)
124 entity_persistent_t *p;
129 if (p->modelindex != e->state_current.modelindex)
131 // reset all interpolation information
132 p->modelindex = e->state_current.modelindex;
133 p->frame1 = p->frame2 = e->state_current.frame;
134 p->frame1time = p->frame2time = cl.time;
137 else if (p->frame2 != e->state_current.frame)
139 // transition to new frame
140 p->frame1 = p->frame2;
141 p->frame1time = p->frame2time;
142 p->frame2 = e->state_current.frame;
143 p->frame2time = cl.time;
149 p->framelerp = (cl.time - p->frame2time) * 10;
150 p->framelerp = bound(0, p->framelerp, 1);
153 r->model = cl.model_precache[e->state_current.modelindex];
154 Mod_CheckLoaded(r->model);
155 r->frame = e->state_current.frame;
156 r->frame1 = p->frame1;
157 r->frame2 = p->frame2;
158 r->framelerp = p->framelerp;
159 r->frame1time = p->frame1time;
160 r->frame2time = p->frame2time;
164 =====================
167 Sends a disconnect message to the server
168 This is also called on Host_Error, so it shouldn't cause any errors
169 =====================
171 void CL_Disconnect (void)
173 if (cls.state == ca_dedicated)
176 // stop sounds (especially looping!)
177 S_StopAllSounds (true);
179 // clear contents blends
180 cl.cshifts[0].percent = 0;
181 cl.cshifts[1].percent = 0;
182 cl.cshifts[2].percent = 0;
183 cl.cshifts[3].percent = 0;
185 cl.worldmodel = NULL;
187 if (cls.demoplayback)
189 else if (cls.state == ca_connected)
191 if (cls.demorecording)
194 Con_DPrintf ("Sending clc_disconnect\n");
195 SZ_Clear (&cls.message);
196 MSG_WriteByte (&cls.message, clc_disconnect);
197 NET_SendUnreliableMessage (cls.netcon, &cls.message);
198 SZ_Clear (&cls.message);
199 NET_Close (cls.netcon);
200 cls.state = ca_disconnected; // prevent this code from executing again during Host_ShutdownServer
201 // if running a local server, shut it down
203 Host_ShutdownServer(false);
205 cls.state = ca_disconnected;
207 cls.demoplayback = cls.timedemo = false;
211 void CL_Disconnect_f (void)
215 Host_ShutdownServer (false);
222 =====================
223 CL_EstablishConnection
225 Host should be either "local" or a net address to be passed on
226 =====================
228 void CL_EstablishConnection (char *host)
237 if (cls.state == ca_dedicated)
240 if (cls.demoplayback)
245 cls.netcon = NET_Connect (host);
247 Host_Error ("CL_Connect: connect failed\n");
248 Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
250 cls.demonum = -1; // not in the demo loop now
251 cls.state = ca_connected;
252 cls.signon = 0; // need all the signon messages before playing
262 static void CL_PrintEntities_f (void)
268 for (i = 0, ent = cl_entities;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
270 if (!ent->state_current.active)
272 if (!ent->render.model)
275 Con_Printf ("%3i:", i);
276 if (!ent->render.model)
278 Con_Printf ("EMPTY\n");
281 strncpy(name, ent->render.model->name, 25);
283 for (j = strlen(name);j < 25;j++)
285 Con_Printf ("%s:%04i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\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, ent->render.scale, ent->render.alpha);
294 Determines the fraction between the last two messages that the objects
298 static float CL_LerpPoint (void)
302 // dropped packet, or start of demo
303 if (cl.mtime[1] < cl.mtime[0] - 0.1)
304 cl.mtime[1] = cl.mtime[0] - 0.1;
306 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
308 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
309 f = cl.mtime[0] - cl.mtime[1];
310 if (!f || cl_nolerp.integer || cls.timedemo || (sv.active && svs.maxclients == 1))
312 cl.time = cl.mtime[0];
316 f = (cl.time - cl.mtime[1]) / f;
317 return bound(0, f, 1);
320 static void CL_RelinkStaticEntities(void)
323 for (i = 0;i < cl.num_statics && r_refdef.numentities < MAX_VISEDICTS;i++)
325 Mod_CheckLoaded(cl_static_entities[i].render.model);
326 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
335 static void CL_RelinkNetworkEntities()
338 int i, glowcolor, effects;
339 float f, d, bobjrotate, bobjoffset, dlightradius, glowsize, lerp;
340 vec3_t oldorg, neworg, delta, dlightcolor;
342 bobjrotate = ANGLEMOD(100*cl.time);
343 if (cl_itembobheight.value)
344 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
348 // start on the entity after the world
349 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
351 // if the object wasn't included in the latest packet, remove it
352 if (!ent->state_current.active)
355 VectorCopy(ent->persistent.trail_origin, oldorg);
357 if (!ent->state_previous.active)
359 // only one state available
361 VectorCopy (ent->state_current.origin, oldorg); // skip trails
362 VectorCopy (ent->state_current.origin, neworg);
363 VectorCopy (ent->state_current.angles, ent->render.angles);
366 // monster interpolation
367 ent->persistent.steplerptime = 0;
368 VectorCopy(ent->state_current.origin, ent->persistent.stepoldorigin);
369 VectorCopy(ent->state_current.angles, ent->persistent.stepoldangles);
370 VectorCopy(ent->state_current.origin, ent->persistent.steporigin);
371 VectorCopy(ent->state_current.angles, ent->persistent.stepangles);
375 else if ((ent->state_current.flags & ent->state_previous.flags) & ENTFLAG_STEP)
377 if (ent->state_current.origin[0] != ent->persistent.steporigin[0]
378 || ent->state_current.origin[1] != ent->persistent.steporigin[1]
379 || ent->state_current.origin[2] != ent->persistent.steporigin[2]
380 || ent->state_current.angles[0] != ent->persistent.stepangles[0]
381 || ent->state_current.angles[1] != ent->persistent.stepangles[1]
382 || ent->state_current.angles[2] != ent->persistent.stepangles[2])
384 // update lerp positions
385 ent->clientpersistent.steplerptime = sv.time;
386 VectorCopy(ent->steporigin, ent->stepoldorigin);
387 VectorCopy(ent->stepangles, ent->stepoldangles);
388 VectorCopy(ent->v.origin, ent->steporigin);
389 VectorCopy(ent->v.angles, ent->stepangles);
391 lerp = (cl.time - ent->persistent.steplerptime) * 10.0;
395 VectorSubtract(ent->persistent.steporigin, ent->persistent.stepoldorigin, delta);
396 VectorMA(ent->persistent.stepoldorigin, lerp, delta, neworg);
399 VectorSubtract(ent->persistent.stepangles, ent->persistent.stepoldangles, delta);
400 // choose shortest rotate (to avoid 'spin around' situations)
401 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
402 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
403 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
404 VectorMA(ent->stepoldangles, lerp, delta, ent->render.angles);
408 VectorCopy(ent->persistent.steporigin, neworg);
409 VectorCopy(ent->persistent.stepangles, ent->render.angles);
416 // monster interpolation
417 ent->persistent.steplerptime = 0;
418 VectorCopy(ent->state_current.origin, ent->persistent.stepoldorigin);
419 VectorCopy(ent->state_current.angles, ent->persistent.stepoldangles);
420 VectorCopy(ent->state_current.origin, ent->persistent.steporigin);
421 VectorCopy(ent->state_current.angles, ent->persistent.stepangles);
424 // if the delta is large, assume a teleport and don't lerp
425 VectorSubtract(ent->state_current.origin, ent->state_previous.origin, delta);
426 // LordHavoc: increased tolerance from 100 to 200, and now to 1000
427 if ((sv.active && svs.maxclients == 1 && !(ent->state_current.flags & RENDER_STEP)) || cls.timedemo || DotProduct(delta, delta) > 1000*1000 || cl_nolerp.integer)
431 f = ent->state_current.time - ent->state_previous.time;
433 lerp = (cl.time - ent->state_previous.time) / f;
440 VectorCopy (ent->state_current.origin, neworg);
441 VectorCopy (ent->state_current.angles, ent->render.angles);
445 // interpolate the origin and angles
446 VectorMA(ent->state_previous.origin, lerp, delta, neworg);
447 VectorSubtract(ent->state_current.angles, ent->state_previous.angles, delta);
448 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
449 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
450 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
451 VectorMA(ent->state_previous.angles, lerp, delta, ent->render.angles);
455 VectorCopy (neworg, ent->persistent.trail_origin);
456 // persistent.modelindex will be updated by CL_LerpUpdate
457 if (ent->state_current.modelindex != ent->persistent.modelindex)
458 VectorCopy(neworg, oldorg);
460 VectorCopy (neworg, ent->render.origin);
461 ent->render.flags = ent->state_current.flags;
462 ent->render.effects = effects = ent->state_current.effects;
463 if (cl.scores == NULL || !ent->state_current.colormap)
464 ent->render.colormap = -1; // no special coloring
466 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
467 ent->render.skinnum = ent->state_current.skin;
468 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
469 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
471 // update interpolation info
474 // handle effects now...
480 // LordHavoc: if the entity has no effects, don't check each
483 if (effects & EF_BRIGHTFIELD)
484 CL_EntityParticles (ent);
485 if (effects & EF_MUZZLEFLASH)
489 AngleVectors (ent->render.angles, v, NULL, NULL);
491 v2[0] = v[0] * 18 + neworg[0];
492 v2[1] = v[1] * 18 + neworg[1];
493 v2[2] = v[2] * 18 + neworg[2] + 16;
494 TraceLine(neworg, v2, v, NULL, 0, true);
496 CL_AllocDlight (NULL, v, 100, 1, 1, 1, 0, 0);
498 if (effects & EF_DIMLIGHT)
500 dlightcolor[0] += 200.0f;
501 dlightcolor[1] += 200.0f;
502 dlightcolor[2] += 200.0f;
504 if (effects & EF_BRIGHTLIGHT)
506 dlightcolor[0] += 400.0f;
507 dlightcolor[1] += 400.0f;
508 dlightcolor[2] += 400.0f;
510 // LordHavoc: added EF_RED and EF_BLUE
511 if (effects & EF_RED) // red
513 dlightcolor[0] += 200.0f;
514 dlightcolor[1] += 20.0f;
515 dlightcolor[2] += 20.0f;
517 if (effects & EF_BLUE) // blue
519 dlightcolor[0] += 20.0f;
520 dlightcolor[1] += 20.0f;
521 dlightcolor[2] += 200.0f;
523 if (effects & EF_FLAME)
525 if (ent->render.model)
530 if (ent->render.angles[0] || ent->render.angles[2])
532 VectorMA(neworg, 0.25f, ent->render.model->rotatedmins, mins);
533 VectorMA(neworg, 0.25f, ent->render.model->rotatedmaxs, maxs);
535 else if (ent->render.angles[1])
537 VectorMA(neworg, 0.25f, ent->render.model->yawmins, mins);
538 VectorMA(neworg, 0.25f, ent->render.model->yawmaxs, maxs);
542 VectorMA(neworg, 0.25f, ent->render.model->normalmins, mins);
543 VectorMA(neworg, 0.25f, ent->render.model->normalmaxs, maxs);
546 mins[0] = neworg[0] - 16.0f;
547 mins[1] = neworg[1] - 16.0f;
548 mins[2] = neworg[2] - 16.0f;
549 maxs[0] = neworg[0] + 16.0f;
550 maxs[1] = neworg[1] + 16.0f;
551 maxs[2] = neworg[2] + 16.0f;
552 // how many flames to make
553 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
554 CL_FlameCube(mins, maxs, temp);
556 d = lhrandom(200, 250);
557 dlightcolor[0] += d * 1.0f;
558 dlightcolor[1] += d * 0.7f;
559 dlightcolor[2] += d * 0.3f;
561 if (effects & EF_STARDUST)
563 if (ent->render.model)
568 if (ent->render.angles[0] || ent->render.angles[2])
570 VectorMA(neworg, 0.25f, ent->render.model->rotatedmins, mins);
571 VectorMA(neworg, 0.25f, ent->render.model->rotatedmaxs, maxs);
573 else if (ent->render.angles[1])
575 VectorMA(neworg, 0.25f, ent->render.model->yawmins, mins);
576 VectorMA(neworg, 0.25f, ent->render.model->yawmaxs, maxs);
580 VectorMA(neworg, 0.25f, ent->render.model->normalmins, mins);
581 VectorMA(neworg, 0.25f, ent->render.model->normalmaxs, maxs);
584 mins[0] = neworg[0] - 16.0f;
585 mins[1] = neworg[1] - 16.0f;
586 mins[2] = neworg[2] - 16.0f;
587 maxs[0] = neworg[0] + 16.0f;
588 maxs[1] = neworg[1] + 16.0f;
589 maxs[2] = neworg[2] + 16.0f;
590 // how many particles to make
591 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
592 CL_Stardust(mins, maxs, temp);
595 dlightcolor[0] += d * 1.0f;
596 dlightcolor[1] += d * 0.7f;
597 dlightcolor[2] += d * 0.3f;
601 // LordHavoc: if the model has no flags, don't check each
602 if (ent->render.model && ent->render.model->flags)
604 if (ent->render.model->flags & EF_ROTATE)
606 ent->render.angles[1] = bobjrotate;
607 ent->render.origin[2] += bobjoffset;
609 // only do trails if present in the previous frame as well
610 if (ent->state_previous.active)
612 if (ent->render.model->flags & EF_GIB)
613 CL_RocketTrail (oldorg, neworg, 2, ent);
614 else if (ent->render.model->flags & EF_ZOMGIB)
615 CL_RocketTrail (oldorg, neworg, 4, ent);
616 else if (ent->render.model->flags & EF_TRACER)
617 CL_RocketTrail (oldorg, neworg, 3, ent);
618 else if (ent->render.model->flags & EF_TRACER2)
619 CL_RocketTrail (oldorg, neworg, 5, ent);
620 else if (ent->render.model->flags & EF_ROCKET)
622 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
623 dlightcolor[0] += 200.0f;
624 dlightcolor[1] += 160.0f;
625 dlightcolor[2] += 80.0f;
627 else if (ent->render.model->flags & EF_GRENADE)
629 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility
630 CL_RocketTrail (oldorg, neworg, 7, ent);
632 CL_RocketTrail (oldorg, neworg, 1, ent);
634 else if (ent->render.model->flags & EF_TRACER3)
635 CL_RocketTrail (oldorg, neworg, 6, ent);
638 // LordHavoc: customizable glow
639 glowsize = ent->state_current.glowsize; // FIXME: interpolate?
640 glowcolor = ent->state_current.glowcolor;
643 qbyte *tempcolor = (qbyte *)&d_8to24table[glowcolor];
644 // * 4 for the expansion from 0-255 to 0-1023 range,
645 // / 255 to scale down byte colors
646 glowsize *= (4.0f / 255.0f);
647 VectorMA(dlightcolor, glowsize, tempcolor, dlightcolor);
649 // LordHavoc: customizable trail
650 if (ent->render.flags & RENDER_GLOWTRAIL)
651 CL_RocketTrail2 (oldorg, neworg, glowcolor, ent);
653 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
656 VectorCopy(neworg, vec);
657 // hack to make glowing player light shine on their gun
658 if (i == cl.viewentity && !chase_active.integer)
660 CL_AllocDlight (/*&ent->render*/ NULL, vec, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
663 if (chase_active.integer)
665 if (ent->render.flags & RENDER_VIEWMODEL)
670 if (i == cl.viewentity || (ent->render.flags & RENDER_EXTERIORMODEL))
674 if (ent->render.model == NULL)
676 if (effects & EF_NODRAW)
678 if (r_refdef.numentities < MAX_VISEDICTS)
679 r_refdef.entities[r_refdef.numentities++] = &ent->render;
683 void CL_LerpPlayer(float frac)
688 if (cl.entitydatabase.numframes)
690 cl.viewentorigin[0] = cl.viewentoriginold[0] + frac * (cl.viewentoriginnew[0] - cl.viewentoriginold[0]);
691 cl.viewentorigin[1] = cl.viewentoriginold[1] + frac * (cl.viewentoriginnew[1] - cl.viewentoriginold[1]);
692 cl.viewentorigin[2] = cl.viewentoriginold[2] + frac * (cl.viewentoriginnew[2] - cl.viewentoriginold[2]);
695 VectorCopy (cl_entities[cl.viewentity].render.origin, cl.viewentorigin);
697 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
699 for (i = 0;i < 3;i++)
700 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
702 if (cls.demoplayback)
704 // interpolate the angles
705 for (i = 0;i < 3;i++)
707 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
712 cl.viewangles[i] = cl.mviewangles[1][i] + frac*d;
717 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
721 if (!modelindex) // sanity check
723 for (i = 0, e = cl_effect;i < MAX_EFFECTS;i++, e++)
728 VectorCopy(org, e->origin);
729 e->modelindex = modelindex;
730 e->starttime = cl.time;
731 e->startframe = startframe;
732 e->endframe = startframe + framecount;
733 e->framerate = framerate;
736 e->frame1time = cl.time;
737 e->frame2time = cl.time;
742 static void CL_RelinkEffects()
749 for (i = 0, e = cl_effect;i < MAX_EFFECTS;i++, e++)
753 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
755 if (intframe < 0 || intframe >= e->endframe)
758 memset(e, 0, sizeof(*e));
762 if (intframe != e->frame)
765 e->frame1time = e->frame2time;
766 e->frame2time = cl.time;
769 if ((vis = CL_NewTempEntity()))
771 // interpolation stuff
772 vis->render.frame1 = intframe;
773 vis->render.frame2 = intframe + 1;
774 if (vis->render.frame2 >= e->endframe)
775 vis->render.frame2 = -1; // disappear
776 vis->render.framelerp = frame - intframe;
777 vis->render.frame1time = e->frame1time;
778 vis->render.frame2time = e->frame2time;
781 VectorCopy(e->origin, vis->render.origin);
782 vis->render.model = cl.model_precache[e->modelindex];
783 vis->render.frame = vis->render.frame2;
784 vis->render.colormap = -1; // no special coloring
785 vis->render.scale = 1;
786 vis->render.alpha = 1;
792 void CL_RelinkEntities (void)
796 // fraction from previous network update to current
797 frac = CL_LerpPoint ();
800 CL_RelinkStaticEntities();
801 CL_RelinkNetworkEntities();
802 TraceLine_ScanForBModels();
815 Read all incoming data from the server
818 int CL_ReadFromServer (void)
822 cl.oldtime = cl.time;
823 cl.time += cl.frametime;
828 ret = CL_GetMessage ();
830 Host_Error ("CL_ReadFromServer: lost server connection");
834 cl.last_received_message = realtime;
836 if (cl_shownet.integer)
839 CL_ParseServerMessage ();
841 while (ret && cls.state == ca_connected);
846 r_refdef.numentities = 0;
847 if (cls.state == ca_connected && cl.worldmodel)
849 CL_RelinkEntities ();
851 // run cgame code (which can add more entities)
856 // bring the links up to date
866 void CL_SendCmd (void)
870 if (cls.state != ca_connected)
873 if (cls.signon == SIGNONS)
875 // get basic movement from keyboard
878 IN_PreMove(); // OS independent code
880 // allow mice or other external controllers to add to the move
883 IN_PostMove(); // OS independent code
885 // send the unreliable message
890 // LordHavoc: fix for NAT routing of netquake:
891 // bounce back a clc_nop message to the newly allocated server port,
892 // to establish a routing connection for incoming frames,
893 // the server waits for this before sending anything
894 if (realtime > cl.sendnoptime)
896 Con_DPrintf("sending clc_nop to get server's attention\n");
897 cl.sendnoptime = realtime + 3;
898 MSG_WriteByte(&cls.message, clc_nop);
902 if (cls.demoplayback)
904 SZ_Clear (&cls.message);
908 // send the reliable message
909 if (!cls.message.cursize)
910 return; // no message at all
912 if (!NET_CanSendMessage (cls.netcon))
914 Con_DPrintf ("CL_WriteToServer: can't send\n");
918 if (NET_SendMessage (cls.netcon, &cls.message) == -1)
919 Host_Error ("CL_WriteToServer: lost server connection");
921 SZ_Clear (&cls.message);
924 // LordHavoc: pausedemo command
925 static void CL_PauseDemo_f (void)
927 cls.demopaused = !cls.demopaused;
929 Con_Printf("Demo paused\n");
931 Con_Printf("Demo unpaused\n");
935 ======================
937 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
938 ======================
940 static void CL_PModel_f (void)
945 if (Cmd_Argc () == 1)
947 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
950 i = atoi(Cmd_Argv(1));
952 if (cmd_source == src_command)
954 if (cl_pmodel.integer == i)
956 Cvar_SetValue ("_cl_pmodel", i);
957 if (cls.state == ca_connected)
958 Cmd_ForwardToServer ();
962 host_client->pmodel = i;
963 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
968 ======================
970 ======================
972 static void CL_Fog_f (void)
974 if (Cmd_Argc () == 1)
976 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
979 fog_density = atof(Cmd_Argv(1));
980 fog_red = atof(Cmd_Argv(2));
981 fog_green = atof(Cmd_Argv(3));
982 fog_blue = atof(Cmd_Argv(4));
992 cl_scores_mempool = Mem_AllocPool("client player info");
994 cl_refdef_mempool = Mem_AllocPool("refdef");
995 memset(&r_refdef, 0, sizeof(r_refdef));
996 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * MAX_VISEDICTS);
998 SZ_Alloc (&cls.message, 1024, "cls.message");
1004 // register our commands
1006 Cvar_RegisterVariable (&cl_name);
1007 Cvar_RegisterVariable (&cl_color);
1008 if (gamemode == GAME_NEHAHRA)
1009 Cvar_RegisterVariable (&cl_pmodel);
1010 Cvar_RegisterVariable (&cl_upspeed);
1011 Cvar_RegisterVariable (&cl_forwardspeed);
1012 Cvar_RegisterVariable (&cl_backspeed);
1013 Cvar_RegisterVariable (&cl_sidespeed);
1014 Cvar_RegisterVariable (&cl_movespeedkey);
1015 Cvar_RegisterVariable (&cl_yawspeed);
1016 Cvar_RegisterVariable (&cl_pitchspeed);
1017 Cvar_RegisterVariable (&cl_anglespeedkey);
1018 Cvar_RegisterVariable (&cl_shownet);
1019 Cvar_RegisterVariable (&cl_nolerp);
1020 Cvar_RegisterVariable (&lookspring);
1021 Cvar_RegisterVariable (&lookstrafe);
1022 Cvar_RegisterVariable (&sensitivity);
1023 Cvar_RegisterVariable (&freelook);
1025 Cvar_RegisterVariable (&m_pitch);
1026 Cvar_RegisterVariable (&m_yaw);
1027 Cvar_RegisterVariable (&m_forward);
1028 Cvar_RegisterVariable (&m_side);
1030 Cvar_RegisterVariable (&cl_itembobspeed);
1031 Cvar_RegisterVariable (&cl_itembobheight);
1033 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1034 Cmd_AddCommand ("bitprofile", CL_BitProfile_f);
1035 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1036 Cmd_AddCommand ("record", CL_Record_f);
1037 Cmd_AddCommand ("stop", CL_Stop_f);
1038 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1039 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1041 Cmd_AddCommand ("fog", CL_Fog_f);
1043 // LordHavoc: added pausedemo
1044 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1045 if (gamemode == GAME_NEHAHRA)
1046 Cmd_AddCommand ("pmodel", CL_PModel_f);
1048 Cvar_RegisterVariable(&cl_draweffects);
1051 CL_Particles_Init();