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 // these two are not intended to be set directly
31 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
32 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
33 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
35 cvar_t cl_shownet = {0, "cl_shownet","0"};
36 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
38 cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
39 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
41 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
42 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
43 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
45 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
46 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
47 cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
48 cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
50 cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
52 cvar_t r_draweffects = {0, "r_draweffects", "1"};
54 cvar_t cl_explosions = {CVAR_SAVE, "cl_explosions", "1"};
55 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
57 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1"};
58 cvar_t cl_beams_relative = {CVAR_SAVE, "cl_beams_relative", "1"};
59 cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0"};
61 cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0"};
63 mempool_t *cl_scores_mempool;
64 mempool_t *cl_refdef_mempool;
65 mempool_t *cl_entities_mempool;
71 int cl_max_static_entities;
72 int cl_max_temp_entities;
76 int cl_max_lightstyle;
77 int cl_max_brushmodel_entities;
79 entity_t *cl_entities;
80 qbyte *cl_entities_active;
81 entity_t *cl_static_entities;
82 entity_t *cl_temp_entities;
83 cl_effect_t *cl_effects;
86 lightstyle_t *cl_lightstyle;
87 entity_render_t **cl_brushmodel_entities;
90 int cl_num_static_entities;
91 int cl_num_temp_entities;
92 int cl_num_brushmodel_entities;
100 void CL_ClearState (void)
107 Mem_EmptyPool(cl_scores_mempool);
108 Mem_EmptyPool(cl_entities_mempool);
110 // wipe the entire cl structure
111 memset (&cl, 0, sizeof(cl));
113 SZ_Clear (&cls.message);
116 cl_num_static_entities = 0;
117 cl_num_temp_entities = 0;
118 cl_num_brushmodel_entities = 0;
120 // tweak these if the game runs out
121 cl_max_entities = MAX_EDICTS;
122 cl_max_static_entities = 256;
123 cl_max_temp_entities = 512;
124 cl_max_effects = 256;
126 cl_max_dlights = MAX_DLIGHTS;
127 cl_max_lightstyle = MAX_LIGHTSTYLES;
128 cl_max_brushmodel_entities = MAX_EDICTS;
130 cl_entities = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(entity_t));
131 cl_entities_active = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(qbyte));
132 cl_static_entities = Mem_Alloc(cl_entities_mempool, cl_max_static_entities * sizeof(entity_t));
133 cl_temp_entities = Mem_Alloc(cl_entities_mempool, cl_max_temp_entities * sizeof(entity_t));
134 cl_effects = Mem_Alloc(cl_entities_mempool, cl_max_effects * sizeof(cl_effect_t));
135 cl_beams = Mem_Alloc(cl_entities_mempool, cl_max_beams * sizeof(beam_t));
136 cl_dlights = Mem_Alloc(cl_entities_mempool, cl_max_dlights * sizeof(dlight_t));
137 cl_lightstyle = Mem_Alloc(cl_entities_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
138 cl_brushmodel_entities = Mem_Alloc(cl_entities_mempool, cl_max_brushmodel_entities * sizeof(entity_render_t *));
142 CL_Particles_Clear();
144 // LordHavoc: have to set up the baseline info for alpha and other stuff
145 for (i = 0;i < cl_max_entities;i++)
147 ClearStateToDefault(&cl_entities[i].state_baseline);
148 ClearStateToDefault(&cl_entities[i].state_previous);
149 ClearStateToDefault(&cl_entities[i].state_current);
156 =====================
159 Sends a disconnect message to the server
160 This is also called on Host_Error, so it shouldn't cause any errors
161 =====================
163 void CL_Disconnect (void)
165 if (cls.state == ca_dedicated)
168 // stop sounds (especially looping!)
169 S_StopAllSounds (true);
171 // clear contents blends
172 cl.cshifts[0].percent = 0;
173 cl.cshifts[1].percent = 0;
174 cl.cshifts[2].percent = 0;
175 cl.cshifts[3].percent = 0;
177 cl.worldmodel = NULL;
179 if (cls.demoplayback)
181 else if (cls.state == ca_connected)
183 if (cls.demorecording)
186 Con_DPrintf ("Sending clc_disconnect\n");
187 SZ_Clear (&cls.message);
188 MSG_WriteByte (&cls.message, clc_disconnect);
189 NET_SendUnreliableMessage (cls.netcon, &cls.message);
190 SZ_Clear (&cls.message);
191 NET_Close (cls.netcon);
192 cls.state = ca_disconnected; // prevent this code from executing again during Host_ShutdownServer
193 // if running a local server, shut it down
195 Host_ShutdownServer(false);
197 cls.state = ca_disconnected;
199 cls.demoplayback = cls.timedemo = false;
203 void CL_Disconnect_f (void)
207 Host_ShutdownServer (false);
214 =====================
215 CL_EstablishConnection
217 Host should be either "local" or a net address to be passed on
218 =====================
220 void CL_EstablishConnection (char *host)
222 if (cls.state == ca_dedicated)
225 if (cls.demoplayback)
230 cls.netcon = NET_Connect (host);
232 Host_Error ("CL_Connect: connect failed\n");
233 Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
235 cls.demonum = -1; // not in the demo loop now
236 cls.state = ca_connected;
237 cls.signon = 0; // need all the signon messages before playing
247 static void CL_PrintEntities_f (void)
253 for (i = 0, ent = cl_entities;i < cl_num_entities;i++, ent++)
255 if (!ent->state_current.active)
258 if (ent->render.model)
259 strncpy(name, ent->render.model->name, 25);
261 strcpy(name, "--no model--");
263 for (j = strlen(name);j < 25;j++)
265 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);
269 //static const vec3_t nomodelmins = {-16, -16, -16};
270 //static const vec3_t nomodelmaxs = {16, 16, 16};
271 void CL_BoundingBoxForEntity(entity_render_t *ent)
275 //if (ent->angles[0] || ent->angles[2])
276 if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
279 ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
280 ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
281 ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
282 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
283 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
284 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
285 //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
286 //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
288 //else if (ent->angles[1])
289 else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
292 ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
293 ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
294 ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
295 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
296 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
297 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
298 //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
299 //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
303 ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
304 ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
305 ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
306 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
307 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
308 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
309 //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
310 //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
315 ent->mins[0] = ent->matrix.m[0][3] - 16;
316 ent->mins[1] = ent->matrix.m[1][3] - 16;
317 ent->mins[2] = ent->matrix.m[2][3] - 16;
318 ent->maxs[0] = ent->matrix.m[0][3] + 16;
319 ent->maxs[1] = ent->matrix.m[1][3] + 16;
320 ent->maxs[2] = ent->matrix.m[2][3] + 16;
321 //VectorAdd(ent->origin, nomodelmins, ent->mins);
322 //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
326 void CL_LerpUpdate(entity_t *e)
328 entity_persistent_t *p;
333 if (p->modelindex != e->state_current.modelindex)
335 // reset all interpolation information
336 p->modelindex = e->state_current.modelindex;
337 p->frame1 = p->frame2 = e->state_current.frame;
338 p->frame1time = p->frame2time = cl.time;
341 else if (p->frame2 != e->state_current.frame)
343 // transition to new frame
344 p->frame1 = p->frame2;
345 p->frame1time = p->frame2time;
346 p->frame2 = e->state_current.frame;
347 p->frame2time = cl.time;
353 p->framelerp = (cl.time - p->frame2time) * 10;
354 p->framelerp = bound(0, p->framelerp, 1);
357 r->model = cl.model_precache[e->state_current.modelindex];
358 Mod_CheckLoaded(r->model);
359 r->frame = e->state_current.frame;
360 r->frame1 = p->frame1;
361 r->frame2 = p->frame2;
362 r->framelerp = p->framelerp;
363 r->frame1time = p->frame1time;
364 r->frame2time = p->frame2time;
371 Determines the fraction between the last two messages that the objects
375 static float CL_LerpPoint (void)
379 // dropped packet, or start of demo
380 if (cl.mtime[1] < cl.mtime[0] - 0.1)
381 cl.mtime[1] = cl.mtime[0] - 0.1;
383 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
385 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
386 f = cl.mtime[0] - cl.mtime[1];
387 if (!f || cl_nolerp.integer || cls.timedemo || (sv.active && svs.maxclients == 1))
389 cl.time = cl.mtime[0];
393 f = (cl.time - cl.mtime[1]) / f;
394 return bound(0, f, 1);
397 void CL_ClearTempEntities (void)
399 cl_num_temp_entities = 0;
402 entity_t *CL_NewTempEntity (void)
406 if (r_refdef.numentities >= r_refdef.maxentities)
408 if (cl_num_temp_entities >= cl_max_temp_entities)
410 ent = &cl_temp_entities[cl_num_temp_entities++];
411 memset (ent, 0, sizeof(*ent));
412 r_refdef.entities[r_refdef.numentities++] = &ent->render;
414 ent->render.colormap = -1; // no special coloring
415 ent->render.scale = 1;
416 ent->render.alpha = 1;
420 void CL_AllocDlight (entity_render_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
426 // first look for an exact key match
430 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
436 // then look for anything else
438 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
442 // unable to find one
446 //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
447 memset (dl, 0, sizeof(*dl));
449 VectorCopy(org, dl->origin);
452 dl->color[1] = green;
456 dl->die = cl.time + lifetime;
461 void CL_DecayLights (void)
467 time = cl.time - cl.oldtime;
470 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
474 if (dl->die < cl.time)
480 dl->radius -= time*dl->decay;
486 void CL_RelinkWorld (void)
488 entity_t *ent = &cl_entities[0];
489 if (cl_num_entities < 1)
491 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
492 Matrix4x4_CreateIdentity(&ent->render.matrix);
493 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
494 CL_BoundingBoxForEntity(&ent->render);
497 static void CL_RelinkStaticEntities(void)
500 for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
502 Mod_CheckLoaded(cl_static_entities[i].render.model);
503 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
512 extern qboolean Nehahrademcompatibility;
513 #define MAXVIEWMODELS 32
514 entity_t *viewmodels[MAXVIEWMODELS];
516 static void CL_RelinkNetworkEntities(void)
519 int i, effects, temp;
520 float d, bobjrotate, bobjoffset, lerp;
521 vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
525 bobjrotate = ANGLEMOD(100*cl.time);
526 if (cl_itembobheight.value)
527 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
531 // start on the entity after the world
532 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
534 // if the object isn't active in the current network frame, skip it
535 if (!cl_entities_active[i])
537 if (!ent->state_current.active)
539 cl_entities_active[i] = false;
543 VectorCopy(ent->persistent.trail_origin, oldorg);
545 if (!ent->state_previous.active)
547 // only one state available
548 VectorCopy (ent->persistent.neworigin, neworg);
549 VectorCopy (ent->persistent.newangles, ent->render.angles);
550 VectorCopy (neworg, oldorg);
554 // if the delta is large, assume a teleport and don't lerp
555 VectorSubtract(ent->persistent.neworigin, ent->persistent.oldorigin, delta);
556 if (ent->persistent.lerpdeltatime > 0)
558 lerp = (cl.time - ent->persistent.lerpstarttime) / ent->persistent.lerpdeltatime;
561 // interpolate the origin and angles
562 VectorMA(ent->persistent.oldorigin, lerp, delta, neworg);
563 VectorSubtract(ent->persistent.newangles, ent->persistent.oldangles, delta);
564 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
565 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
566 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
567 VectorMA(ent->persistent.oldangles, lerp, delta, ent->render.angles);
572 VectorCopy (ent->persistent.neworigin, neworg);
573 VectorCopy (ent->persistent.newangles, ent->render.angles);
579 VectorCopy (ent->persistent.neworigin, neworg);
580 VectorCopy (ent->persistent.newangles, ent->render.angles);
584 if (!ent->render.model || ent->render.model->type != mod_brush)
585 ent->render.angles[0] = -ent->render.angles[0];
587 VectorCopy (neworg, ent->persistent.trail_origin);
588 // persistent.modelindex will be updated by CL_LerpUpdate
589 if (ent->state_current.modelindex != ent->persistent.modelindex || !ent->state_previous.active)
590 VectorCopy(neworg, oldorg);
592 VectorCopy (neworg, ent->render.origin);
593 ent->render.flags = ent->state_current.flags;
594 if (i == cl.viewentity)
595 ent->render.flags |= RENDER_EXTERIORMODEL;
596 ent->render.effects = effects = ent->state_current.effects;
597 if (ent->state_current.flags & RENDER_COLORMAPPED)
598 ent->render.colormap = ent->state_current.colormap;
599 else if (cl.scores == NULL || !ent->state_current.colormap)
600 ent->render.colormap = -1; // no special coloring
602 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
603 ent->render.skinnum = ent->state_current.skin;
604 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
605 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
607 if (ent->render.model && ent->render.model->flags & EF_ROTATE)
609 ent->render.angles[1] = bobjrotate;
610 ent->render.origin[2] += bobjoffset;
613 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);
615 // update interpolation info
618 // handle effects now...
623 // LordHavoc: if the entity has no effects, don't check each
626 if (effects & EF_BRIGHTFIELD)
628 if (gamemode == GAME_NEXIUZ)
630 dlightcolor[0] += 100.0f;
631 dlightcolor[1] += 200.0f;
632 dlightcolor[2] += 400.0f;
633 // don't do trail if we have no previous location
634 if (ent->state_previous.active)
635 CL_RocketTrail (oldorg, neworg, 8, ent);
638 CL_EntityParticles (ent);
640 if (effects & EF_MUZZLEFLASH)
641 ent->persistent.muzzleflash = 100.0f;
642 if (effects & EF_DIMLIGHT)
644 dlightcolor[0] += 200.0f;
645 dlightcolor[1] += 200.0f;
646 dlightcolor[2] += 200.0f;
648 if (effects & EF_BRIGHTLIGHT)
650 dlightcolor[0] += 400.0f;
651 dlightcolor[1] += 400.0f;
652 dlightcolor[2] += 400.0f;
654 // LordHavoc: added EF_RED and EF_BLUE
655 if (effects & EF_RED) // red
657 dlightcolor[0] += 200.0f;
658 dlightcolor[1] += 20.0f;
659 dlightcolor[2] += 20.0f;
661 if (effects & EF_BLUE) // blue
663 dlightcolor[0] += 20.0f;
664 dlightcolor[1] += 20.0f;
665 dlightcolor[2] += 200.0f;
667 if (effects & EF_FLAME)
669 if (ent->render.model)
671 mins[0] = neworg[0] - 16.0f;
672 mins[1] = neworg[1] - 16.0f;
673 mins[2] = neworg[2] - 16.0f;
674 maxs[0] = neworg[0] + 16.0f;
675 maxs[1] = neworg[1] + 16.0f;
676 maxs[2] = neworg[2] + 16.0f;
677 // how many flames to make
678 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
679 CL_FlameCube(mins, maxs, temp);
681 d = lhrandom(200, 250);
682 dlightcolor[0] += d * 1.0f;
683 dlightcolor[1] += d * 0.7f;
684 dlightcolor[2] += d * 0.3f;
686 if (effects & EF_STARDUST)
688 if (ent->render.model)
690 mins[0] = neworg[0] - 16.0f;
691 mins[1] = neworg[1] - 16.0f;
692 mins[2] = neworg[2] - 16.0f;
693 maxs[0] = neworg[0] + 16.0f;
694 maxs[1] = neworg[1] + 16.0f;
695 maxs[2] = neworg[2] + 16.0f;
696 // how many particles to make
697 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
698 CL_Stardust(mins, maxs, temp);
701 dlightcolor[0] += d * 1.0f;
702 dlightcolor[1] += d * 0.7f;
703 dlightcolor[2] += d * 0.3f;
707 if (ent->persistent.muzzleflash > 0)
709 v2[0] = ent->render.matrix.m[0][0] * 18 + neworg[0];
710 v2[1] = ent->render.matrix.m[0][1] * 18 + neworg[1];
711 v2[2] = ent->render.matrix.m[0][2] * 18 + neworg[2] + 16;
712 CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
714 CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
715 ent->persistent.muzzleflash -= cl.frametime * 1000;
718 // LordHavoc: if the model has no flags, don't check each
719 if (ent->render.model && ent->render.model->flags)
721 // note: EF_ROTATE handled above, above matrix calculation
722 // only do trails if present in the previous frame as well
723 if (ent->state_previous.active)
725 if (ent->render.model->flags & EF_GIB)
726 CL_RocketTrail (oldorg, neworg, 2, ent);
727 else if (ent->render.model->flags & EF_ZOMGIB)
728 CL_RocketTrail (oldorg, neworg, 4, ent);
729 else if (ent->render.model->flags & EF_TRACER)
731 CL_RocketTrail (oldorg, neworg, 3, ent);
732 dlightcolor[0] += 0x10;
733 dlightcolor[1] += 0x40;
734 dlightcolor[2] += 0x10;
736 else if (ent->render.model->flags & EF_TRACER2)
738 CL_RocketTrail (oldorg, neworg, 5, ent);
739 dlightcolor[0] += 0x50;
740 dlightcolor[1] += 0x30;
741 dlightcolor[2] += 0x10;
743 else if (ent->render.model->flags & EF_ROCKET)
745 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
746 dlightcolor[0] += 200.0f;
747 dlightcolor[1] += 160.0f;
748 dlightcolor[2] += 80.0f;
750 else if (ent->render.model->flags & EF_GRENADE)
752 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility (cigar smoke)
753 CL_RocketTrail (oldorg, neworg, 7, ent);
755 CL_RocketTrail (oldorg, neworg, 1, ent);
757 else if (ent->render.model->flags & EF_TRACER3)
759 CL_RocketTrail (oldorg, neworg, 6, ent);
760 dlightcolor[0] += 0x50;
761 dlightcolor[1] += 0x20;
762 dlightcolor[2] += 0x40;
766 // LordHavoc: customizable glow
767 if (ent->state_current.glowsize)
769 // * 4 for the expansion from 0-255 to 0-1023 range,
770 // / 255 to scale down byte colors
771 VectorMA(dlightcolor, ent->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[ent->state_current.glowcolor], dlightcolor);
773 // LordHavoc: customizable trail
774 if (ent->render.flags & RENDER_GLOWTRAIL)
775 CL_RocketTrail2 (oldorg, neworg, ent->state_current.glowcolor, ent);
777 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
779 VectorCopy(neworg, v);
780 // hack to make glowing player light shine on their gun
781 if (i == cl.viewentity/* && !chase_active.integer*/)
783 CL_AllocDlight (&ent->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
786 if (chase_active.integer && (ent->render.flags & RENDER_VIEWMODEL))
789 // don't show entities with no modelindex (note: this still shows
790 // entities which have a modelindex that resolved to a NULL model)
791 if (!ent->state_current.modelindex)
793 if (effects & EF_NODRAW)
796 // store a list of view-relative entities for later adjustment in view code
797 if (ent->render.flags & RENDER_VIEWMODEL)
799 if (numviewmodels < MAXVIEWMODELS)
800 viewmodels[numviewmodels++] = ent;
804 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
806 CL_BoundingBoxForEntity(&ent->render);
807 if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
808 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
810 // note: the cl.viewentity and intermission check is to hide player
811 // shadow during intermission and during the Nehahra movie and
812 // Nehahra cinematics
813 if (!(ent->state_current.effects & EF_NOSHADOW)
814 && !(ent->state_current.effects & EF_ADDITIVE)
815 && (ent->state_current.alpha == 255)
816 && !(ent->render.flags & RENDER_VIEWMODEL)
817 && (i != cl.viewentity || (!cl.intermission && !Nehahrademcompatibility && !cl_noplayershadow.integer)))
818 ent->render.flags |= RENDER_SHADOW;
820 if (r_refdef.numentities < r_refdef.maxentities)
821 r_refdef.entities[r_refdef.numentities++] = &ent->render;
823 if (cl_num_entities < i + 1)
824 cl_num_entities = i + 1;
828 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
832 if (!modelindex) // sanity check
834 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
839 VectorCopy(org, e->origin);
840 e->modelindex = modelindex;
841 e->starttime = cl.time;
842 e->startframe = startframe;
843 e->endframe = startframe + framecount;
844 e->framerate = framerate;
847 e->frame1time = cl.time;
848 e->frame2time = cl.time;
853 static void CL_RelinkEffects(void)
860 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
864 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
866 if (intframe < 0 || intframe >= e->endframe)
869 memset(e, 0, sizeof(*e));
873 if (intframe != e->frame)
876 e->frame1time = e->frame2time;
877 e->frame2time = cl.time;
880 // if we're drawing effects, get a new temp entity
881 // (NewTempEntity adds it to the render entities list for us)
882 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
884 // interpolation stuff
885 ent->render.frame1 = intframe;
886 ent->render.frame2 = intframe + 1;
887 if (ent->render.frame2 >= e->endframe)
888 ent->render.frame2 = -1; // disappear
889 ent->render.framelerp = frame - intframe;
890 ent->render.frame1time = e->frame1time;
891 ent->render.frame2time = e->frame2time;
894 //VectorCopy(e->origin, ent->render.origin);
895 ent->render.model = cl.model_precache[e->modelindex];
896 ent->render.frame = ent->render.frame2;
897 ent->render.colormap = -1; // no special coloring
898 //ent->render.scale = 1;
899 ent->render.alpha = 1;
901 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
902 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
903 CL_BoundingBoxForEntity(&ent->render);
909 void CL_RelinkBeams (void)
919 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
921 if (!b->model || b->endtime < cl.time)
924 // if coming from the player, update the start position
925 //if (b->entity == cl.viewentity)
926 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
927 if (cl_beams_relative.integer && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
929 entity_state_t *p = &cl_entities[b->entity].state_previous;
930 //entity_state_t *c = &cl_entities[b->entity].state_current;
931 entity_render_t *r = &cl_entities[b->entity].render;
932 matrix4x4_t matrix, imatrix;
933 if (b->relativestartvalid == 2)
935 // not really valid yet, we need to get the orientation now
936 // (ParseBeam flagged this because it is received before
937 // entities are received, by now they have been received)
938 // note: because players create lightning in their think
939 // function (which occurs before movement), they actually
940 // have some lag in it's location, so compare to the
941 // previous player state, not the latest
942 if (b->entity == cl.viewentity)
943 Matrix4x4_CreateFromQuakeEntity(&matrix, cl.viewentoriginold[0], cl.viewentoriginold[1], cl.viewentoriginold[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
945 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
946 Matrix4x4_Invert_Simple(&imatrix, &matrix);
947 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
948 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
949 b->relativestartvalid = 1;
953 if (b->entity == cl.viewentity)
954 Matrix4x4_CreateFromQuakeEntity(&matrix, cl.viewentorigin[0], cl.viewentorigin[1], cl.viewentorigin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
956 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
957 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
958 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
964 if (cl_beams_lightatend.integer)
965 CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
966 if (cl_beams_polygons.integer)
970 // calculate pitch and yaw
971 VectorSubtract (b->end, b->start, dist);
973 if (dist[1] == 0 && dist[0] == 0)
983 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
987 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
988 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
993 // add new entities for the lightning
994 VectorCopy (b->start, org);
995 d = VectorNormalizeLength(dist);
998 ent = CL_NewTempEntity ();
1001 //VectorCopy (org, ent->render.origin);
1002 ent->render.model = b->model;
1003 ent->render.effects = EF_FULLBRIGHT;
1004 //ent->render.angles[0] = pitch;
1005 //ent->render.angles[1] = yaw;
1006 //ent->render.angles[2] = rand()%360;
1007 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], pitch, yaw, lhrandom(0, 360), 1);
1008 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1009 CL_BoundingBoxForEntity(&ent->render);
1010 VectorMA(org, 30, dist, org);
1016 cvar_t r_lightningbeam_thickness = {CVAR_SAVE, "r_lightningbeam_thickness", "4"};
1017 cvar_t r_lightningbeam_scroll = {CVAR_SAVE, "r_lightningbeam_scroll", "5"};
1018 cvar_t r_lightningbeam_repeatdistance = {CVAR_SAVE, "r_lightningbeam_repeatdistance", "1024"};
1019 cvar_t r_lightningbeam_color_red = {CVAR_SAVE, "r_lightningbeam_color_red", "1"};
1020 cvar_t r_lightningbeam_color_green = {CVAR_SAVE, "r_lightningbeam_color_green", "1"};
1021 cvar_t r_lightningbeam_color_blue = {CVAR_SAVE, "r_lightningbeam_color_blue", "1"};
1022 cvar_t r_lightningbeam_qmbtexture = {CVAR_SAVE, "r_lightningbeam_qmbtexture", "0"};
1024 rtexture_t *r_lightningbeamtexture;
1025 rtexture_t *r_lightningbeamqmbtexture;
1026 rtexturepool_t *r_lightningbeamtexturepool;
1028 int r_lightningbeamelements[18] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11};
1030 void r_lightningbeams_start(void)
1032 r_lightningbeamtexturepool = R_AllocTexturePool();
1033 r_lightningbeamtexture = NULL;
1034 r_lightningbeamqmbtexture = NULL;
1037 void r_lightningbeams_setupqmbtexture(void)
1039 r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
1040 if (r_lightningbeamqmbtexture == NULL)
1041 Cvar_SetValueQuick(&r_lightningbeam_qmbtexture, false);
1044 void r_lightningbeams_setuptexture(void)
1047 #define BEAMWIDTH 128
1048 #define BEAMHEIGHT 64
1049 #define PATHPOINTS 8
1050 int i, j, px, py, nearestpathindex, imagenumber;
1051 float particlex, particley, particlexv, particleyv, dx, dy, s, maxpathstrength;
1054 struct {float x, y, strength;} path[PATHPOINTS], temppath;
1056 image = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1057 pixels = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(qbyte[4]));
1059 for (imagenumber = 0, maxpathstrength = 0.0339476;maxpathstrength < 0.5;imagenumber++, maxpathstrength += 0.01)
1061 for (i = 0;i < PATHPOINTS;i++)
1063 path[i].x = lhrandom(0, 1);
1064 path[i].y = lhrandom(0.2, 0.8);
1065 path[i].strength = lhrandom(0, 1);
1067 for (i = 0;i < PATHPOINTS;i++)
1069 for (j = i + 1;j < PATHPOINTS;j++)
1071 if (path[j].x < path[i].x)
1079 particlex = path[0].x;
1080 particley = path[0].y;
1081 particlexv = lhrandom(0, 0.02);
1082 particlexv = lhrandom(-0.02, 0.02);
1083 memset(image, 0, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1084 for (i = 0;i < 65536;i++)
1086 for (nearestpathindex = 0;nearestpathindex < PATHPOINTS;nearestpathindex++)
1087 if (path[nearestpathindex].x > particlex)
1089 nearestpathindex %= PATHPOINTS;
1090 dx = path[nearestpathindex].x + lhrandom(-0.01, 0.01);dx = bound(0, dx, 1) - particlex;if (dx < 0) dx += 1;
1091 dy = path[nearestpathindex].y + lhrandom(-0.01, 0.01);dy = bound(0, dy, 1) - particley;
1092 s = path[nearestpathindex].strength / sqrt(dx*dx+dy*dy);
1093 particlexv = particlexv /* (1 - lhrandom(0.08, 0.12))*/ + dx * s;
1094 particleyv = particleyv /* (1 - lhrandom(0.08, 0.12))*/ + dy * s;
1095 particlex += particlexv * maxpathstrength;particlex -= (int) particlex;
1096 particley += particleyv * maxpathstrength;particley = bound(0, particley, 1);
1097 px = particlex * BEAMWIDTH;
1098 py = particley * BEAMHEIGHT;
1099 if (px >= 0 && py >= 0 && px < BEAMWIDTH && py < BEAMHEIGHT)
1100 image[py*BEAMWIDTH+px] += 16;
1103 for (py = 0;py < BEAMHEIGHT;py++)
1105 for (px = 0;px < BEAMWIDTH;px++)
1107 pixels[(py*BEAMWIDTH+px)*4+0] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1108 pixels[(py*BEAMWIDTH+px)*4+1] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1109 pixels[(py*BEAMWIDTH+px)*4+2] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1110 pixels[(py*BEAMWIDTH+px)*4+3] = 255;
1114 Image_WriteTGARGBA(va("lightningbeam%i.tga", imagenumber), BEAMWIDTH, BEAMHEIGHT, pixels);
1117 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, pixels, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1122 #define BEAMWIDTH 64
1123 #define BEAMHEIGHT 128
1124 float r, g, b, intensity, fx, width, center;
1126 qbyte *data, *noise1, *noise2;
1128 data = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * 4);
1129 noise1 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1130 noise2 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1131 fractalnoise(noise1, BEAMHEIGHT, BEAMHEIGHT / 8);
1132 fractalnoise(noise2, BEAMHEIGHT, BEAMHEIGHT / 16);
1134 for (y = 0;y < BEAMHEIGHT;y++)
1136 width = 0.15;//((noise1[y * BEAMHEIGHT] * (1.0f / 256.0f)) * 0.1f + 0.1f);
1137 center = (noise1[y * BEAMHEIGHT + (BEAMHEIGHT / 2)] / 256.0f) * (1.0f - width * 2.0f) + width;
1138 for (x = 0;x < BEAMWIDTH;x++, fx++)
1140 fx = (((float) x / BEAMWIDTH) - center) / width;
1141 intensity = 1.0f - sqrt(fx * fx);
1143 intensity = pow(intensity, 2) * ((noise2[y * BEAMHEIGHT + x] * (1.0f / 256.0f)) * 0.33f + 0.66f);
1144 intensity = bound(0, intensity, 1);
1145 r = intensity * 1.0f;
1146 g = intensity * 1.0f;
1147 b = intensity * 1.0f;
1148 data[(y * BEAMWIDTH + x) * 4 + 0] = (qbyte)(bound(0, r, 1) * 255.0f);
1149 data[(y * BEAMWIDTH + x) * 4 + 1] = (qbyte)(bound(0, g, 1) * 255.0f);
1150 data[(y * BEAMWIDTH + x) * 4 + 2] = (qbyte)(bound(0, b, 1) * 255.0f);
1151 data[(y * BEAMWIDTH + x) * 4 + 3] = (qbyte)255;
1155 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1162 void r_lightningbeams_shutdown(void)
1164 r_lightningbeamtexture = NULL;
1165 r_lightningbeamqmbtexture = NULL;
1166 R_FreeTexturePool(&r_lightningbeamtexturepool);
1169 void r_lightningbeams_newmap(void)
1173 void R_LightningBeams_Init(void)
1175 Cvar_RegisterVariable(&r_lightningbeam_thickness);
1176 Cvar_RegisterVariable(&r_lightningbeam_scroll);
1177 Cvar_RegisterVariable(&r_lightningbeam_repeatdistance);
1178 Cvar_RegisterVariable(&r_lightningbeam_color_red);
1179 Cvar_RegisterVariable(&r_lightningbeam_color_green);
1180 Cvar_RegisterVariable(&r_lightningbeam_color_blue);
1181 Cvar_RegisterVariable(&r_lightningbeam_qmbtexture);
1182 R_RegisterModule("R_LightningBeams", r_lightningbeams_start, r_lightningbeams_shutdown, r_lightningbeams_newmap);
1185 void R_CalcLightningBeamPolygonVertex3f(float *v, const float *start, const float *end, const float *offset)
1187 // near right corner
1188 VectorAdd (start, offset, (v + 0));
1190 VectorSubtract(start, offset, (v + 3));
1192 VectorSubtract(end , offset, (v + 6));
1194 VectorAdd (end , offset, (v + 9));
1197 void R_CalcLightningBeamPolygonTexCoord2f(float *tc, float t1, float t2)
1199 if (r_lightningbeam_qmbtexture.integer)
1201 // near right corner
1202 tc[0] = t1;tc[1] = 0;
1204 tc[2] = t1;tc[3] = 1;
1206 tc[4] = t2;tc[5] = 1;
1208 tc[6] = t2;tc[7] = 0;
1212 // near right corner
1213 tc[0] = 0;tc[1] = t1;
1215 tc[2] = 1;tc[3] = t1;
1217 tc[4] = 1;tc[5] = t2;
1219 tc[6] = 0;tc[7] = t2;
1223 void R_FogLightningBeam_Vertex3f_Color4f(const float *v, float *c, int numverts, float r, float g, float b, float a)
1228 for (i = 0;i < numverts;i++, v += 3, c += 4)
1230 VectorSubtract(v, r_origin, fogvec);
1231 ifog = 1 - exp(fogdensity/DotProduct(fogvec,fogvec));
1239 float beamrepeatscale;
1241 void R_DrawLightningBeamCallback(const void *calldata1, int calldata2)
1243 const beam_t *b = calldata1;
1245 vec3_t beamdir, right, up, offset;
1246 float length, t1, t2;
1247 memset(&m, 0, sizeof(m));
1248 m.blendfunc1 = GL_SRC_ALPHA;
1249 m.blendfunc2 = GL_ONE;
1250 if (r_lightningbeam_qmbtexture.integer && r_lightningbeamqmbtexture == NULL)
1251 r_lightningbeams_setupqmbtexture();
1252 if (!r_lightningbeam_qmbtexture.integer && r_lightningbeamtexture == NULL)
1253 r_lightningbeams_setuptexture();
1254 if (r_lightningbeam_qmbtexture.integer)
1255 m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
1257 m.tex[0] = R_GetTexture(r_lightningbeamtexture);
1259 R_Mesh_Matrix(&r_identitymatrix);
1261 // calculate beam direction (beamdir) vector and beam length
1262 // get difference vector
1263 VectorSubtract(b->end, b->start, beamdir);
1264 // find length of difference vector
1265 length = sqrt(DotProduct(beamdir, beamdir));
1266 // calculate scale to make beamdir a unit vector (normalized)
1268 // scale beamdir so it is now normalized
1269 VectorScale(beamdir, t1, beamdir);
1271 // calculate up vector such that it points toward viewer, and rotates around the beamdir
1272 // get direction from start of beam to viewer
1273 VectorSubtract(r_origin, b->start, up);
1274 // remove the portion of the vector that moves along the beam
1275 // (this leaves only a vector pointing directly away from the beam)
1276 t1 = -DotProduct(up, beamdir);
1277 VectorMA(up, t1, beamdir, up);
1278 // now we have a vector pointing away from the beam, now we need to normalize it
1279 VectorNormalizeFast(up);
1280 // generate right vector from forward and up, the result is already normalized
1281 // (CrossProduct returns a vector of multiplied length of the two inputs)
1282 CrossProduct(beamdir, up, right);
1284 // calculate T coordinate scrolling (start and end texcoord along the beam)
1285 t1 = cl.time * -r_lightningbeam_scroll.value;// + beamrepeatscale * DotProduct(b->start, beamdir);
1287 t2 = t1 + beamrepeatscale * length;
1289 // the beam is 3 polygons in this configuration:
1295 // they are showing different portions of the beam texture, creating an
1296 // illusion of a beam that appears to curl around in 3D space
1297 // (and realize that the whole polygon assembly orients itself to face
1300 R_Mesh_GetSpace(12);
1302 // polygon 1, verts 0-3
1303 VectorScale(right, r_lightningbeam_thickness.value, offset);
1304 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f, b->start, b->end, offset);
1305 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0], t1, t2);
1307 // polygon 2, verts 4-7
1308 VectorAdd(right, up, offset);
1309 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1310 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 12, b->start, b->end, offset);
1311 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 8, t1 + 0.33, t2 + 0.33);
1313 // polygon 3, verts 8-11
1314 VectorSubtract(right, up, offset);
1315 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1316 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 24, b->start, b->end, offset);
1317 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 16, t1 + 0.66, t2 + 0.66);
1321 // per vertex colors if fog is used
1323 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);
1327 // solid color if fog is not used
1328 GL_Color(r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
1331 // draw the 3 polygons as one batch of 6 triangles using the 12 vertices
1332 R_Mesh_Draw(12, 6, r_lightningbeamelements);
1335 void R_DrawLightningBeams (void)
1341 if (!cl_beams_polygons.integer)
1344 beamrepeatscale = 1.0f / r_lightningbeam_repeatdistance.value;
1345 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1347 if (b->model && b->endtime >= cl.time && b->lightning)
1349 VectorAdd(b->start, b->end, org);
1350 VectorScale(org, 0.5f, org);
1351 R_MeshQueue_AddTransparent(org, R_DrawLightningBeamCallback, b, 0);
1357 void CL_LerpPlayer(float frac)
1362 if (cl.entitydatabase.numframes && cl.viewentity == cl.playerentity)
1364 cl.viewentorigin[0] = cl.viewentoriginold[0] + frac * (cl.viewentoriginnew[0] - cl.viewentoriginold[0]);
1365 cl.viewentorigin[1] = cl.viewentoriginold[1] + frac * (cl.viewentoriginnew[1] - cl.viewentoriginold[1]);
1366 cl.viewentorigin[2] = cl.viewentoriginold[2] + frac * (cl.viewentoriginnew[2] - cl.viewentoriginold[2]);
1370 VectorCopy (cl_entities[cl.viewentity].state_previous.origin, cl.viewentoriginold);
1371 VectorCopy (cl_entities[cl.viewentity].state_current.origin, cl.viewentoriginnew);
1372 VectorCopy (cl_entities[cl.viewentity].render.origin, cl.viewentorigin);
1375 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
1377 for (i = 0;i < 3;i++)
1378 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1380 if (cls.demoplayback)
1382 // interpolate the angles
1383 for (i = 0;i < 3;i++)
1385 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1390 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1395 void CL_RelinkEntities (void)
1399 // fraction from previous network update to current
1400 frac = CL_LerpPoint();
1402 CL_ClearTempEntities();
1405 CL_RelinkStaticEntities();
1406 CL_RelinkNetworkEntities();
1410 CL_LerpPlayer(frac);
1420 Read all incoming data from the server
1423 int CL_ReadFromServer (void)
1427 cl.oldtime = cl.time;
1428 cl.time += cl.frametime;
1433 ret = CL_GetMessage ();
1435 Host_Error ("CL_ReadFromServer: lost server connection");
1439 cl.last_received_message = realtime;
1441 if (cl_shownet.integer)
1444 CL_ParseServerMessage ();
1446 while (ret && cls.state == ca_connected);
1451 r_refdef.numentities = 0;
1452 cl_num_entities = 0;
1453 cl_num_brushmodel_entities = 0;
1455 if (cls.state == ca_connected && cls.signon == SIGNONS)
1457 CL_RelinkEntities ();
1459 // run cgame code (which can add more entities)
1464 // bring the links up to date
1474 void CL_SendCmd (void)
1478 if (cls.state != ca_connected)
1481 if (cls.signon == SIGNONS)
1483 // get basic movement from keyboard
1486 IN_PreMove(); // OS independent code
1488 // allow mice or other external controllers to add to the move
1491 IN_PostMove(); // OS independent code
1493 // send the unreliable message
1496 #ifndef NOROUTINGFIX
1497 else if (cls.signon == 0 && !cls.demoplayback)
1499 // LordHavoc: fix for NAT routing of netquake:
1500 // bounce back a clc_nop message to the newly allocated server port,
1501 // to establish a routing connection for incoming frames,
1502 // the server waits for this before sending anything
1503 if (realtime > cl.sendnoptime)
1505 cl.sendnoptime = realtime + 3;
1506 Con_DPrintf("sending clc_nop to get server's attention\n");
1513 MSG_WriteByte(&buf, clc_nop);
1514 if (NET_SendUnreliableMessage (cls.netcon, &buf) == -1)
1516 Con_Printf ("CL_SendCmd: lost server connection\n");
1524 if (cls.demoplayback)
1526 SZ_Clear (&cls.message);
1530 // send the reliable message
1531 if (!cls.message.cursize)
1532 return; // no message at all
1534 if (!NET_CanSendMessage (cls.netcon))
1536 Con_DPrintf ("CL_WriteToServer: can't send\n");
1537 if (developer.integer)
1538 SZ_HexDumpToConsole(&cls.message);
1542 if (NET_SendMessage (cls.netcon, &cls.message) == -1)
1543 Host_Error ("CL_WriteToServer: lost server connection");
1545 SZ_Clear (&cls.message);
1548 // LordHavoc: pausedemo command
1549 static void CL_PauseDemo_f (void)
1551 cls.demopaused = !cls.demopaused;
1553 Con_Printf("Demo paused\n");
1555 Con_Printf("Demo unpaused\n");
1559 ======================
1561 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1562 ======================
1564 static void CL_PModel_f (void)
1569 if (Cmd_Argc () == 1)
1571 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1574 i = atoi(Cmd_Argv(1));
1576 if (cmd_source == src_command)
1578 if (cl_pmodel.integer == i)
1580 Cvar_SetValue ("_cl_pmodel", i);
1581 if (cls.state == ca_connected)
1582 Cmd_ForwardToServer ();
1586 host_client->pmodel = i;
1587 if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1592 ======================
1594 ======================
1596 static void CL_Fog_f (void)
1598 if (Cmd_Argc () == 1)
1600 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1603 fog_density = atof(Cmd_Argv(1));
1604 fog_red = atof(Cmd_Argv(2));
1605 fog_green = atof(Cmd_Argv(3));
1606 fog_blue = atof(Cmd_Argv(4));
1616 cl_scores_mempool = Mem_AllocPool("client player info");
1617 cl_entities_mempool = Mem_AllocPool("client entities");
1618 cl_refdef_mempool = Mem_AllocPool("refdef");
1620 memset(&r_refdef, 0, sizeof(r_refdef));
1621 // max entities sent to renderer per frame
1622 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1623 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1624 // 256k drawqueue buffer
1625 r_refdef.maxdrawqueuesize = 256 * 1024;
1626 r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1628 SZ_Alloc (&cls.message, 1024, "cls.message");
1634 // register our commands
1636 Cvar_RegisterVariable (&cl_name);
1637 Cvar_RegisterVariable (&cl_color);
1638 if (gamemode == GAME_NEHAHRA)
1639 Cvar_RegisterVariable (&cl_pmodel);
1640 Cvar_RegisterVariable (&cl_upspeed);
1641 Cvar_RegisterVariable (&cl_forwardspeed);
1642 Cvar_RegisterVariable (&cl_backspeed);
1643 Cvar_RegisterVariable (&cl_sidespeed);
1644 Cvar_RegisterVariable (&cl_movespeedkey);
1645 Cvar_RegisterVariable (&cl_yawspeed);
1646 Cvar_RegisterVariable (&cl_pitchspeed);
1647 Cvar_RegisterVariable (&cl_anglespeedkey);
1648 Cvar_RegisterVariable (&cl_shownet);
1649 Cvar_RegisterVariable (&cl_nolerp);
1650 Cvar_RegisterVariable (&lookspring);
1651 Cvar_RegisterVariable (&lookstrafe);
1652 Cvar_RegisterVariable (&sensitivity);
1653 Cvar_RegisterVariable (&freelook);
1655 Cvar_RegisterVariable (&m_pitch);
1656 Cvar_RegisterVariable (&m_yaw);
1657 Cvar_RegisterVariable (&m_forward);
1658 Cvar_RegisterVariable (&m_side);
1660 Cvar_RegisterVariable (&cl_itembobspeed);
1661 Cvar_RegisterVariable (&cl_itembobheight);
1663 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1664 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1665 Cmd_AddCommand ("record", CL_Record_f);
1666 Cmd_AddCommand ("stop", CL_Stop_f);
1667 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1668 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1670 Cmd_AddCommand ("fog", CL_Fog_f);
1672 // LordHavoc: added pausedemo
1673 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1674 if (gamemode == GAME_NEHAHRA)
1675 Cmd_AddCommand ("pmodel", CL_PModel_f);
1677 Cvar_RegisterVariable(&r_draweffects);
1678 Cvar_RegisterVariable(&cl_explosions);
1679 Cvar_RegisterVariable(&cl_stainmaps);
1680 Cvar_RegisterVariable(&cl_beams_polygons);
1681 Cvar_RegisterVariable(&cl_beams_relative);
1682 Cvar_RegisterVariable(&cl_beams_lightatend);
1683 Cvar_RegisterVariable(&cl_noplayershadow);
1685 R_LightningBeams_Init();
1688 CL_Particles_Init();