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
23 #include "cl_collision.h"
26 // we need to declare some mouse variables here, because the menu system
27 // references them even when on a unix system.
29 // these two are not intended to be set directly
30 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
31 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
32 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
34 cvar_t cl_shownet = {0, "cl_shownet","0"};
35 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
37 cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
38 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
40 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
41 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
42 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
44 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
45 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
46 cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
47 cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
49 cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
51 cvar_t r_draweffects = {0, "r_draweffects", "1"};
53 cvar_t cl_explosions = {CVAR_SAVE, "cl_explosions", "1"};
54 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
56 mempool_t *cl_scores_mempool;
57 mempool_t *cl_refdef_mempool;
58 mempool_t *cl_entities_mempool;
64 int cl_max_static_entities;
65 int cl_max_temp_entities;
69 int cl_max_lightstyle;
70 int cl_max_brushmodel_entities;
72 entity_t *cl_entities;
73 qbyte *cl_entities_active;
74 entity_t *cl_static_entities;
75 entity_t *cl_temp_entities;
76 cl_effect_t *cl_effects;
79 lightstyle_t *cl_lightstyle;
80 entity_render_t **cl_brushmodel_entities;
83 int cl_num_static_entities;
84 int cl_num_temp_entities;
85 int cl_num_brushmodel_entities;
93 void CL_ClearState (void)
100 Mem_EmptyPool(cl_scores_mempool);
101 Mem_EmptyPool(cl_entities_mempool);
103 // wipe the entire cl structure
104 memset (&cl, 0, sizeof(cl));
106 SZ_Clear (&cls.message);
109 cl_num_static_entities = 0;
110 cl_num_temp_entities = 0;
111 cl_num_brushmodel_entities = 0;
113 // tweak these if the game runs out
114 cl_max_entities = MAX_EDICTS;
115 cl_max_static_entities = 256;
116 cl_max_temp_entities = 512;
117 cl_max_effects = 256;
119 cl_max_dlights = MAX_DLIGHTS;
120 cl_max_lightstyle = MAX_LIGHTSTYLES;
121 cl_max_brushmodel_entities = MAX_EDICTS;
123 cl_entities = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(entity_t));
124 cl_entities_active = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(qbyte));
125 cl_static_entities = Mem_Alloc(cl_entities_mempool, cl_max_static_entities * sizeof(entity_t));
126 cl_temp_entities = Mem_Alloc(cl_entities_mempool, cl_max_temp_entities * sizeof(entity_t));
127 cl_effects = Mem_Alloc(cl_entities_mempool, cl_max_effects * sizeof(cl_effect_t));
128 cl_beams = Mem_Alloc(cl_entities_mempool, cl_max_beams * sizeof(beam_t));
129 cl_dlights = Mem_Alloc(cl_entities_mempool, cl_max_dlights * sizeof(dlight_t));
130 cl_lightstyle = Mem_Alloc(cl_entities_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
131 cl_brushmodel_entities = Mem_Alloc(cl_entities_mempool, cl_max_brushmodel_entities * sizeof(entity_render_t *));
135 CL_Particles_Clear();
137 // LordHavoc: have to set up the baseline info for alpha and other stuff
138 for (i = 0;i < cl_max_entities;i++)
140 ClearStateToDefault(&cl_entities[i].state_baseline);
141 ClearStateToDefault(&cl_entities[i].state_previous);
142 ClearStateToDefault(&cl_entities[i].state_current);
149 =====================
152 Sends a disconnect message to the server
153 This is also called on Host_Error, so it shouldn't cause any errors
154 =====================
156 void CL_Disconnect (void)
158 if (cls.state == ca_dedicated)
161 // stop sounds (especially looping!)
162 S_StopAllSounds (true);
164 // clear contents blends
165 cl.cshifts[0].percent = 0;
166 cl.cshifts[1].percent = 0;
167 cl.cshifts[2].percent = 0;
168 cl.cshifts[3].percent = 0;
170 cl.worldmodel = NULL;
172 if (cls.demoplayback)
174 else if (cls.state == ca_connected)
176 if (cls.demorecording)
179 Con_DPrintf ("Sending clc_disconnect\n");
180 SZ_Clear (&cls.message);
181 MSG_WriteByte (&cls.message, clc_disconnect);
182 NET_SendUnreliableMessage (cls.netcon, &cls.message);
183 SZ_Clear (&cls.message);
184 NET_Close (cls.netcon);
185 cls.state = ca_disconnected; // prevent this code from executing again during Host_ShutdownServer
186 // if running a local server, shut it down
188 Host_ShutdownServer(false);
190 cls.state = ca_disconnected;
192 cls.demoplayback = cls.timedemo = false;
196 void CL_Disconnect_f (void)
200 Host_ShutdownServer (false);
207 =====================
208 CL_EstablishConnection
210 Host should be either "local" or a net address to be passed on
211 =====================
213 void CL_EstablishConnection (char *host)
215 if (cls.state == ca_dedicated)
218 if (cls.demoplayback)
223 cls.netcon = NET_Connect (host);
225 Host_Error ("CL_Connect: connect failed\n");
226 Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
228 cls.demonum = -1; // not in the demo loop now
229 cls.state = ca_connected;
230 cls.signon = 0; // need all the signon messages before playing
240 static void CL_PrintEntities_f (void)
246 for (i = 0, ent = cl_entities;i < cl_num_entities;i++, ent++)
248 if (!ent->state_current.active)
251 if (ent->render.model)
252 strncpy(name, ent->render.model->name, 25);
254 strcpy(name, "--no model--");
256 for (j = strlen(name);j < 25;j++)
258 Con_Printf ("%3i: %s:%04i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.origin[0], (int) ent->render.origin[1], (int) ent->render.origin[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
262 static const vec3_t nomodelmins = {-16, -16, -16};
263 static const vec3_t nomodelmaxs = {16, 16, 16};
264 void CL_BoundingBoxForEntity(entity_render_t *ent)
268 if (ent->angles[0] || ent->angles[2])
271 VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
272 VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
274 else if (ent->angles[1])
277 VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
278 VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
282 VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
283 VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
288 VectorAdd(ent->origin, nomodelmins, ent->mins);
289 VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
293 void CL_LerpUpdate(entity_t *e)
295 entity_persistent_t *p;
300 if (p->modelindex != e->state_current.modelindex)
302 // reset all interpolation information
303 p->modelindex = e->state_current.modelindex;
304 p->frame1 = p->frame2 = e->state_current.frame;
305 p->frame1time = p->frame2time = cl.time;
308 else if (p->frame2 != e->state_current.frame)
310 // transition to new frame
311 p->frame1 = p->frame2;
312 p->frame1time = p->frame2time;
313 p->frame2 = e->state_current.frame;
314 p->frame2time = cl.time;
320 p->framelerp = (cl.time - p->frame2time) * 10;
321 p->framelerp = bound(0, p->framelerp, 1);
324 r->model = cl.model_precache[e->state_current.modelindex];
325 Mod_CheckLoaded(r->model);
326 r->frame = e->state_current.frame;
327 r->frame1 = p->frame1;
328 r->frame2 = p->frame2;
329 r->framelerp = p->framelerp;
330 r->frame1time = p->frame1time;
331 r->frame2time = p->frame2time;
338 Determines the fraction between the last two messages that the objects
342 static float CL_LerpPoint (void)
346 // dropped packet, or start of demo
347 if (cl.mtime[1] < cl.mtime[0] - 0.1)
348 cl.mtime[1] = cl.mtime[0] - 0.1;
350 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
352 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
353 f = cl.mtime[0] - cl.mtime[1];
354 if (!f || cl_nolerp.integer || cls.timedemo || (sv.active && svs.maxclients == 1))
356 cl.time = cl.mtime[0];
360 f = (cl.time - cl.mtime[1]) / f;
361 return bound(0, f, 1);
364 void CL_ClearTempEntities (void)
366 cl_num_temp_entities = 0;
369 entity_t *CL_NewTempEntity (void)
373 if (r_refdef.numentities >= r_refdef.maxentities)
375 if (cl_num_temp_entities >= cl_max_temp_entities)
377 ent = &cl_temp_entities[cl_num_temp_entities++];
378 memset (ent, 0, sizeof(*ent));
379 r_refdef.entities[r_refdef.numentities++] = &ent->render;
381 ent->render.colormap = -1; // no special coloring
382 ent->render.scale = 1;
383 ent->render.alpha = 1;
387 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
393 // first look for an exact key match
397 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
403 // then look for anything else
405 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
409 // unable to find one
413 //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
414 memset (dl, 0, sizeof(*dl));
416 VectorCopy(org, dl->origin);
419 dl->color[1] = green;
423 dl->die = cl.time + lifetime;
428 void CL_DecayLights (void)
434 time = cl.time - cl.oldtime;
437 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
441 if (dl->die < cl.time)
447 dl->radius -= time*dl->decay;
453 void CL_RelinkWorld (void)
455 if (cl_num_entities < 1)
457 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &cl_entities[0].render;
458 CL_BoundingBoxForEntity(&cl_entities[0].render);
461 static void CL_RelinkStaticEntities(void)
464 for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
466 Mod_CheckLoaded(cl_static_entities[i].render.model);
467 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
476 static void CL_RelinkNetworkEntities(void)
479 int i, effects, temp;
480 float d, bobjrotate, bobjoffset, lerp;
481 vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
483 bobjrotate = ANGLEMOD(100*cl.time);
484 if (cl_itembobheight.value)
485 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
489 // start on the entity after the world
490 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
492 // if the object isn't active in the current network frame, skip it
493 if (!cl_entities_active[i])
495 if (!ent->state_current.active)
497 cl_entities_active[i] = false;
501 VectorCopy(ent->persistent.trail_origin, oldorg);
503 if (!ent->state_previous.active)
505 // only one state available
506 VectorCopy (ent->persistent.neworigin, neworg);
507 VectorCopy (ent->persistent.newangles, ent->render.angles);
508 VectorCopy (neworg, oldorg);
512 // if the delta is large, assume a teleport and don't lerp
513 VectorSubtract(ent->persistent.neworigin, ent->persistent.oldorigin, delta);
514 if (ent->persistent.lerpdeltatime > 0)
516 lerp = (cl.time - ent->persistent.lerpstarttime) / ent->persistent.lerpdeltatime;
519 // interpolate the origin and angles
520 VectorMA(ent->persistent.oldorigin, lerp, delta, neworg);
521 VectorSubtract(ent->persistent.newangles, ent->persistent.oldangles, delta);
522 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
523 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
524 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
525 VectorMA(ent->persistent.oldangles, lerp, delta, ent->render.angles);
530 VectorCopy (ent->persistent.neworigin, neworg);
531 VectorCopy (ent->persistent.newangles, ent->render.angles);
537 VectorCopy (ent->persistent.neworigin, neworg);
538 VectorCopy (ent->persistent.newangles, ent->render.angles);
542 VectorCopy (neworg, ent->persistent.trail_origin);
543 // persistent.modelindex will be updated by CL_LerpUpdate
544 if (ent->state_current.modelindex != ent->persistent.modelindex)
545 VectorCopy(neworg, oldorg);
547 VectorCopy (neworg, ent->render.origin);
548 ent->render.flags = ent->state_current.flags;
549 if (i == cl.viewentity)
550 ent->render.flags |= RENDER_EXTERIORMODEL;
551 ent->render.effects = effects = ent->state_current.effects;
552 if (ent->state_current.flags & RENDER_COLORMAPPED)
553 ent->render.colormap = ent->state_current.colormap;
554 else if (cl.scores == NULL || !ent->state_current.colormap)
555 ent->render.colormap = -1; // no special coloring
557 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
558 ent->render.skinnum = ent->state_current.skin;
559 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
560 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
562 // update interpolation info
565 // handle effects now...
570 // LordHavoc: if the entity has no effects, don't check each
573 if (effects & EF_BRIGHTFIELD)
574 CL_EntityParticles (ent);
575 if (effects & EF_MUZZLEFLASH)
576 ent->persistent.muzzleflash = 100.0f;
577 if (effects & EF_DIMLIGHT)
579 dlightcolor[0] += 200.0f;
580 dlightcolor[1] += 200.0f;
581 dlightcolor[2] += 200.0f;
583 if (effects & EF_BRIGHTLIGHT)
585 dlightcolor[0] += 400.0f;
586 dlightcolor[1] += 400.0f;
587 dlightcolor[2] += 400.0f;
589 // LordHavoc: added EF_RED and EF_BLUE
590 if (effects & EF_RED) // red
592 dlightcolor[0] += 200.0f;
593 dlightcolor[1] += 20.0f;
594 dlightcolor[2] += 20.0f;
596 if (effects & EF_BLUE) // blue
598 dlightcolor[0] += 20.0f;
599 dlightcolor[1] += 20.0f;
600 dlightcolor[2] += 200.0f;
602 if (effects & EF_FLAME)
604 if (ent->render.model)
606 mins[0] = neworg[0] - 16.0f;
607 mins[1] = neworg[1] - 16.0f;
608 mins[2] = neworg[2] - 16.0f;
609 maxs[0] = neworg[0] + 16.0f;
610 maxs[1] = neworg[1] + 16.0f;
611 maxs[2] = neworg[2] + 16.0f;
612 // how many flames to make
613 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
614 CL_FlameCube(mins, maxs, temp);
616 d = lhrandom(200, 250);
617 dlightcolor[0] += d * 1.0f;
618 dlightcolor[1] += d * 0.7f;
619 dlightcolor[2] += d * 0.3f;
621 if (effects & EF_STARDUST)
623 if (ent->render.model)
625 mins[0] = neworg[0] - 16.0f;
626 mins[1] = neworg[1] - 16.0f;
627 mins[2] = neworg[2] - 16.0f;
628 maxs[0] = neworg[0] + 16.0f;
629 maxs[1] = neworg[1] + 16.0f;
630 maxs[2] = neworg[2] + 16.0f;
631 // how many particles to make
632 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
633 CL_Stardust(mins, maxs, temp);
636 dlightcolor[0] += d * 1.0f;
637 dlightcolor[1] += d * 0.7f;
638 dlightcolor[2] += d * 0.3f;
642 if (ent->persistent.muzzleflash > 0)
644 AngleVectors (ent->render.angles, v, NULL, NULL);
646 v2[0] = v[0] * 18 + neworg[0];
647 v2[1] = v[1] * 18 + neworg[1];
648 v2[2] = v[2] * 18 + neworg[2] + 16;
649 CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
651 CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
652 ent->persistent.muzzleflash -= cl.frametime * 1000;
655 // LordHavoc: if the model has no flags, don't check each
656 if (ent->render.model && ent->render.model->flags)
658 if (ent->render.model->flags & EF_ROTATE)
660 ent->render.angles[1] = bobjrotate;
661 ent->render.origin[2] += bobjoffset;
663 // only do trails if present in the previous frame as well
664 if (ent->state_previous.active)
666 if (ent->render.model->flags & EF_GIB)
667 CL_RocketTrail (oldorg, neworg, 2, ent);
668 else if (ent->render.model->flags & EF_ZOMGIB)
669 CL_RocketTrail (oldorg, neworg, 4, ent);
670 else if (ent->render.model->flags & EF_TRACER)
672 CL_RocketTrail (oldorg, neworg, 3, ent);
673 dlightcolor[0] += 0x10;
674 dlightcolor[1] += 0x40;
675 dlightcolor[2] += 0x10;
677 else if (ent->render.model->flags & EF_TRACER2)
679 CL_RocketTrail (oldorg, neworg, 5, ent);
680 dlightcolor[0] += 0x50;
681 dlightcolor[1] += 0x30;
682 dlightcolor[2] += 0x10;
684 else if (ent->render.model->flags & EF_ROCKET)
686 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
687 dlightcolor[0] += 200.0f;
688 dlightcolor[1] += 160.0f;
689 dlightcolor[2] += 80.0f;
691 else if (ent->render.model->flags & EF_GRENADE)
693 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility (cigar smoke)
694 CL_RocketTrail (oldorg, neworg, 7, ent);
696 CL_RocketTrail (oldorg, neworg, 1, ent);
698 else if (ent->render.model->flags & EF_TRACER3)
700 CL_RocketTrail (oldorg, neworg, 6, ent);
701 dlightcolor[0] += 0x50;
702 dlightcolor[1] += 0x20;
703 dlightcolor[2] += 0x40;
707 // LordHavoc: customizable glow
708 if (ent->state_current.glowsize)
710 // * 4 for the expansion from 0-255 to 0-1023 range,
711 // / 255 to scale down byte colors
712 VectorMA(dlightcolor, ent->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[ent->state_current.glowcolor], dlightcolor);
714 // LordHavoc: customizable trail
715 if (ent->render.flags & RENDER_GLOWTRAIL)
716 CL_RocketTrail2 (oldorg, neworg, ent->state_current.glowcolor, ent);
718 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
720 VectorCopy(neworg, v);
721 // hack to make glowing player light shine on their gun
722 if (i == cl.viewentity/* && !chase_active.integer*/)
724 CL_AllocDlight (&ent->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
727 if (chase_active.integer && (ent->render.flags & RENDER_VIEWMODEL))
730 // don't show entities with no modelindex (note: this still shows
731 // entities which have a modelindex that resolved to a NULL model)
732 if (!ent->state_current.modelindex)
734 if (effects & EF_NODRAW)
737 CL_BoundingBoxForEntity(&ent->render);
738 if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
739 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
741 if (r_refdef.numentities < r_refdef.maxentities)
742 r_refdef.entities[r_refdef.numentities++] = &ent->render;
744 if (cl_num_entities < i + 1)
745 cl_num_entities = i + 1;
749 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
753 if (!modelindex) // sanity check
755 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
760 VectorCopy(org, e->origin);
761 e->modelindex = modelindex;
762 e->starttime = cl.time;
763 e->startframe = startframe;
764 e->endframe = startframe + framecount;
765 e->framerate = framerate;
768 e->frame1time = cl.time;
769 e->frame2time = cl.time;
774 static void CL_RelinkEffects(void)
781 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
785 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
787 if (intframe < 0 || intframe >= e->endframe)
790 memset(e, 0, sizeof(*e));
794 if (intframe != e->frame)
797 e->frame1time = e->frame2time;
798 e->frame2time = cl.time;
801 // if we're drawing effects, get a new temp entity
802 // (NewTempEntity adds it to the render entities list for us)
803 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
805 // interpolation stuff
806 ent->render.frame1 = intframe;
807 ent->render.frame2 = intframe + 1;
808 if (ent->render.frame2 >= e->endframe)
809 ent->render.frame2 = -1; // disappear
810 ent->render.framelerp = frame - intframe;
811 ent->render.frame1time = e->frame1time;
812 ent->render.frame2time = e->frame2time;
815 VectorCopy(e->origin, ent->render.origin);
816 ent->render.model = cl.model_precache[e->modelindex];
817 ent->render.frame = ent->render.frame2;
818 ent->render.colormap = -1; // no special coloring
819 ent->render.scale = 1;
820 ent->render.alpha = 1;
822 CL_BoundingBoxForEntity(&ent->render);
828 void CL_RelinkBeams (void)
838 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
840 if (!b->model || b->endtime < cl.time)
843 // if coming from the player, update the start position
844 //if (b->entity == cl.viewentity)
845 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
846 if (b->entity && cl_entities[b->entity].state_current.active)
848 VectorCopy (cl_entities[b->entity].render.origin, b->start);
852 // calculate pitch and yaw
853 VectorSubtract (b->end, b->start, dist);
855 if (dist[1] == 0 && dist[0] == 0)
865 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
869 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
870 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
875 // add new entities for the lightning
876 VectorCopy (b->start, org);
877 d = VectorNormalizeLength(dist);
880 ent = CL_NewTempEntity ();
883 VectorCopy (org, ent->render.origin);
884 ent->render.model = b->model;
885 ent->render.effects = EF_FULLBRIGHT;
886 ent->render.angles[0] = pitch;
887 ent->render.angles[1] = yaw;
888 ent->render.angles[2] = rand()%360;
889 CL_BoundingBoxForEntity(&ent->render);
890 VectorMA(org, 30, dist, org);
896 void CL_LerpPlayer(float frac)
901 if (cl.entitydatabase.numframes && cl.viewentity == cl.playerentity)
903 cl.viewentorigin[0] = cl.viewentoriginold[0] + frac * (cl.viewentoriginnew[0] - cl.viewentoriginold[0]);
904 cl.viewentorigin[1] = cl.viewentoriginold[1] + frac * (cl.viewentoriginnew[1] - cl.viewentoriginold[1]);
905 cl.viewentorigin[2] = cl.viewentoriginold[2] + frac * (cl.viewentoriginnew[2] - cl.viewentoriginold[2]);
908 VectorCopy (cl_entities[cl.viewentity].render.origin, cl.viewentorigin);
910 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
912 for (i = 0;i < 3;i++)
913 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
915 if (cls.demoplayback)
917 // interpolate the angles
918 for (i = 0;i < 3;i++)
920 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
925 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
930 void CL_RelinkEntities (void)
934 // fraction from previous network update to current
935 frac = CL_LerpPoint();
937 CL_ClearTempEntities();
940 CL_RelinkStaticEntities();
941 CL_RelinkNetworkEntities();
954 Read all incoming data from the server
957 int CL_ReadFromServer (void)
961 cl.oldtime = cl.time;
962 cl.time += cl.frametime;
967 ret = CL_GetMessage ();
969 Host_Error ("CL_ReadFromServer: lost server connection");
973 cl.last_received_message = realtime;
975 if (cl_shownet.integer)
978 CL_ParseServerMessage ();
980 while (ret && cls.state == ca_connected);
985 r_refdef.numentities = 0;
987 cl_num_brushmodel_entities = 0;
989 if (cls.state == ca_connected && cls.signon == SIGNONS)
991 CL_RelinkEntities ();
993 // run cgame code (which can add more entities)
998 // bring the links up to date
1008 void CL_SendCmd (void)
1012 if (cls.state != ca_connected)
1015 if (cls.signon == SIGNONS)
1017 // get basic movement from keyboard
1020 IN_PreMove(); // OS independent code
1022 // allow mice or other external controllers to add to the move
1025 IN_PostMove(); // OS independent code
1027 // send the unreliable message
1030 #ifndef NOROUTINGFIX
1031 else if (cls.signon == 0 && !cls.demoplayback)
1033 // LordHavoc: fix for NAT routing of netquake:
1034 // bounce back a clc_nop message to the newly allocated server port,
1035 // to establish a routing connection for incoming frames,
1036 // the server waits for this before sending anything
1037 if (realtime > cl.sendnoptime)
1039 cl.sendnoptime = realtime + 3;
1040 Con_DPrintf("sending clc_nop to get server's attention\n");
1047 MSG_WriteByte(&buf, clc_nop);
1048 if (NET_SendUnreliableMessage (cls.netcon, &buf) == -1)
1050 Con_Printf ("CL_SendCmd: lost server connection\n");
1058 if (cls.demoplayback)
1060 SZ_Clear (&cls.message);
1064 // send the reliable message
1065 if (!cls.message.cursize)
1066 return; // no message at all
1068 if (!NET_CanSendMessage (cls.netcon))
1070 Con_DPrintf ("CL_WriteToServer: can't send\n");
1071 if (developer.integer)
1072 SZ_HexDumpToConsole(&cls.message);
1076 if (NET_SendMessage (cls.netcon, &cls.message) == -1)
1077 Host_Error ("CL_WriteToServer: lost server connection");
1079 SZ_Clear (&cls.message);
1082 // LordHavoc: pausedemo command
1083 static void CL_PauseDemo_f (void)
1085 cls.demopaused = !cls.demopaused;
1087 Con_Printf("Demo paused\n");
1089 Con_Printf("Demo unpaused\n");
1093 ======================
1095 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1096 ======================
1098 static void CL_PModel_f (void)
1103 if (Cmd_Argc () == 1)
1105 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1108 i = atoi(Cmd_Argv(1));
1110 if (cmd_source == src_command)
1112 if (cl_pmodel.integer == i)
1114 Cvar_SetValue ("_cl_pmodel", i);
1115 if (cls.state == ca_connected)
1116 Cmd_ForwardToServer ();
1120 host_client->pmodel = i;
1121 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1126 ======================
1128 ======================
1130 static void CL_Fog_f (void)
1132 if (Cmd_Argc () == 1)
1134 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1137 fog_density = atof(Cmd_Argv(1));
1138 fog_red = atof(Cmd_Argv(2));
1139 fog_green = atof(Cmd_Argv(3));
1140 fog_blue = atof(Cmd_Argv(4));
1150 cl_scores_mempool = Mem_AllocPool("client player info");
1151 cl_entities_mempool = Mem_AllocPool("client entities");
1152 cl_refdef_mempool = Mem_AllocPool("refdef");
1154 memset(&r_refdef, 0, sizeof(r_refdef));
1155 // max entities sent to renderer per frame
1156 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1157 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1158 // 256k drawqueue buffer
1159 r_refdef.maxdrawqueuesize = 256 * 1024;
1160 r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1162 SZ_Alloc (&cls.message, 1024, "cls.message");
1168 // register our commands
1170 Cvar_RegisterVariable (&cl_name);
1171 Cvar_RegisterVariable (&cl_color);
1172 if (gamemode == GAME_NEHAHRA)
1173 Cvar_RegisterVariable (&cl_pmodel);
1174 Cvar_RegisterVariable (&cl_upspeed);
1175 Cvar_RegisterVariable (&cl_forwardspeed);
1176 Cvar_RegisterVariable (&cl_backspeed);
1177 Cvar_RegisterVariable (&cl_sidespeed);
1178 Cvar_RegisterVariable (&cl_movespeedkey);
1179 Cvar_RegisterVariable (&cl_yawspeed);
1180 Cvar_RegisterVariable (&cl_pitchspeed);
1181 Cvar_RegisterVariable (&cl_anglespeedkey);
1182 Cvar_RegisterVariable (&cl_shownet);
1183 Cvar_RegisterVariable (&cl_nolerp);
1184 Cvar_RegisterVariable (&lookspring);
1185 Cvar_RegisterVariable (&lookstrafe);
1186 Cvar_RegisterVariable (&sensitivity);
1187 Cvar_RegisterVariable (&freelook);
1189 Cvar_RegisterVariable (&m_pitch);
1190 Cvar_RegisterVariable (&m_yaw);
1191 Cvar_RegisterVariable (&m_forward);
1192 Cvar_RegisterVariable (&m_side);
1194 Cvar_RegisterVariable (&cl_itembobspeed);
1195 Cvar_RegisterVariable (&cl_itembobheight);
1197 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1198 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1199 Cmd_AddCommand ("record", CL_Record_f);
1200 Cmd_AddCommand ("stop", CL_Stop_f);
1201 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1202 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1204 Cmd_AddCommand ("fog", CL_Fog_f);
1206 // LordHavoc: added pausedemo
1207 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1208 if (gamemode == GAME_NEHAHRA)
1209 Cmd_AddCommand ("pmodel", CL_PModel_f);
1211 Cvar_RegisterVariable(&r_draweffects);
1212 Cvar_RegisterVariable(&cl_explosions);
1213 Cvar_RegisterVariable(&cl_stainmaps);
1216 CL_Particles_Init();