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));
455 cl.worldmodel->FindNonSolidLocation(cl.worldmodel, org, dl->origin, 6);
456 //VectorCopy(org, dl->origin);
459 dl->color[1] = green;
463 dl->die = cl.time + lifetime;
468 void CL_DecayLights (void)
474 time = cl.time - cl.oldtime;
477 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
481 if (dl->die < cl.time)
487 dl->radius -= time*dl->decay;
493 void CL_RelinkWorld (void)
495 entity_t *ent = &cl_entities[0];
496 if (cl_num_entities < 1)
498 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
499 Matrix4x4_CreateIdentity(&ent->render.matrix);
500 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
501 CL_BoundingBoxForEntity(&ent->render);
504 static void CL_RelinkStaticEntities(void)
507 for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
509 Mod_CheckLoaded(cl_static_entities[i].render.model);
510 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
519 extern qboolean Nehahrademcompatibility;
520 #define MAXVIEWMODELS 32
521 entity_t *viewmodels[MAXVIEWMODELS];
523 static void CL_RelinkNetworkEntities(void)
526 int i, effects, temp;
527 float d, bobjrotate, bobjoffset, lerp;
528 vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
532 bobjrotate = ANGLEMOD(100*cl.time);
533 if (cl_itembobheight.value)
534 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
538 // start on the entity after the world
539 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
541 // if the object isn't active in the current network frame, skip it
542 if (!cl_entities_active[i])
544 if (!ent->state_current.active)
546 cl_entities_active[i] = false;
550 VectorCopy(ent->persistent.trail_origin, oldorg);
552 if (!ent->state_previous.active)
554 // only one state available
555 VectorCopy (ent->persistent.neworigin, neworg);
556 VectorCopy (ent->persistent.newangles, ent->render.angles);
557 VectorCopy (neworg, oldorg);
561 // if the delta is large, assume a teleport and don't lerp
562 VectorSubtract(ent->persistent.neworigin, ent->persistent.oldorigin, delta);
563 if (ent->persistent.lerpdeltatime > 0)
565 lerp = (cl.time - ent->persistent.lerpstarttime) / ent->persistent.lerpdeltatime;
568 // interpolate the origin and angles
569 VectorMA(ent->persistent.oldorigin, lerp, delta, neworg);
570 VectorSubtract(ent->persistent.newangles, ent->persistent.oldangles, delta);
571 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
572 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
573 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
574 VectorMA(ent->persistent.oldangles, lerp, delta, ent->render.angles);
579 VectorCopy (ent->persistent.neworigin, neworg);
580 VectorCopy (ent->persistent.newangles, ent->render.angles);
586 VectorCopy (ent->persistent.neworigin, neworg);
587 VectorCopy (ent->persistent.newangles, ent->render.angles);
591 if (!ent->render.model || ent->render.model->type != mod_brush)
592 ent->render.angles[0] = -ent->render.angles[0];
594 VectorCopy (neworg, ent->persistent.trail_origin);
595 // persistent.modelindex will be updated by CL_LerpUpdate
596 if (ent->state_current.modelindex != ent->persistent.modelindex || !ent->state_previous.active)
597 VectorCopy(neworg, oldorg);
599 VectorCopy (neworg, ent->render.origin);
600 ent->render.flags = ent->state_current.flags;
601 if (i == cl.viewentity)
602 ent->render.flags |= RENDER_EXTERIORMODEL;
603 ent->render.effects = effects = ent->state_current.effects;
604 if (ent->state_current.flags & RENDER_COLORMAPPED)
605 ent->render.colormap = ent->state_current.colormap;
606 else if (cl.scores == NULL || !ent->state_current.colormap)
607 ent->render.colormap = -1; // no special coloring
609 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
610 ent->render.skinnum = ent->state_current.skin;
611 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
612 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
614 if (ent->render.model && ent->render.model->flags & EF_ROTATE)
616 ent->render.angles[1] = bobjrotate;
617 ent->render.origin[2] += bobjoffset;
620 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);
622 // update interpolation info
625 // handle effects now...
630 // LordHavoc: if the entity has no effects, don't check each
633 if (effects & EF_BRIGHTFIELD)
635 if (gamemode == GAME_NEXUIZ)
637 dlightcolor[0] += 100.0f;
638 dlightcolor[1] += 200.0f;
639 dlightcolor[2] += 400.0f;
640 // don't do trail if we have no previous location
641 if (ent->state_previous.active)
642 CL_RocketTrail (oldorg, neworg, 8, ent);
645 CL_EntityParticles (ent);
647 if (effects & EF_MUZZLEFLASH)
648 ent->persistent.muzzleflash = 100.0f;
649 if (effects & EF_DIMLIGHT)
651 dlightcolor[0] += 200.0f;
652 dlightcolor[1] += 200.0f;
653 dlightcolor[2] += 200.0f;
655 if (effects & EF_BRIGHTLIGHT)
657 dlightcolor[0] += 400.0f;
658 dlightcolor[1] += 400.0f;
659 dlightcolor[2] += 400.0f;
661 // LordHavoc: added EF_RED and EF_BLUE
662 if (effects & EF_RED) // red
664 dlightcolor[0] += 200.0f;
665 dlightcolor[1] += 20.0f;
666 dlightcolor[2] += 20.0f;
668 if (effects & EF_BLUE) // blue
670 dlightcolor[0] += 20.0f;
671 dlightcolor[1] += 20.0f;
672 dlightcolor[2] += 200.0f;
674 if (effects & EF_FLAME)
676 if (ent->render.model)
678 mins[0] = neworg[0] - 16.0f;
679 mins[1] = neworg[1] - 16.0f;
680 mins[2] = neworg[2] - 16.0f;
681 maxs[0] = neworg[0] + 16.0f;
682 maxs[1] = neworg[1] + 16.0f;
683 maxs[2] = neworg[2] + 16.0f;
684 // how many flames to make
685 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
686 CL_FlameCube(mins, maxs, temp);
688 d = lhrandom(200, 250);
689 dlightcolor[0] += d * 1.0f;
690 dlightcolor[1] += d * 0.7f;
691 dlightcolor[2] += d * 0.3f;
693 if (effects & EF_STARDUST)
695 if (ent->render.model)
697 mins[0] = neworg[0] - 16.0f;
698 mins[1] = neworg[1] - 16.0f;
699 mins[2] = neworg[2] - 16.0f;
700 maxs[0] = neworg[0] + 16.0f;
701 maxs[1] = neworg[1] + 16.0f;
702 maxs[2] = neworg[2] + 16.0f;
703 // how many particles to make
704 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
705 CL_Stardust(mins, maxs, temp);
708 dlightcolor[0] += d * 1.0f;
709 dlightcolor[1] += d * 0.7f;
710 dlightcolor[2] += d * 0.3f;
714 if (ent->persistent.muzzleflash > 0)
716 v2[0] = ent->render.matrix.m[0][0] * 18 + neworg[0];
717 v2[1] = ent->render.matrix.m[0][1] * 18 + neworg[1];
718 v2[2] = ent->render.matrix.m[0][2] * 18 + neworg[2] + 16;
719 CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
721 CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
722 ent->persistent.muzzleflash -= cl.frametime * 1000;
725 // LordHavoc: if the model has no flags, don't check each
726 if (ent->render.model && ent->render.model->flags)
728 // note: EF_ROTATE handled above, above matrix calculation
729 // only do trails if present in the previous frame as well
730 if (ent->state_previous.active)
732 if (ent->render.model->flags & EF_GIB)
733 CL_RocketTrail (oldorg, neworg, 2, ent);
734 else if (ent->render.model->flags & EF_ZOMGIB)
735 CL_RocketTrail (oldorg, neworg, 4, ent);
736 else if (ent->render.model->flags & EF_TRACER)
738 CL_RocketTrail (oldorg, neworg, 3, ent);
739 dlightcolor[0] += 0x10;
740 dlightcolor[1] += 0x40;
741 dlightcolor[2] += 0x10;
743 else if (ent->render.model->flags & EF_TRACER2)
745 CL_RocketTrail (oldorg, neworg, 5, ent);
746 dlightcolor[0] += 0x50;
747 dlightcolor[1] += 0x30;
748 dlightcolor[2] += 0x10;
750 else if (ent->render.model->flags & EF_ROCKET)
752 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
753 dlightcolor[0] += 200.0f;
754 dlightcolor[1] += 160.0f;
755 dlightcolor[2] += 80.0f;
757 else if (ent->render.model->flags & EF_GRENADE)
759 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility (cigar smoke)
760 CL_RocketTrail (oldorg, neworg, 7, ent);
762 CL_RocketTrail (oldorg, neworg, 1, ent);
764 else if (ent->render.model->flags & EF_TRACER3)
766 CL_RocketTrail (oldorg, neworg, 6, ent);
767 dlightcolor[0] += 0x50;
768 dlightcolor[1] += 0x20;
769 dlightcolor[2] += 0x40;
773 // LordHavoc: customizable glow
774 if (ent->state_current.glowsize)
776 // * 4 for the expansion from 0-255 to 0-1023 range,
777 // / 255 to scale down byte colors
778 VectorMA(dlightcolor, ent->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[ent->state_current.glowcolor], dlightcolor);
780 // LordHavoc: customizable trail
781 if (ent->render.flags & RENDER_GLOWTRAIL)
782 CL_RocketTrail2 (oldorg, neworg, ent->state_current.glowcolor, ent);
784 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
786 VectorCopy(neworg, v);
787 // hack to make glowing player light shine on their gun
788 if (i == cl.viewentity/* && !chase_active.integer*/)
790 CL_AllocDlight (&ent->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
793 if (chase_active.integer && (ent->render.flags & RENDER_VIEWMODEL))
796 // don't show entities with no modelindex (note: this still shows
797 // entities which have a modelindex that resolved to a NULL model)
798 if (!ent->state_current.modelindex)
800 if (effects & EF_NODRAW)
803 // store a list of view-relative entities for later adjustment in view code
804 if (ent->render.flags & RENDER_VIEWMODEL)
806 if (numviewmodels < MAXVIEWMODELS)
807 viewmodels[numviewmodels++] = ent;
811 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
813 CL_BoundingBoxForEntity(&ent->render);
814 if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
815 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
817 // note: the cl.viewentity and intermission check is to hide player
818 // shadow during intermission and during the Nehahra movie and
819 // Nehahra cinematics
820 if (!(ent->state_current.effects & EF_NOSHADOW)
821 && !(ent->state_current.effects & EF_ADDITIVE)
822 && (ent->state_current.alpha == 255)
823 && !(ent->render.flags & RENDER_VIEWMODEL)
824 && (i != cl.viewentity || (!cl.intermission && !Nehahrademcompatibility && !cl_noplayershadow.integer)))
825 ent->render.flags |= RENDER_SHADOW;
827 if (r_refdef.numentities < r_refdef.maxentities)
828 r_refdef.entities[r_refdef.numentities++] = &ent->render;
830 if (cl_num_entities < i + 1)
831 cl_num_entities = i + 1;
835 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
839 if (!modelindex) // sanity check
841 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
846 VectorCopy(org, e->origin);
847 e->modelindex = modelindex;
848 e->starttime = cl.time;
849 e->startframe = startframe;
850 e->endframe = startframe + framecount;
851 e->framerate = framerate;
854 e->frame1time = cl.time;
855 e->frame2time = cl.time;
860 static void CL_RelinkEffects(void)
867 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
871 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
873 if (intframe < 0 || intframe >= e->endframe)
876 memset(e, 0, sizeof(*e));
880 if (intframe != e->frame)
883 e->frame1time = e->frame2time;
884 e->frame2time = cl.time;
887 // if we're drawing effects, get a new temp entity
888 // (NewTempEntity adds it to the render entities list for us)
889 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
891 // interpolation stuff
892 ent->render.frame1 = intframe;
893 ent->render.frame2 = intframe + 1;
894 if (ent->render.frame2 >= e->endframe)
895 ent->render.frame2 = -1; // disappear
896 ent->render.framelerp = frame - intframe;
897 ent->render.frame1time = e->frame1time;
898 ent->render.frame2time = e->frame2time;
901 //VectorCopy(e->origin, ent->render.origin);
902 ent->render.model = cl.model_precache[e->modelindex];
903 ent->render.frame = ent->render.frame2;
904 ent->render.colormap = -1; // no special coloring
905 //ent->render.scale = 1;
906 ent->render.alpha = 1;
908 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
909 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
910 CL_BoundingBoxForEntity(&ent->render);
916 void CL_RelinkBeams (void)
926 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
928 if (!b->model || b->endtime < cl.time)
931 // if coming from the player, update the start position
932 //if (b->entity == cl.viewentity)
933 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
934 if (cl_beams_relative.integer && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
936 entity_state_t *p = &cl_entities[b->entity].state_previous;
937 //entity_state_t *c = &cl_entities[b->entity].state_current;
938 entity_render_t *r = &cl_entities[b->entity].render;
939 matrix4x4_t matrix, imatrix;
940 if (b->relativestartvalid == 2)
942 // not really valid yet, we need to get the orientation now
943 // (ParseBeam flagged this because it is received before
944 // entities are received, by now they have been received)
945 // note: because players create lightning in their think
946 // function (which occurs before movement), they actually
947 // have some lag in it's location, so compare to the
948 // previous player state, not the latest
949 if (b->entity == cl.viewentity)
950 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
952 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
953 Matrix4x4_Invert_Simple(&imatrix, &matrix);
954 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
955 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
956 b->relativestartvalid = 1;
960 if (b->entity == cl.viewentity)
961 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
963 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
964 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
965 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
971 if (cl_beams_lightatend.integer)
972 CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
973 if (cl_beams_polygons.integer)
977 // calculate pitch and yaw
978 VectorSubtract (b->end, b->start, dist);
980 if (dist[1] == 0 && dist[0] == 0)
990 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
994 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
995 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
1000 // add new entities for the lightning
1001 VectorCopy (b->start, org);
1002 d = VectorNormalizeLength(dist);
1005 ent = CL_NewTempEntity ();
1008 //VectorCopy (org, ent->render.origin);
1009 ent->render.model = b->model;
1010 ent->render.effects = EF_FULLBRIGHT;
1011 //ent->render.angles[0] = pitch;
1012 //ent->render.angles[1] = yaw;
1013 //ent->render.angles[2] = rand()%360;
1014 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1015 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1016 CL_BoundingBoxForEntity(&ent->render);
1017 VectorMA(org, 30, dist, org);
1023 cvar_t r_lightningbeam_thickness = {CVAR_SAVE, "r_lightningbeam_thickness", "4"};
1024 cvar_t r_lightningbeam_scroll = {CVAR_SAVE, "r_lightningbeam_scroll", "5"};
1025 cvar_t r_lightningbeam_repeatdistance = {CVAR_SAVE, "r_lightningbeam_repeatdistance", "1024"};
1026 cvar_t r_lightningbeam_color_red = {CVAR_SAVE, "r_lightningbeam_color_red", "1"};
1027 cvar_t r_lightningbeam_color_green = {CVAR_SAVE, "r_lightningbeam_color_green", "1"};
1028 cvar_t r_lightningbeam_color_blue = {CVAR_SAVE, "r_lightningbeam_color_blue", "1"};
1029 cvar_t r_lightningbeam_qmbtexture = {CVAR_SAVE, "r_lightningbeam_qmbtexture", "0"};
1031 rtexture_t *r_lightningbeamtexture;
1032 rtexture_t *r_lightningbeamqmbtexture;
1033 rtexturepool_t *r_lightningbeamtexturepool;
1035 int r_lightningbeamelements[18] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11};
1037 void r_lightningbeams_start(void)
1039 r_lightningbeamtexturepool = R_AllocTexturePool();
1040 r_lightningbeamtexture = NULL;
1041 r_lightningbeamqmbtexture = NULL;
1044 void r_lightningbeams_setupqmbtexture(void)
1046 r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
1047 if (r_lightningbeamqmbtexture == NULL)
1048 Cvar_SetValueQuick(&r_lightningbeam_qmbtexture, false);
1051 void r_lightningbeams_setuptexture(void)
1054 #define BEAMWIDTH 128
1055 #define BEAMHEIGHT 64
1056 #define PATHPOINTS 8
1057 int i, j, px, py, nearestpathindex, imagenumber;
1058 float particlex, particley, particlexv, particleyv, dx, dy, s, maxpathstrength;
1061 struct {float x, y, strength;} path[PATHPOINTS], temppath;
1063 image = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1064 pixels = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(qbyte[4]));
1066 for (imagenumber = 0, maxpathstrength = 0.0339476;maxpathstrength < 0.5;imagenumber++, maxpathstrength += 0.01)
1068 for (i = 0;i < PATHPOINTS;i++)
1070 path[i].x = lhrandom(0, 1);
1071 path[i].y = lhrandom(0.2, 0.8);
1072 path[i].strength = lhrandom(0, 1);
1074 for (i = 0;i < PATHPOINTS;i++)
1076 for (j = i + 1;j < PATHPOINTS;j++)
1078 if (path[j].x < path[i].x)
1086 particlex = path[0].x;
1087 particley = path[0].y;
1088 particlexv = lhrandom(0, 0.02);
1089 particlexv = lhrandom(-0.02, 0.02);
1090 memset(image, 0, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1091 for (i = 0;i < 65536;i++)
1093 for (nearestpathindex = 0;nearestpathindex < PATHPOINTS;nearestpathindex++)
1094 if (path[nearestpathindex].x > particlex)
1096 nearestpathindex %= PATHPOINTS;
1097 dx = path[nearestpathindex].x + lhrandom(-0.01, 0.01);dx = bound(0, dx, 1) - particlex;if (dx < 0) dx += 1;
1098 dy = path[nearestpathindex].y + lhrandom(-0.01, 0.01);dy = bound(0, dy, 1) - particley;
1099 s = path[nearestpathindex].strength / sqrt(dx*dx+dy*dy);
1100 particlexv = particlexv /* (1 - lhrandom(0.08, 0.12))*/ + dx * s;
1101 particleyv = particleyv /* (1 - lhrandom(0.08, 0.12))*/ + dy * s;
1102 particlex += particlexv * maxpathstrength;particlex -= (int) particlex;
1103 particley += particleyv * maxpathstrength;particley = bound(0, particley, 1);
1104 px = particlex * BEAMWIDTH;
1105 py = particley * BEAMHEIGHT;
1106 if (px >= 0 && py >= 0 && px < BEAMWIDTH && py < BEAMHEIGHT)
1107 image[py*BEAMWIDTH+px] += 16;
1110 for (py = 0;py < BEAMHEIGHT;py++)
1112 for (px = 0;px < BEAMWIDTH;px++)
1114 pixels[(py*BEAMWIDTH+px)*4+0] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1115 pixels[(py*BEAMWIDTH+px)*4+1] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1116 pixels[(py*BEAMWIDTH+px)*4+2] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1117 pixels[(py*BEAMWIDTH+px)*4+3] = 255;
1121 Image_WriteTGARGBA(va("lightningbeam%i.tga", imagenumber), BEAMWIDTH, BEAMHEIGHT, pixels);
1124 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, pixels, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1129 #define BEAMWIDTH 64
1130 #define BEAMHEIGHT 128
1131 float r, g, b, intensity, fx, width, center;
1133 qbyte *data, *noise1, *noise2;
1135 data = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * 4);
1136 noise1 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1137 noise2 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1138 fractalnoise(noise1, BEAMHEIGHT, BEAMHEIGHT / 8);
1139 fractalnoise(noise2, BEAMHEIGHT, BEAMHEIGHT / 16);
1141 for (y = 0;y < BEAMHEIGHT;y++)
1143 width = 0.15;//((noise1[y * BEAMHEIGHT] * (1.0f / 256.0f)) * 0.1f + 0.1f);
1144 center = (noise1[y * BEAMHEIGHT + (BEAMHEIGHT / 2)] / 256.0f) * (1.0f - width * 2.0f) + width;
1145 for (x = 0;x < BEAMWIDTH;x++, fx++)
1147 fx = (((float) x / BEAMWIDTH) - center) / width;
1148 intensity = 1.0f - sqrt(fx * fx);
1150 intensity = pow(intensity, 2) * ((noise2[y * BEAMHEIGHT + x] * (1.0f / 256.0f)) * 0.33f + 0.66f);
1151 intensity = bound(0, intensity, 1);
1152 r = intensity * 1.0f;
1153 g = intensity * 1.0f;
1154 b = intensity * 1.0f;
1155 data[(y * BEAMWIDTH + x) * 4 + 0] = (qbyte)(bound(0, r, 1) * 255.0f);
1156 data[(y * BEAMWIDTH + x) * 4 + 1] = (qbyte)(bound(0, g, 1) * 255.0f);
1157 data[(y * BEAMWIDTH + x) * 4 + 2] = (qbyte)(bound(0, b, 1) * 255.0f);
1158 data[(y * BEAMWIDTH + x) * 4 + 3] = (qbyte)255;
1162 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1169 void r_lightningbeams_shutdown(void)
1171 r_lightningbeamtexture = NULL;
1172 r_lightningbeamqmbtexture = NULL;
1173 R_FreeTexturePool(&r_lightningbeamtexturepool);
1176 void r_lightningbeams_newmap(void)
1180 void R_LightningBeams_Init(void)
1182 Cvar_RegisterVariable(&r_lightningbeam_thickness);
1183 Cvar_RegisterVariable(&r_lightningbeam_scroll);
1184 Cvar_RegisterVariable(&r_lightningbeam_repeatdistance);
1185 Cvar_RegisterVariable(&r_lightningbeam_color_red);
1186 Cvar_RegisterVariable(&r_lightningbeam_color_green);
1187 Cvar_RegisterVariable(&r_lightningbeam_color_blue);
1188 Cvar_RegisterVariable(&r_lightningbeam_qmbtexture);
1189 R_RegisterModule("R_LightningBeams", r_lightningbeams_start, r_lightningbeams_shutdown, r_lightningbeams_newmap);
1192 void R_CalcLightningBeamPolygonVertex3f(float *v, const float *start, const float *end, const float *offset)
1194 // near right corner
1195 VectorAdd (start, offset, (v + 0));
1197 VectorSubtract(start, offset, (v + 3));
1199 VectorSubtract(end , offset, (v + 6));
1201 VectorAdd (end , offset, (v + 9));
1204 void R_CalcLightningBeamPolygonTexCoord2f(float *tc, float t1, float t2)
1206 if (r_lightningbeam_qmbtexture.integer)
1208 // near right corner
1209 tc[0] = t1;tc[1] = 0;
1211 tc[2] = t1;tc[3] = 1;
1213 tc[4] = t2;tc[5] = 1;
1215 tc[6] = t2;tc[7] = 0;
1219 // near right corner
1220 tc[0] = 0;tc[1] = t1;
1222 tc[2] = 1;tc[3] = t1;
1224 tc[4] = 1;tc[5] = t2;
1226 tc[6] = 0;tc[7] = t2;
1230 void R_FogLightningBeam_Vertex3f_Color4f(const float *v, float *c, int numverts, float r, float g, float b, float a)
1235 for (i = 0;i < numverts;i++, v += 3, c += 4)
1237 VectorSubtract(v, r_origin, fogvec);
1238 ifog = 1 - exp(fogdensity/DotProduct(fogvec,fogvec));
1246 float beamrepeatscale;
1248 void R_DrawLightningBeamCallback(const void *calldata1, int calldata2)
1250 const beam_t *b = calldata1;
1252 vec3_t beamdir, right, up, offset;
1253 float length, t1, t2;
1255 R_Mesh_Matrix(&r_identitymatrix);
1257 // calculate beam direction (beamdir) vector and beam length
1258 // get difference vector
1259 VectorSubtract(b->end, b->start, beamdir);
1260 // find length of difference vector
1261 length = sqrt(DotProduct(beamdir, beamdir));
1262 // calculate scale to make beamdir a unit vector (normalized)
1264 // scale beamdir so it is now normalized
1265 VectorScale(beamdir, t1, beamdir);
1267 // calculate up vector such that it points toward viewer, and rotates around the beamdir
1268 // get direction from start of beam to viewer
1269 VectorSubtract(r_origin, b->start, up);
1270 // remove the portion of the vector that moves along the beam
1271 // (this leaves only a vector pointing directly away from the beam)
1272 t1 = -DotProduct(up, beamdir);
1273 VectorMA(up, t1, beamdir, up);
1274 // now we have a vector pointing away from the beam, now we need to normalize it
1275 VectorNormalizeFast(up);
1276 // generate right vector from forward and up, the result is already normalized
1277 // (CrossProduct returns a vector of multiplied length of the two inputs)
1278 CrossProduct(beamdir, up, right);
1280 // calculate T coordinate scrolling (start and end texcoord along the beam)
1281 t1 = cl.time * -r_lightningbeam_scroll.value;// + beamrepeatscale * DotProduct(b->start, beamdir);
1283 t2 = t1 + beamrepeatscale * length;
1285 // the beam is 3 polygons in this configuration:
1291 // they are showing different portions of the beam texture, creating an
1292 // illusion of a beam that appears to curl around in 3D space
1293 // (and realize that the whole polygon assembly orients itself to face
1296 memset(&m, 0, sizeof(m));
1297 if (r_lightningbeam_qmbtexture.integer)
1298 m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
1300 m.tex[0] = R_GetTexture(r_lightningbeamtexture);
1301 m.pointer_texcoord[0] = varray_texcoord2f[0];
1302 R_Mesh_State_Texture(&m);
1304 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1305 GL_DepthMask(false);
1307 if (r_lightningbeam_qmbtexture.integer && r_lightningbeamqmbtexture == NULL)
1308 r_lightningbeams_setupqmbtexture();
1309 if (!r_lightningbeam_qmbtexture.integer && r_lightningbeamtexture == NULL)
1310 r_lightningbeams_setuptexture();
1312 // polygon 1, verts 0-3
1313 VectorScale(right, r_lightningbeam_thickness.value, offset);
1314 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 0, b->start, b->end, offset);
1315 // polygon 2, verts 4-7
1316 VectorAdd(right, up, offset);
1317 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1318 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 12, b->start, b->end, offset);
1319 // polygon 3, verts 8-11
1320 VectorSubtract(right, up, offset);
1321 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1322 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 24, b->start, b->end, offset);
1323 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 0, t1, t2);
1324 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 8, t1 + 0.33, t2 + 0.33);
1325 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 16, t1 + 0.66, t2 + 0.66);
1326 GL_VertexPointer(varray_vertex3f);
1330 // per vertex colors if fog is used
1331 GL_ColorPointer(varray_color4f);
1332 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);
1336 // solid color if fog is not used
1337 GL_Color(r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
1340 // draw the 3 polygons as one batch of 6 triangles using the 12 vertices
1341 R_Mesh_Draw(12, 6, r_lightningbeamelements);
1344 void R_DrawLightningBeams (void)
1350 if (!cl_beams_polygons.integer)
1353 beamrepeatscale = 1.0f / r_lightningbeam_repeatdistance.value;
1354 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1356 if (b->model && b->endtime >= cl.time && b->lightning)
1358 VectorAdd(b->start, b->end, org);
1359 VectorScale(org, 0.5f, org);
1360 R_MeshQueue_AddTransparent(org, R_DrawLightningBeamCallback, b, 0);
1366 void CL_LerpPlayer(float frac)
1371 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
1373 for (i = 0;i < 3;i++)
1374 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1376 if (cls.demoplayback)
1378 // interpolate the angles
1379 for (i = 0;i < 3;i++)
1381 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1386 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1391 void CL_RelinkEntities (void)
1395 // fraction from previous network update to current
1396 frac = CL_LerpPoint();
1398 CL_ClearTempEntities();
1401 CL_RelinkStaticEntities();
1402 CL_RelinkNetworkEntities();
1406 CL_LerpPlayer(frac);
1416 Read all incoming data from the server
1419 int CL_ReadFromServer(void)
1421 CL_ReadDemoMessage();
1423 r_refdef.numentities = 0;
1424 cl_num_entities = 0;
1425 cl_num_brushmodel_entities = 0;
1427 if (cls.state == ca_connected && cls.signon == SIGNONS)
1429 CL_RelinkEntities();
1431 // run cgame code (which can add more entities)
1443 void CL_SendCmd(void)
1447 if (cls.signon == SIGNONS)
1449 // get basic movement from keyboard
1452 // OS independent code
1455 // allow mice or other external controllers to add to the move
1458 // OS independent code
1461 // send the unreliable message
1465 if (cls.demoplayback)
1467 SZ_Clear(&cls.message);
1471 // send the reliable message (forwarded commands) if there is one
1472 if (cls.message.cursize && NetConn_CanSendMessage(cls.netcon))
1474 if (developer.integer)
1476 Con_Printf("CL_SendCmd: sending reliable message:\n");
1477 SZ_HexDumpToConsole(&cls.message);
1479 if (NetConn_SendReliableMessage(cls.netcon, &cls.message) == -1)
1480 Host_Error("CL_WriteToServer: lost server connection");
1481 SZ_Clear(&cls.message);
1485 // LordHavoc: pausedemo command
1486 static void CL_PauseDemo_f (void)
1488 cls.demopaused = !cls.demopaused;
1490 Con_Printf("Demo paused\n");
1492 Con_Printf("Demo unpaused\n");
1496 ======================
1498 ======================
1500 static void CL_Fog_f (void)
1502 if (Cmd_Argc () == 1)
1504 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1507 fog_density = atof(Cmd_Argv(1));
1508 fog_red = atof(Cmd_Argv(2));
1509 fog_green = atof(Cmd_Argv(3));
1510 fog_blue = atof(Cmd_Argv(4));
1520 cl_entities_mempool = Mem_AllocPool("client entities");
1521 cl_refdef_mempool = Mem_AllocPool("refdef");
1523 memset(&r_refdef, 0, sizeof(r_refdef));
1524 // max entities sent to renderer per frame
1525 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1526 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1527 // 256k drawqueue buffer
1528 r_refdef.maxdrawqueuesize = 256 * 1024;
1529 r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1531 SZ_Alloc (&cls.message, 1024, "cls.message");
1537 // register our commands
1539 Cvar_RegisterVariable (&cl_upspeed);
1540 Cvar_RegisterVariable (&cl_forwardspeed);
1541 Cvar_RegisterVariable (&cl_backspeed);
1542 Cvar_RegisterVariable (&cl_sidespeed);
1543 Cvar_RegisterVariable (&cl_movespeedkey);
1544 Cvar_RegisterVariable (&cl_yawspeed);
1545 Cvar_RegisterVariable (&cl_pitchspeed);
1546 Cvar_RegisterVariable (&cl_anglespeedkey);
1547 Cvar_RegisterVariable (&cl_shownet);
1548 Cvar_RegisterVariable (&cl_nolerp);
1549 Cvar_RegisterVariable (&lookspring);
1550 Cvar_RegisterVariable (&lookstrafe);
1551 Cvar_RegisterVariable (&sensitivity);
1552 Cvar_RegisterVariable (&freelook);
1554 Cvar_RegisterVariable (&m_pitch);
1555 Cvar_RegisterVariable (&m_yaw);
1556 Cvar_RegisterVariable (&m_forward);
1557 Cvar_RegisterVariable (&m_side);
1559 Cvar_RegisterVariable (&cl_itembobspeed);
1560 Cvar_RegisterVariable (&cl_itembobheight);
1562 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1563 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1564 Cmd_AddCommand ("record", CL_Record_f);
1565 Cmd_AddCommand ("stop", CL_Stop_f);
1566 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1567 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1569 Cmd_AddCommand ("fog", CL_Fog_f);
1571 // LordHavoc: added pausedemo
1572 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1574 Cvar_RegisterVariable(&r_draweffects);
1575 Cvar_RegisterVariable(&cl_explosions);
1576 Cvar_RegisterVariable(&cl_stainmaps);
1577 Cvar_RegisterVariable(&cl_beams_polygons);
1578 Cvar_RegisterVariable(&cl_beams_relative);
1579 Cvar_RegisterVariable(&cl_beams_lightatend);
1580 Cvar_RegisterVariable(&cl_noplayershadow);
1582 R_LightningBeams_Init();
1585 CL_Particles_Init();