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 = Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
155 cl_entities_active = Mem_Alloc(cl_mempool, cl_max_brushmodel_entities * sizeof(qbyte));
156 cl_static_entities = Mem_Alloc(cl_mempool, cl_max_static_entities * sizeof(entity_t));
157 cl_temp_entities = Mem_Alloc(cl_mempool, cl_max_temp_entities * sizeof(entity_t));
158 cl_effects = Mem_Alloc(cl_mempool, cl_max_effects * sizeof(cl_effect_t));
159 cl_beams = Mem_Alloc(cl_mempool, cl_max_beams * sizeof(beam_t));
160 cl_dlights = Mem_Alloc(cl_mempool, cl_max_dlights * sizeof(dlight_t));
161 cl_lightstyle = Mem_Alloc(cl_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
162 cl_brushmodel_entities = 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 = 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 if (e->state_current.flags & RENDER_COLORMAPPED)
592 e->render.colormap = e->state_current.colormap;
593 else if (cl.scores != NULL && e->state_current.colormap)
594 e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it
596 e->render.colormap = -1; // no special coloring
597 e->render.skinnum = e->state_current.skin;
598 VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod);
599 if (e->render.flags & RENDER_VIEWMODEL && !e->state_current.tagentity)
601 if (!r_drawviewmodel.integer || chase_active.integer || envmap)
604 CL_LinkNetworkEntity(cl_entities + cl.viewentity);
605 matrix = &viewmodelmatrix;
606 if (e == &cl.viewent && cl_entities[cl.viewentity].state_current.active)
608 e->state_current.alpha = cl_entities[cl.viewentity].state_current.alpha;
609 e->state_current.effects = EF_NOSHADOW | (cl_entities[cl.viewentity].state_current.effects & (EF_ADDITIVE | EF_REFLECTIVE | EF_FULLBRIGHT | EF_NODEPTHTEST));
614 // if the tag entity is currently impossible, skip it
615 if (e->state_current.tagentity >= cl_num_entities)
617 t = cl_entities + e->state_current.tagentity;
618 // if the tag entity is inactive, skip it
619 if (!t->state_current.active)
621 // note: this can link to world
622 CL_LinkNetworkEntity(t);
623 // make relative to the entity
624 matrix = &t->render.matrix;
625 // some properties of the tag entity carry over
626 e->render.flags |= t->render.flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL);
627 // if a valid tagindex is used, make it relative to that tag instead
628 // FIXME: use a model function to get tag info (need to handle skeletal)
629 if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model))
631 // blend the matrices
632 memset(&blendmatrix, 0, sizeof(blendmatrix));
633 for (j = 0;j < 4 && t->render.frameblend[j].lerp > 0;j++)
635 matrix4x4_t tagmatrix;
636 Mod_Alias_GetTagMatrix(model, t->render.frameblend[j].frame, e->state_current.tagindex - 1, &tagmatrix);
637 d = t->render.frameblend[j].lerp;
638 for (l = 0;l < 4;l++)
639 for (k = 0;k < 4;k++)
640 blendmatrix.m[l][k] += d * tagmatrix.m[l][k];
642 // concat the tag matrices onto the entity matrix
643 Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
644 // use the constructed tag matrix
645 matrix = &tempmatrix;
650 // if it's the player entity, update according to client movement
651 if (e == cl_entities + cl.playerentity && cl.movement)
653 lerp = (cl.time - cl.mtime[1]) / (cl.mtime[0] - cl.mtime[1]);
654 lerp = bound(0, lerp, 1);
655 VectorLerp(cl.movement_oldorigin, lerp, cl.movement_origin, origin);
656 VectorSet(angles, 0, cl.viewangles[1], 0);
658 else if (e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
660 // interpolate the origin and angles
661 VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin);
662 VectorSubtract(e->persistent.newangles, e->persistent.oldangles, delta);
663 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
664 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
665 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
666 VectorMA(e->persistent.oldangles, lerp, delta, angles);
671 VectorCopy(e->persistent.neworigin, origin);
672 VectorCopy(e->persistent.newangles, angles);
675 // model setup and some modelflags
676 e->render.model = cl.model_precache[e->state_current.modelindex];
679 Mod_CheckLoaded(e->render.model);
680 // if model is alias or this is a tenebrae-like dlight, reverse pitch direction
681 if (e->render.model->type == mod_alias || (e->state_current.lightpflags & PFLAGS_FULLDYNAMIC))
682 angles[0] = -angles[0];
683 if ((e->render.model->flags & EF_ROTATE) && (!e->state_current.tagentity && !(e->render.flags & RENDER_VIEWMODEL)))
685 angles[1] = ANGLEMOD(100*cl.time);
686 if (cl_itembobheight.value)
687 origin[2] += (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
689 // transfer certain model flags to effects
690 e->render.effects |= e->render.model->flags2 & (EF_FULLBRIGHT | EF_ADDITIVE);
691 if (cl_prydoncursor.integer && (e->render.effects & EF_SELECTABLE) && cl.cmd.cursor_entitynumber == e->state_current.number)
692 VectorScale(e->render.colormod, 2, e->render.colormod);
696 if (e->render.frame2 == e->state_current.frame)
698 // update frame lerp fraction
699 e->render.framelerp = 1;
700 if (e->render.frame2time > e->render.frame1time)
702 // make sure frame lerp won't last longer than 100ms
703 // (this mainly helps with models that use framegroups and
704 // switch between them infrequently)
705 e->render.framelerp = (cl.time - e->render.frame2time) / min(e->render.frame2time - e->render.frame1time, 0.1);
706 e->render.framelerp = bound(0, e->render.framelerp, 1);
711 // begin a new frame lerp
712 e->render.frame1 = e->render.frame2;
713 e->render.frame1time = e->render.frame2time;
714 e->render.frame = e->render.frame2 = e->state_current.frame;
715 e->render.frame2time = cl.time;
716 e->render.framelerp = 0;
718 R_LerpAnimation(&e->render);
720 // set up the render matrix
721 // FIXME: e->render.scale should go away
722 Matrix4x4_CreateFromQuakeEntity(&matrix2, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale);
723 // concat the matrices to make the entity relative to its tag
724 Matrix4x4_Concat(&e->render.matrix, matrix, &matrix2);
725 // make the other useful stuff
726 Matrix4x4_Invert_Simple(&e->render.inversematrix, &e->render.matrix);
727 CL_BoundingBoxForEntity(&e->render);
729 // handle effects now that we know where this entity is in the world...
730 if (e->render.model && e->render.model->soundfromcenter)
732 // bmodels are treated specially since their origin is usually '0 0 0'
734 VectorMAM(0.5f, e->render.model->normalmins, 0.5f, e->render.model->normalmaxs, o);
735 Matrix4x4_Transform(&e->render.matrix, o, origin);
739 origin[0] = e->render.matrix.m[0][3];
740 origin[1] = e->render.matrix.m[1][3];
741 origin[2] = e->render.matrix.m[2][3];
748 // LordHavoc: if the entity has no effects, don't check each
749 if (e->render.effects)
751 if (e->render.effects & EF_BRIGHTFIELD)
753 if (gamemode == GAME_NEXUIZ)
755 dlightradius = max(dlightradius, 200);
756 dlightcolor[0] += 0.75f;
757 dlightcolor[1] += 1.50f;
758 dlightcolor[2] += 3.00f;
762 CL_EntityParticles(e);
764 if (e->render.effects & EF_MUZZLEFLASH)
765 e->persistent.muzzleflash = 1.0f;
766 if (e->render.effects & EF_DIMLIGHT)
768 dlightradius = max(dlightradius, 200);
769 dlightcolor[0] += 1.50f;
770 dlightcolor[1] += 1.50f;
771 dlightcolor[2] += 1.50f;
773 if (e->render.effects & EF_BRIGHTLIGHT)
775 dlightradius = max(dlightradius, 400);
776 dlightcolor[0] += 3.00f;
777 dlightcolor[1] += 3.00f;
778 dlightcolor[2] += 3.00f;
780 // LordHavoc: more effects
781 if (e->render.effects & EF_RED) // red
783 dlightradius = max(dlightradius, 200);
784 dlightcolor[0] += 1.50f;
785 dlightcolor[1] += 0.15f;
786 dlightcolor[2] += 0.15f;
788 if (e->render.effects & EF_BLUE) // blue
790 dlightradius = max(dlightradius, 200);
791 dlightcolor[0] += 0.15f;
792 dlightcolor[1] += 0.15f;
793 dlightcolor[2] += 1.50f;
795 if (e->render.effects & EF_FLAME)
797 mins[0] = origin[0] - 16.0f;
798 mins[1] = origin[1] - 16.0f;
799 mins[2] = origin[2] - 16.0f;
800 maxs[0] = origin[0] + 16.0f;
801 maxs[1] = origin[1] + 16.0f;
802 maxs[2] = origin[2] + 16.0f;
803 // how many flames to make
804 temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
805 CL_FlameCube(mins, maxs, temp);
806 d = lhrandom(0.75f, 1);
807 dlightradius = max(dlightradius, 200);
808 dlightcolor[0] += d * 2.0f;
809 dlightcolor[1] += d * 1.5f;
810 dlightcolor[2] += d * 0.5f;
812 if (e->render.effects & EF_STARDUST)
814 mins[0] = origin[0] - 16.0f;
815 mins[1] = origin[1] - 16.0f;
816 mins[2] = origin[2] - 16.0f;
817 maxs[0] = origin[0] + 16.0f;
818 maxs[1] = origin[1] + 16.0f;
819 maxs[2] = origin[2] + 16.0f;
820 // how many particles to make
821 temp = (int) (cl.time * 200) - (int) (cl.oldtime * 200);
822 CL_Stardust(mins, maxs, temp);
823 dlightradius = max(dlightradius, 200);
824 dlightcolor[0] += 1.0f;
825 dlightcolor[1] += 0.7f;
826 dlightcolor[2] += 0.3f;
829 // muzzleflash fades over time, and is offset a bit
830 if (e->persistent.muzzleflash > 0)
832 Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
833 trace = CL_TraceBox(origin, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
834 tempmatrix = e->render.matrix;
835 tempmatrix.m[0][3] = trace.endpos[0];
836 tempmatrix.m[1][3] = trace.endpos[1];
837 tempmatrix.m[2][3] = trace.endpos[2];
838 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);
839 e->persistent.muzzleflash -= cl.frametime * 10;
841 // LordHavoc: if the model has no flags, don't check each
842 if (e->render.model && e->render.model->flags && (!e->state_current.tagentity && !(e->render.flags & RENDER_VIEWMODEL)))
844 if (e->render.model->flags & EF_GIB)
846 else if (e->render.model->flags & EF_ZOMGIB)
848 else if (e->render.model->flags & EF_TRACER)
851 dlightradius = max(dlightradius, 100);
852 dlightcolor[0] += 0.25f;
853 dlightcolor[1] += 1.00f;
854 dlightcolor[2] += 0.25f;
856 else if (e->render.model->flags & EF_TRACER2)
859 dlightradius = max(dlightradius, 100);
860 dlightcolor[0] += 1.00f;
861 dlightcolor[1] += 0.60f;
862 dlightcolor[2] += 0.20f;
864 else if (e->render.model->flags & EF_ROCKET)
867 dlightradius = max(dlightradius, 200);
868 dlightcolor[0] += 3.00f;
869 dlightcolor[1] += 1.50f;
870 dlightcolor[2] += 0.50f;
872 else if (e->render.model->flags & EF_GRENADE)
874 // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
875 trailtype = e->render.alpha == -1 ? 7 : 1;
877 else if (e->render.model->flags & EF_TRACER3)
880 if (gamemode == GAME_PRYDON)
882 dlightradius = max(dlightradius, 100);
883 dlightcolor[0] += 0.30f;
884 dlightcolor[1] += 0.60f;
885 dlightcolor[2] += 1.20f;
889 dlightradius = max(dlightradius, 200);
890 dlightcolor[0] += 1.20f;
891 dlightcolor[1] += 0.50f;
892 dlightcolor[2] += 1.00f;
896 // LordHavoc: customizable glow
897 if (e->state_current.glowsize)
899 // * 4 for the expansion from 0-255 to 0-1023 range,
900 // / 255 to scale down byte colors
901 dlightradius = max(dlightradius, e->state_current.glowsize * 4);
902 VectorMA(dlightcolor, (1.0f / 255.0f), (qbyte *)&palette_complete[e->state_current.glowcolor], dlightcolor);
904 // make the glow dlight
905 if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL))
907 //dlightmatrix = e->render.matrix;
908 // hack to make glowing player light shine on their gun
909 //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
910 // dlightmatrix.m[2][3] += 30;
911 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);
914 if (e->state_current.lightpflags & PFLAGS_FULLDYNAMIC)
917 VectorScale(e->state_current.light, (1.0f / 256.0f), light);
918 light[3] = e->state_current.light[3];
919 if (light[0] == 0 && light[1] == 0 && light[2] == 0)
920 VectorSet(light, 1, 1, 1);
923 // FIXME: add ambient/diffuse/specular scales as an extension ontop of TENEBRAE_GFX_DLIGHTS?
924 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);
927 if (e->render.flags & RENDER_GLOWTRAIL)
930 CL_RocketTrail(e->persistent.trail_origin, origin, trailtype, e->state_current.glowcolor, e);
931 VectorCopy(origin, e->persistent.trail_origin);
932 // tenebrae's sprites are all additive mode (weird)
933 if (gamemode == GAME_TENEBRAE && e->render.model && e->render.model->type == mod_sprite)
934 e->render.effects |= EF_ADDITIVE;
935 // player model is only shown with chase_active on
936 if (e->state_current.number == cl.viewentity)
937 e->render.flags |= RENDER_EXTERIORMODEL;
938 // transparent stuff can't be lit during the opaque stage
939 if (e->render.effects & (EF_ADDITIVE | EF_NODEPTHTEST) || e->render.alpha < 1)
940 e->render.flags |= RENDER_TRANSPARENT;
941 // either fullbright or lit
942 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
943 e->render.flags |= RENDER_LIGHT;
944 // hide player shadow during intermission or nehahra movie
945 if (!(e->render.effects & EF_NOSHADOW)
946 && !(e->render.flags & (RENDER_VIEWMODEL | RENDER_TRANSPARENT))
947 && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cl.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer)))
948 e->render.flags |= RENDER_SHADOW;
949 // as soon as player is known we can call V_CalcRefDef
950 if (e->state_current.number == cl.viewentity)
952 if (e->render.model && e->render.model->name[0] == '*' && e->render.model->TraceBox)
953 cl_brushmodel_entities[cl_num_brushmodel_entities++] = e->state_current.number;
954 // don't show entities with no modelindex (note: this still shows
955 // entities which have a modelindex that resolved to a NULL model)
956 if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
957 r_refdef.entities[r_refdef.numentities++] = &e->render;
958 //if (cl.viewentity && e->state_current.number == cl.viewentity)
959 // Matrix4x4_Print(&e->render.matrix);
963 void CL_RelinkWorld(void)
965 entity_t *ent = &cl_entities[0];
966 cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
967 // FIXME: this should be done at load
968 Matrix4x4_CreateIdentity(&ent->render.matrix);
969 Matrix4x4_CreateIdentity(&ent->render.inversematrix);
970 R_LerpAnimation(&ent->render);
971 CL_BoundingBoxForEntity(&ent->render);
972 ent->render.flags = RENDER_SHADOW;
973 if (!r_fullbright.integer)
974 ent->render.flags |= RENDER_LIGHT;
975 VectorSet(ent->render.colormod, 1, 1, 1);
976 r_refdef.worldentity = &ent->render;
977 r_refdef.worldmodel = cl.worldmodel;
980 static void CL_RelinkStaticEntities(void)
984 for (i = 0, e = cl_static_entities;i < cl_num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++, e++)
986 Mod_CheckLoaded(e->render.model);
988 // transparent stuff can't be lit during the opaque stage
989 if (e->render.effects & (EF_ADDITIVE | EF_NODEPTHTEST) || e->render.alpha < 1)
990 e->render.flags |= RENDER_TRANSPARENT;
991 // either fullbright or lit
992 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
993 e->render.flags |= RENDER_LIGHT;
994 // hide player shadow during intermission or nehahra movie
995 if (!(e->render.effects & EF_NOSHADOW) && !(e->render.flags & RENDER_TRANSPARENT))
996 e->render.flags |= RENDER_SHADOW;
997 VectorSet(e->render.colormod, 1, 1, 1);
998 R_LerpAnimation(&e->render);
999 r_refdef.entities[r_refdef.numentities++] = &e->render;
1008 static void CL_RelinkNetworkEntities(void)
1014 ent->state_previous = ent->state_current;
1015 ent->state_current = defaultstate;
1016 ent->state_current.time = cl.time;
1017 ent->state_current.number = -1;
1018 ent->state_current.active = true;
1019 ent->state_current.modelindex = cl.stats[STAT_WEAPON];
1020 ent->state_current.frame = cl.stats[STAT_WEAPONFRAME];
1021 ent->state_current.flags = RENDER_VIEWMODEL;
1022 if ((cl.stats[STAT_HEALTH] <= 0 && cl_deathnoviewmodel.integer) || cl.intermission)
1023 ent->state_current.modelindex = 0;
1024 else if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
1026 if (gamemode == GAME_TRANSFUSION)
1027 ent->state_current.alpha = 128;
1029 ent->state_current.modelindex = 0;
1032 // reset animation interpolation on weaponmodel if model changed
1033 if (ent->state_previous.modelindex != ent->state_current.modelindex)
1035 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
1036 ent->render.frame1time = ent->render.frame2time = cl.time;
1037 ent->render.framelerp = 1;
1040 // start on the entity after the world
1041 entitylinkframenumber++;
1042 for (i = 1;i < cl_num_entities;i++)
1044 if (cl_entities_active[i])
1046 ent = cl_entities + i;
1047 if (ent->state_current.active)
1048 CL_LinkNetworkEntity(ent);
1050 cl_entities_active[i] = false;
1053 CL_LinkNetworkEntity(&cl.viewent);
1056 static void CL_RelinkEffects(void)
1063 for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
1067 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
1069 if (intframe < 0 || intframe >= e->endframe)
1071 memset(e, 0, sizeof(*e));
1075 if (intframe != e->frame)
1077 e->frame = intframe;
1078 e->frame1time = e->frame2time;
1079 e->frame2time = cl.time;
1082 // if we're drawing effects, get a new temp entity
1083 // (NewTempEntity adds it to the render entities list for us)
1084 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
1086 // interpolation stuff
1087 ent->render.frame1 = intframe;
1088 ent->render.frame2 = intframe + 1;
1089 if (ent->render.frame2 >= e->endframe)
1090 ent->render.frame2 = -1; // disappear
1091 ent->render.framelerp = frame - intframe;
1092 ent->render.frame1time = e->frame1time;
1093 ent->render.frame2time = e->frame2time;
1096 ent->render.model = cl.model_precache[e->modelindex];
1097 ent->render.frame = ent->render.frame2;
1098 ent->render.colormap = -1; // no special coloring
1099 ent->render.alpha = 1;
1100 VectorSet(ent->render.colormod, 1, 1, 1);
1102 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
1103 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1104 R_LerpAnimation(&ent->render);
1105 CL_BoundingBoxForEntity(&ent->render);
1111 void CL_RelinkBeams(void)
1120 matrix4x4_t tempmatrix;
1122 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
1124 if (!b->model || b->endtime < cl.time)
1127 // if coming from the player, update the start position
1128 //if (b->entity == cl.viewentity)
1129 // VectorCopy (cl_entities[cl.viewentity].render.origin, b->start);
1130 if (cl_beams_relative.integer && b->entity == cl.viewentity && b->entity && cl_entities[b->entity].state_current.active && b->relativestartvalid)
1132 entity_state_t *p = &cl_entities[b->entity].state_previous;
1133 //entity_state_t *c = &cl_entities[b->entity].state_current;
1134 entity_render_t *r = &cl_entities[b->entity].render;
1135 matrix4x4_t matrix, imatrix;
1136 if (b->relativestartvalid == 2)
1138 // not really valid yet, we need to get the orientation now
1139 // (ParseBeam flagged this because it is received before
1140 // entities are received, by now they have been received)
1141 // note: because players create lightning in their think
1142 // function (which occurs before movement), they actually
1143 // have some lag in it's location, so compare to the
1144 // previous player state, not the latest
1145 if (b->entity == cl.viewentity)
1146 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
1148 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2] + 16, p->angles[0], p->angles[1], p->angles[2], 1);
1149 Matrix4x4_Invert_Simple(&imatrix, &matrix);
1150 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
1151 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
1152 b->relativestartvalid = 1;
1156 if (b->entity == cl.viewentity)
1157 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, cl.viewangles[0], cl.viewangles[1], cl.viewangles[2], 1);
1159 Matrix4x4_CreateFromQuakeEntity(&matrix, r->origin[0], r->origin[1], r->origin[2] + 16, r->angles[0], r->angles[1], r->angles[2], 1);
1160 Matrix4x4_Transform(&matrix, b->relativestart, b->start);
1161 Matrix4x4_Transform(&matrix, b->relativeend, b->end);
1167 if (cl_beams_lightatend.integer)
1169 // FIXME: create a matrix from the beam start/end orientation
1170 Matrix4x4_CreateTranslate(&tempmatrix, b->end[0], b->end[1], b->end[2]);
1171 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);
1173 if (cl_beams_polygons.integer)
1177 // calculate pitch and yaw
1178 VectorSubtract (b->end, b->start, dist);
1180 if (dist[1] == 0 && dist[0] == 0)
1190 yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
1194 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
1195 pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
1200 // add new entities for the lightning
1201 VectorCopy (b->start, org);
1202 d = VectorNormalizeLength(dist);
1205 ent = CL_NewTempEntity ();
1208 //VectorCopy (org, ent->render.origin);
1209 ent->render.model = b->model;
1210 //ent->render.effects = EF_FULLBRIGHT;
1211 //ent->render.angles[0] = pitch;
1212 //ent->render.angles[1] = yaw;
1213 //ent->render.angles[2] = rand()%360;
1214 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1215 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
1216 R_LerpAnimation(&ent->render);
1217 CL_BoundingBoxForEntity(&ent->render);
1218 VectorMA(org, 30, dist, org);
1224 void CL_LerpPlayer(float frac)
1229 cl.viewzoom = cl.mviewzoom[1] + frac * (cl.mviewzoom[0] - cl.mviewzoom[1]);
1230 for (i = 0;i < 3;i++)
1232 cl.punchangle[i] = cl.mpunchangle[1][i] + frac * (cl.mpunchangle[0][i] - cl.mpunchangle[1][i]);
1233 cl.punchvector[i] = cl.mpunchvector[1][i] + frac * (cl.mpunchvector[0][i] - cl.mpunchvector[1][i]);
1234 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1237 if (cls.demoplayback)
1239 // interpolate the angles
1240 for (i = 0;i < 3;i++)
1242 d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1247 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1256 Read all incoming data from the server
1259 extern void CL_ClientMovement_Replay();
1260 int CL_ReadFromServer(void)
1262 CL_ReadDemoMessage();
1264 r_refdef.time = cl.time;
1265 r_refdef.extraupdate = !r_speeds.integer;
1266 r_refdef.numentities = 0;
1267 Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
1268 cl_num_brushmodel_entities = 0;
1270 if (cls.state == ca_connected && cls.signon == SIGNONS)
1272 // prepare for a new frame
1273 CL_LerpPlayer(CL_LerpPoint());
1275 CL_ClearTempEntities();
1279 // relink network entities (note: this sets up the view!)
1280 CL_ClientMovement_Replay();
1281 CL_RelinkNetworkEntities();
1289 CL_RelinkStaticEntities();
1293 // run cgame code (which can add more entities)
1296 // update view blend
1308 void CL_UpdatePrydonCursor(void);
1309 void CL_SendCmd(void)
1311 if (cls.demoplayback)
1313 SZ_Clear(&cls.message);
1317 // send the reliable message (forwarded commands) if there is one
1318 if (cls.message.cursize && NetConn_CanSendMessage(cls.netcon))
1320 if (developer.integer)
1322 Con_Print("CL_SendCmd: sending reliable message:\n");
1323 SZ_HexDumpToConsole(&cls.message);
1325 if (NetConn_SendReliableMessage(cls.netcon, &cls.message) == -1)
1326 Host_Error("CL_WriteToServer: lost server connection");
1327 SZ_Clear(&cls.message);
1331 // LordHavoc: pausedemo command
1332 static void CL_PauseDemo_f (void)
1334 cls.demopaused = !cls.demopaused;
1336 Con_Print("Demo paused\n");
1338 Con_Print("Demo unpaused\n");
1342 ======================
1344 ======================
1346 static void CL_Fog_f (void)
1348 if (Cmd_Argc () == 1)
1350 Con_Printf("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
1353 fog_density = atof(Cmd_Argv(1));
1354 fog_red = atof(Cmd_Argv(2));
1355 fog_green = atof(Cmd_Argv(3));
1356 fog_blue = atof(Cmd_Argv(4));
1360 ====================
1363 For program optimization
1364 ====================
1366 static void CL_TimeRefresh_f (void)
1369 float timestart, timedelta, oldangles[3];
1371 r_refdef.extraupdate = false;
1372 VectorCopy(cl.viewangles, oldangles);
1373 VectorClear(cl.viewangles);
1375 timestart = Sys_DoubleTime();
1376 for (i = 0;i < 128;i++)
1378 Matrix4x4_CreateFromQuakeEntity(&r_refdef.viewentitymatrix, r_vieworigin[0], r_vieworigin[1], r_vieworigin[2], 0, i / 128.0 * 360.0, 0, 1);
1381 timedelta = Sys_DoubleTime() - timestart;
1383 VectorCopy(oldangles, cl.viewangles);
1384 Con_Printf("%f seconds (%f fps)\n", timedelta, 128/timedelta);
1392 void CL_Shutdown (void)
1395 CL_Particles_Shutdown();
1396 CL_Parse_Shutdown();
1398 Mem_FreePool (&cl_mempool);
1408 cl_mempool = Mem_AllocPool("client", 0, NULL);
1410 memset(&r_refdef, 0, sizeof(r_refdef));
1411 // max entities sent to renderer per frame
1412 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
1413 r_refdef.entities = Mem_Alloc(cl_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
1414 // 256k drawqueue buffer
1415 r_refdef.maxdrawqueuesize = 256 * 1024;
1416 r_refdef.drawqueue = Mem_Alloc(cl_mempool, r_refdef.maxdrawqueuesize);
1418 cls.message.data = cls.message_buf;
1419 cls.message.maxsize = sizeof(cls.message_buf);
1420 cls.message.cursize = 0;
1425 // register our commands
1427 Cvar_RegisterVariable (&cl_upspeed);
1428 Cvar_RegisterVariable (&cl_forwardspeed);
1429 Cvar_RegisterVariable (&cl_backspeed);
1430 Cvar_RegisterVariable (&cl_sidespeed);
1431 Cvar_RegisterVariable (&cl_movespeedkey);
1432 Cvar_RegisterVariable (&cl_yawspeed);
1433 Cvar_RegisterVariable (&cl_pitchspeed);
1434 Cvar_RegisterVariable (&cl_anglespeedkey);
1435 Cvar_RegisterVariable (&cl_shownet);
1436 Cvar_RegisterVariable (&cl_nolerp);
1437 Cvar_RegisterVariable (&lookspring);
1438 Cvar_RegisterVariable (&lookstrafe);
1439 Cvar_RegisterVariable (&sensitivity);
1440 Cvar_RegisterVariable (&freelook);
1442 Cvar_RegisterVariable (&m_pitch);
1443 Cvar_RegisterVariable (&m_yaw);
1444 Cvar_RegisterVariable (&m_forward);
1445 Cvar_RegisterVariable (&m_side);
1447 Cvar_RegisterVariable (&cl_itembobspeed);
1448 Cvar_RegisterVariable (&cl_itembobheight);
1450 Cmd_AddCommand ("entities", CL_PrintEntities_f);
1451 Cmd_AddCommand ("disconnect", CL_Disconnect_f);
1452 Cmd_AddCommand ("record", CL_Record_f);
1453 Cmd_AddCommand ("stop", CL_Stop_f);
1454 Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
1455 Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
1457 Cmd_AddCommand ("fog", CL_Fog_f);
1459 // LordHavoc: added pausedemo
1460 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
1462 Cvar_RegisterVariable(&r_draweffects);
1463 Cvar_RegisterVariable(&cl_explosions_alpha_start);
1464 Cvar_RegisterVariable(&cl_explosions_alpha_end);
1465 Cvar_RegisterVariable(&cl_explosions_size_start);
1466 Cvar_RegisterVariable(&cl_explosions_size_end);
1467 Cvar_RegisterVariable(&cl_explosions_lifetime);
1468 Cvar_RegisterVariable(&cl_stainmaps);
1469 Cvar_RegisterVariable(&cl_stainmaps_clearonload);
1470 Cvar_RegisterVariable(&cl_beams_polygons);
1471 Cvar_RegisterVariable(&cl_beams_relative);
1472 Cvar_RegisterVariable(&cl_beams_lightatend);
1473 Cvar_RegisterVariable(&cl_noplayershadow);
1475 Cvar_RegisterVariable(&cl_prydoncursor);
1477 Cvar_RegisterVariable(&cl_deathnoviewmodel);
1479 Cmd_AddCommand("timerefresh", CL_TimeRefresh_f);
1482 CL_Particles_Init();