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"
27 // we need to declare some mouse variables here, because the menu system
28 // references them even when on a unix system.
30 cvar_t cl_shownet = {0, "cl_shownet","0"};
31 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
33 cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
34 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
36 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
37 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
38 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
40 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
41 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
42 cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
43 cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
45 cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
47 cvar_t r_draweffects = {0, "r_draweffects", "1"};
49 cvar_t cl_explosions = {CVAR_SAVE, "cl_explosions", "1"};
50 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
52 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1"};
53 cvar_t cl_beams_relative = {CVAR_SAVE, "cl_beams_relative", "1"};
54 cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0"};
56 cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0"};
58 mempool_t *cl_refdef_mempool;
59 mempool_t *cl_entities_mempool;
65 int cl_max_static_entities;
66 int cl_max_temp_entities;
70 int cl_max_lightstyle;
71 int cl_max_brushmodel_entities;
73 entity_t *cl_entities;
74 qbyte *cl_entities_active;
75 entity_t *cl_static_entities;
76 entity_t *cl_temp_entities;
77 cl_effect_t *cl_effects;
80 lightstyle_t *cl_lightstyle;
81 entity_render_t **cl_brushmodel_entities;
84 int cl_num_static_entities;
85 int cl_num_temp_entities;
86 int cl_num_brushmodel_entities;
94 void CL_ClearState (void)
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)
176 if (cls.demorecording)
179 Con_DPrintf("Sending clc_disconnect\n");
180 SZ_Clear(&cls.message);
181 MSG_WriteByte(&cls.message, clc_disconnect);
182 NetConn_SendUnreliableMessage(cls.netcon, &cls.message);
183 SZ_Clear(&cls.message);
184 NetConn_Close(cls.netcon);
186 // if running a local server, shut it down
189 // prevent this code from executing again during Host_ShutdownServer
190 cls.state = ca_disconnected;
191 Host_ShutdownServer(false);
194 cls.state = ca_disconnected;
196 cls.demoplayback = cls.timedemo = false;
200 void CL_Disconnect_f (void)
204 Host_ShutdownServer (false);
211 =====================
212 CL_EstablishConnection
214 Host should be either "local" or a net address
215 =====================
217 void CL_EstablishConnection(const char *host)
219 if (cls.state == ca_dedicated)
222 // clear menu's connect error message
223 m_return_reason[0] = 0;
225 // stop demo loop in case this fails
229 if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
231 cls.connect_trying = true;
232 cls.connect_remainingtries = 3;
233 cls.connect_nextsendtime = 0;
236 NetConn_ClientFrame();
237 NetConn_ServerFrame();
238 NetConn_ClientFrame();
239 NetConn_ServerFrame();
240 NetConn_ClientFrame();
241 NetConn_ServerFrame();
242 NetConn_ClientFrame();
243 NetConn_ServerFrame();
253 static void CL_PrintEntities_f (void)
259 for (i = 0, ent = cl_entities;i < cl_num_entities;i++, ent++)
261 if (!ent->state_current.active)
264 if (ent->render.model)
265 strncpy(name, ent->render.model->name, 25);
267 strcpy(name, "--no model--");
269 for (j = strlen(name);j < 25;j++)
271 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);
275 //static const vec3_t nomodelmins = {-16, -16, -16};
276 //static const vec3_t nomodelmaxs = {16, 16, 16};
277 void CL_BoundingBoxForEntity(entity_render_t *ent)
281 //if (ent->angles[0] || ent->angles[2])
282 if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
285 ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
286 ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
287 ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
288 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
289 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
290 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
291 //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
292 //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
294 //else if (ent->angles[1])
295 else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
298 ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
299 ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
300 ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
301 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
302 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
303 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
304 //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
305 //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
309 ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
310 ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
311 ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
312 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
313 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
314 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
315 //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
316 //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
321 ent->mins[0] = ent->matrix.m[0][3] - 16;
322 ent->mins[1] = ent->matrix.m[1][3] - 16;
323 ent->mins[2] = ent->matrix.m[2][3] - 16;
324 ent->maxs[0] = ent->matrix.m[0][3] + 16;
325 ent->maxs[1] = ent->matrix.m[1][3] + 16;
326 ent->maxs[2] = ent->matrix.m[2][3] + 16;
327 //VectorAdd(ent->origin, nomodelmins, ent->mins);
328 //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
332 void CL_LerpUpdate(entity_t *e)
334 entity_persistent_t *p;
339 if (p->modelindex != e->state_current.modelindex)
341 // reset all interpolation information
342 p->modelindex = e->state_current.modelindex;
343 p->frame1 = p->frame2 = e->state_current.frame;
344 p->frame1time = p->frame2time = cl.time;
347 else if (p->frame2 != e->state_current.frame)
349 // transition to new frame
350 p->frame1 = p->frame2;
351 p->frame1time = p->frame2time;
352 p->frame2 = e->state_current.frame;
353 p->frame2time = cl.time;
359 p->framelerp = (cl.time - p->frame2time) * 10;
360 p->framelerp = bound(0, p->framelerp, 1);
363 r->model = cl.model_precache[e->state_current.modelindex];
364 Mod_CheckLoaded(r->model);
365 r->frame = e->state_current.frame;
366 r->frame1 = p->frame1;
367 r->frame2 = p->frame2;
368 r->framelerp = p->framelerp;
369 r->frame1time = p->frame1time;
370 r->frame2time = p->frame2time;
377 Determines the fraction between the last two messages that the objects
381 static float CL_LerpPoint (void)
385 // dropped packet, or start of demo
386 if (cl.mtime[1] < cl.mtime[0] - 0.1)
387 cl.mtime[1] = cl.mtime[0] - 0.1;
389 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
391 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
392 f = cl.mtime[0] - cl.mtime[1];
393 if (!f || cl_nolerp.integer || cls.timedemo || (sv.active && svs.maxclients == 1))
395 cl.time = cl.mtime[0];
399 f = (cl.time - cl.mtime[1]) / f;
400 return bound(0, f, 1);
403 void CL_ClearTempEntities (void)
405 cl_num_temp_entities = 0;
408 entity_t *CL_NewTempEntity (void)
412 if (r_refdef.numentities >= r_refdef.maxentities)
414 if (cl_num_temp_entities >= cl_max_temp_entities)
416 ent = &cl_temp_entities[cl_num_temp_entities++];
417 memset (ent, 0, sizeof(*ent));
418 r_refdef.entities[r_refdef.numentities++] = &ent->render;
420 ent->render.colormap = -1; // no special coloring
421 ent->render.scale = 1;
422 ent->render.alpha = 1;
426 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
432 // first look for an exact key match
436 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
442 // then look for anything else
444 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
448 // unable to find one
452 //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
453 memset (dl, 0, sizeof(*dl));
456 cl.worldmodel->FindNonSolidLocation(cl.worldmodel, org, dl->origin, 6);
457 //VectorCopy(org, dl->origin);
460 dl->color[1] = green;
464 dl->die = cl.time + lifetime;
469 void CL_DecayLights (void)
475 time = cl.time - cl.oldtime;
478 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
482 if (dl->die < cl.time)
488 dl->radius -= time*dl->decay;
494 void CL_RelinkWorld (void)
496 entity_t *ent = &cl_entities[0];
497 if (cl_num_entities < 1)
499 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
500 Matrix4x4_CreateIdentity(&ent->render.matrix);
501 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
502 CL_BoundingBoxForEntity(&ent->render);
505 static void CL_RelinkStaticEntities(void)
508 for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
510 Mod_CheckLoaded(cl_static_entities[i].render.model);
511 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
520 extern qboolean Nehahrademcompatibility;
521 #define MAXVIEWMODELS 32
522 entity_t *viewmodels[MAXVIEWMODELS];
524 static void CL_RelinkNetworkEntities(void)
527 int i, effects, temp;
528 float d, bobjrotate, bobjoffset, lerp;
529 vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
533 bobjrotate = ANGLEMOD(100*cl.time);
534 if (cl_itembobheight.value)
535 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
539 // start on the entity after the world
540 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
542 // if the object isn't active in the current network frame, skip it
543 if (!cl_entities_active[i])
545 if (!ent->state_current.active)
547 cl_entities_active[i] = false;
551 VectorCopy(ent->persistent.trail_origin, oldorg);
553 if (!ent->state_previous.active)
555 // only one state available
556 VectorCopy (ent->persistent.neworigin, neworg);
557 VectorCopy (ent->persistent.newangles, ent->render.angles);
558 VectorCopy (neworg, oldorg);
562 // if the delta is large, assume a teleport and don't lerp
563 VectorSubtract(ent->persistent.neworigin, ent->persistent.oldorigin, delta);
564 if (ent->persistent.lerpdeltatime > 0)
566 lerp = (cl.time - ent->persistent.lerpstarttime) / ent->persistent.lerpdeltatime;
569 // interpolate the origin and angles
570 VectorMA(ent->persistent.oldorigin, lerp, delta, neworg);
571 VectorSubtract(ent->persistent.newangles, ent->persistent.oldangles, delta);
572 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
573 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
574 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
575 VectorMA(ent->persistent.oldangles, lerp, delta, ent->render.angles);
580 VectorCopy (ent->persistent.neworigin, neworg);
581 VectorCopy (ent->persistent.newangles, ent->render.angles);
587 VectorCopy (ent->persistent.neworigin, neworg);
588 VectorCopy (ent->persistent.newangles, ent->render.angles);
592 if (!ent->render.model || ent->render.model->type != mod_brush)
593 ent->render.angles[0] = -ent->render.angles[0];
595 VectorCopy (neworg, ent->persistent.trail_origin);
596 // persistent.modelindex will be updated by CL_LerpUpdate
597 if (ent->state_current.modelindex != ent->persistent.modelindex || !ent->state_previous.active)
598 VectorCopy(neworg, oldorg);
600 VectorCopy (neworg, ent->render.origin);
601 ent->render.flags = ent->state_current.flags;
602 if (i == cl.viewentity)
603 ent->render.flags |= RENDER_EXTERIORMODEL;
604 ent->render.effects = effects = ent->state_current.effects;
605 if (ent->state_current.flags & RENDER_COLORMAPPED)
606 ent->render.colormap = ent->state_current.colormap;
607 else if (cl.scores == NULL || !ent->state_current.colormap)
608 ent->render.colormap = -1; // no special coloring
610 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
611 ent->render.skinnum = ent->state_current.skin;
612 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
613 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
615 if (ent->render.model && ent->render.model->flags & EF_ROTATE)
617 ent->render.angles[1] = bobjrotate;
618 ent->render.origin[2] += bobjoffset;
621 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2], ent->render.scale);
623 // update interpolation info
626 // handle effects now...
631 // LordHavoc: if the entity has no effects, don't check each
634 if (effects & EF_BRIGHTFIELD)
636 if (gamemode == GAME_NEXUIZ)
638 dlightcolor[0] += 100.0f;
639 dlightcolor[1] += 200.0f;
640 dlightcolor[2] += 400.0f;
641 // don't do trail if we have no previous location
642 if (ent->state_previous.active)
643 CL_RocketTrail (oldorg, neworg, 8, ent);
646 CL_EntityParticles (ent);
648 if (effects & EF_MUZZLEFLASH)
649 ent->persistent.muzzleflash = 100.0f;
650 if (effects & EF_DIMLIGHT)
652 dlightcolor[0] += 200.0f;
653 dlightcolor[1] += 200.0f;
654 dlightcolor[2] += 200.0f;
656 if (effects & EF_BRIGHTLIGHT)
658 dlightcolor[0] += 400.0f;
659 dlightcolor[1] += 400.0f;
660 dlightcolor[2] += 400.0f;
662 // LordHavoc: added EF_RED and EF_BLUE
663 if (effects & EF_RED) // red
665 dlightcolor[0] += 200.0f;
666 dlightcolor[1] += 20.0f;
667 dlightcolor[2] += 20.0f;
669 if (effects & EF_BLUE) // blue
671 dlightcolor[0] += 20.0f;
672 dlightcolor[1] += 20.0f;
673 dlightcolor[2] += 200.0f;
675 if (effects & EF_FLAME)
677 if (ent->render.model)
679 mins[0] = neworg[0] - 16.0f;
680 mins[1] = neworg[1] - 16.0f;
681 mins[2] = neworg[2] - 16.0f;
682 maxs[0] = neworg[0] + 16.0f;
683 maxs[1] = neworg[1] + 16.0f;
684 maxs[2] = neworg[2] + 16.0f;
685 // how many flames to make
686 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
687 CL_FlameCube(mins, maxs, temp);
689 d = lhrandom(200, 250);
690 dlightcolor[0] += d * 1.0f;
691 dlightcolor[1] += d * 0.7f;
692 dlightcolor[2] += d * 0.3f;
694 if (effects & EF_STARDUST)
696 if (ent->render.model)
698 mins[0] = neworg[0] - 16.0f;
699 mins[1] = neworg[1] - 16.0f;
700 mins[2] = neworg[2] - 16.0f;
701 maxs[0] = neworg[0] + 16.0f;
702 maxs[1] = neworg[1] + 16.0f;
703 maxs[2] = neworg[2] + 16.0f;
704 // how many particles to make
705 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
706 CL_Stardust(mins, maxs, temp);
709 dlightcolor[0] += d * 1.0f;
710 dlightcolor[1] += d * 0.7f;
711 dlightcolor[2] += d * 0.3f;
715 if (ent->persistent.muzzleflash > 0)
717 v2[0] = ent->render.matrix.m[0][0] * 18 + neworg[0];
718 v2[1] = ent->render.matrix.m[0][1] * 18 + neworg[1];
719 v2[2] = ent->render.matrix.m[0][2] * 18 + neworg[2] + 16;
720 CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
722 CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
723 ent->persistent.muzzleflash -= cl.frametime * 1000;
726 // LordHavoc: if the model has no flags, don't check each
727 if (ent->render.model && ent->render.model->flags)
729 // note: EF_ROTATE handled above, above matrix calculation
730 // only do trails if present in the previous frame as well
731 if (ent->state_previous.active)
733 if (ent->render.model->flags & EF_GIB)
734 CL_RocketTrail (oldorg, neworg, 2, ent);
735 else if (ent->render.model->flags & EF_ZOMGIB)
736 CL_RocketTrail (oldorg, neworg, 4, ent);
737 else if (ent->render.model->flags & EF_TRACER)
739 CL_RocketTrail (oldorg, neworg, 3, ent);
740 dlightcolor[0] += 0x10;
741 dlightcolor[1] += 0x40;
742 dlightcolor[2] += 0x10;
744 else if (ent->render.model->flags & EF_TRACER2)
746 CL_RocketTrail (oldorg, neworg, 5, ent);
747 dlightcolor[0] += 0x50;
748 dlightcolor[1] += 0x30;
749 dlightcolor[2] += 0x10;
751 else if (ent->render.model->flags & EF_ROCKET)
753 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
754 dlightcolor[0] += 200.0f;
755 dlightcolor[1] += 160.0f;
756 dlightcolor[2] += 80.0f;
758 else if (ent->render.model->flags & EF_GRENADE)
760 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility (cigar smoke)
761 CL_RocketTrail (oldorg, neworg, 7, ent);
763 CL_RocketTrail (oldorg, neworg, 1, ent);
765 else if (ent->render.model->flags & EF_TRACER3)
767 CL_RocketTrail (oldorg, neworg, 6, ent);
768 dlightcolor[0] += 0x50;
769 dlightcolor[1] += 0x20;
770 dlightcolor[2] += 0x40;
774 // LordHavoc: customizable glow
775 if (ent->state_current.glowsize)
777 // * 4 for the expansion from 0-255 to 0-1023 range,
778 // / 255 to scale down byte colors
779 VectorMA(dlightcolor, ent->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[ent->state_current.glowcolor], dlightcolor);
781 // LordHavoc: customizable trail
782 if (ent->render.flags & RENDER_GLOWTRAIL)
783 CL_RocketTrail2 (oldorg, neworg, ent->state_current.glowcolor, ent);
785 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
787 VectorCopy(neworg, v);
788 // hack to make glowing player light shine on their gun
789 if (i == cl.viewentity/* && !chase_active.integer*/)
791 CL_AllocDlight (&ent->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
794 if (chase_active.integer && (ent->render.flags & RENDER_VIEWMODEL))
797 // don't show entities with no modelindex (note: this still shows
798 // entities which have a modelindex that resolved to a NULL model)
799 if (!ent->state_current.modelindex)
801 if (effects & EF_NODRAW)
804 // store a list of view-relative entities for later adjustment in view code
805 if (ent->render.flags & RENDER_VIEWMODEL)
807 if (numviewmodels < MAXVIEWMODELS)
808 viewmodels[numviewmodels++] = ent;
812 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
814 CL_BoundingBoxForEntity(&ent->render);
815 if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
816 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
818 // note: the cl.viewentity and intermission check is to hide player
819 // shadow during intermission and during the Nehahra movie and
820 // Nehahra cinematics
821 if (!(ent->state_current.effects & EF_NOSHADOW)
822 && !(ent->state_current.effects & EF_ADDITIVE)
823 && (ent->state_current.alpha == 255)
824 && !(ent->render.flags & RENDER_VIEWMODEL)
825 && (i != cl.viewentity || (!cl.intermission && !Nehahrademcompatibility && !cl_noplayershadow.integer)))
826 ent->render.flags |= RENDER_SHADOW;
828 if (r_refdef.numentities < r_refdef.maxentities)
829 r_refdef.entities[r_refdef.numentities++] = &ent->render;
831 if (cl_num_entities < i + 1)
832 cl_num_entities = i + 1;
836 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
840 if (!modelindex) // sanity check
842 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
847 VectorCopy(org, e->origin);
848 e->modelindex = modelindex;
849 e->starttime = cl.time;
850 e->startframe = startframe;
851 e->endframe = startframe + framecount;
852 e->framerate = framerate;
855 e->frame1time = cl.time;
856 e->frame2time = cl.time;
861 static void CL_RelinkEffects(void)
868 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
872 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
874 if (intframe < 0 || intframe >= e->endframe)
877 memset(e, 0, sizeof(*e));
881 if (intframe != e->frame)
884 e->frame1time = e->frame2time;
885 e->frame2time = cl.time;
888 // if we're drawing effects, get a new temp entity
889 // (NewTempEntity adds it to the render entities list for us)
890 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
892 // interpolation stuff
893 ent->render.frame1 = intframe;
894 ent->render.frame2 = intframe + 1;
895 if (ent->render.frame2 >= e->endframe)
896 ent->render.frame2 = -1; // disappear
897 ent->render.framelerp = frame - intframe;
898 ent->render.frame1time = e->frame1time;
899 ent->render.frame2time = e->frame2time;
902 //VectorCopy(e->origin, ent->render.origin);
903 ent->render.model = cl.model_precache[e->modelindex];
904 ent->render.frame = ent->render.frame2;
905 ent->render.colormap = -1; // no special coloring
906 //ent->render.scale = 1;
907 ent->render.alpha = 1;
909 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
910 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
911 CL_BoundingBoxForEntity(&ent->render);
917 void CL_RelinkBeams (void)
927 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
929 if (!b->model || b->endtime < cl.time)
932 // if coming from the player, update the start position
933 //if (b->entity == cl.viewentity)
934 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
935 if (cl_beams_relative.integer && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
937 entity_state_t *p = &cl_entities[b->entity].state_previous;
938 //entity_state_t *c = &cl_entities[b->entity].state_current;
939 entity_render_t *r = &cl_entities[b->entity].render;
940 matrix4x4_t matrix, imatrix;
941 if (b->relativestartvalid == 2)
943 // not really valid yet, we need to get the orientation now
944 // (ParseBeam flagged this because it is received before
945 // entities are received, by now they have been received)
946 // note: because players create lightning in their think
947 // function (which occurs before movement), they actually
948 // have some lag in it's location, so compare to the
949 // previous player state, not the latest
950 if (b->entity == cl.viewentity)
951 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
953 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
954 Matrix4x4_Invert_Simple(&imatrix, &matrix);
955 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
956 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
957 b->relativestartvalid = 1;
961 if (b->entity == cl.viewentity)
962 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
964 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
965 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
966 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
972 if (cl_beams_lightatend.integer)
973 CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
974 if (cl_beams_polygons.integer)
978 // calculate pitch and yaw
979 VectorSubtract (b->end, b->start, dist);
981 if (dist[1] == 0 && dist[0] == 0)
991 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
995 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
996 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
1001 // add new entities for the lightning
1002 VectorCopy (b->start, org);
1003 d = VectorNormalizeLength(dist);
1006 ent = CL_NewTempEntity ();
1009 //VectorCopy (org, ent->render.origin);
1010 ent->render.model = b->model;
1011 ent->render.effects = EF_FULLBRIGHT;
1012 //ent->render.angles[0] = pitch;
1013 //ent->render.angles[1] = yaw;
1014 //ent->render.angles[2] = rand()%360;
1015 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1016 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1017 CL_BoundingBoxForEntity(&ent->render);
1018 VectorMA(org, 30, dist, org);
1024 cvar_t r_lightningbeam_thickness = {CVAR_SAVE, "r_lightningbeam_thickness", "4"};
1025 cvar_t r_lightningbeam_scroll = {CVAR_SAVE, "r_lightningbeam_scroll", "5"};
1026 cvar_t r_lightningbeam_repeatdistance = {CVAR_SAVE, "r_lightningbeam_repeatdistance", "1024"};
1027 cvar_t r_lightningbeam_color_red = {CVAR_SAVE, "r_lightningbeam_color_red", "1"};
1028 cvar_t r_lightningbeam_color_green = {CVAR_SAVE, "r_lightningbeam_color_green", "1"};
1029 cvar_t r_lightningbeam_color_blue = {CVAR_SAVE, "r_lightningbeam_color_blue", "1"};
1030 cvar_t r_lightningbeam_qmbtexture = {CVAR_SAVE, "r_lightningbeam_qmbtexture", "0"};
1032 rtexture_t *r_lightningbeamtexture;
1033 rtexture_t *r_lightningbeamqmbtexture;
1034 rtexturepool_t *r_lightningbeamtexturepool;
1036 int r_lightningbeamelements[18] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11};
1038 void r_lightningbeams_start(void)
1040 r_lightningbeamtexturepool = R_AllocTexturePool();
1041 r_lightningbeamtexture = NULL;
1042 r_lightningbeamqmbtexture = NULL;
1045 void r_lightningbeams_setupqmbtexture(void)
1047 r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
1048 if (r_lightningbeamqmbtexture == NULL)
1049 Cvar_SetValueQuick(&r_lightningbeam_qmbtexture, false);
1052 void r_lightningbeams_setuptexture(void)
1055 #define BEAMWIDTH 128
1056 #define BEAMHEIGHT 64
1057 #define PATHPOINTS 8
1058 int i, j, px, py, nearestpathindex, imagenumber;
1059 float particlex, particley, particlexv, particleyv, dx, dy, s, maxpathstrength;
1062 struct {float x, y, strength;} path[PATHPOINTS], temppath;
1064 image = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1065 pixels = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(qbyte[4]));
1067 for (imagenumber = 0, maxpathstrength = 0.0339476;maxpathstrength < 0.5;imagenumber++, maxpathstrength += 0.01)
1069 for (i = 0;i < PATHPOINTS;i++)
1071 path[i].x = lhrandom(0, 1);
1072 path[i].y = lhrandom(0.2, 0.8);
1073 path[i].strength = lhrandom(0, 1);
1075 for (i = 0;i < PATHPOINTS;i++)
1077 for (j = i + 1;j < PATHPOINTS;j++)
1079 if (path[j].x < path[i].x)
1087 particlex = path[0].x;
1088 particley = path[0].y;
1089 particlexv = lhrandom(0, 0.02);
1090 particlexv = lhrandom(-0.02, 0.02);
1091 memset(image, 0, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1092 for (i = 0;i < 65536;i++)
1094 for (nearestpathindex = 0;nearestpathindex < PATHPOINTS;nearestpathindex++)
1095 if (path[nearestpathindex].x > particlex)
1097 nearestpathindex %= PATHPOINTS;
1098 dx = path[nearestpathindex].x + lhrandom(-0.01, 0.01);dx = bound(0, dx, 1) - particlex;if (dx < 0) dx += 1;
1099 dy = path[nearestpathindex].y + lhrandom(-0.01, 0.01);dy = bound(0, dy, 1) - particley;
1100 s = path[nearestpathindex].strength / sqrt(dx*dx+dy*dy);
1101 particlexv = particlexv /* (1 - lhrandom(0.08, 0.12))*/ + dx * s;
1102 particleyv = particleyv /* (1 - lhrandom(0.08, 0.12))*/ + dy * s;
1103 particlex += particlexv * maxpathstrength;particlex -= (int) particlex;
1104 particley += particleyv * maxpathstrength;particley = bound(0, particley, 1);
1105 px = particlex * BEAMWIDTH;
1106 py = particley * BEAMHEIGHT;
1107 if (px >= 0 && py >= 0 && px < BEAMWIDTH && py < BEAMHEIGHT)
1108 image[py*BEAMWIDTH+px] += 16;
1111 for (py = 0;py < BEAMHEIGHT;py++)
1113 for (px = 0;px < BEAMWIDTH;px++)
1115 pixels[(py*BEAMWIDTH+px)*4+0] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1116 pixels[(py*BEAMWIDTH+px)*4+1] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1117 pixels[(py*BEAMWIDTH+px)*4+2] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1118 pixels[(py*BEAMWIDTH+px)*4+3] = 255;
1122 Image_WriteTGARGBA(va("lightningbeam%i.tga", imagenumber), BEAMWIDTH, BEAMHEIGHT, pixels);
1125 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, pixels, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1130 #define BEAMWIDTH 64
1131 #define BEAMHEIGHT 128
1132 float r, g, b, intensity, fx, width, center;
1134 qbyte *data, *noise1, *noise2;
1136 data = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * 4);
1137 noise1 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1138 noise2 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1139 fractalnoise(noise1, BEAMHEIGHT, BEAMHEIGHT / 8);
1140 fractalnoise(noise2, BEAMHEIGHT, BEAMHEIGHT / 16);
1142 for (y = 0;y < BEAMHEIGHT;y++)
1144 width = 0.15;//((noise1[y * BEAMHEIGHT] * (1.0f / 256.0f)) * 0.1f + 0.1f);
1145 center = (noise1[y * BEAMHEIGHT + (BEAMHEIGHT / 2)] / 256.0f) * (1.0f - width * 2.0f) + width;
1146 for (x = 0;x < BEAMWIDTH;x++, fx++)
1148 fx = (((float) x / BEAMWIDTH) - center) / width;
1149 intensity = 1.0f - sqrt(fx * fx);
1151 intensity = pow(intensity, 2) * ((noise2[y * BEAMHEIGHT + x] * (1.0f / 256.0f)) * 0.33f + 0.66f);
1152 intensity = bound(0, intensity, 1);
1153 r = intensity * 1.0f;
1154 g = intensity * 1.0f;
1155 b = intensity * 1.0f;
1156 data[(y * BEAMWIDTH + x) * 4 + 0] = (qbyte)(bound(0, r, 1) * 255.0f);
1157 data[(y * BEAMWIDTH + x) * 4 + 1] = (qbyte)(bound(0, g, 1) * 255.0f);
1158 data[(y * BEAMWIDTH + x) * 4 + 2] = (qbyte)(bound(0, b, 1) * 255.0f);
1159 data[(y * BEAMWIDTH + x) * 4 + 3] = (qbyte)255;
1163 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1170 void r_lightningbeams_shutdown(void)
1172 r_lightningbeamtexture = NULL;
1173 r_lightningbeamqmbtexture = NULL;
1174 R_FreeTexturePool(&r_lightningbeamtexturepool);
1177 void r_lightningbeams_newmap(void)
1181 void R_LightningBeams_Init(void)
1183 Cvar_RegisterVariable(&r_lightningbeam_thickness);
1184 Cvar_RegisterVariable(&r_lightningbeam_scroll);
1185 Cvar_RegisterVariable(&r_lightningbeam_repeatdistance);
1186 Cvar_RegisterVariable(&r_lightningbeam_color_red);
1187 Cvar_RegisterVariable(&r_lightningbeam_color_green);
1188 Cvar_RegisterVariable(&r_lightningbeam_color_blue);
1189 Cvar_RegisterVariable(&r_lightningbeam_qmbtexture);
1190 R_RegisterModule("R_LightningBeams", r_lightningbeams_start, r_lightningbeams_shutdown, r_lightningbeams_newmap);
1193 void R_CalcLightningBeamPolygonVertex3f(float *v, const float *start, const float *end, const float *offset)
1195 // near right corner
1196 VectorAdd (start, offset, (v + 0));
1198 VectorSubtract(start, offset, (v + 3));
1200 VectorSubtract(end , offset, (v + 6));
1202 VectorAdd (end , offset, (v + 9));
1205 void R_CalcLightningBeamPolygonTexCoord2f(float *tc, float t1, float t2)
1207 if (r_lightningbeam_qmbtexture.integer)
1209 // near right corner
1210 tc[0] = t1;tc[1] = 0;
1212 tc[2] = t1;tc[3] = 1;
1214 tc[4] = t2;tc[5] = 1;
1216 tc[6] = t2;tc[7] = 0;
1220 // near right corner
1221 tc[0] = 0;tc[1] = t1;
1223 tc[2] = 1;tc[3] = t1;
1225 tc[4] = 1;tc[5] = t2;
1227 tc[6] = 0;tc[7] = t2;
1231 void R_FogLightningBeam_Vertex3f_Color4f(const float *v, float *c, int numverts, float r, float g, float b, float a)
1236 for (i = 0;i < numverts;i++, v += 3, c += 4)
1238 VectorSubtract(v, r_origin, fogvec);
1239 ifog = 1 - exp(fogdensity/DotProduct(fogvec,fogvec));
1247 float beamrepeatscale;
1249 void R_DrawLightningBeamCallback(const void *calldata1, int calldata2)
1251 const beam_t *b = calldata1;
1253 vec3_t beamdir, right, up, offset;
1254 float length, t1, t2;
1256 R_Mesh_Matrix(&r_identitymatrix);
1258 // calculate beam direction (beamdir) vector and beam length
1259 // get difference vector
1260 VectorSubtract(b->end, b->start, beamdir);
1261 // find length of difference vector
1262 length = sqrt(DotProduct(beamdir, beamdir));
1263 // calculate scale to make beamdir a unit vector (normalized)
1265 // scale beamdir so it is now normalized
1266 VectorScale(beamdir, t1, beamdir);
1268 // calculate up vector such that it points toward viewer, and rotates around the beamdir
1269 // get direction from start of beam to viewer
1270 VectorSubtract(r_origin, b->start, up);
1271 // remove the portion of the vector that moves along the beam
1272 // (this leaves only a vector pointing directly away from the beam)
1273 t1 = -DotProduct(up, beamdir);
1274 VectorMA(up, t1, beamdir, up);
1275 // now we have a vector pointing away from the beam, now we need to normalize it
1276 VectorNormalizeFast(up);
1277 // generate right vector from forward and up, the result is already normalized
1278 // (CrossProduct returns a vector of multiplied length of the two inputs)
1279 CrossProduct(beamdir, up, right);
1281 // calculate T coordinate scrolling (start and end texcoord along the beam)
1282 t1 = cl.time * -r_lightningbeam_scroll.value;// + beamrepeatscale * DotProduct(b->start, beamdir);
1284 t2 = t1 + beamrepeatscale * length;
1286 // the beam is 3 polygons in this configuration:
1292 // they are showing different portions of the beam texture, creating an
1293 // illusion of a beam that appears to curl around in 3D space
1294 // (and realize that the whole polygon assembly orients itself to face
1297 memset(&m, 0, sizeof(m));
1298 if (r_lightningbeam_qmbtexture.integer)
1299 m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
1301 m.tex[0] = R_GetTexture(r_lightningbeamtexture);
1302 m.pointer_texcoord[0] = varray_texcoord2f[0];
1303 R_Mesh_State_Texture(&m);
1305 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1306 GL_DepthMask(false);
1308 if (r_lightningbeam_qmbtexture.integer && r_lightningbeamqmbtexture == NULL)
1309 r_lightningbeams_setupqmbtexture();
1310 if (!r_lightningbeam_qmbtexture.integer && r_lightningbeamtexture == NULL)
1311 r_lightningbeams_setuptexture();
1313 // polygon 1, verts 0-3
1314 VectorScale(right, r_lightningbeam_thickness.value, offset);
1315 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 0, b->start, b->end, offset);
1316 // polygon 2, verts 4-7
1317 VectorAdd(right, up, offset);
1318 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1319 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 12, b->start, b->end, offset);
1320 // polygon 3, verts 8-11
1321 VectorSubtract(right, up, offset);
1322 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1323 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 24, b->start, b->end, offset);
1324 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 0, t1, t2);
1325 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 8, t1 + 0.33, t2 + 0.33);
1326 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 16, t1 + 0.66, t2 + 0.66);
1327 GL_VertexPointer(varray_vertex3f);
1331 // per vertex colors if fog is used
1332 GL_ColorPointer(varray_color4f);
1333 R_FogLightningBeam_Vertex3f_Color4f(varray_vertex3f, varray_color4f, 12, r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
1337 // solid color if fog is not used
1338 GL_Color(r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
1341 // draw the 3 polygons as one batch of 6 triangles using the 12 vertices
1342 R_Mesh_Draw(12, 6, r_lightningbeamelements);
1345 void R_DrawLightningBeams (void)
1351 if (!cl_beams_polygons.integer)
1354 beamrepeatscale = 1.0f / r_lightningbeam_repeatdistance.value;
1355 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1357 if (b->model && b->endtime >= cl.time && b->lightning)
1359 VectorAdd(b->start, b->end, org);
1360 VectorScale(org, 0.5f, org);
1361 R_MeshQueue_AddTransparent(org, R_DrawLightningBeamCallback, b, 0);
1367 void CL_LerpPlayer(float frac)
1372 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
1374 for (i = 0;i < 3;i++)
1375 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1377 if (cls.demoplayback)
1379 // interpolate the angles
1380 for (i = 0;i < 3;i++)
1382 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1387 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1392 void CL_RelinkEntities (void)
1396 // fraction from previous network update to current
1397 frac = CL_LerpPoint();
1399 CL_ClearTempEntities();
1402 CL_RelinkStaticEntities();
1403 CL_RelinkNetworkEntities();
1407 CL_LerpPlayer(frac);
1417 Read all incoming data from the server
1420 int CL_ReadFromServer(void)
1422 CL_ReadDemoMessage();
1424 r_refdef.numentities = 0;
1425 cl_num_entities = 0;
1426 cl_num_brushmodel_entities = 0;
1428 if (cls.state == ca_connected && cls.signon == SIGNONS)
1430 CL_RelinkEntities();
1432 // run cgame code (which can add more entities)
1444 void CL_SendCmd(void)
1448 if (cls.signon == SIGNONS)
1450 // get basic movement from keyboard
1453 // OS independent code
1456 // allow mice or other external controllers to add to the move
1459 // OS independent code
1462 // send the unreliable message
1466 if (cls.demoplayback)
1468 SZ_Clear(&cls.message);
1472 // send the reliable message (forwarded commands) if there is one
1473 if (cls.message.cursize && NetConn_CanSendMessage(cls.netcon))
1475 if (developer.integer)
1477 Con_Printf("CL_SendCmd: sending reliable message:\n");
1478 SZ_HexDumpToConsole(&cls.message);
1480 if (NetConn_SendReliableMessage(cls.netcon, &cls.message) == -1)
1481 Host_Error("CL_WriteToServer: lost server connection");
1482 SZ_Clear(&cls.message);
1486 // LordHavoc: pausedemo command
1487 static void CL_PauseDemo_f (void)
1489 cls.demopaused = !cls.demopaused;
1491 Con_Printf("Demo paused\n");
1493 Con_Printf("Demo unpaused\n");
1497 ======================
1499 ======================
1501 static void CL_Fog_f (void)
1503 if (Cmd_Argc () == 1)
1505 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1508 fog_density = atof(Cmd_Argv(1));
1509 fog_red = atof(Cmd_Argv(2));
1510 fog_green = atof(Cmd_Argv(3));
1511 fog_blue = atof(Cmd_Argv(4));
1521 cl_entities_mempool = Mem_AllocPool("client entities");
1522 cl_refdef_mempool = Mem_AllocPool("refdef");
1524 memset(&r_refdef, 0, sizeof(r_refdef));
1525 // max entities sent to renderer per frame
1526 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1527 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1528 // 256k drawqueue buffer
1529 r_refdef.maxdrawqueuesize = 256 * 1024;
1530 r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1532 SZ_Alloc (&cls.message, 1024, "cls.message");
1538 // register our commands
1540 Cvar_RegisterVariable (&cl_upspeed);
1541 Cvar_RegisterVariable (&cl_forwardspeed);
1542 Cvar_RegisterVariable (&cl_backspeed);
1543 Cvar_RegisterVariable (&cl_sidespeed);
1544 Cvar_RegisterVariable (&cl_movespeedkey);
1545 Cvar_RegisterVariable (&cl_yawspeed);
1546 Cvar_RegisterVariable (&cl_pitchspeed);
1547 Cvar_RegisterVariable (&cl_anglespeedkey);
1548 Cvar_RegisterVariable (&cl_shownet);
1549 Cvar_RegisterVariable (&cl_nolerp);
1550 Cvar_RegisterVariable (&lookspring);
1551 Cvar_RegisterVariable (&lookstrafe);
1552 Cvar_RegisterVariable (&sensitivity);
1553 Cvar_RegisterVariable (&freelook);
1555 Cvar_RegisterVariable (&m_pitch);
1556 Cvar_RegisterVariable (&m_yaw);
1557 Cvar_RegisterVariable (&m_forward);
1558 Cvar_RegisterVariable (&m_side);
1560 Cvar_RegisterVariable (&cl_itembobspeed);
1561 Cvar_RegisterVariable (&cl_itembobheight);
1563 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1564 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1565 Cmd_AddCommand ("record", CL_Record_f);
1566 Cmd_AddCommand ("stop", CL_Stop_f);
1567 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1568 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1570 Cmd_AddCommand ("fog", CL_Fog_f);
1572 // LordHavoc: added pausedemo
1573 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1575 Cvar_RegisterVariable(&r_draweffects);
1576 Cvar_RegisterVariable(&cl_explosions);
1577 Cvar_RegisterVariable(&cl_stainmaps);
1578 Cvar_RegisterVariable(&cl_beams_polygons);
1579 Cvar_RegisterVariable(&cl_beams_relative);
1580 Cvar_RegisterVariable(&cl_beams_lightatend);
1581 Cvar_RegisterVariable(&cl_noplayershadow);
1583 R_LightningBeams_Init();
1586 CL_Particles_Init();