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 Mod_FindNonSolidLocation(org, dl->origin, cl.worldmodel, 6);
450 //VectorCopy(org, dl->origin);
453 dl->color[1] = green;
457 dl->die = cl.time + lifetime;
462 void CL_DecayLights (void)
468 time = cl.time - cl.oldtime;
471 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
475 if (dl->die < cl.time)
481 dl->radius -= time*dl->decay;
487 void CL_RelinkWorld (void)
489 entity_t *ent = &cl_entities[0];
490 if (cl_num_entities < 1)
492 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
493 Matrix4x4_CreateIdentity(&ent->render.matrix);
494 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
495 CL_BoundingBoxForEntity(&ent->render);
498 static void CL_RelinkStaticEntities(void)
501 for (i = 0;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++)
503 Mod_CheckLoaded(cl_static_entities[i].render.model);
504 r_refdef.entities[r_refdef.numentities++] = &cl_static_entities[i].render;
513 extern qboolean Nehahrademcompatibility;
514 #define MAXVIEWMODELS 32
515 entity_t *viewmodels[MAXVIEWMODELS];
517 static void CL_RelinkNetworkEntities(void)
520 int i, effects, temp;
521 float d, bobjrotate, bobjoffset, lerp;
522 vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
526 bobjrotate = ANGLEMOD(100*cl.time);
527 if (cl_itembobheight.value)
528 bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
532 // start on the entity after the world
533 for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
535 // if the object isn't active in the current network frame, skip it
536 if (!cl_entities_active[i])
538 if (!ent->state_current.active)
540 cl_entities_active[i] = false;
544 VectorCopy(ent->persistent.trail_origin, oldorg);
546 if (!ent->state_previous.active)
548 // only one state available
549 VectorCopy (ent->persistent.neworigin, neworg);
550 VectorCopy (ent->persistent.newangles, ent->render.angles);
551 VectorCopy (neworg, oldorg);
555 // if the delta is large, assume a teleport and don't lerp
556 VectorSubtract(ent->persistent.neworigin, ent->persistent.oldorigin, delta);
557 if (ent->persistent.lerpdeltatime > 0)
559 lerp = (cl.time - ent->persistent.lerpstarttime) / ent->persistent.lerpdeltatime;
562 // interpolate the origin and angles
563 VectorMA(ent->persistent.oldorigin, lerp, delta, neworg);
564 VectorSubtract(ent->persistent.newangles, ent->persistent.oldangles, delta);
565 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
566 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
567 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
568 VectorMA(ent->persistent.oldangles, lerp, delta, ent->render.angles);
573 VectorCopy (ent->persistent.neworigin, neworg);
574 VectorCopy (ent->persistent.newangles, ent->render.angles);
580 VectorCopy (ent->persistent.neworigin, neworg);
581 VectorCopy (ent->persistent.newangles, ent->render.angles);
585 if (!ent->render.model || ent->render.model->type != mod_brush)
586 ent->render.angles[0] = -ent->render.angles[0];
588 VectorCopy (neworg, ent->persistent.trail_origin);
589 // persistent.modelindex will be updated by CL_LerpUpdate
590 if (ent->state_current.modelindex != ent->persistent.modelindex || !ent->state_previous.active)
591 VectorCopy(neworg, oldorg);
593 VectorCopy (neworg, ent->render.origin);
594 ent->render.flags = ent->state_current.flags;
595 if (i == cl.viewentity)
596 ent->render.flags |= RENDER_EXTERIORMODEL;
597 ent->render.effects = effects = ent->state_current.effects;
598 if (ent->state_current.flags & RENDER_COLORMAPPED)
599 ent->render.colormap = ent->state_current.colormap;
600 else if (cl.scores == NULL || !ent->state_current.colormap)
601 ent->render.colormap = -1; // no special coloring
603 ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
604 ent->render.skinnum = ent->state_current.skin;
605 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
606 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
608 if (ent->render.model && ent->render.model->flags & EF_ROTATE)
610 ent->render.angles[1] = bobjrotate;
611 ent->render.origin[2] += bobjoffset;
614 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);
616 // update interpolation info
619 // handle effects now...
624 // LordHavoc: if the entity has no effects, don't check each
627 if (effects & EF_BRIGHTFIELD)
629 if (gamemode == GAME_NEXUIZ)
631 dlightcolor[0] += 100.0f;
632 dlightcolor[1] += 200.0f;
633 dlightcolor[2] += 400.0f;
634 // don't do trail if we have no previous location
635 if (ent->state_previous.active)
636 CL_RocketTrail (oldorg, neworg, 8, ent);
639 CL_EntityParticles (ent);
641 if (effects & EF_MUZZLEFLASH)
642 ent->persistent.muzzleflash = 100.0f;
643 if (effects & EF_DIMLIGHT)
645 dlightcolor[0] += 200.0f;
646 dlightcolor[1] += 200.0f;
647 dlightcolor[2] += 200.0f;
649 if (effects & EF_BRIGHTLIGHT)
651 dlightcolor[0] += 400.0f;
652 dlightcolor[1] += 400.0f;
653 dlightcolor[2] += 400.0f;
655 // LordHavoc: added EF_RED and EF_BLUE
656 if (effects & EF_RED) // red
658 dlightcolor[0] += 200.0f;
659 dlightcolor[1] += 20.0f;
660 dlightcolor[2] += 20.0f;
662 if (effects & EF_BLUE) // blue
664 dlightcolor[0] += 20.0f;
665 dlightcolor[1] += 20.0f;
666 dlightcolor[2] += 200.0f;
668 if (effects & EF_FLAME)
670 if (ent->render.model)
672 mins[0] = neworg[0] - 16.0f;
673 mins[1] = neworg[1] - 16.0f;
674 mins[2] = neworg[2] - 16.0f;
675 maxs[0] = neworg[0] + 16.0f;
676 maxs[1] = neworg[1] + 16.0f;
677 maxs[2] = neworg[2] + 16.0f;
678 // how many flames to make
679 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
680 CL_FlameCube(mins, maxs, temp);
682 d = lhrandom(200, 250);
683 dlightcolor[0] += d * 1.0f;
684 dlightcolor[1] += d * 0.7f;
685 dlightcolor[2] += d * 0.3f;
687 if (effects & EF_STARDUST)
689 if (ent->render.model)
691 mins[0] = neworg[0] - 16.0f;
692 mins[1] = neworg[1] - 16.0f;
693 mins[2] = neworg[2] - 16.0f;
694 maxs[0] = neworg[0] + 16.0f;
695 maxs[1] = neworg[1] + 16.0f;
696 maxs[2] = neworg[2] + 16.0f;
697 // how many particles to make
698 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
699 CL_Stardust(mins, maxs, temp);
702 dlightcolor[0] += d * 1.0f;
703 dlightcolor[1] += d * 0.7f;
704 dlightcolor[2] += d * 0.3f;
708 if (ent->persistent.muzzleflash > 0)
710 v2[0] = ent->render.matrix.m[0][0] * 18 + neworg[0];
711 v2[1] = ent->render.matrix.m[0][1] * 18 + neworg[1];
712 v2[2] = ent->render.matrix.m[0][2] * 18 + neworg[2] + 16;
713 CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
715 CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
716 ent->persistent.muzzleflash -= cl.frametime * 1000;
719 // LordHavoc: if the model has no flags, don't check each
720 if (ent->render.model && ent->render.model->flags)
722 // note: EF_ROTATE handled above, above matrix calculation
723 // only do trails if present in the previous frame as well
724 if (ent->state_previous.active)
726 if (ent->render.model->flags & EF_GIB)
727 CL_RocketTrail (oldorg, neworg, 2, ent);
728 else if (ent->render.model->flags & EF_ZOMGIB)
729 CL_RocketTrail (oldorg, neworg, 4, ent);
730 else if (ent->render.model->flags & EF_TRACER)
732 CL_RocketTrail (oldorg, neworg, 3, ent);
733 dlightcolor[0] += 0x10;
734 dlightcolor[1] += 0x40;
735 dlightcolor[2] += 0x10;
737 else if (ent->render.model->flags & EF_TRACER2)
739 CL_RocketTrail (oldorg, neworg, 5, ent);
740 dlightcolor[0] += 0x50;
741 dlightcolor[1] += 0x30;
742 dlightcolor[2] += 0x10;
744 else if (ent->render.model->flags & EF_ROCKET)
746 CL_RocketTrail (oldorg, ent->render.origin, 0, ent);
747 dlightcolor[0] += 200.0f;
748 dlightcolor[1] += 160.0f;
749 dlightcolor[2] += 80.0f;
751 else if (ent->render.model->flags & EF_GRENADE)
753 if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility (cigar smoke)
754 CL_RocketTrail (oldorg, neworg, 7, ent);
756 CL_RocketTrail (oldorg, neworg, 1, ent);
758 else if (ent->render.model->flags & EF_TRACER3)
760 CL_RocketTrail (oldorg, neworg, 6, ent);
761 dlightcolor[0] += 0x50;
762 dlightcolor[1] += 0x20;
763 dlightcolor[2] += 0x40;
767 // LordHavoc: customizable glow
768 if (ent->state_current.glowsize)
770 // * 4 for the expansion from 0-255 to 0-1023 range,
771 // / 255 to scale down byte colors
772 VectorMA(dlightcolor, ent->state_current.glowsize * (4.0f / 255.0f), (qbyte *)&palette_complete[ent->state_current.glowcolor], dlightcolor);
774 // LordHavoc: customizable trail
775 if (ent->render.flags & RENDER_GLOWTRAIL)
776 CL_RocketTrail2 (oldorg, neworg, ent->state_current.glowcolor, ent);
778 if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
780 VectorCopy(neworg, v);
781 // hack to make glowing player light shine on their gun
782 if (i == cl.viewentity/* && !chase_active.integer*/)
784 CL_AllocDlight (&ent->render, v, 1, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0);
787 if (chase_active.integer && (ent->render.flags & RENDER_VIEWMODEL))
790 // don't show entities with no modelindex (note: this still shows
791 // entities which have a modelindex that resolved to a NULL model)
792 if (!ent->state_current.modelindex)
794 if (effects & EF_NODRAW)
797 // store a list of view-relative entities for later adjustment in view code
798 if (ent->render.flags & RENDER_VIEWMODEL)
800 if (numviewmodels < MAXVIEWMODELS)
801 viewmodels[numviewmodels++] = ent;
805 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
807 CL_BoundingBoxForEntity(&ent->render);
808 if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
809 cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
811 // note: the cl.viewentity and intermission check is to hide player
812 // shadow during intermission and during the Nehahra movie and
813 // Nehahra cinematics
814 if (!(ent->state_current.effects & EF_NOSHADOW)
815 && !(ent->state_current.effects & EF_ADDITIVE)
816 && (ent->state_current.alpha == 255)
817 && !(ent->render.flags & RENDER_VIEWMODEL)
818 && (i != cl.viewentity || (!cl.intermission && !Nehahrademcompatibility && !cl_noplayershadow.integer)))
819 ent->render.flags |= RENDER_SHADOW;
821 if (r_refdef.numentities < r_refdef.maxentities)
822 r_refdef.entities[r_refdef.numentities++] = &ent->render;
824 if (cl_num_entities < i + 1)
825 cl_num_entities = i + 1;
829 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
833 if (!modelindex) // sanity check
835 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
840 VectorCopy(org, e->origin);
841 e->modelindex = modelindex;
842 e->starttime = cl.time;
843 e->startframe = startframe;
844 e->endframe = startframe + framecount;
845 e->framerate = framerate;
848 e->frame1time = cl.time;
849 e->frame2time = cl.time;
854 static void CL_RelinkEffects(void)
861 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
865 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
867 if (intframe < 0 || intframe >= e->endframe)
870 memset(e, 0, sizeof(*e));
874 if (intframe != e->frame)
877 e->frame1time = e->frame2time;
878 e->frame2time = cl.time;
881 // if we're drawing effects, get a new temp entity
882 // (NewTempEntity adds it to the render entities list for us)
883 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
885 // interpolation stuff
886 ent->render.frame1 = intframe;
887 ent->render.frame2 = intframe + 1;
888 if (ent->render.frame2 >= e->endframe)
889 ent->render.frame2 = -1; // disappear
890 ent->render.framelerp = frame - intframe;
891 ent->render.frame1time = e->frame1time;
892 ent->render.frame2time = e->frame2time;
895 //VectorCopy(e->origin, ent->render.origin);
896 ent->render.model = cl.model_precache[e->modelindex];
897 ent->render.frame = ent->render.frame2;
898 ent->render.colormap = -1; // no special coloring
899 //ent->render.scale = 1;
900 ent->render.alpha = 1;
902 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
903 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
904 CL_BoundingBoxForEntity(&ent->render);
910 void CL_RelinkBeams (void)
920 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
922 if (!b->model || b->endtime < cl.time)
925 // if coming from the player, update the start position
926 //if (b->entity == cl.viewentity)
927 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
928 if (cl_beams_relative.integer && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
930 entity_state_t *p = &cl_entities[b->entity].state_previous;
931 //entity_state_t *c = &cl_entities[b->entity].state_current;
932 entity_render_t *r = &cl_entities[b->entity].render;
933 matrix4x4_t matrix, imatrix;
934 if (b->relativestartvalid == 2)
936 // not really valid yet, we need to get the orientation now
937 // (ParseBeam flagged this because it is received before
938 // entities are received, by now they have been received)
939 // note: because players create lightning in their think
940 // function (which occurs before movement), they actually
941 // have some lag in it's location, so compare to the
942 // previous player state, not the latest
943 if (b->entity == cl.viewentity)
944 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
946 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
947 Matrix4x4_Invert_Simple(&imatrix, &matrix);
948 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
949 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
950 b->relativestartvalid = 1;
954 if (b->entity == cl.viewentity)
955 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
957 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
958 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
959 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
965 if (cl_beams_lightatend.integer)
966 CL_AllocDlight (NULL, b->end, 200, 0.3, 0.7, 1, 0, 0);
967 if (cl_beams_polygons.integer)
971 // calculate pitch and yaw
972 VectorSubtract (b->end, b->start, dist);
974 if (dist[1] == 0 && dist[0] == 0)
984 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
988 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
989 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
994 // add new entities for the lightning
995 VectorCopy (b->start, org);
996 d = VectorNormalizeLength(dist);
999 ent = CL_NewTempEntity ();
1002 //VectorCopy (org, ent->render.origin);
1003 ent->render.model = b->model;
1004 ent->render.effects = EF_FULLBRIGHT;
1005 //ent->render.angles[0] = pitch;
1006 //ent->render.angles[1] = yaw;
1007 //ent->render.angles[2] = rand()%360;
1008 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1009 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1010 CL_BoundingBoxForEntity(&ent->render);
1011 VectorMA(org, 30, dist, org);
1017 cvar_t r_lightningbeam_thickness = {CVAR_SAVE, "r_lightningbeam_thickness", "4"};
1018 cvar_t r_lightningbeam_scroll = {CVAR_SAVE, "r_lightningbeam_scroll", "5"};
1019 cvar_t r_lightningbeam_repeatdistance = {CVAR_SAVE, "r_lightningbeam_repeatdistance", "1024"};
1020 cvar_t r_lightningbeam_color_red = {CVAR_SAVE, "r_lightningbeam_color_red", "1"};
1021 cvar_t r_lightningbeam_color_green = {CVAR_SAVE, "r_lightningbeam_color_green", "1"};
1022 cvar_t r_lightningbeam_color_blue = {CVAR_SAVE, "r_lightningbeam_color_blue", "1"};
1023 cvar_t r_lightningbeam_qmbtexture = {CVAR_SAVE, "r_lightningbeam_qmbtexture", "0"};
1025 rtexture_t *r_lightningbeamtexture;
1026 rtexture_t *r_lightningbeamqmbtexture;
1027 rtexturepool_t *r_lightningbeamtexturepool;
1029 int r_lightningbeamelements[18] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11};
1031 void r_lightningbeams_start(void)
1033 r_lightningbeamtexturepool = R_AllocTexturePool();
1034 r_lightningbeamtexture = NULL;
1035 r_lightningbeamqmbtexture = NULL;
1038 void r_lightningbeams_setupqmbtexture(void)
1040 r_lightningbeamqmbtexture = loadtextureimage(r_lightningbeamtexturepool, "textures/particles/lightning.pcx", 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE);
1041 if (r_lightningbeamqmbtexture == NULL)
1042 Cvar_SetValueQuick(&r_lightningbeam_qmbtexture, false);
1045 void r_lightningbeams_setuptexture(void)
1048 #define BEAMWIDTH 128
1049 #define BEAMHEIGHT 64
1050 #define PATHPOINTS 8
1051 int i, j, px, py, nearestpathindex, imagenumber;
1052 float particlex, particley, particlexv, particleyv, dx, dy, s, maxpathstrength;
1055 struct {float x, y, strength;} path[PATHPOINTS], temppath;
1057 image = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1058 pixels = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(qbyte[4]));
1060 for (imagenumber = 0, maxpathstrength = 0.0339476;maxpathstrength < 0.5;imagenumber++, maxpathstrength += 0.01)
1062 for (i = 0;i < PATHPOINTS;i++)
1064 path[i].x = lhrandom(0, 1);
1065 path[i].y = lhrandom(0.2, 0.8);
1066 path[i].strength = lhrandom(0, 1);
1068 for (i = 0;i < PATHPOINTS;i++)
1070 for (j = i + 1;j < PATHPOINTS;j++)
1072 if (path[j].x < path[i].x)
1080 particlex = path[0].x;
1081 particley = path[0].y;
1082 particlexv = lhrandom(0, 0.02);
1083 particlexv = lhrandom(-0.02, 0.02);
1084 memset(image, 0, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
1085 for (i = 0;i < 65536;i++)
1087 for (nearestpathindex = 0;nearestpathindex < PATHPOINTS;nearestpathindex++)
1088 if (path[nearestpathindex].x > particlex)
1090 nearestpathindex %= PATHPOINTS;
1091 dx = path[nearestpathindex].x + lhrandom(-0.01, 0.01);dx = bound(0, dx, 1) - particlex;if (dx < 0) dx += 1;
1092 dy = path[nearestpathindex].y + lhrandom(-0.01, 0.01);dy = bound(0, dy, 1) - particley;
1093 s = path[nearestpathindex].strength / sqrt(dx*dx+dy*dy);
1094 particlexv = particlexv /* (1 - lhrandom(0.08, 0.12))*/ + dx * s;
1095 particleyv = particleyv /* (1 - lhrandom(0.08, 0.12))*/ + dy * s;
1096 particlex += particlexv * maxpathstrength;particlex -= (int) particlex;
1097 particley += particleyv * maxpathstrength;particley = bound(0, particley, 1);
1098 px = particlex * BEAMWIDTH;
1099 py = particley * BEAMHEIGHT;
1100 if (px >= 0 && py >= 0 && px < BEAMWIDTH && py < BEAMHEIGHT)
1101 image[py*BEAMWIDTH+px] += 16;
1104 for (py = 0;py < BEAMHEIGHT;py++)
1106 for (px = 0;px < BEAMWIDTH;px++)
1108 pixels[(py*BEAMWIDTH+px)*4+0] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1109 pixels[(py*BEAMWIDTH+px)*4+1] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1110 pixels[(py*BEAMWIDTH+px)*4+2] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
1111 pixels[(py*BEAMWIDTH+px)*4+3] = 255;
1115 Image_WriteTGARGBA(va("lightningbeam%i.tga", imagenumber), BEAMWIDTH, BEAMHEIGHT, pixels);
1118 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, pixels, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1123 #define BEAMWIDTH 64
1124 #define BEAMHEIGHT 128
1125 float r, g, b, intensity, fx, width, center;
1127 qbyte *data, *noise1, *noise2;
1129 data = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * 4);
1130 noise1 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1131 noise2 = Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
1132 fractalnoise(noise1, BEAMHEIGHT, BEAMHEIGHT / 8);
1133 fractalnoise(noise2, BEAMHEIGHT, BEAMHEIGHT / 16);
1135 for (y = 0;y < BEAMHEIGHT;y++)
1137 width = 0.15;//((noise1[y * BEAMHEIGHT] * (1.0f / 256.0f)) * 0.1f + 0.1f);
1138 center = (noise1[y * BEAMHEIGHT + (BEAMHEIGHT / 2)] / 256.0f) * (1.0f - width * 2.0f) + width;
1139 for (x = 0;x < BEAMWIDTH;x++, fx++)
1141 fx = (((float) x / BEAMWIDTH) - center) / width;
1142 intensity = 1.0f - sqrt(fx * fx);
1144 intensity = pow(intensity, 2) * ((noise2[y * BEAMHEIGHT + x] * (1.0f / 256.0f)) * 0.33f + 0.66f);
1145 intensity = bound(0, intensity, 1);
1146 r = intensity * 1.0f;
1147 g = intensity * 1.0f;
1148 b = intensity * 1.0f;
1149 data[(y * BEAMWIDTH + x) * 4 + 0] = (qbyte)(bound(0, r, 1) * 255.0f);
1150 data[(y * BEAMWIDTH + x) * 4 + 1] = (qbyte)(bound(0, g, 1) * 255.0f);
1151 data[(y * BEAMWIDTH + x) * 4 + 2] = (qbyte)(bound(0, b, 1) * 255.0f);
1152 data[(y * BEAMWIDTH + x) * 4 + 3] = (qbyte)255;
1156 r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
1163 void r_lightningbeams_shutdown(void)
1165 r_lightningbeamtexture = NULL;
1166 r_lightningbeamqmbtexture = NULL;
1167 R_FreeTexturePool(&r_lightningbeamtexturepool);
1170 void r_lightningbeams_newmap(void)
1174 void R_LightningBeams_Init(void)
1176 Cvar_RegisterVariable(&r_lightningbeam_thickness);
1177 Cvar_RegisterVariable(&r_lightningbeam_scroll);
1178 Cvar_RegisterVariable(&r_lightningbeam_repeatdistance);
1179 Cvar_RegisterVariable(&r_lightningbeam_color_red);
1180 Cvar_RegisterVariable(&r_lightningbeam_color_green);
1181 Cvar_RegisterVariable(&r_lightningbeam_color_blue);
1182 Cvar_RegisterVariable(&r_lightningbeam_qmbtexture);
1183 R_RegisterModule("R_LightningBeams", r_lightningbeams_start, r_lightningbeams_shutdown, r_lightningbeams_newmap);
1186 void R_CalcLightningBeamPolygonVertex3f(float *v, const float *start, const float *end, const float *offset)
1188 // near right corner
1189 VectorAdd (start, offset, (v + 0));
1191 VectorSubtract(start, offset, (v + 3));
1193 VectorSubtract(end , offset, (v + 6));
1195 VectorAdd (end , offset, (v + 9));
1198 void R_CalcLightningBeamPolygonTexCoord2f(float *tc, float t1, float t2)
1200 if (r_lightningbeam_qmbtexture.integer)
1202 // near right corner
1203 tc[0] = t1;tc[1] = 0;
1205 tc[2] = t1;tc[3] = 1;
1207 tc[4] = t2;tc[5] = 1;
1209 tc[6] = t2;tc[7] = 0;
1213 // near right corner
1214 tc[0] = 0;tc[1] = t1;
1216 tc[2] = 1;tc[3] = t1;
1218 tc[4] = 1;tc[5] = t2;
1220 tc[6] = 0;tc[7] = t2;
1224 void R_FogLightningBeam_Vertex3f_Color4f(const float *v, float *c, int numverts, float r, float g, float b, float a)
1229 for (i = 0;i < numverts;i++, v += 3, c += 4)
1231 VectorSubtract(v, r_origin, fogvec);
1232 ifog = 1 - exp(fogdensity/DotProduct(fogvec,fogvec));
1240 float beamrepeatscale;
1242 void R_DrawLightningBeamCallback(const void *calldata1, int calldata2)
1244 const beam_t *b = calldata1;
1246 vec3_t beamdir, right, up, offset;
1247 float length, t1, t2;
1248 memset(&m, 0, sizeof(m));
1249 m.blendfunc1 = GL_SRC_ALPHA;
1250 m.blendfunc2 = GL_ONE;
1251 if (r_lightningbeam_qmbtexture.integer && r_lightningbeamqmbtexture == NULL)
1252 r_lightningbeams_setupqmbtexture();
1253 if (!r_lightningbeam_qmbtexture.integer && r_lightningbeamtexture == NULL)
1254 r_lightningbeams_setuptexture();
1255 if (r_lightningbeam_qmbtexture.integer)
1256 m.tex[0] = R_GetTexture(r_lightningbeamqmbtexture);
1258 m.tex[0] = R_GetTexture(r_lightningbeamtexture);
1260 R_Mesh_Matrix(&r_identitymatrix);
1262 // calculate beam direction (beamdir) vector and beam length
1263 // get difference vector
1264 VectorSubtract(b->end, b->start, beamdir);
1265 // find length of difference vector
1266 length = sqrt(DotProduct(beamdir, beamdir));
1267 // calculate scale to make beamdir a unit vector (normalized)
1269 // scale beamdir so it is now normalized
1270 VectorScale(beamdir, t1, beamdir);
1272 // calculate up vector such that it points toward viewer, and rotates around the beamdir
1273 // get direction from start of beam to viewer
1274 VectorSubtract(r_origin, b->start, up);
1275 // remove the portion of the vector that moves along the beam
1276 // (this leaves only a vector pointing directly away from the beam)
1277 t1 = -DotProduct(up, beamdir);
1278 VectorMA(up, t1, beamdir, up);
1279 // now we have a vector pointing away from the beam, now we need to normalize it
1280 VectorNormalizeFast(up);
1281 // generate right vector from forward and up, the result is already normalized
1282 // (CrossProduct returns a vector of multiplied length of the two inputs)
1283 CrossProduct(beamdir, up, right);
1285 // calculate T coordinate scrolling (start and end texcoord along the beam)
1286 t1 = cl.time * -r_lightningbeam_scroll.value;// + beamrepeatscale * DotProduct(b->start, beamdir);
1288 t2 = t1 + beamrepeatscale * length;
1290 // the beam is 3 polygons in this configuration:
1296 // they are showing different portions of the beam texture, creating an
1297 // illusion of a beam that appears to curl around in 3D space
1298 // (and realize that the whole polygon assembly orients itself to face
1301 R_Mesh_GetSpace(12);
1303 // polygon 1, verts 0-3
1304 VectorScale(right, r_lightningbeam_thickness.value, offset);
1305 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f, b->start, b->end, offset);
1306 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0], t1, t2);
1308 // polygon 2, verts 4-7
1309 VectorAdd(right, up, offset);
1310 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1311 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 12, b->start, b->end, offset);
1312 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 8, t1 + 0.33, t2 + 0.33);
1314 // polygon 3, verts 8-11
1315 VectorSubtract(right, up, offset);
1316 VectorScale(offset, r_lightningbeam_thickness.value * 0.70710681f, offset);
1317 R_CalcLightningBeamPolygonVertex3f(varray_vertex3f + 24, b->start, b->end, offset);
1318 R_CalcLightningBeamPolygonTexCoord2f(varray_texcoord2f[0] + 16, t1 + 0.66, t2 + 0.66);
1322 // per vertex colors if fog is used
1324 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);
1328 // solid color if fog is not used
1329 GL_Color(r_lightningbeam_color_red.value, r_lightningbeam_color_green.value, r_lightningbeam_color_blue.value, 1);
1332 // draw the 3 polygons as one batch of 6 triangles using the 12 vertices
1333 R_Mesh_Draw(12, 6, r_lightningbeamelements);
1336 void R_DrawLightningBeams (void)
1342 if (!cl_beams_polygons.integer)
1345 beamrepeatscale = 1.0f / r_lightningbeam_repeatdistance.value;
1346 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1348 if (b->model && b->endtime >= cl.time && b->lightning)
1350 VectorAdd(b->start, b->end, org);
1351 VectorScale(org, 0.5f, org);
1352 R_MeshQueue_AddTransparent(org, R_DrawLightningBeamCallback, b, 0);
1358 void CL_LerpPlayer(float frac)
1363 cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
1365 for (i = 0;i < 3;i++)
1366 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1368 if (cls.demoplayback)
1370 // interpolate the angles
1371 for (i = 0;i < 3;i++)
1373 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1378 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1383 void CL_RelinkEntities (void)
1387 // fraction from previous network update to current
1388 frac = CL_LerpPoint();
1390 CL_ClearTempEntities();
1393 CL_RelinkStaticEntities();
1394 CL_RelinkNetworkEntities();
1398 CL_LerpPlayer(frac);
1408 Read all incoming data from the server
1411 int CL_ReadFromServer (void)
1415 cl.oldtime = cl.time;
1416 cl.time += cl.frametime;
1421 ret = CL_GetMessage ();
1423 Host_Error ("CL_ReadFromServer: lost server connection");
1427 cl.last_received_message = realtime;
1429 if (cl_shownet.integer)
1432 CL_ParseServerMessage ();
1434 while (ret && cls.state == ca_connected);
1439 r_refdef.numentities = 0;
1440 cl_num_entities = 0;
1441 cl_num_brushmodel_entities = 0;
1443 if (cls.state == ca_connected && cls.signon == SIGNONS)
1445 CL_RelinkEntities ();
1447 // run cgame code (which can add more entities)
1452 // bring the links up to date
1462 void CL_SendCmd (void)
1466 if (cls.state != ca_connected)
1469 if (cls.signon == SIGNONS)
1471 // get basic movement from keyboard
1474 IN_PreMove(); // OS independent code
1476 // allow mice or other external controllers to add to the move
1479 IN_PostMove(); // OS independent code
1481 // send the unreliable message
1484 else if (cls.signon == 0 && !cls.demoplayback)
1486 // LordHavoc: fix for NAT routing of netquake:
1487 // bounce back a clc_nop message to the newly allocated server port,
1488 // to establish a routing connection for incoming frames,
1489 // the server waits for this before sending anything
1490 if (realtime > cl.sendnoptime)
1492 cl.sendnoptime = realtime + 3;
1493 Con_DPrintf("sending clc_nop to get server's attention\n");
1500 MSG_WriteByte(&buf, clc_nop);
1501 if (NET_SendUnreliableMessage (cls.netcon, &buf) == -1)
1503 Con_Printf ("CL_SendCmd: lost server connection\n");
1510 if (cls.demoplayback)
1512 SZ_Clear (&cls.message);
1516 // send the reliable message
1517 if (!cls.message.cursize)
1518 return; // no message at all
1520 if (!NET_CanSendMessage (cls.netcon))
1522 Con_DPrintf ("CL_WriteToServer: can't send\n");
1523 if (developer.integer)
1524 SZ_HexDumpToConsole(&cls.message);
1528 if (NET_SendMessage (cls.netcon, &cls.message) == -1)
1529 Host_Error ("CL_WriteToServer: lost server connection");
1531 SZ_Clear (&cls.message);
1534 // LordHavoc: pausedemo command
1535 static void CL_PauseDemo_f (void)
1537 cls.demopaused = !cls.demopaused;
1539 Con_Printf("Demo paused\n");
1541 Con_Printf("Demo unpaused\n");
1545 ======================
1547 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1548 ======================
1550 static void CL_PModel_f (void)
1555 if (Cmd_Argc () == 1)
1557 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1560 i = atoi(Cmd_Argv(1));
1562 if (cmd_source == src_command)
1564 if (cl_pmodel.integer == i)
1566 Cvar_SetValue ("_cl_pmodel", i);
1567 if (cls.state == ca_connected)
1568 Cmd_ForwardToServer ();
1572 host_client->pmodel = i;
1573 if ((val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)))
1578 ======================
1580 ======================
1582 static void CL_Fog_f (void)
1584 if (Cmd_Argc () == 1)
1586 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1589 fog_density = atof(Cmd_Argv(1));
1590 fog_red = atof(Cmd_Argv(2));
1591 fog_green = atof(Cmd_Argv(3));
1592 fog_blue = atof(Cmd_Argv(4));
1602 cl_scores_mempool = Mem_AllocPool("client player info");
1603 cl_entities_mempool = Mem_AllocPool("client entities");
1604 cl_refdef_mempool = Mem_AllocPool("refdef");
1606 memset(&r_refdef, 0, sizeof(r_refdef));
1607 // max entities sent to renderer per frame
1608 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1609 r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1610 // 256k drawqueue buffer
1611 r_refdef.maxdrawqueuesize = 256 * 1024;
1612 r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
1614 SZ_Alloc (&cls.message, 1024, "cls.message");
1620 // register our commands
1622 Cvar_RegisterVariable (&cl_name);
1623 Cvar_RegisterVariable (&cl_color);
1624 if (gamemode == GAME_NEHAHRA)
1625 Cvar_RegisterVariable (&cl_pmodel);
1626 Cvar_RegisterVariable (&cl_upspeed);
1627 Cvar_RegisterVariable (&cl_forwardspeed);
1628 Cvar_RegisterVariable (&cl_backspeed);
1629 Cvar_RegisterVariable (&cl_sidespeed);
1630 Cvar_RegisterVariable (&cl_movespeedkey);
1631 Cvar_RegisterVariable (&cl_yawspeed);
1632 Cvar_RegisterVariable (&cl_pitchspeed);
1633 Cvar_RegisterVariable (&cl_anglespeedkey);
1634 Cvar_RegisterVariable (&cl_shownet);
1635 Cvar_RegisterVariable (&cl_nolerp);
1636 Cvar_RegisterVariable (&lookspring);
1637 Cvar_RegisterVariable (&lookstrafe);
1638 Cvar_RegisterVariable (&sensitivity);
1639 Cvar_RegisterVariable (&freelook);
1641 Cvar_RegisterVariable (&m_pitch);
1642 Cvar_RegisterVariable (&m_yaw);
1643 Cvar_RegisterVariable (&m_forward);
1644 Cvar_RegisterVariable (&m_side);
1646 Cvar_RegisterVariable (&cl_itembobspeed);
1647 Cvar_RegisterVariable (&cl_itembobheight);
1649 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1650 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1651 Cmd_AddCommand ("record", CL_Record_f);
1652 Cmd_AddCommand ("stop", CL_Stop_f);
1653 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1654 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1656 Cmd_AddCommand ("fog", CL_Fog_f);
1658 // LordHavoc: added pausedemo
1659 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1660 if (gamemode == GAME_NEHAHRA)
1661 Cmd_AddCommand ("pmodel", CL_PModel_f);
1663 Cvar_RegisterVariable(&r_draweffects);
1664 Cvar_RegisterVariable(&cl_explosions);
1665 Cvar_RegisterVariable(&cl_stainmaps);
1666 Cvar_RegisterVariable(&cl_beams_polygons);
1667 Cvar_RegisterVariable(&cl_beams_relative);
1668 Cvar_RegisterVariable(&cl_beams_lightatend);
1669 Cvar_RegisterVariable(&cl_noplayershadow);
1671 R_LightningBeams_Init();
1674 CL_Particles_Init();