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", "0"}; // try 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_alpha_start = {CVAR_SAVE, "cl_explosions_alpha_start", "1.5"};
50 cvar_t cl_explosions_alpha_end = {CVAR_SAVE, "cl_explosions_alpha_end", "0"};
51 cvar_t cl_explosions_size_start = {CVAR_SAVE, "cl_explosions_size_start", "16"};
52 cvar_t cl_explosions_size_end = {CVAR_SAVE, "cl_explosions_size_end", "128"};
53 cvar_t cl_explosions_lifetime = {CVAR_SAVE, "cl_explosions_lifetime", "0.5"};
55 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
56 cvar_t cl_stainmaps_clearonload = {CVAR_SAVE, "cl_stainmaps_clearonload", "1"};
58 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1"};
59 cvar_t cl_beams_relative = {CVAR_SAVE, "cl_beams_relative", "1"};
60 cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0"};
62 cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0"};
64 cvar_t cl_prydoncursor = {0, "cl_prydoncursor", "0"};
66 cvar_t cl_deathnoviewmodel = {0, "cl_deathnoviewmodel", "1"};
68 vec3_t cl_playerstandmins;
69 vec3_t cl_playerstandmaxs;
70 vec3_t cl_playercrouchmins;
71 vec3_t cl_playercrouchmaxs;
73 mempool_t *cl_mempool;
79 int cl_max_static_entities;
80 int cl_max_temp_entities;
84 int cl_max_lightstyle;
85 int cl_max_brushmodel_entities;
87 entity_t *cl_entities;
88 qbyte *cl_entities_active;
89 entity_t *cl_static_entities;
90 entity_t *cl_temp_entities;
91 cl_effect_t *cl_effects;
94 lightstyle_t *cl_lightstyle;
95 int *cl_brushmodel_entities;
98 int cl_num_static_entities;
99 int cl_num_temp_entities;
100 int cl_num_brushmodel_entities;
102 // keep track of quake entities because they need to be killed if they get stale
103 extern int cl_lastquakeentity;
104 extern qbyte cl_isquakeentity[MAX_EDICTS];
107 =====================
110 =====================
112 void CL_ClearState(void)
116 if (cl_entities) Mem_Free(cl_entities);cl_entities = NULL;
117 if (cl_entities_active) Mem_Free(cl_entities_active);cl_entities_active = NULL;
118 if (cl_static_entities) Mem_Free(cl_static_entities);cl_static_entities = NULL;
119 if (cl_temp_entities) Mem_Free(cl_temp_entities);cl_temp_entities = NULL;
120 if (cl_effects) Mem_Free(cl_effects);cl_effects = NULL;
121 if (cl_beams) Mem_Free(cl_beams);cl_beams = NULL;
122 if (cl_dlights) Mem_Free(cl_dlights);cl_dlights = NULL;
123 if (cl_lightstyle) Mem_Free(cl_lightstyle);cl_lightstyle = NULL;
124 if (cl_brushmodel_entities) Mem_Free(cl_brushmodel_entities);cl_brushmodel_entities = NULL;
125 if (cl.entitydatabase) EntityFrame_FreeDatabase(cl.entitydatabase);cl.entitydatabase = NULL;
126 if (cl.entitydatabase4) EntityFrame4_FreeDatabase(cl.entitydatabase4);cl.entitydatabase4 = NULL;
127 if (cl.scores) Mem_Free(cl.scores);cl.scores = NULL;
132 // wipe the entire cl structure
133 memset (&cl, 0, sizeof(cl));
134 // reset the view zoom interpolation
135 cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
137 SZ_Clear (&cls.message);
140 cl_num_static_entities = 0;
141 cl_num_temp_entities = 0;
142 cl_num_brushmodel_entities = 0;
144 // tweak these if the game runs out
145 cl_max_entities = 256;
146 cl_max_static_entities = 256;
147 cl_max_temp_entities = 512;
148 cl_max_effects = 256;
150 cl_max_dlights = MAX_DLIGHTS;
151 cl_max_lightstyle = MAX_LIGHTSTYLES;
152 cl_max_brushmodel_entities = MAX_EDICTS;
154 cl_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
155 cl_entities_active = (qbyte *)Mem_Alloc(cl_mempool, cl_max_brushmodel_entities * sizeof(qbyte));
156 cl_static_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_static_entities * sizeof(entity_t));
157 cl_temp_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_temp_entities * sizeof(entity_t));
158 cl_effects = (cl_effect_t *)Mem_Alloc(cl_mempool, cl_max_effects * sizeof(cl_effect_t));
159 cl_beams = (beam_t *)Mem_Alloc(cl_mempool, cl_max_beams * sizeof(beam_t));
160 cl_dlights = (dlight_t *)Mem_Alloc(cl_mempool, cl_max_dlights * sizeof(dlight_t));
161 cl_lightstyle = (lightstyle_t *)Mem_Alloc(cl_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
162 cl_brushmodel_entities = (int *)Mem_Alloc(cl_mempool, cl_max_brushmodel_entities * sizeof(int));
164 cl_lastquakeentity = 0;
165 memset(cl_isquakeentity, 0, sizeof(cl_isquakeentity));
167 // LordHavoc: have to set up the baseline info for alpha and other stuff
168 for (i = 0;i < cl_max_entities;i++)
170 cl_entities[i].state_baseline = defaultstate;
171 cl_entities[i].state_previous = defaultstate;
172 cl_entities[i].state_current = defaultstate;
175 if (gamemode == GAME_NEXUIZ)
177 VectorSet(cl_playerstandmins, -16, -16, -24);
178 VectorSet(cl_playerstandmaxs, 16, 16, 45);
179 VectorSet(cl_playercrouchmins, -16, -16, -24);
180 VectorSet(cl_playercrouchmaxs, 16, 16, 25);
184 VectorSet(cl_playerstandmins, -16, -16, -24);
185 VectorSet(cl_playerstandmaxs, 16, 16, 24);
186 VectorSet(cl_playercrouchmins, -16, -16, -24);
187 VectorSet(cl_playercrouchmaxs, 16, 16, 24);
191 CL_Particles_Clear();
195 void CL_ExpandEntities(int num)
197 int i, oldmaxentities;
198 entity_t *oldentities;
199 if (num >= cl_max_entities)
202 Sys_Error("CL_ExpandEntities: cl_entities not initialized\n");
203 if (num >= MAX_EDICTS)
204 Host_Error("CL_ExpandEntities: num %i >= %i\n", num, MAX_EDICTS);
205 oldmaxentities = cl_max_entities;
206 oldentities = cl_entities;
207 cl_max_entities = (num & ~255) + 256;
208 cl_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
209 memcpy(cl_entities, oldentities, oldmaxentities * sizeof(entity_t));
210 Mem_Free(oldentities);
211 for (i = oldmaxentities;i < cl_max_entities;i++)
213 cl_entities[i].state_baseline = defaultstate;
214 cl_entities[i].state_previous = defaultstate;
215 cl_entities[i].state_current = defaultstate;
221 =====================
224 Sends a disconnect message to the server
225 This is also called on Host_Error, so it shouldn't cause any errors
226 =====================
228 void CL_Disconnect(void)
230 if (cls.state == ca_dedicated)
233 Con_DPrintf("CL_Disconnect\n");
235 // stop sounds (especially looping!)
238 // clear contents blends
239 cl.cshifts[0].percent = 0;
240 cl.cshifts[1].percent = 0;
241 cl.cshifts[2].percent = 0;
242 cl.cshifts[3].percent = 0;
244 cl.worldmodel = NULL;
246 if (cls.demoplayback)
250 if (cls.demorecording)
253 Con_DPrint("Sending clc_disconnect\n");
254 SZ_Clear(&cls.message);
255 MSG_WriteByte(&cls.message, clc_disconnect);
256 NetConn_SendUnreliableMessage(cls.netcon, &cls.message);
257 SZ_Clear(&cls.message);
258 NetConn_Close(cls.netcon);
261 cls.state = ca_disconnected;
263 cls.demoplayback = cls.timedemo = false;
267 void CL_Disconnect_f(void)
271 Host_ShutdownServer (false);
278 =====================
279 CL_EstablishConnection
281 Host should be either "local" or a net address
282 =====================
284 void CL_EstablishConnection(const char *host)
286 if (cls.state == ca_dedicated)
289 // clear menu's connect error message
290 M_Update_Return_Reason("");
293 // stop demo loop in case this fails
295 NetConn_ClientFrame();
296 NetConn_ServerFrame();
298 if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
300 cls.connect_trying = true;
301 cls.connect_remainingtries = 3;
302 cls.connect_nextsendtime = 0;
303 M_Update_Return_Reason("Trying to connect...");
306 NetConn_ClientFrame();
307 NetConn_ServerFrame();
308 NetConn_ClientFrame();
309 NetConn_ServerFrame();
310 NetConn_ClientFrame();
311 NetConn_ServerFrame();
312 NetConn_ClientFrame();
313 NetConn_ServerFrame();
318 Con_Print("Unable to find a suitable network socket to connect to server.\n");
319 M_Update_Return_Reason("No network");
328 static void CL_PrintEntities_f(void)
334 for (i = 0, ent = cl_entities;i < cl_num_entities;i++, ent++)
336 if (!ent->state_current.active)
339 if (ent->render.model)
340 strlcpy (name, ent->render.model->name, 25);
342 strcpy(name, "--no model--");
343 for (j = (int)strlen(name);j < 25;j++)
345 Con_Printf("%3i: %s:%4i (%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);
349 //static const vec3_t nomodelmins = {-16, -16, -16};
350 //static const vec3_t nomodelmaxs = {16, 16, 16};
351 void CL_BoundingBoxForEntity(entity_render_t *ent)
355 //if (ent->angles[0] || ent->angles[2])
356 if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
359 ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
360 ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
361 ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
362 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
363 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
364 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
365 //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
366 //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
368 //else if (ent->angles[1])
369 else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
372 ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
373 ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
374 ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
375 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
376 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
377 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
378 //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
379 //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
383 ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
384 ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
385 ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
386 ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
387 ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
388 ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
389 //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
390 //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
395 ent->mins[0] = ent->matrix.m[0][3] - 16;
396 ent->mins[1] = ent->matrix.m[1][3] - 16;
397 ent->mins[2] = ent->matrix.m[2][3] - 16;
398 ent->maxs[0] = ent->matrix.m[0][3] + 16;
399 ent->maxs[1] = ent->matrix.m[1][3] + 16;
400 ent->maxs[2] = ent->matrix.m[2][3] + 16;
401 //VectorAdd(ent->origin, nomodelmins, ent->mins);
402 //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
410 Determines the fraction between the last two messages that the objects
414 static float CL_LerpPoint(void)
418 // dropped packet, or start of demo
419 if (cl.mtime[1] < cl.mtime[0] - 0.1)
420 cl.mtime[1] = cl.mtime[0] - 0.1;
422 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
424 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
425 f = cl.mtime[0] - cl.mtime[1];
426 if (!f || cl_nolerp.integer || cls.timedemo || cl.islocalgame)
428 cl.time = cl.mtime[0];
432 f = (cl.time - cl.mtime[1]) / f;
433 return bound(0, f, 1);
436 void CL_ClearTempEntities (void)
438 cl_num_temp_entities = 0;
441 entity_t *CL_NewTempEntity(void)
445 if (r_refdef.numentities >= r_refdef.maxentities)
447 if (cl_num_temp_entities >= cl_max_temp_entities)
449 ent = &cl_temp_entities[cl_num_temp_entities++];
450 memset (ent, 0, sizeof(*ent));
451 r_refdef.entities[r_refdef.numentities++] = &ent->render;
453 ent->render.colormap = -1; // no special coloring
454 ent->render.scale = 1;
455 ent->render.alpha = 1;
456 VectorSet(ent->render.colormod, 1, 1, 1);
460 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
464 if (!modelindex) // sanity check
466 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
471 VectorCopy(org, e->origin);
472 e->modelindex = modelindex;
473 e->starttime = cl.time;
474 e->startframe = startframe;
475 e->endframe = startframe + framecount;
476 e->framerate = framerate;
479 e->frame1time = cl.time;
480 e->frame2time = cl.time;
485 void CL_AllocDlight(entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, int cubemapnum, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags)
491 // first look for an exact key match
495 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
501 // then look for anything else
503 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
507 // unable to find one
511 //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
512 memset (dl, 0, sizeof(*dl));
513 dl->matrix = *matrix;
515 dl->origin[0] = dl->matrix.m[0][3];
516 dl->origin[1] = dl->matrix.m[1][3];
517 dl->origin[2] = dl->matrix.m[2][3];
518 CL_FindNonSolidLocation(dl->origin, dl->origin, 6);
519 dl->matrix.m[0][3] = dl->origin[0];
520 dl->matrix.m[1][3] = dl->origin[1];
521 dl->matrix.m[2][3] = dl->origin[2];
524 dl->color[1] = green;
528 dl->die = cl.time + lifetime;
531 dl->cubemapnum = cubemapnum;
533 dl->shadow = shadowenable;
536 dl->coronasizescale = coronasizescale;
537 dl->ambientscale = ambientscale;
538 dl->diffusescale = diffusescale;
539 dl->specularscale = specularscale;
542 void CL_DecayLights(void)
548 time = cl.time - cl.oldtime;
549 for (i = 0, dl = cl_dlights;i < MAX_DLIGHTS;i++, dl++)
551 dl->radius = (cl.time < dl->die) ? max(0, dl->radius - time * dl->decay) : 0;
554 #define MAXVIEWMODELS 32
555 entity_t *viewmodels[MAXVIEWMODELS];
558 matrix4x4_t viewmodelmatrix;
560 static int entitylinkframenumber;
562 static const vec3_t muzzleflashorigin = {18, 0, 0};
564 extern void V_DriftPitch(void);
565 extern void V_FadeViewFlashs(void);
566 extern void V_CalcViewBlend(void);
568 extern void V_CalcRefdef(void);
569 // note this is a recursive function, but it can never get in a runaway loop (because of the delayedlink flags)
570 void CL_LinkNetworkEntity(entity_t *e)
572 matrix4x4_t *matrix, blendmatrix, tempmatrix, matrix2;
573 //matrix4x4_t dlightmatrix;
574 int j, k, l, trailtype, temp;
575 float origin[3], angles[3], delta[3], lerp, dlightcolor[3], dlightradius, mins[3], maxs[3], v2[3], d;
579 //entity_persistent_t *p = &e->persistent;
580 //entity_render_t *r = &e->render;
581 if (e->persistent.linkframe != entitylinkframenumber)
583 e->persistent.linkframe = entitylinkframenumber;
584 // skip inactive entities and world
585 if (!e->state_current.active || e == cl_entities)
587 e->render.alpha = e->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
588 e->render.scale = e->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
589 e->render.flags = e->state_current.flags;
590 e->render.effects = e->state_current.effects;
591 VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod);
592 if (e->state_current.flags & RENDER_COLORMAPPED)
596 e->render.colormap = e->state_current.colormap;
597 cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
598 cbcolor = (qbyte *) (&palette_complete[cb]);
599 e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0];
600 e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1];
601 e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2];
602 cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
603 cbcolor = (qbyte *) (&palette_complete[cb]);
604 e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0];
605 e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1];
606 e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2];
608 else if (e->state_current.colormap && cl.scores != NULL)
612 e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it
613 cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
614 cbcolor = (qbyte *) (&palette_complete[cb]);
615 e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0];
616 e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1];
617 e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2];
618 cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
619 cbcolor = (qbyte *) (&palette_complete[cb]);
620 e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0];
621 e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1];
622 e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2];
626 e->render.colormap = -1; // no special coloring
627 VectorClear(e->render.colormap_pantscolor);
628 VectorClear(e->render.colormap_shirtcolor);
630 e->render.skinnum = e->state_current.skin;
631 if (e->render.flags & RENDER_VIEWMODEL && !e->state_current.tagentity)
633 if (!r_drawviewmodel.integer || chase_active.integer || envmap)
636 CL_LinkNetworkEntity(cl_entities + cl.viewentity);
637 matrix = &viewmodelmatrix;
638 if (e == &cl.viewent && cl_entities[cl.viewentity].state_current.active)
640 e->state_current.alpha = cl_entities[cl.viewentity].state_current.alpha;
641 e->state_current.effects = EF_NOSHADOW | (cl_entities[cl.viewentity].state_current.effects & (EF_ADDITIVE | EF_REFLECTIVE | EF_FULLBRIGHT | EF_NODEPTHTEST));
646 // if the tag entity is currently impossible, skip it
647 if (e->state_current.tagentity >= cl_num_entities)
649 t = cl_entities + e->state_current.tagentity;
650 // if the tag entity is inactive, skip it
651 if (!t->state_current.active)
653 // note: this can link to world
654 CL_LinkNetworkEntity(t);
655 // make relative to the entity
656 matrix = &t->render.matrix;
657 // some properties of the tag entity carry over
658 e->render.flags |= t->render.flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL);
659 // if a valid tagindex is used, make it relative to that tag instead
660 // FIXME: use a model function to get tag info (need to handle skeletal)
661 if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model))
663 // blend the matrices
664 memset(&blendmatrix, 0, sizeof(blendmatrix));
665 for (j = 0;j < 4 && t->render.frameblend[j].lerp > 0;j++)
667 matrix4x4_t tagmatrix;
668 Mod_Alias_GetTagMatrix(model, t->render.frameblend[j].frame, e->state_current.tagindex - 1, &tagmatrix);
669 d = t->render.frameblend[j].lerp;
670 for (l = 0;l < 4;l++)
671 for (k = 0;k < 4;k++)
672 blendmatrix.m[l][k] += d * tagmatrix.m[l][k];
674 // concat the tag matrices onto the entity matrix
675 Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
676 // use the constructed tag matrix
677 matrix = &tempmatrix;
682 // if it's the player entity, update according to client movement
683 if (e == cl_entities + cl.playerentity && cl.movement)
685 lerp = (cl.time - cl.mtime[1]) / (cl.mtime[0] - cl.mtime[1]);
686 lerp = bound(0, lerp, 1);
687 VectorLerp(cl.movement_oldorigin, lerp, cl.movement_origin, origin);
688 VectorSet(angles, 0, cl.viewangles[1], 0);
690 else if (e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
692 // interpolate the origin and angles
693 VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin);
694 VectorSubtract(e->persistent.newangles, e->persistent.oldangles, delta);
695 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
696 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
697 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
698 VectorMA(e->persistent.oldangles, lerp, delta, angles);
703 VectorCopy(e->persistent.neworigin, origin);
704 VectorCopy(e->persistent.newangles, angles);
707 // model setup and some modelflags
708 e->render.model = cl.model_precache[e->state_current.modelindex];
711 // if model is alias or this is a tenebrae-like dlight, reverse pitch direction
712 if (e->render.model->type == mod_alias || (e->state_current.lightpflags & PFLAGS_FULLDYNAMIC))
713 angles[0] = -angles[0];
714 if ((e->render.model->flags & EF_ROTATE) && (!e->state_current.tagentity && !(e->render.flags & RENDER_VIEWMODEL)))
716 angles[1] = ANGLEMOD(100*cl.time);
717 if (cl_itembobheight.value)
718 origin[2] += (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
720 // transfer certain model flags to effects
721 e->render.effects |= e->render.model->flags2 & (EF_FULLBRIGHT | EF_ADDITIVE);
722 if (cl_prydoncursor.integer && (e->render.effects & EF_SELECTABLE) && cl.cmd.cursor_entitynumber == e->state_current.number)
723 VectorScale(e->render.colormod, 2, e->render.colormod);
727 if (e->render.frame2 == e->state_current.frame)
729 // update frame lerp fraction
730 e->render.framelerp = 1;
731 if (e->render.frame2time > e->render.frame1time)
733 // make sure frame lerp won't last longer than 100ms
734 // (this mainly helps with models that use framegroups and
735 // switch between them infrequently)
736 e->render.framelerp = (cl.time - e->render.frame2time) / min(e->render.frame2time - e->render.frame1time, 0.1);
737 e->render.framelerp = bound(0, e->render.framelerp, 1);
742 // begin a new frame lerp
743 e->render.frame1 = e->render.frame2;
744 e->render.frame1time = e->render.frame2time;
745 e->render.frame = e->render.frame2 = e->state_current.frame;
746 e->render.frame2time = cl.time;
747 e->render.framelerp = 0;
749 R_LerpAnimation(&e->render);
751 // set up the render matrix
752 // FIXME: e->render.scale should go away
753 Matrix4x4_CreateFromQuakeEntity(&matrix2, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale);
754 // concat the matrices to make the entity relative to its tag
755 Matrix4x4_Concat(&e->render.matrix, matrix, &matrix2);
756 // make the other useful stuff
757 Matrix4x4_Invert_Simple(&e->render.inversematrix, &e->render.matrix);
758 CL_BoundingBoxForEntity(&e->render);
760 // handle effects now that we know where this entity is in the world...
761 if (e->render.model && e->render.model->soundfromcenter)
763 // bmodels are treated specially since their origin is usually '0 0 0'
765 VectorMAM(0.5f, e->render.model->normalmins, 0.5f, e->render.model->normalmaxs, o);
766 Matrix4x4_Transform(&e->render.matrix, o, origin);
770 origin[0] = e->render.matrix.m[0][3];
771 origin[1] = e->render.matrix.m[1][3];
772 origin[2] = e->render.matrix.m[2][3];
779 // LordHavoc: if the entity has no effects, don't check each
780 if (e->render.effects)
782 if (e->render.effects & EF_BRIGHTFIELD)
784 if (gamemode == GAME_NEXUIZ)
786 dlightradius = max(dlightradius, 200);
787 dlightcolor[0] += 0.75f;
788 dlightcolor[1] += 1.50f;
789 dlightcolor[2] += 3.00f;
793 CL_EntityParticles(e);
795 if (e->render.effects & EF_MUZZLEFLASH)
796 e->persistent.muzzleflash = 1.0f;
797 if (e->render.effects & EF_DIMLIGHT)
799 dlightradius = max(dlightradius, 200);
800 dlightcolor[0] += 1.50f;
801 dlightcolor[1] += 1.50f;
802 dlightcolor[2] += 1.50f;
804 if (e->render.effects & EF_BRIGHTLIGHT)
806 dlightradius = max(dlightradius, 400);
807 dlightcolor[0] += 3.00f;
808 dlightcolor[1] += 3.00f;
809 dlightcolor[2] += 3.00f;
811 // LordHavoc: more effects
812 if (e->render.effects & EF_RED) // red
814 dlightradius = max(dlightradius, 200);
815 dlightcolor[0] += 1.50f;
816 dlightcolor[1] += 0.15f;
817 dlightcolor[2] += 0.15f;
819 if (e->render.effects & EF_BLUE) // blue
821 dlightradius = max(dlightradius, 200);
822 dlightcolor[0] += 0.15f;
823 dlightcolor[1] += 0.15f;
824 dlightcolor[2] += 1.50f;
826 if (e->render.effects & EF_FLAME)
828 mins[0] = origin[0] - 16.0f;
829 mins[1] = origin[1] - 16.0f;
830 mins[2] = origin[2] - 16.0f;
831 maxs[0] = origin[0] + 16.0f;
832 maxs[1] = origin[1] + 16.0f;
833 maxs[2] = origin[2] + 16.0f;
834 // how many flames to make
835 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
836 CL_FlameCube(mins, maxs, temp);
837 d = lhrandom(0.75f, 1);
838 dlightradius = max(dlightradius, 200);
839 dlightcolor[0] += d * 2.0f;
840 dlightcolor[1] += d * 1.5f;
841 dlightcolor[2] += d * 0.5f;
843 if (e->render.effects & EF_STARDUST)
845 mins[0] = origin[0] - 16.0f;
846 mins[1] = origin[1] - 16.0f;
847 mins[2] = origin[2] - 16.0f;
848 maxs[0] = origin[0] + 16.0f;
849 maxs[1] = origin[1] + 16.0f;
850 maxs[2] = origin[2] + 16.0f;
851 // how many particles to make
852 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
853 CL_Stardust(mins, maxs, temp);
854 dlightradius = max(dlightradius, 200);
855 dlightcolor[0] += 1.0f;
856 dlightcolor[1] += 0.7f;
857 dlightcolor[2] += 0.3f;
860 // muzzleflash fades over time, and is offset a bit
861 if (e->persistent.muzzleflash > 0)
863 Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
864 trace = CL_TraceBox(origin, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
865 tempmatrix = e->render.matrix;
866 tempmatrix.m[0][3] = trace.endpos[0];
867 tempmatrix.m[1][3] = trace.endpos[1];
868 tempmatrix.m[2][3] = trace.endpos[2];
869 CL_AllocDlight(NULL, &tempmatrix, 100, e->persistent.muzzleflash, e->persistent.muzzleflash, e->persistent.muzzleflash, 0, 0, 0, -1, true, 0, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
870 e->persistent.muzzleflash -= cl.frametime * 10;
872 // LordHavoc: if the model has no flags, don't check each
873 if (e->render.model && e->render.model->flags && (!e->state_current.tagentity && !(e->render.flags & RENDER_VIEWMODEL)))
875 if (e->render.model->flags & EF_GIB)
877 else if (e->render.model->flags & EF_ZOMGIB)
879 else if (e->render.model->flags & EF_TRACER)
882 dlightradius = max(dlightradius, 100);
883 dlightcolor[0] += 0.25f;
884 dlightcolor[1] += 1.00f;
885 dlightcolor[2] += 0.25f;
887 else if (e->render.model->flags & EF_TRACER2)
890 dlightradius = max(dlightradius, 100);
891 dlightcolor[0] += 1.00f;
892 dlightcolor[1] += 0.60f;
893 dlightcolor[2] += 0.20f;
895 else if (e->render.model->flags & EF_ROCKET)
898 dlightradius = max(dlightradius, 200);
899 dlightcolor[0] += 3.00f;
900 dlightcolor[1] += 1.50f;
901 dlightcolor[2] += 0.50f;
903 else if (e->render.model->flags & EF_GRENADE)
905 // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
906 trailtype = e->render.alpha == -1 ? 7 : 1;
908 else if (e->render.model->flags & EF_TRACER3)
911 if (gamemode == GAME_PRYDON)
913 dlightradius = max(dlightradius, 100);
914 dlightcolor[0] += 0.30f;
915 dlightcolor[1] += 0.60f;
916 dlightcolor[2] += 1.20f;
920 dlightradius = max(dlightradius, 200);
921 dlightcolor[0] += 1.20f;
922 dlightcolor[1] += 0.50f;
923 dlightcolor[2] += 1.00f;
927 // LordHavoc: customizable glow
928 if (e->state_current.glowsize)
930 // * 4 for the expansion from 0-255 to 0-1023 range,
931 // / 255 to scale down byte colors
932 dlightradius = max(dlightradius, e->state_current.glowsize * 4);
933 VectorMA(dlightcolor, (1.0f / 255.0f), (qbyte *)&palette_complete[e->state_current.glowcolor], dlightcolor);
935 // make the glow dlight
936 if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL))
938 //dlightmatrix = e->render.matrix;
939 // hack to make glowing player light shine on their gun
940 //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
941 // dlightmatrix.m[2][3] += 30;
942 CL_AllocDlight(&e->render, &e->render.matrix, dlightradius, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
945 if (e->state_current.lightpflags & PFLAGS_FULLDYNAMIC)
948 VectorScale(e->state_current.light, (1.0f / 256.0f), light);
949 light[3] = e->state_current.light[3];
950 if (light[0] == 0 && light[1] == 0 && light[2] == 0)
951 VectorSet(light, 1, 1, 1);
954 // FIXME: add ambient/diffuse/specular scales as an extension ontop of TENEBRAE_GFX_DLIGHTS?
955 CL_AllocDlight(&e->render, &e->render.matrix, light[3], light[0], light[1], light[2], 0, 0, e->state_current.skin, e->state_current.lightstyle, !(e->state_current.lightpflags & PFLAGS_NOSHADOW), (e->state_current.lightpflags & PFLAGS_CORONA) != 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
958 if (e->render.flags & RENDER_GLOWTRAIL)
961 CL_RocketTrail(e->persistent.trail_origin, origin, trailtype, e->state_current.glowcolor, e);
962 VectorCopy(origin, e->persistent.trail_origin);
963 // tenebrae's sprites are all additive mode (weird)
964 if (gamemode == GAME_TENEBRAE && e->render.model && e->render.model->type == mod_sprite)
965 e->render.effects |= EF_ADDITIVE;
966 // player model is only shown with chase_active on
967 if (e->state_current.number == cl.viewentity)
968 e->render.flags |= RENDER_EXTERIORMODEL;
969 // transparent stuff can't be lit during the opaque stage
970 if (e->render.effects & (EF_ADDITIVE | EF_NODEPTHTEST) || e->render.alpha < 1)
971 e->render.flags |= RENDER_TRANSPARENT;
972 // either fullbright or lit
973 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
974 e->render.flags |= RENDER_LIGHT;
975 // hide player shadow during intermission or nehahra movie
976 if (!(e->render.effects & EF_NOSHADOW)
977 && !(e->render.flags & (RENDER_VIEWMODEL | RENDER_TRANSPARENT))
978 && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cl.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer)))
979 e->render.flags |= RENDER_SHADOW;
980 // as soon as player is known we can call V_CalcRefDef
981 if (e->state_current.number == cl.viewentity)
983 if (e->render.model && e->render.model->name[0] == '*' && e->render.model->TraceBox)
984 cl_brushmodel_entities[cl_num_brushmodel_entities++] = e->state_current.number;
985 // don't show entities with no modelindex (note: this still shows
986 // entities which have a modelindex that resolved to a NULL model)
987 if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
988 r_refdef.entities[r_refdef.numentities++] = &e->render;
989 //if (cl.viewentity && e->state_current.number == cl.viewentity)
990 // Matrix4x4_Print(&e->render.matrix);
994 void CL_RelinkWorld(void)
996 entity_t *ent = &cl_entities[0];
997 cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
998 // FIXME: this should be done at load
999 Matrix4x4_CreateIdentity(&ent->render.matrix);
1000 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
1001 R_LerpAnimation(&ent->render);
1002 CL_BoundingBoxForEntity(&ent->render);
1003 ent->render.flags = RENDER_SHADOW;
1004 if (!r_fullbright.integer)
1005 ent->render.flags |= RENDER_LIGHT;
1006 VectorSet(ent->render.colormod, 1, 1, 1);
1007 r_refdef.worldentity = &ent->render;
1008 r_refdef.worldmodel = cl.worldmodel;
1011 static void CL_RelinkStaticEntities(void)
1015 for (i = 0, e = cl_static_entities;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++, e++)
1017 e->render.flags = 0;
1018 // transparent stuff can't be lit during the opaque stage
1019 if (e->render.effects & (EF_ADDITIVE | EF_NODEPTHTEST) || e->render.alpha < 1)
1020 e->render.flags |= RENDER_TRANSPARENT;
1021 // either fullbright or lit
1022 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
1023 e->render.flags |= RENDER_LIGHT;
1024 // hide player shadow during intermission or nehahra movie
1025 if (!(e->render.effects & EF_NOSHADOW) && !(e->render.flags & RENDER_TRANSPARENT))
1026 e->render.flags |= RENDER_SHADOW;
1027 VectorSet(e->render.colormod, 1, 1, 1);
1028 R_LerpAnimation(&e->render);
1029 r_refdef.entities[r_refdef.numentities++] = &e->render;
1038 static void CL_RelinkNetworkEntities(void)
1044 ent->state_previous = ent->state_current;
1045 ent->state_current = defaultstate;
1046 ent->state_current.time = cl.time;
1047 ent->state_current.number = -1;
1048 ent->state_current.active = true;
1049 ent->state_current.modelindex = cl.stats[STAT_WEAPON];
1050 ent->state_current.frame = cl.stats[STAT_WEAPONFRAME];
1051 ent->state_current.flags = RENDER_VIEWMODEL;
1052 if ((cl.stats[STAT_HEALTH] <= 0 && cl_deathnoviewmodel.integer) || cl.intermission)
1053 ent->state_current.modelindex = 0;
1054 else if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
1056 if (gamemode == GAME_TRANSFUSION)
1057 ent->state_current.alpha = 128;
1059 ent->state_current.modelindex = 0;
1062 // reset animation interpolation on weaponmodel if model changed
1063 if (ent->state_previous.modelindex != ent->state_current.modelindex)
1065 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
1066 ent->render.frame1time = ent->render.frame2time = cl.time;
1067 ent->render.framelerp = 1;
1070 // start on the entity after the world
1071 entitylinkframenumber++;
1072 for (i = 1;i < cl_num_entities;i++)
1074 if (cl_entities_active[i])
1076 ent = cl_entities + i;
1077 if (ent->state_current.active)
1078 CL_LinkNetworkEntity(ent);
1080 cl_entities_active[i] = false;
1083 CL_LinkNetworkEntity(&cl.viewent);
1086 static void CL_RelinkEffects(void)
1093 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
1097 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
1099 if (intframe < 0 || intframe >= e->endframe)
1101 memset(e, 0, sizeof(*e));
1105 if (intframe != e->frame)
1107 e->frame = intframe;
1108 e->frame1time = e->frame2time;
1109 e->frame2time = cl.time;
1112 // if we're drawing effects, get a new temp entity
1113 // (NewTempEntity adds it to the render entities list for us)
1114 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
1116 // interpolation stuff
1117 ent->render.frame1 = intframe;
1118 ent->render.frame2 = intframe + 1;
1119 if (ent->render.frame2 >= e->endframe)
1120 ent->render.frame2 = -1; // disappear
1121 ent->render.framelerp = frame - intframe;
1122 ent->render.frame1time = e->frame1time;
1123 ent->render.frame2time = e->frame2time;
1126 ent->render.model = cl.model_precache[e->modelindex];
1127 ent->render.frame = ent->render.frame2;
1128 ent->render.colormap = -1; // no special coloring
1129 ent->render.alpha = 1;
1130 VectorSet(ent->render.colormod, 1, 1, 1);
1132 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
1133 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1134 R_LerpAnimation(&ent->render);
1135 CL_BoundingBoxForEntity(&ent->render);
1141 void CL_RelinkBeams(void)
1150 matrix4x4_t tempmatrix;
1152 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1154 if (!b->model || b->endtime < cl.time)
1157 // if coming from the player, update the start position
1158 //if (b->entity == cl.viewentity)
1159 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
1160 if (cl_beams_relative.integer && b->entity == cl.viewentity && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
1162 entity_state_t *p = &cl_entities[b->entity].state_previous;
1163 //entity_state_t *c = &cl_entities[b->entity].state_current;
1164 entity_render_t *r = &cl_entities[b->entity].render;
1165 matrix4x4_t matrix, imatrix;
1166 if (b->relativestartvalid == 2)
1168 // not really valid yet, we need to get the orientation now
1169 // (ParseBeam flagged this because it is received before
1170 // entities are received, by now they have been received)
1171 // note: because players create lightning in their think
1172 // function (which occurs before movement), they actually
1173 // have some lag in it's location, so compare to the
1174 // previous player state, not the latest
1175 if (b->entity == cl.viewentity)
1176 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
1178 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
1179 Matrix4x4_Invert_Simple(&imatrix, &matrix);
1180 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
1181 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
1182 b->relativestartvalid = 1;
1186 if (b->entity == cl.viewentity)
1187 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
1189 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
1190 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
1191 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
1197 if (cl_beams_lightatend.integer)
1199 // FIXME: create a matrix from the beam start/end orientation
1200 Matrix4x4_CreateTranslate(&tempmatrix, b->end[0], b->end[1], b->end[2]);
1201 CL_AllocDlight (NULL, &tempmatrix, 200, 0.3, 0.7, 1, 0, 0, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1203 if (cl_beams_polygons.integer)
1207 // calculate pitch and yaw
1208 VectorSubtract (b->end, b->start, dist);
1210 if (dist[1] == 0 && dist[0] == 0)
1220 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
1224 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
1225 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
1230 // add new entities for the lightning
1231 VectorCopy (b->start, org);
1232 d = VectorNormalizeLength(dist);
1235 ent = CL_NewTempEntity ();
1238 //VectorCopy (org, ent->render.origin);
1239 ent->render.model = b->model;
1240 //ent->render.effects = EF_FULLBRIGHT;
1241 //ent->render.angles[0] = pitch;
1242 //ent->render.angles[1] = yaw;
1243 //ent->render.angles[2] = rand()%360;
1244 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1245 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1246 R_LerpAnimation(&ent->render);
1247 CL_BoundingBoxForEntity(&ent->render);
1248 VectorMA(org, 30, dist, org);
1254 void CL_LerpPlayer(float frac)
1259 cl.viewzoom = cl.mviewzoom[1] + frac * (cl.mviewzoom[0] - cl.mviewzoom[1]);
1260 for (i = 0;i < 3;i++)
1262 cl.punchangle[i] = cl.mpunchangle[1][i] + frac * (cl.mpunchangle[0][i] - cl.mpunchangle[1][i]);
1263 cl.punchvector[i] = cl.mpunchvector[1][i] + frac * (cl.mpunchvector[0][i] - cl.mpunchvector[1][i]);
1264 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1267 if (cls.demoplayback)
1269 // interpolate the angles
1270 for (i = 0;i < 3;i++)
1272 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1277 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1286 Read all incoming data from the server
1289 extern void CL_ClientMovement_Replay();
1290 int CL_ReadFromServer(void)
1292 CL_ReadDemoMessage();
1294 r_refdef.time = cl.time;
1295 r_refdef.extraupdate = !r_speeds.integer;
1296 r_refdef.numentities = 0;
1297 Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
1298 cl_num_brushmodel_entities = 0;
1300 if (cls.state == ca_connected && cls.signon == SIGNONS)
1302 // prepare for a new frame
1303 CL_LerpPlayer(CL_LerpPoint());
1305 CL_ClearTempEntities();
1309 // relink network entities (note: this sets up the view!)
1310 CL_ClientMovement_Replay();
1311 CL_RelinkNetworkEntities();
1319 CL_RelinkStaticEntities();
1323 // run cgame code (which can add more entities)
1326 // update view blend
1338 void CL_UpdatePrydonCursor(void);
1339 void CL_SendCmd(void)
1341 if (cls.demoplayback)
1343 SZ_Clear(&cls.message);
1347 // send the reliable message (forwarded commands) if there is one
1348 if (cls.message.cursize && NetConn_CanSendMessage(cls.netcon))
1350 if (developer.integer)
1352 Con_Print("CL_SendCmd: sending reliable message:\n");
1353 SZ_HexDumpToConsole(&cls.message);
1355 if (NetConn_SendReliableMessage(cls.netcon, &cls.message) == -1)
1356 Host_Error("CL_WriteToServer: lost server connection");
1357 SZ_Clear(&cls.message);
1361 // LordHavoc: pausedemo command
1362 static void CL_PauseDemo_f (void)
1364 cls.demopaused = !cls.demopaused;
1366 Con_Print("Demo paused\n");
1368 Con_Print("Demo unpaused\n");
1372 ======================
1374 ======================
1376 static void CL_Fog_f (void)
1378 if (Cmd_Argc () == 1)
1380 Con_Printf("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1383 fog_density = atof(Cmd_Argv(1));
1384 fog_red = atof(Cmd_Argv(2));
1385 fog_green = atof(Cmd_Argv(3));
1386 fog_blue = atof(Cmd_Argv(4));
1390 ====================
1393 For program optimization
1394 ====================
1396 static void CL_TimeRefresh_f (void)
1399 float timestart, timedelta, oldangles[3];
1401 r_refdef.extraupdate = false;
1402 VectorCopy(cl.viewangles, oldangles);
1403 VectorClear(cl.viewangles);
1405 timestart = Sys_DoubleTime();
1406 for (i = 0;i < 128;i++)
1408 Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, r_vieworigin[0], r_vieworigin[1], r_vieworigin[2], 0, i / 128.0 * 360.0, 0, 1);
1411 timedelta = Sys_DoubleTime() - timestart;
1413 VectorCopy(oldangles, cl.viewangles);
1414 Con_Printf("%f seconds (%f fps)\n", timedelta, 128/timedelta);
1422 void CL_Shutdown (void)
1425 CL_Particles_Shutdown();
1426 CL_Parse_Shutdown();
1428 Mem_FreePool (&cl_mempool);
1438 cl_mempool = Mem_AllocPool("client", 0, NULL);
1440 memset(&r_refdef, 0, sizeof(r_refdef));
1441 // max entities sent to renderer per frame
1442 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1443 r_refdef.entities = (entity_render_t **)Mem_Alloc(cl_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1444 // 256k drawqueue buffer
1445 r_refdef.maxdrawqueuesize = 256 * 1024;
1446 r_refdef.drawqueue = (qbyte *)Mem_Alloc(cl_mempool, r_refdef.maxdrawqueuesize);
1448 cls.message.data = cls.message_buf;
1449 cls.message.maxsize = sizeof(cls.message_buf);
1450 cls.message.cursize = 0;
1455 // register our commands
1457 Cvar_RegisterVariable (&cl_upspeed);
1458 Cvar_RegisterVariable (&cl_forwardspeed);
1459 Cvar_RegisterVariable (&cl_backspeed);
1460 Cvar_RegisterVariable (&cl_sidespeed);
1461 Cvar_RegisterVariable (&cl_movespeedkey);
1462 Cvar_RegisterVariable (&cl_yawspeed);
1463 Cvar_RegisterVariable (&cl_pitchspeed);
1464 Cvar_RegisterVariable (&cl_anglespeedkey);
1465 Cvar_RegisterVariable (&cl_shownet);
1466 Cvar_RegisterVariable (&cl_nolerp);
1467 Cvar_RegisterVariable (&lookspring);
1468 Cvar_RegisterVariable (&lookstrafe);
1469 Cvar_RegisterVariable (&sensitivity);
1470 Cvar_RegisterVariable (&freelook);
1472 Cvar_RegisterVariable (&m_pitch);
1473 Cvar_RegisterVariable (&m_yaw);
1474 Cvar_RegisterVariable (&m_forward);
1475 Cvar_RegisterVariable (&m_side);
1477 Cvar_RegisterVariable (&cl_itembobspeed);
1478 Cvar_RegisterVariable (&cl_itembobheight);
1480 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1481 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1482 Cmd_AddCommand ("record", CL_Record_f);
1483 Cmd_AddCommand ("stop", CL_Stop_f);
1484 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1485 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1487 Cmd_AddCommand ("fog", CL_Fog_f);
1489 // LordHavoc: added pausedemo
1490 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1492 Cvar_RegisterVariable(&r_draweffects);
1493 Cvar_RegisterVariable(&cl_explosions_alpha_start);
1494 Cvar_RegisterVariable(&cl_explosions_alpha_end);
1495 Cvar_RegisterVariable(&cl_explosions_size_start);
1496 Cvar_RegisterVariable(&cl_explosions_size_end);
1497 Cvar_RegisterVariable(&cl_explosions_lifetime);
1498 Cvar_RegisterVariable(&cl_stainmaps);
1499 Cvar_RegisterVariable(&cl_stainmaps_clearonload);
1500 Cvar_RegisterVariable(&cl_beams_polygons);
1501 Cvar_RegisterVariable(&cl_beams_relative);
1502 Cvar_RegisterVariable(&cl_beams_lightatend);
1503 Cvar_RegisterVariable(&cl_noplayershadow);
1505 Cvar_RegisterVariable(&cl_prydoncursor);
1507 Cvar_RegisterVariable(&cl_deathnoviewmodel);
1509 Cmd_AddCommand("timerefresh", CL_TimeRefresh_f);
1512 CL_Particles_Init();