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"
32 // we need to declare some mouse variables here, because the menu system
33 // references them even when on a unix system.
35 cvar_t csqc_progname = {0, "csqc_progname","csprogs.dat","name of csprogs.dat file to load"};
36 cvar_t csqc_progcrc = {CVAR_READONLY, "csqc_progcrc","-1","CRC of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
37 cvar_t csqc_progsize = {CVAR_READONLY, "csqc_progsize","-1","file size of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
39 cvar_t cl_shownet = {0, "cl_shownet","0","1 = print packet size, 2 = print packet message list"};
40 cvar_t cl_nolerp = {0, "cl_nolerp", "0","network update smoothing"};
42 cvar_t cl_itembobheight = {0, "cl_itembobheight", "0","how much items bob up and down (try 8)"};
43 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5","how frequently items bob up and down"};
45 cvar_t lookspring = {CVAR_SAVE, "lookspring","0","returns pitch to level with the floor when no longer holding a pitch key"};
46 cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0","move instead of turning"};
47 cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3","mouse speed multiplier"};
49 cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022","mouse pitch speed multiplier"};
50 cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022","mouse yaw speed multiplier"};
51 cvar_t m_forward = {CVAR_SAVE, "m_forward","1","mouse forward speed multiplier"};
52 cvar_t m_side = {CVAR_SAVE, "m_side","0.8","mouse side speed multiplier"};
54 cvar_t freelook = {CVAR_SAVE, "freelook", "1","mouse controls pitch instead of forward/back"};
56 cvar_t cl_autodemo = {CVAR_SAVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" };
57 cvar_t cl_autodemo_nameformat = {CVAR_SAVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name" };
59 cvar_t r_draweffects = {0, "r_draweffects", "1","renders temporary sprite effects"};
61 cvar_t cl_explosions_alpha_start = {CVAR_SAVE, "cl_explosions_alpha_start", "1.5","starting alpha of an explosion shell"};
62 cvar_t cl_explosions_alpha_end = {CVAR_SAVE, "cl_explosions_alpha_end", "0","end alpha of an explosion shell (just before it disappears)"};
63 cvar_t cl_explosions_size_start = {CVAR_SAVE, "cl_explosions_size_start", "16","starting size of an explosion shell"};
64 cvar_t cl_explosions_size_end = {CVAR_SAVE, "cl_explosions_size_end", "128","ending alpha of an explosion shell (just before it disappears)"};
65 cvar_t cl_explosions_lifetime = {CVAR_SAVE, "cl_explosions_lifetime", "0.5","how long an explosion shell lasts"};
67 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "0","stains lightmaps, much faster than decals but blurred"};
68 cvar_t cl_stainmaps_clearonload = {CVAR_SAVE, "cl_stainmaps_clearonload", "1","clear stainmaps on map restart"};
70 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1","use beam polygons instead of models"};
71 cvar_t cl_beams_quakepositionhack = {CVAR_SAVE, "cl_beams_quakepositionhack", "1", "makes your lightning gun appear to fire from your waist (as in Quake and QuakeWorld)"};
72 cvar_t cl_beams_instantaimhack = {CVAR_SAVE, "cl_beams_instantaimhack", "0", "makes your lightning gun aiming update instantly"};
73 cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0", "make a light at the end of the beam"};
75 cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0","hide player shadow"};
77 cvar_t cl_dlights_decayradius = {CVAR_SAVE, "cl_dlights_decayradius", "1", "reduces size of light flashes over time"};
78 cvar_t cl_dlights_decaybrightness = {CVAR_SAVE, "cl_dlights_decaybrightness", "1", "reduces brightness of light flashes over time"};
80 cvar_t qport = {0, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"};
82 cvar_t cl_prydoncursor = {0, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"};
84 cvar_t cl_deathnoviewmodel = {0, "cl_deathnoviewmodel", "1", "hides gun model when dead"};
86 cvar_t cl_locs_enable = {CVAR_SAVE, "locs_enable", "1", "enables replacement of certain % codes in chat messages: %l (location), %d (last death location), %h (health), %a (armor), %x (rockets), %c (cells), %r (rocket launcher status), %p (powerup status), %w (weapon status), %t (current time in level)"};
87 cvar_t cl_locs_show = {0, "locs_show", "0", "shows defined locations for editing purposes"};
92 #define MAX_PARTICLES 32768 // default max # of particles at one time
93 #define MAX_DECALS 32768 // default max # of decals at one time
94 #define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's on the command line
100 =====================
102 void CL_ClearState(void)
107 // wipe the entire cl structure
108 Mem_EmptyPool(cls.levelmempool);
109 memset (&cl, 0, sizeof(cl));
113 // reset the view zoom interpolation
114 cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
115 cl.sensitivityscale = 1.0f;
117 // enable rendering of the world and such
118 cl.csqc_vidvars.drawworld = true;
119 cl.csqc_vidvars.drawenginesbar = true;
120 cl.csqc_vidvars.drawcrosshair = true;
122 // set up the float version of the stats array for easier access to float stats
123 cl.statsf = (float *)cl.stats;
126 cl.num_static_entities = 0;
127 cl.num_temp_entities = 0;
128 cl.num_brushmodel_entities = 0;
130 // tweak these if the game runs out
131 cl.max_entities = 256;
132 cl.max_static_entities = 256;
133 cl.max_temp_entities = 512;
134 cl.max_effects = 256;
136 cl.max_dlights = MAX_DLIGHTS;
137 cl.max_lightstyle = MAX_LIGHTSTYLES;
138 cl.max_brushmodel_entities = MAX_EDICTS;
139 cl.max_particles = MAX_PARTICLES;
140 cl.max_decals = MAX_DECALS;
143 // COMMANDLINEOPTION: Client: -particles <number> changes maximum number of particles at once, default 32768
144 i = COM_CheckParm ("-particles");
145 if (i && i < com_argc - 1)
147 cl.max_particles = (int)(atoi(com_argv[i+1]));
148 if (cl.max_particles < ABSOLUTE_MIN_PARTICLES)
149 cl.max_particles = ABSOLUTE_MIN_PARTICLES;
156 cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t));
157 cl.entities_active = (unsigned char *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(unsigned char));
158 cl.static_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_static_entities * sizeof(entity_t));
159 cl.temp_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_temp_entities * sizeof(entity_t));
160 cl.effects = (cl_effect_t *)Mem_Alloc(cls.levelmempool, cl.max_effects * sizeof(cl_effect_t));
161 cl.beams = (beam_t *)Mem_Alloc(cls.levelmempool, cl.max_beams * sizeof(beam_t));
162 cl.dlights = (dlight_t *)Mem_Alloc(cls.levelmempool, cl.max_dlights * sizeof(dlight_t));
163 cl.lightstyle = (lightstyle_t *)Mem_Alloc(cls.levelmempool, cl.max_lightstyle * sizeof(lightstyle_t));
164 cl.brushmodel_entities = (int *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(int));
165 cl.particles = (particle_t *) Mem_Alloc(cls.levelmempool, cl.max_particles * sizeof(particle_t));
166 cl.decals = (decal_t *) Mem_Alloc(cls.levelmempool, cl.max_decals * sizeof(decal_t));
169 // LordHavoc: have to set up the baseline info for alpha and other stuff
170 for (i = 0;i < cl.max_entities;i++)
172 cl.entities[i].state_baseline = defaultstate;
173 cl.entities[i].state_previous = defaultstate;
174 cl.entities[i].state_current = defaultstate;
177 if (gamemode == GAME_NEXUIZ)
179 VectorSet(cl.playerstandmins, -16, -16, -24);
180 VectorSet(cl.playerstandmaxs, 16, 16, 45);
181 VectorSet(cl.playercrouchmins, -16, -16, -24);
182 VectorSet(cl.playercrouchmaxs, 16, 16, 25);
186 VectorSet(cl.playerstandmins, -16, -16, -24);
187 VectorSet(cl.playerstandmaxs, 16, 16, 24);
188 VectorSet(cl.playercrouchmins, -16, -16, -24);
189 VectorSet(cl.playercrouchmaxs, 16, 16, 24);
192 // disable until we get textures for it
195 ent = &cl.entities[0];
196 // entire entity array was cleared, so just fill in a few fields
197 ent->state_current.active = true;
198 ent->render.model = cl.worldmodel = NULL; // no world model yet
199 ent->render.alpha = 1;
200 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
201 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
202 CL_UpdateRenderEntity(&ent->render);
204 // noclip is turned off at start
205 noclip_anglehack = false;
207 // mark all frames invalid for delta
208 memset(cl.qw_deltasequence, -1, sizeof(cl.qw_deltasequence));
210 // set bestweapon data back to Quake data
211 IN_BestWeapon_ResetData();
216 void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allowstarkey, qboolean allowmodel, qboolean quiet)
219 qboolean fail = false;
220 if (!allowstarkey && key[0] == '*')
222 if (!allowmodel && (!strcasecmp(key, "pmodel") || !strcasecmp(key, "emodel")))
224 for (i = 0;key[i];i++)
225 if (key[i] <= ' ' || key[i] == '\"')
227 for (i = 0;value[i];i++)
228 if (value[i] == '\r' || value[i] == '\n' || value[i] == '\"')
233 Con_Printf("Can't setinfo \"%s\" \"%s\"\n", key, value);
236 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), key, value);
237 if (cls.state == ca_connected && cls.netcon)
239 if (cls.protocol == PROTOCOL_QUAKEWORLD)
241 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
242 MSG_WriteString(&cls.netcon->message, va("setinfo \"%s\" \"%s\"", key, value));
244 else if (!strcasecmp(key, "name"))
246 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
247 MSG_WriteString(&cls.netcon->message, va("name \"%s\"", value));
249 else if (!strcasecmp(key, "playermodel"))
251 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
252 MSG_WriteString(&cls.netcon->message, va("playermodel \"%s\"", value));
254 else if (!strcasecmp(key, "playerskin"))
256 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
257 MSG_WriteString(&cls.netcon->message, va("playerskin \"%s\"", value));
259 else if (!strcasecmp(key, "topcolor"))
261 // don't send anything, the combined color code will be updated manually
263 else if (!strcasecmp(key, "bottomcolor"))
265 // don't send anything, the combined color code will be updated manually
267 else if (!strcasecmp(key, "rate"))
269 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
270 MSG_WriteString(&cls.netcon->message, va("rate \"%s\"", value));
275 void CL_ExpandEntities(int num)
277 int i, oldmaxentities;
278 entity_t *oldentities;
279 if (num >= cl.max_entities)
282 Sys_Error("CL_ExpandEntities: cl.entities not initialized");
283 if (num >= MAX_EDICTS)
284 Host_Error("CL_ExpandEntities: num %i >= %i", num, MAX_EDICTS);
285 oldmaxentities = cl.max_entities;
286 oldentities = cl.entities;
287 cl.max_entities = (num & ~255) + 256;
288 cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t));
289 memcpy(cl.entities, oldentities, oldmaxentities * sizeof(entity_t));
290 Mem_Free(oldentities);
291 for (i = oldmaxentities;i < cl.max_entities;i++)
293 cl.entities[i].state_baseline = defaultstate;
294 cl.entities[i].state_previous = defaultstate;
295 cl.entities[i].state_current = defaultstate;
300 void CL_VM_ShutDown (void);
302 =====================
305 Sends a disconnect message to the server
306 This is also called on Host_Error, so it shouldn't cause any errors
307 =====================
309 void CL_Disconnect(void)
311 if (cls.state == ca_dedicated)
314 Curl_Clear_forthismap();
316 Con_DPrintf("CL_Disconnect\n");
319 // stop sounds (especially looping!)
322 cl.parsingtextexpectingpingforscores = 0; // just in case no reply has come yet
324 // clear contents blends
325 cl.cshifts[0].percent = 0;
326 cl.cshifts[1].percent = 0;
327 cl.cshifts[2].percent = 0;
328 cl.cshifts[3].percent = 0;
330 cl.worldmodel = NULL;
332 CL_Parse_ErrorCleanUp();
334 if (cls.demoplayback)
339 unsigned char bufdata[8];
340 if (cls.demorecording)
343 // send disconnect message 3 times to improve chances of server
344 // receiving it (but it still fails sometimes)
345 memset(&buf, 0, sizeof(buf));
347 buf.maxsize = sizeof(bufdata);
348 if (cls.protocol == PROTOCOL_QUAKEWORLD)
350 Con_DPrint("Sending drop command\n");
351 MSG_WriteByte(&buf, qw_clc_stringcmd);
352 MSG_WriteString(&buf, "drop");
356 Con_DPrint("Sending clc_disconnect\n");
357 MSG_WriteByte(&buf, clc_disconnect);
359 NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, false);
360 NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, false);
361 NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, false);
362 NetConn_Close(cls.netcon);
365 cls.state = ca_disconnected;
367 cls.demoplayback = cls.timedemo = false;
371 void CL_Disconnect_f(void)
375 Host_ShutdownServer ();
382 =====================
383 CL_EstablishConnection
385 Host should be either "local" or a net address
386 =====================
388 void CL_EstablishConnection(const char *host)
390 if (cls.state == ca_dedicated)
393 // clear menu's connect error message
394 M_Update_Return_Reason("");
397 // stop demo loop in case this fails
398 if (cls.demoplayback)
401 // if downloads are running, cancel their finishing action
402 Curl_Clear_forthismap();
404 // make sure the client ports are open before attempting to connect
405 NetConn_UpdateSockets();
407 // run a network frame
408 //NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
410 if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
412 cls.connect_trying = true;
413 cls.connect_remainingtries = 3;
414 cls.connect_nextsendtime = 0;
415 M_Update_Return_Reason("Trying to connect...");
416 // run several network frames to jump into the game quickly
419 // NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
420 // NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
421 // NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
422 // NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
427 Con_Print("Unable to find a suitable network socket to connect to server.\n");
428 M_Update_Return_Reason("No network");
437 static void CL_PrintEntities_f(void)
442 for (i = 0, ent = cl.entities;i < cl.num_entities;i++, ent++)
444 const char* modelname;
446 if (!ent->state_current.active)
449 if (ent->render.model)
450 modelname = ent->render.model->name;
452 modelname = "--no model--";
453 Con_Printf("%3i: %-25s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, modelname, ent->render.frame2, (int) ent->state_current.origin[0], (int) ent->state_current.origin[1], (int) ent->state_current.origin[2], (int) ent->state_current.angles[0] % 360, (int) ent->state_current.angles[1] % 360, (int) ent->state_current.angles[2] % 360, ent->render.scale, ent->render.alpha);
461 List information on all models in the client modelindex
464 static void CL_ModelIndexList_f(void)
469 Con_Printf("%3s: %-30s %-8s %-8s\n", "ID", "Name", "Type", "Triangles");
471 while(cl.model_precache[i] && i != MAX_MODELS)
473 if(cl.model_precache[i]->loaded || cl.model_precache[i]->isworldmodel)
474 Con_Printf("%3i: %-30s %-8s %-10i\n", i, cl.model_precache[i]->name, cl.model_precache[i]->modeldatatypestring, cl.model_precache[i]->surfmesh.num_triangles);
476 Con_Printf("%3i: %-30s %-30s\n", i, cl.model_precache[i]->name, "--no local model found--");
485 List all sounds in the client soundindex
488 static void CL_SoundIndexList_f(void)
492 while(cl.sound_precache[i] && i != MAX_SOUNDS)
494 Con_Printf("%i : %s\n", i, cl.sound_precache[i]->name);
499 static void CL_UpdateRenderEntity_Lighting(entity_render_t *ent)
501 vec3_t tempdiffusenormal;
503 // fetch the lighting from the worldmodel data
504 VectorSet(ent->modellight_ambient, r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f), r_ambient.value * (2.0f / 128.0f));
505 VectorClear(ent->modellight_diffuse);
506 VectorClear(tempdiffusenormal);
507 if ((ent->flags & RENDER_LIGHT) && cl.worldmodel && cl.worldmodel->brush.LightPoint)
510 Matrix4x4_OriginFromMatrix(&ent->matrix, org);
511 cl.worldmodel->brush.LightPoint(cl.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal);
514 VectorSet(ent->modellight_ambient, 1, 1, 1);
516 // move the light direction into modelspace coordinates for lighting code
517 Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, ent->modellight_lightdir);
518 if(VectorLength2(ent->modellight_lightdir) <= 0)
519 VectorSet(ent->modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here
520 VectorNormalize(ent->modellight_lightdir);
523 //static const vec3_t nomodelmins = {-16, -16, -16};
524 //static const vec3_t nomodelmaxs = {16, 16, 16};
525 void CL_UpdateRenderEntity(entity_render_t *ent)
529 model_t *model = ent->model;
530 // update the inverse matrix for the renderer
531 Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
532 // update the animation blend state
533 R_LerpAnimation(ent);
534 // we need the matrix origin to center the box
535 Matrix4x4_OriginFromMatrix(&ent->matrix, org);
536 // update entity->render.scale because the renderer needs it
537 ent->scale = scale = Matrix4x4_ScaleFromMatrix(&ent->matrix);
540 // NOTE: this directly extracts vector components from the matrix, which relies on the matrix orientation!
541 #ifdef MATRIX4x4_OPENGLORIENTATION
542 if (ent->matrix.m[0][2] != 0 || ent->matrix.m[1][2] != 0)
544 if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
548 VectorMA(org, scale, model->rotatedmins, ent->mins);
549 VectorMA(org, scale, model->rotatedmaxs, ent->maxs);
551 #ifdef MATRIX4x4_OPENGLORIENTATION
552 else if (ent->matrix.m[1][0] != 0 || ent->matrix.m[0][1] != 0)
554 else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
558 VectorMA(org, scale, model->yawmins, ent->mins);
559 VectorMA(org, scale, model->yawmaxs, ent->maxs);
563 VectorMA(org, scale, model->normalmins, ent->mins);
564 VectorMA(org, scale, model->normalmaxs, ent->maxs);
569 ent->mins[0] = org[0] - 16;
570 ent->mins[1] = org[1] - 16;
571 ent->mins[2] = org[2] - 16;
572 ent->maxs[0] = org[0] + 16;
573 ent->maxs[1] = org[1] + 16;
574 ent->maxs[2] = org[2] + 16;
576 CL_UpdateRenderEntity_Lighting(ent);
583 Determines the fraction between the last two messages that the objects
587 static float CL_LerpPoint(void)
591 if (cl_nettimesyncboundmode.integer == 1)
592 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
594 // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
595 if (cl.mtime[0] <= cl.mtime[1])
597 cl.time = cl.mtime[0];
601 f = (cl.time - cl.mtime[1]) / (cl.mtime[0] - cl.mtime[1]);
602 return bound(0, f, 1);
605 void CL_ClearTempEntities (void)
607 cl.num_temp_entities = 0;
610 entity_t *CL_NewTempEntity(void)
614 if (r_refdef.numentities >= r_refdef.maxentities)
616 if (cl.num_temp_entities >= cl.max_temp_entities)
618 ent = &cl.temp_entities[cl.num_temp_entities++];
619 memset (ent, 0, sizeof(*ent));
620 r_refdef.entities[r_refdef.numentities++] = &ent->render;
622 ent->render.alpha = 1;
623 VectorSet(ent->render.colormod, 1, 1, 1);
627 void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate)
631 if (!modelindex) // sanity check
635 Con_Printf("CL_Effect: framerate %f is < 1\n", framerate);
640 Con_Printf("CL_Effect: framecount %i is < 1\n", framecount);
643 for (i = 0, e = cl.effects;i < cl.max_effects;i++, e++)
648 VectorCopy(org, e->origin);
649 e->modelindex = modelindex;
650 e->starttime = cl.time;
651 e->startframe = startframe;
652 e->endframe = startframe + framecount;
653 e->framerate = framerate;
656 e->frame1time = cl.time;
657 e->frame2time = cl.time;
658 cl.num_effects = max(cl.num_effects, i + 1);
663 void CL_AllocLightFlash(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)
669 // first look for an exact key match
673 for (i = 0;i < cl.num_dlights;i++, dl++)
679 // then look for anything else
681 for (i = 0;i < cl.num_dlights;i++, dl++)
684 // if we hit the end of the active dlights and found no gaps, add a new one
687 cl.num_dlights = i + 1;
691 // unable to find one
695 //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
696 memset (dl, 0, sizeof(*dl));
697 Matrix4x4_Normalize(&dl->matrix, matrix);
699 Matrix4x4_OriginFromMatrix(&dl->matrix, dl->origin);
700 CL_FindNonSolidLocation(dl->origin, dl->origin, 6);
701 Matrix4x4_SetOrigin(&dl->matrix, dl->origin[0], dl->origin[1], dl->origin[2]);
704 dl->color[1] = green;
706 dl->initialradius = radius;
707 dl->initialcolor[0] = red;
708 dl->initialcolor[1] = green;
709 dl->initialcolor[2] = blue;
710 dl->decay = decay / radius; // changed decay to be a percentage decrease
711 dl->intensity = 1; // this is what gets decayed
713 dl->die = cl.time + lifetime;
717 dpsnprintf(dl->cubemapname, sizeof(dl->cubemapname), "cubemaps/%i", cubemapnum);
719 dl->cubemapname[0] = 0;
721 dl->shadow = shadowenable;
724 dl->coronasizescale = coronasizescale;
725 dl->ambientscale = ambientscale;
726 dl->diffusescale = diffusescale;
727 dl->specularscale = specularscale;
730 void CL_DecayLightFlashes(void)
736 time = bound(0, cl.time - cl.oldtime, 0.1);
737 oldmax = cl.num_dlights;
739 for (i = 0, dl = cl.dlights;i < oldmax;i++, dl++)
743 dl->intensity -= time * dl->decay;
744 if (cl.time < dl->die && dl->intensity > 0)
746 if (cl_dlights_decayradius.integer)
747 dl->radius = dl->initialradius * dl->intensity;
749 dl->radius = dl->initialradius;
750 if (cl_dlights_decaybrightness.integer)
751 VectorScale(dl->initialcolor, dl->intensity, dl->color);
753 VectorCopy(dl->initialcolor, dl->color);
754 cl.num_dlights = i + 1;
762 // called before entity relinking
763 void CL_RelinkLightFlashes(void)
768 matrix4x4_t tempmatrix;
770 if (r_dynamic.integer)
772 for (i = 0, dl = cl.dlights;i < cl.num_dlights && r_refdef.numlights < MAX_DLIGHTS;i++, dl++)
776 tempmatrix = dl->matrix;
777 Matrix4x4_Scale(&tempmatrix, dl->radius, 1);
778 R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &tempmatrix, dl->color, dl->style, dl->cubemapname, dl->shadow, dl->corona, dl->coronasizescale, dl->ambientscale, dl->diffusescale, dl->specularscale, dl->flags);
784 // 'm' is normal light, 'a' is no light, 'z' is double bright
788 for (j = 0;j < cl.max_lightstyle;j++)
790 if (!cl.lightstyle || !cl.lightstyle[j].length)
792 r_refdef.rtlightstylevalue[j] = 1;
793 r_refdef.lightstylevalue[j] = 256;
796 k = i % cl.lightstyle[j].length;
797 l = (i-1) % cl.lightstyle[j].length;
798 k = cl.lightstyle[j].map[k] - 'a';
799 l = cl.lightstyle[j].map[l] - 'a';
800 // rtlightstylevalue is always interpolated because it has no bad
801 // consequences for performance
802 // lightstylevalue is subject to a cvar for performance reasons;
803 // skipping lightmap updates on most rendered frames substantially
804 // improves framerates (but makes light fades look bad)
805 r_refdef.rtlightstylevalue[j] = ((k*frac)+(l*(1-frac)))*(22/256.0f);
806 r_refdef.lightstylevalue[j] = r_lerplightstyles.integer ? (unsigned short)(((k*frac)+(l*(1-frac)))*22) : k*22;
810 void CL_AddQWCTFFlagModel(entity_t *player, int skin)
814 matrix4x4_t flagmatrix;
816 // this code taken from QuakeWorld
818 if (player->render.frame2 >= 29 && player->render.frame2 <= 40)
820 if (player->render.frame2 >= 29 && player->render.frame2 <= 34)
822 if (player->render.frame2 == 29) f = f + 2;
823 else if (player->render.frame2 == 30) f = f + 8;
824 else if (player->render.frame2 == 31) f = f + 12;
825 else if (player->render.frame2 == 32) f = f + 11;
826 else if (player->render.frame2 == 33) f = f + 10;
827 else if (player->render.frame2 == 34) f = f + 4;
829 else if (player->render.frame2 >= 35 && player->render.frame2 <= 40)
831 if (player->render.frame2 == 35) f = f + 2;
832 else if (player->render.frame2 == 36) f = f + 10;
833 else if (player->render.frame2 == 37) f = f + 10;
834 else if (player->render.frame2 == 38) f = f + 8;
835 else if (player->render.frame2 == 39) f = f + 4;
836 else if (player->render.frame2 == 40) f = f + 2;
839 else if (player->render.frame2 >= 103 && player->render.frame2 <= 118)
841 if (player->render.frame2 >= 103 && player->render.frame2 <= 104) f = f + 6; //nailattack
842 else if (player->render.frame2 >= 105 && player->render.frame2 <= 106) f = f + 6; //light
843 else if (player->render.frame2 >= 107 && player->render.frame2 <= 112) f = f + 7; //rocketattack
844 else if (player->render.frame2 >= 112 && player->render.frame2 <= 118) f = f + 7; //shotattack
846 // end of code taken from QuakeWorld
848 flag = CL_NewTempEntity();
852 flag->render.model = cl.model_precache[cl.qw_modelindex_flag];
853 flag->render.skinnum = skin;
854 flag->render.alpha = 1;
855 VectorSet(flag->render.colormod, 1, 1, 1);
856 // attach the flag to the player matrix
857 Matrix4x4_CreateFromQuakeEntity(&flagmatrix, -f, -22, 0, 0, 0, -45, 1);
858 Matrix4x4_Concat(&flag->render.matrix, &player->render.matrix, &flagmatrix);
859 CL_UpdateRenderEntity(&flag->render);
862 matrix4x4_t viewmodelmatrix;
864 static const vec3_t muzzleflashorigin = {18, 0, 0};
866 extern void V_DriftPitch(void);
867 extern void V_FadeViewFlashs(void);
868 extern void V_CalcViewBlend(void);
869 extern void V_CalcRefdef(void);
871 void CL_SetEntityColormapColors(entity_render_t *ent, int colormap)
873 const unsigned char *cbcolor;
876 cbcolor = palette_rgb_pantscolormap[colormap & 0xF];
877 VectorScale(cbcolor, (1.0f / 255.0f), ent->colormap_pantscolor);
878 cbcolor = palette_rgb_shirtcolormap[(colormap & 0xF0) >> 4];
879 VectorScale(cbcolor, (1.0f / 255.0f), ent->colormap_shirtcolor);
883 VectorClear(ent->colormap_pantscolor);
884 VectorClear(ent->colormap_shirtcolor);
888 // note this is a recursive function, recursionlimit should be 32 or so on the initial call
889 void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolate)
891 const matrix4x4_t *matrix;
892 matrix4x4_t blendmatrix, tempmatrix, matrix2;
894 float origin[3], angles[3], delta[3], lerp, d;
897 //entity_persistent_t *p = &e->persistent;
898 //entity_render_t *r = &e->render;
899 // skip inactive entities and world
900 if (!e->state_current.active || e == cl.entities)
902 if (recursionlimit < 1)
904 e->render.alpha = e->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
905 e->render.scale = e->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
906 e->render.flags = e->state_current.flags;
907 e->render.effects = e->state_current.effects;
908 VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod);
909 e->render.entitynumber = e - cl.entities;
910 if (e->state_current.flags & RENDER_COLORMAPPED)
911 CL_SetEntityColormapColors(&e->render, e->state_current.colormap);
912 else if (e->state_current.colormap > 0 && e->state_current.colormap <= cl.maxclients && cl.scores != NULL)
913 CL_SetEntityColormapColors(&e->render, cl.scores[e->state_current.colormap-1].colors);
915 CL_SetEntityColormapColors(&e->render, -1);
916 e->render.skinnum = e->state_current.skin;
917 if (e->state_current.tagentity)
919 // attached entity (gun held in player model's hand, etc)
920 // if the tag entity is currently impossible, skip it
921 if (e->state_current.tagentity >= cl.num_entities)
923 t = cl.entities + e->state_current.tagentity;
924 // if the tag entity is inactive, skip it
925 if (!t->state_current.active)
927 // update the parent first
928 CL_UpdateNetworkEntity(t, recursionlimit - 1, interpolate);
929 // make relative to the entity
930 matrix = &t->render.matrix;
931 // some properties of the tag entity carry over
932 e->render.flags |= t->render.flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL);
933 // if a valid tagindex is used, make it relative to that tag instead
934 // FIXME: use a model function to get tag info (need to handle skeletal)
935 if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model))
937 // blend the matrices
938 memset(&blendmatrix, 0, sizeof(blendmatrix));
939 for (j = 0;j < 4 && t->render.frameblend[j].lerp > 0;j++)
941 matrix4x4_t tagmatrix;
942 Mod_Alias_GetTagMatrix(model, t->render.frameblend[j].frame, e->state_current.tagindex - 1, &tagmatrix);
943 d = t->render.frameblend[j].lerp;
944 for (l = 0;l < 4;l++)
945 for (k = 0;k < 4;k++)
946 blendmatrix.m[l][k] += d * tagmatrix.m[l][k];
948 // concat the tag matrices onto the entity matrix
949 Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
950 // use the constructed tag matrix
951 matrix = &tempmatrix;
954 else if (e->render.flags & RENDER_VIEWMODEL)
956 // view-relative entity (guns and such)
957 if (e->render.effects & EF_NOGUNBOB)
958 matrix = &r_view.matrix; // really attached to view
960 matrix = &viewmodelmatrix; // attached to gun bob matrix
964 // world-relative entity (the normal kind)
965 matrix = &identitymatrix;
969 // if it's the predicted player entity, update according to client movement
970 // but don't lerp if going through a teleporter as it causes a bad lerp
971 // also don't use the predicted location if fixangle was set on both of
972 // the most recent server messages, as that cause means you are spectating
973 // someone or watching a cutscene of some sort
974 if (cl_nolerp.integer || cls.timedemo)
976 if (e == cl.entities + cl.playerentity && cl.movement_predicted && (!cl.fixangle[1] || !cl.fixangle[0]))
978 lerp = (cl.time - cl.movement_time[2]) / (cl.movement_time[0] - cl.movement_time[1]);
979 lerp = bound(0, lerp, 1);
982 VectorLerp(cl.movement_oldorigin, lerp, cl.movement_origin, origin);
983 VectorSet(angles, 0, cl.viewangles[1], 0);
985 else if (interpolate && e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
987 // interpolate the origin and angles
989 VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin);
990 VectorSubtract(e->persistent.newangles, e->persistent.oldangles, delta);
991 if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360;
992 if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360;
993 if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360;
994 VectorMA(e->persistent.oldangles, lerp, delta, angles);
999 VectorCopy(e->persistent.neworigin, origin);
1000 VectorCopy(e->persistent.newangles, angles);
1003 // model setup and some modelflags
1004 frame = e->state_current.frame;
1005 if (e->state_current.modelindex < MAX_MODELS)
1006 e->render.model = cl.model_precache[e->state_current.modelindex];
1008 e->render.model = NULL;
1009 if (e->render.model)
1011 if (e->render.skinnum >= e->render.model->numskins)
1012 e->render.skinnum = 0;
1013 if (frame >= e->render.model->numframes)
1015 // models can set flags such as EF_ROCKET
1016 // this 0xFF800000 mask is EF_NOMODELFLAGS plus all the higher EF_ flags such as EF_ROCKET
1017 if (!(e->render.effects & 0xFF800000))
1018 e->render.effects |= e->render.model->effects;
1019 // if model is alias or this is a tenebrae-like dlight, reverse pitch direction
1020 if (e->render.model->type == mod_alias)
1021 angles[0] = -angles[0];
1022 if ((e->render.effects & EF_SELECTABLE) && cl.cmd.cursor_entitynumber == e->state_current.number)
1023 VectorScale(e->render.colormod, 2, e->render.colormod);
1025 // if model is alias or this is a tenebrae-like dlight, reverse pitch direction
1026 else if (e->state_current.lightpflags & PFLAGS_FULLDYNAMIC)
1027 angles[0] = -angles[0];
1029 if ((e->render.effects & EF_ROTATE) && !(e->render.flags & RENDER_VIEWMODEL))
1031 angles[1] = ANGLEMOD(100*cl.time);
1032 if (cl_itembobheight.value)
1033 origin[2] += (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
1037 if (e->render.frame2 == frame)
1039 // update frame lerp fraction
1040 e->render.framelerp = 1;
1041 if (e->render.frame2time > e->render.frame1time)
1043 // make sure frame lerp won't last longer than 100ms
1044 // (this mainly helps with models that use framegroups and
1045 // switch between them infrequently)
1046 e->render.framelerp = (cl.time - e->render.frame2time) / min(e->render.frame2time - e->render.frame1time, 0.1);
1047 e->render.framelerp = bound(0, e->render.framelerp, 1);
1052 // begin a new frame lerp
1053 e->render.frame1 = e->render.frame2;
1054 e->render.frame1time = e->render.frame2time;
1055 e->render.frame2 = frame;
1056 e->render.frame2time = cl.time;
1057 e->render.framelerp = 0;
1060 // set up the render matrix
1063 // attached entity, this requires a matrix multiply (concat)
1064 // FIXME: e->render.scale should go away
1065 Matrix4x4_CreateFromQuakeEntity(&matrix2, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale);
1066 // concat the matrices to make the entity relative to its tag
1067 Matrix4x4_Concat(&e->render.matrix, matrix, &matrix2);
1068 // get the origin from the new matrix
1069 Matrix4x4_OriginFromMatrix(&e->render.matrix, origin);
1073 // unattached entities are faster to process
1074 Matrix4x4_CreateFromQuakeEntity(&e->render.matrix, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], e->render.scale);
1077 // tenebrae's sprites are all additive mode (weird)
1078 if (gamemode == GAME_TENEBRAE && e->render.model && e->render.model->type == mod_sprite)
1079 e->render.effects |= EF_ADDITIVE;
1080 // player model is only shown with chase_active on
1081 if (e->state_current.number == cl.viewentity)
1082 e->render.flags |= RENDER_EXTERIORMODEL;
1083 // either fullbright or lit
1084 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
1085 e->render.flags |= RENDER_LIGHT;
1086 // hide player shadow during intermission or nehahra movie
1087 if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST))
1088 && (e->render.alpha >= 1)
1089 && !(e->render.flags & RENDER_VIEWMODEL)
1090 && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cls.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer)))
1091 e->render.flags |= RENDER_SHADOW;
1092 if (e->render.flags & RENDER_VIEWMODEL)
1093 e->render.flags |= RENDER_NOSELFSHADOW;
1095 // make the other useful stuff
1096 CL_UpdateRenderEntity(&e->render);
1099 // creates light and trails from an entity
1100 void CL_UpdateNetworkEntityTrail(entity_t *e)
1102 effectnameindex_t trailtype;
1105 // bmodels are treated specially since their origin is usually '0 0 0' and
1106 // their actual geometry is far from '0 0 0'
1107 if (e->render.model && e->render.model->soundfromcenter)
1110 VectorMAM(0.5f, e->render.model->normalmins, 0.5f, e->render.model->normalmaxs, o);
1111 Matrix4x4_Transform(&e->render.matrix, o, origin);
1114 Matrix4x4_OriginFromMatrix(&e->render.matrix, origin);
1116 // handle particle trails and such effects now that we know where this
1117 // entity is in the world...
1118 trailtype = EFFECT_NONE;
1119 // LordHavoc: if the entity has no effects, don't check each
1120 if (e->render.effects & (EF_BRIGHTFIELD | EF_FLAME | EF_STARDUST))
1122 if (e->render.effects & EF_BRIGHTFIELD)
1124 if (gamemode == GAME_NEXUIZ)
1125 trailtype = EFFECT_TR_NEXUIZPLASMA;
1127 CL_EntityParticles(e);
1129 if (e->render.effects & EF_FLAME)
1130 CL_ParticleTrail(EFFECT_EF_FLAME, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true);
1131 if (e->render.effects & EF_STARDUST)
1132 CL_ParticleTrail(EFFECT_EF_STARDUST, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true);
1134 if (e->render.internaleffects & (INTEF_FLAG1QW | INTEF_FLAG2QW))
1136 // these are only set on player entities
1137 CL_AddQWCTFFlagModel(e, (e->render.internaleffects & INTEF_FLAG2QW) != 0);
1139 // muzzleflash fades over time
1140 if (e->persistent.muzzleflash > 0)
1141 e->persistent.muzzleflash -= bound(0, cl.time - cl.oldtime, 0.1) * 20;
1142 // LordHavoc: if the entity has no effects, don't check each
1143 if (e->render.effects && !(e->render.flags & RENDER_VIEWMODEL))
1145 if (e->render.effects & EF_GIB)
1146 trailtype = EFFECT_TR_BLOOD;
1147 else if (e->render.effects & EF_ZOMGIB)
1148 trailtype = EFFECT_TR_SLIGHTBLOOD;
1149 else if (e->render.effects & EF_TRACER)
1150 trailtype = EFFECT_TR_WIZSPIKE;
1151 else if (e->render.effects & EF_TRACER2)
1152 trailtype = EFFECT_TR_KNIGHTSPIKE;
1153 else if (e->render.effects & EF_ROCKET)
1154 trailtype = EFFECT_TR_ROCKET;
1155 else if (e->render.effects & EF_GRENADE)
1157 // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
1158 trailtype = e->render.alpha == -1 ? EFFECT_TR_NEHAHRASMOKE : EFFECT_TR_GRENADE;
1160 else if (e->render.effects & EF_TRACER3)
1161 trailtype = EFFECT_TR_VORESPIKE;
1164 if (e->render.flags & RENDER_GLOWTRAIL)
1165 trailtype = EFFECT_TR_GLOWTRAIL;
1166 // check if a trail is allowed (it is not after a teleport for example)
1167 if (trailtype && e->persistent.trail_allowed)
1171 VectorSubtract(e->state_current.origin, e->state_previous.origin, vel);
1172 len = e->state_current.time - e->state_previous.time;
1175 VectorScale(vel, len, vel);
1176 CL_ParticleTrail(trailtype, 1, e->persistent.trail_origin, origin, vel, vel, e, e->state_current.glowcolor, false, true);
1178 // now that the entity has survived one trail update it is allowed to
1179 // leave a real trail on later frames
1180 e->persistent.trail_allowed = true;
1181 VectorCopy(origin, e->persistent.trail_origin);
1187 CL_UpdateViewEntities
1190 void CL_UpdateViewEntities(void)
1193 // update any RENDER_VIEWMODEL entities to use the new view matrix
1194 for (i = 1;i < cl.num_entities;i++)
1196 if (cl.entities_active[i])
1198 entity_t *ent = cl.entities + i;
1199 if ((ent->render.flags & RENDER_VIEWMODEL) || ent->state_current.tagentity)
1200 CL_UpdateNetworkEntity(ent, 32, true);
1203 // and of course the engine viewmodel needs updating as well
1204 CL_UpdateNetworkEntity(&cl.viewent, 32, true);
1209 CL_UpdateNetworkCollisionEntities
1212 void CL_UpdateNetworkCollisionEntities(void)
1217 // start on the entity after the world
1218 cl.num_brushmodel_entities = 0;
1219 for (i = cl.maxclients + 1;i < cl.num_entities;i++)
1221 if (cl.entities_active[i])
1223 ent = cl.entities + i;
1224 if (ent->state_current.active && ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->TraceBox)
1226 // do not interpolate the bmodels for this
1227 CL_UpdateNetworkEntity(ent, 32, false);
1228 cl.brushmodel_entities[cl.num_brushmodel_entities++] = i;
1236 CL_UpdateNetworkEntities
1239 void CL_UpdateNetworkEntities(void)
1244 // start on the entity after the world
1245 for (i = 1;i < cl.num_entities;i++)
1247 if (cl.entities_active[i])
1249 ent = cl.entities + i;
1250 if (ent->state_current.active)
1252 CL_UpdateNetworkEntity(ent, 32, true);
1253 // view models should never create light/trails
1254 if (!(ent->render.flags & RENDER_VIEWMODEL))
1255 CL_UpdateNetworkEntityTrail(ent);
1258 cl.entities_active[i] = false;
1263 void CL_UpdateViewModel(void)
1267 ent->state_previous = ent->state_current;
1268 ent->state_current = defaultstate;
1269 ent->state_current.time = cl.time;
1270 ent->state_current.number = -1;
1271 ent->state_current.active = true;
1272 ent->state_current.modelindex = cl.stats[STAT_WEAPON];
1273 ent->state_current.frame = cl.stats[STAT_WEAPONFRAME];
1274 ent->state_current.flags = RENDER_VIEWMODEL;
1275 if ((cl.stats[STAT_HEALTH] <= 0 && cl_deathnoviewmodel.integer) || cl.intermission)
1276 ent->state_current.modelindex = 0;
1277 else if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
1279 if (gamemode == GAME_TRANSFUSION)
1280 ent->state_current.alpha = 128;
1282 ent->state_current.modelindex = 0;
1284 ent->state_current.alpha = cl.entities[cl.viewentity].state_current.alpha;
1285 ent->state_current.effects = EF_NOSHADOW | (cl.entities[cl.viewentity].state_current.effects & (EF_ADDITIVE | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB));
1287 // reset animation interpolation on weaponmodel if model changed
1288 if (ent->state_previous.modelindex != ent->state_current.modelindex)
1290 ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
1291 ent->render.frame1time = ent->render.frame2time = cl.time;
1292 ent->render.framelerp = 1;
1294 CL_UpdateNetworkEntity(ent, 32, true);
1297 // note this is a recursive function, but it can never get in a runaway loop (because of the delayedlink flags)
1298 void CL_LinkNetworkEntity(entity_t *e)
1300 effectnameindex_t trailtype;
1305 // skip inactive entities and world
1306 if (!e->state_current.active || e == cl.entities)
1308 if (e->state_current.tagentity)
1310 // if the tag entity is currently impossible, skip it
1311 if (e->state_current.tagentity >= cl.num_entities)
1313 // if the tag entity is inactive, skip it
1314 if (!cl.entities[e->state_current.tagentity].state_current.active)
1318 // create entity dlights associated with this entity
1319 if (e->render.model && e->render.model->soundfromcenter)
1321 // bmodels are treated specially since their origin is usually '0 0 0'
1323 VectorMAM(0.5f, e->render.model->normalmins, 0.5f, e->render.model->normalmaxs, o);
1324 Matrix4x4_Transform(&e->render.matrix, o, origin);
1327 Matrix4x4_OriginFromMatrix(&e->render.matrix, origin);
1328 trailtype = EFFECT_NONE;
1333 // LordHavoc: if the entity has no effects, don't check each
1334 if (e->render.effects & (EF_BRIGHTFIELD | EF_DIMLIGHT | EF_BRIGHTLIGHT | EF_RED | EF_BLUE | EF_FLAME | EF_STARDUST))
1336 if (e->render.effects & EF_BRIGHTFIELD)
1338 if (gamemode == GAME_NEXUIZ)
1339 trailtype = EFFECT_TR_NEXUIZPLASMA;
1341 if (e->render.effects & EF_DIMLIGHT)
1343 dlightradius = max(dlightradius, 200);
1344 dlightcolor[0] += 1.50f;
1345 dlightcolor[1] += 1.50f;
1346 dlightcolor[2] += 1.50f;
1348 if (e->render.effects & EF_BRIGHTLIGHT)
1350 dlightradius = max(dlightradius, 400);
1351 dlightcolor[0] += 3.00f;
1352 dlightcolor[1] += 3.00f;
1353 dlightcolor[2] += 3.00f;
1355 // LordHavoc: more effects
1356 if (e->render.effects & EF_RED) // red
1358 dlightradius = max(dlightradius, 200);
1359 dlightcolor[0] += 1.50f;
1360 dlightcolor[1] += 0.15f;
1361 dlightcolor[2] += 0.15f;
1363 if (e->render.effects & EF_BLUE) // blue
1365 dlightradius = max(dlightradius, 200);
1366 dlightcolor[0] += 0.15f;
1367 dlightcolor[1] += 0.15f;
1368 dlightcolor[2] += 1.50f;
1370 if (e->render.effects & EF_FLAME)
1371 CL_ParticleTrail(EFFECT_EF_FLAME, 0, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false);
1372 if (e->render.effects & EF_STARDUST)
1373 CL_ParticleTrail(EFFECT_EF_STARDUST, 0, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false);
1375 // muzzleflash fades over time, and is offset a bit
1376 if (e->persistent.muzzleflash > 0 && r_refdef.numlights < MAX_DLIGHTS)
1381 matrix4x4_t tempmatrix;
1382 Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
1383 trace = CL_Move(origin, vec3_origin, vec3_origin, v2, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, true, false, NULL, false);
1384 Matrix4x4_Normalize(&tempmatrix, &e->render.matrix);
1385 Matrix4x4_SetOrigin(&tempmatrix, trace.endpos[0], trace.endpos[1], trace.endpos[2]);
1386 Matrix4x4_Scale(&tempmatrix, 150, 1);
1387 VectorSet(color, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f, e->persistent.muzzleflash * 4.0f);
1388 R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &tempmatrix, color, -1, NULL, true, 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1390 // LordHavoc: if the model has no flags, don't check each
1391 if (e->render.model && e->render.effects && !(e->render.flags & RENDER_VIEWMODEL))
1393 if (e->render.effects & EF_GIB)
1394 trailtype = EFFECT_TR_BLOOD;
1395 else if (e->render.effects & EF_ZOMGIB)
1396 trailtype = EFFECT_TR_SLIGHTBLOOD;
1397 else if (e->render.effects & EF_TRACER)
1398 trailtype = EFFECT_TR_WIZSPIKE;
1399 else if (e->render.effects & EF_TRACER2)
1400 trailtype = EFFECT_TR_KNIGHTSPIKE;
1401 else if (e->render.effects & EF_ROCKET)
1402 trailtype = EFFECT_TR_ROCKET;
1403 else if (e->render.effects & EF_GRENADE)
1405 // LordHavoc: e->render.alpha == -1 is for Nehahra dem compatibility (cigar smoke)
1406 trailtype = e->render.alpha == -1 ? EFFECT_TR_NEHAHRASMOKE : EFFECT_TR_GRENADE;
1408 else if (e->render.effects & EF_TRACER3)
1409 trailtype = EFFECT_TR_VORESPIKE;
1411 // LordHavoc: customizable glow
1412 if (e->state_current.glowsize)
1414 // * 4 for the expansion from 0-255 to 0-1023 range,
1415 // / 255 to scale down byte colors
1416 dlightradius = max(dlightradius, e->state_current.glowsize * 4);
1417 VectorMA(dlightcolor, (1.0f / 255.0f), palette_rgb[e->state_current.glowcolor], dlightcolor);
1419 // make the glow dlight
1420 if (dlightradius > 0 && (dlightcolor[0] || dlightcolor[1] || dlightcolor[2]) && !(e->render.flags & RENDER_VIEWMODEL) && r_refdef.numlights < MAX_DLIGHTS)
1422 matrix4x4_t dlightmatrix;
1423 Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
1424 // hack to make glowing player light shine on their gun
1425 //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
1426 // Matrix4x4_AdjustOrigin(&dlightmatrix, 0, 0, 30);
1427 Matrix4x4_Scale(&dlightmatrix, dlightradius, 1);
1428 R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &dlightmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1431 if ((e->state_current.lightpflags & PFLAGS_FULLDYNAMIC) && r_refdef.numlights < MAX_DLIGHTS)
1433 matrix4x4_t dlightmatrix;
1435 VectorScale(e->state_current.light, (1.0f / 256.0f), light);
1436 light[3] = e->state_current.light[3];
1437 if (light[0] == 0 && light[1] == 0 && light[2] == 0)
1438 VectorSet(light, 1, 1, 1);
1441 // FIXME: add ambient/diffuse/specular scales as an extension ontop of TENEBRAE_GFX_DLIGHTS?
1442 Matrix4x4_Normalize(&dlightmatrix, &e->render.matrix);
1443 Matrix4x4_Scale(&dlightmatrix, light[3], 1);
1444 R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &dlightmatrix, light, e->state_current.lightstyle, e->state_current.skin > 0 ? va("cubemaps/%i", e->state_current.skin) : NULL, !(e->state_current.lightpflags & PFLAGS_NOSHADOW), (e->state_current.lightpflags & PFLAGS_CORONA) != 0, 0.25, 0, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1447 if (e->render.flags & RENDER_GLOWTRAIL)
1448 trailtype = EFFECT_TR_GLOWTRAIL;
1450 CL_ParticleTrail(trailtype, 0, origin, origin, vec3_origin, vec3_origin, NULL, e->state_current.glowcolor, true, false);
1452 // don't show viewmodels in certain situations
1453 if (e->render.flags & RENDER_VIEWMODEL)
1454 if (!r_drawviewmodel.integer || chase_active.integer || r_refdef.envmap)
1456 // don't show entities with no modelindex (note: this still shows
1457 // entities which have a modelindex that resolved to a NULL model)
1458 if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.numentities < r_refdef.maxentities)
1459 r_refdef.entities[r_refdef.numentities++] = &e->render;
1460 //if (cl.viewentity && e->state_current.number == cl.viewentity)
1461 // Matrix4x4_Print(&e->render.matrix);
1464 void CL_RelinkWorld(void)
1466 entity_t *ent = &cl.entities[0];
1467 // FIXME: this should be done at load
1468 ent->render.matrix = identitymatrix;
1469 ent->render.flags = RENDER_SHADOW;
1470 if (!r_fullbright.integer)
1471 ent->render.flags |= RENDER_LIGHT;
1472 VectorSet(ent->render.colormod, 1, 1, 1);
1473 CL_UpdateRenderEntity(&ent->render);
1474 r_refdef.worldentity = &ent->render;
1475 r_refdef.worldmodel = cl.worldmodel;
1478 static void CL_RelinkStaticEntities(void)
1482 for (i = 0, e = cl.static_entities;i < cl.num_static_entities && r_refdef.numentities < r_refdef.maxentities;i++, e++)
1484 e->render.flags = 0;
1485 // if the model was not loaded when the static entity was created we
1486 // need to re-fetch the model pointer
1487 e->render.model = cl.model_precache[e->state_baseline.modelindex];
1488 // either fullbright or lit
1489 if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer)
1490 e->render.flags |= RENDER_LIGHT;
1491 // hide player shadow during intermission or nehahra movie
1492 if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (e->render.alpha >= 1))
1493 e->render.flags |= RENDER_SHADOW;
1494 VectorSet(e->render.colormod, 1, 1, 1);
1495 R_LerpAnimation(&e->render);
1496 CL_UpdateRenderEntity(&e->render);
1497 r_refdef.entities[r_refdef.numentities++] = &e->render;
1506 static void CL_RelinkNetworkEntities(void)
1511 // start on the entity after the world
1512 for (i = 1;i < cl.num_entities;i++)
1514 if (cl.entities_active[i])
1516 ent = cl.entities + i;
1517 if (ent->state_current.active)
1518 CL_LinkNetworkEntity(ent);
1520 cl.entities_active[i] = false;
1525 static void CL_RelinkEffects(void)
1532 for (i = 0, e = cl.effects;i < cl.num_effects;i++, e++)
1536 frame = (cl.time - e->starttime) * e->framerate + e->startframe;
1537 intframe = (int)frame;
1538 if (intframe < 0 || intframe >= e->endframe)
1540 memset(e, 0, sizeof(*e));
1541 while (cl.num_effects > 0 && !cl.effects[cl.num_effects - 1].active)
1546 if (intframe != e->frame)
1548 e->frame = intframe;
1549 e->frame1time = e->frame2time;
1550 e->frame2time = cl.time;
1553 // if we're drawing effects, get a new temp entity
1554 // (NewTempEntity adds it to the render entities list for us)
1555 if (r_draweffects.integer && (ent = CL_NewTempEntity()))
1557 // interpolation stuff
1558 ent->render.frame1 = intframe;
1559 ent->render.frame2 = intframe + 1;
1560 if (ent->render.frame2 >= e->endframe)
1561 ent->render.frame2 = -1; // disappear
1562 ent->render.framelerp = frame - intframe;
1563 ent->render.frame1time = e->frame1time;
1564 ent->render.frame2time = e->frame2time;
1567 if(e->modelindex < MAX_MODELS)
1568 ent->render.model = cl.model_precache[e->modelindex];
1570 ent->render.model = cl.csqc_model_precache[-(e->modelindex+1)];
1571 ent->render.alpha = 1;
1572 VectorSet(ent->render.colormod, 1, 1, 1);
1574 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
1575 CL_UpdateRenderEntity(&ent->render);
1581 void CL_Beam_CalculatePositions(const beam_t *b, vec3_t start, vec3_t end)
1583 VectorCopy(b->start, start);
1584 VectorCopy(b->end, end);
1586 // if coming from the player, update the start position
1587 if (b->entity == cl.viewentity)
1589 if (cl_beams_quakepositionhack.integer && !chase_active.integer)
1591 // LordHavoc: this is a stupid hack from Quake that makes your
1592 // lightning appear to come from your waist and cover less of your
1594 // in Quake this hack was applied to all players (causing the
1595 // infamous crotch-lightning), but in darkplaces and QuakeWorld it
1596 // only applies to your own lightning, and only in first person
1597 Matrix4x4_OriginFromMatrix(&cl.entities[cl.viewentity].render.matrix, start);
1599 if (cl_beams_instantaimhack.integer)
1601 vec3_t dir, localend;
1603 // LordHavoc: this updates the beam direction to match your
1605 VectorSubtract(end, start, dir);
1606 len = VectorLength(dir);
1607 VectorNormalize(dir);
1608 VectorSet(localend, len, 0, 0);
1609 Matrix4x4_Transform(&r_view.matrix, localend, end);
1614 void CL_RelinkBeams(void)
1618 vec3_t dist, org, start, end;
1623 matrix4x4_t tempmatrix;
1625 for (i = 0, b = cl.beams;i < cl.num_beams;i++, b++)
1629 if (b->endtime < cl.time)
1635 CL_Beam_CalculatePositions(b, start, end);
1639 if (cl_beams_lightatend.integer && r_refdef.numlights < MAX_DLIGHTS)
1641 // FIXME: create a matrix from the beam start/end orientation
1643 VectorSet(dlightcolor, 0.3, 0.7, 1);
1644 Matrix4x4_CreateFromQuakeEntity(&tempmatrix, end[0], end[1], end[2], 0, 0, 0, 200);
1645 R_RTLight_Update(&r_refdef.lights[r_refdef.numlights++], false, &tempmatrix, dlightcolor, -1, NULL, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1647 if (cl_beams_polygons.integer)
1651 // calculate pitch and yaw
1652 // (this is similar to the QuakeC builtin function vectoangles)
1653 VectorSubtract(end, start, dist);
1654 if (dist[1] == 0 && dist[0] == 0)
1664 yaw = atan2(dist[1], dist[0]) * 180 / M_PI;
1668 forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
1669 pitch = atan2(dist[2], forward) * 180 / M_PI;
1674 // add new entities for the lightning
1675 VectorCopy (start, org);
1676 d = VectorNormalizeLength(dist);
1679 ent = CL_NewTempEntity ();
1682 //VectorCopy (org, ent->render.origin);
1683 ent->render.model = b->model;
1684 //ent->render.effects = EF_FULLBRIGHT;
1685 //ent->render.angles[0] = pitch;
1686 //ent->render.angles[1] = yaw;
1687 //ent->render.angles[2] = rand()%360;
1688 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1);
1689 CL_UpdateRenderEntity(&ent->render);
1690 VectorMA(org, 30, dist, org);
1695 while (cl.num_beams > 0 && !cl.beams[cl.num_beams - 1].model)
1699 static void CL_RelinkQWNails(void)
1705 for (i = 0;i < cl.qw_num_nails;i++)
1709 // if we're drawing effects, get a new temp entity
1710 // (NewTempEntity adds it to the render entities list for us)
1711 if (!(ent = CL_NewTempEntity()))
1715 ent->render.model = cl.model_precache[cl.qw_modelindex_spike];
1716 ent->render.alpha = 1;
1717 VectorSet(ent->render.colormod, 1, 1, 1);
1719 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, v[0], v[1], v[2], v[3], v[4], v[5], 1);
1720 CL_UpdateRenderEntity(&ent->render);
1724 void CL_LerpPlayer(float frac)
1728 cl.viewzoom = cl.mviewzoom[1] + frac * (cl.mviewzoom[0] - cl.mviewzoom[1]);
1729 for (i = 0;i < 3;i++)
1731 cl.punchangle[i] = cl.mpunchangle[1][i] + frac * (cl.mpunchangle[0][i] - cl.mpunchangle[1][i]);
1732 cl.punchvector[i] = cl.mpunchvector[1][i] + frac * (cl.mpunchvector[0][i] - cl.mpunchvector[1][i]);
1733 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
1736 // interpolate the angles if playing a demo or spectating someone
1737 if (cls.demoplayback || cl.fixangle[0])
1739 for (i = 0;i < 3;i++)
1741 float d = cl.mviewangles[0][i] - cl.mviewangles[1][i];
1746 cl.viewangles[i] = cl.mviewangles[1][i] + frac * d;
1751 void CSQC_RelinkAllEntities (int drawmask)
1755 CL_RelinkStaticEntities();
1760 if (drawmask & ENTMASK_ENGINE)
1762 CL_RelinkNetworkEntities();
1763 if (drawmask & ENTMASK_ENGINEVIEWMODELS)
1764 CL_LinkNetworkEntity(&cl.viewent); // link gun model
1768 // update view blend
1776 Update client game world for a new frame
1779 void CL_UpdateWorld(void)
1781 r_refdef.extraupdate = !r_speeds.integer;
1782 r_refdef.numentities = 0;
1783 r_refdef.numlights = 0;
1784 r_view.matrix = identitymatrix;
1786 cl.num_brushmodel_entities = 0;
1788 if (cls.state == ca_connected && cls.signon == SIGNONS)
1790 // prepare for a new frame
1791 CL_LerpPlayer(CL_LerpPoint());
1792 CL_DecayLightFlashes();
1793 CL_ClearTempEntities();
1797 // if prediction is enabled we have to update all the collidable
1798 // network entities before the prediction code can be run
1799 CL_UpdateNetworkCollisionEntities();
1801 // now update the player prediction
1802 CL_ClientMovement_Replay();
1804 // update the player entity (which may be predicted)
1805 CL_UpdateNetworkEntity(cl.entities + cl.viewentity, 32, true);
1807 // now update the view (which depends on that player entity)
1810 // now update all the network entities and create particle trails
1811 // (some entities may depend on the view)
1812 CL_UpdateNetworkEntities();
1814 // update the engine-based viewmodel
1815 CL_UpdateViewModel();
1817 CL_RelinkLightFlashes();
1818 CSQC_RelinkAllEntities(ENTMASK_ENGINE | ENTMASK_ENGINEVIEWMODELS);
1820 // move decals, particles, and any other effects
1826 r_refdef.time = cl.time;
1829 // LordHavoc: pausedemo command
1830 static void CL_PauseDemo_f (void)
1832 cls.demopaused = !cls.demopaused;
1834 Con_Print("Demo paused\n");
1836 Con_Print("Demo unpaused\n");
1840 ======================
1842 ======================
1844 static void CL_Fog_f (void)
1846 if (Cmd_Argc () == 1)
1848 Con_Printf("\"fog\" is \"%f %f %f %f %f %f %f\"\n", r_refdef.fog_density, r_refdef.fog_red, r_refdef.fog_green, r_refdef.fog_blue, r_refdef.fog_alpha, r_refdef.fog_start, r_refdef.fog_end);
1851 r_refdef.fog_start = 0;
1852 r_refdef.fog_end = 16384;
1853 r_refdef.fog_alpha = 1;
1855 r_refdef.fog_density = atof(Cmd_Argv(1));
1857 r_refdef.fog_red = atof(Cmd_Argv(2));
1859 r_refdef.fog_green = atof(Cmd_Argv(3));
1861 r_refdef.fog_blue = atof(Cmd_Argv(4));
1863 r_refdef.fog_alpha = atof(Cmd_Argv(5));
1865 r_refdef.fog_start = atof(Cmd_Argv(6));
1867 r_refdef.fog_end = atof(Cmd_Argv(7));
1871 ====================
1874 For program optimization
1875 ====================
1877 static void CL_TimeRefresh_f (void)
1880 float timestart, timedelta;
1882 r_refdef.extraupdate = false;
1884 timestart = Sys_DoubleTime();
1885 for (i = 0;i < 128;i++)
1887 Matrix4x4_CreateFromQuakeEntity(&r_view.matrix, r_view.origin[0], r_view.origin[1], r_view.origin[2], 0, i / 128.0 * 360.0, 0, 1);
1890 timedelta = Sys_DoubleTime() - timestart;
1892 Con_Printf("%f seconds (%f fps)\n", timedelta, 128/timedelta);
1895 void CL_AreaStats_f(void)
1897 World_PrintAreaStats(&cl.world, "client");
1900 cl_locnode_t *CL_Locs_FindNearest(const vec3_t point)
1905 vec3_t nearestpoint;
1906 vec_t dist, bestdist;
1909 for (loc = cl.locnodes;loc;loc = loc->next)
1911 for (i = 0;i < 3;i++)
1912 nearestpoint[i] = bound(loc->mins[i], point[i], loc->maxs[i]);
1913 dist = VectorDistance2(nearestpoint, point);
1914 if (bestdist > dist || !best)
1925 void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point)
1928 loc = CL_Locs_FindNearest(point);
1930 strlcpy(buffer, loc->name, buffersize);
1932 dpsnprintf(buffer, buffersize, "LOC=%.0f:%.0f:%.0f", point[0], point[1], point[2]);
1935 void CL_Locs_FreeNode(cl_locnode_t *node)
1937 cl_locnode_t **pointer, **next;
1938 for (pointer = &cl.locnodes;*pointer;pointer = next)
1940 next = &(*pointer)->next;
1941 if (*pointer == node)
1943 *pointer = node->next;
1947 Con_Printf("CL_Locs_FreeNode: no such node! (%p)\n", node);
1950 void CL_Locs_AddNode(vec3_t mins, vec3_t maxs, const char *name)
1952 cl_locnode_t *node, **pointer;
1956 namelen = strlen(name);
1957 node = Mem_Alloc(cls.levelmempool, sizeof(cl_locnode_t) + namelen + 1);
1958 VectorSet(node->mins, min(mins[0], maxs[0]), min(mins[1], maxs[1]), min(mins[2], maxs[2]));
1959 VectorSet(node->maxs, max(mins[0], maxs[0]), max(mins[1], maxs[1]), max(mins[2], maxs[2]));
1960 node->name = (char *)(node + 1);
1961 memcpy(node->name, name, namelen);
1962 node->name[namelen] = 0;
1963 // link it into the tail of the list to preserve the order
1964 for (pointer = &cl.locnodes;*pointer;pointer = &(*pointer)->next)
1969 void CL_Locs_Add_f(void)
1972 if (Cmd_Argc() != 5 && Cmd_Argc() != 8)
1974 Con_Printf("usage: %s x y z[ x y z] name\n", Cmd_Argv(0));
1977 mins[0] = atof(Cmd_Argv(1));
1978 mins[1] = atof(Cmd_Argv(2));
1979 mins[2] = atof(Cmd_Argv(3));
1980 if (Cmd_Argc() == 8)
1982 maxs[0] = atof(Cmd_Argv(4));
1983 maxs[1] = atof(Cmd_Argv(5));
1984 maxs[2] = atof(Cmd_Argv(6));
1985 CL_Locs_AddNode(mins, maxs, Cmd_Argv(7));
1988 CL_Locs_AddNode(mins, mins, Cmd_Argv(4));
1991 void CL_Locs_RemoveNearest_f(void)
1994 loc = CL_Locs_FindNearest(r_view.origin);
1996 CL_Locs_FreeNode(loc);
1998 Con_Printf("no loc point or box found for your location\n");
2001 void CL_Locs_Clear_f(void)
2004 CL_Locs_FreeNode(cl.locnodes);
2007 void CL_Locs_Save_f(void)
2011 char locfilename[MAX_QPATH];
2014 Con_Printf("No loc points/boxes exist!\n");
2017 if (cls.state != ca_connected || !cl.worldmodel)
2019 Con_Printf("No level loaded!\n");
2022 FS_StripExtension(cl.worldmodel->name, locfilename, sizeof(locfilename));
2023 strlcat(locfilename, ".loc", sizeof(locfilename));
2025 outfile = FS_Open(locfilename, "w", false, false);
2028 // if any boxes are used then this is a proquake-format loc file, which
2029 // allows comments, so add some relevant information at the start
2030 for (loc = cl.locnodes;loc;loc = loc->next)
2031 if (!VectorCompare(loc->mins, loc->maxs))
2035 FS_Printf(outfile, "// %s %s saved by %s\n// x,y,z,x,y,z,\"name\"\n\n", locfilename, Sys_TimeString("%Y-%m-%d"), engineversion);
2036 for (loc = cl.locnodes;loc;loc = loc->next)
2037 if (VectorCompare(loc->mins, loc->maxs))
2040 Con_Printf("Warning: writing loc file containing a mixture of qizmo-style points and proquake-style boxes may not work in qizmo or proquake!\n");
2042 for (loc = cl.locnodes;loc;loc = loc->next)
2044 if (VectorCompare(loc->mins, loc->maxs))
2048 const char *in = loc->name;
2049 char name[MAX_INPUTLINE];
2050 for (len = 0;len < (int)sizeof(name) - 1 && *in;)
2052 if (*in == ' ') {s = "$loc_name_separator";in++;}
2053 else if (!strncmp(in, "SSG", 3)) {s = "$loc_name_ssg";in += 3;}
2054 else if (!strncmp(in, "NG", 2)) {s = "$loc_name_ng";in += 2;}
2055 else if (!strncmp(in, "SNG", 3)) {s = "$loc_name_sng";in += 3;}
2056 else if (!strncmp(in, "GL", 2)) {s = "$loc_name_gl";in += 2;}
2057 else if (!strncmp(in, "RL", 2)) {s = "$loc_name_rl";in += 2;}
2058 else if (!strncmp(in, "LG", 2)) {s = "$loc_name_lg";in += 2;}
2059 else if (!strncmp(in, "GA", 2)) {s = "$loc_name_ga";in += 2;}
2060 else if (!strncmp(in, "YA", 2)) {s = "$loc_name_ya";in += 2;}
2061 else if (!strncmp(in, "RA", 2)) {s = "$loc_name_ra";in += 2;}
2062 else if (!strncmp(in, "MEGA", 4)) {s = "$loc_name_mh";in += 4;}
2066 while (len < (int)sizeof(name) - 1 && *s)
2070 name[len++] = *in++;
2073 FS_Printf(outfile, "%.0f %.0f %.0f %s\n", loc->mins[0]*8, loc->mins[1]*8, loc->mins[2]*8, name);
2076 FS_Printf(outfile, "%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,\"%s\"\n", loc->mins[0], loc->mins[1], loc->mins[2], loc->maxs[0], loc->maxs[1], loc->maxs[2], loc->name);
2081 void CL_Locs_Reload_f(void)
2083 int i, linenumber, limit, len;
2085 char *filedata, *text, *textend, *linestart, *linetext, *lineend;
2086 fs_offset_t filesize;
2088 char locfilename[MAX_QPATH];
2089 char name[MAX_INPUTLINE];
2091 if (cls.state != ca_connected || !cl.worldmodel)
2093 Con_Printf("No level loaded!\n");
2099 // try maps/something.loc first (LordHavoc: where I think they should be)
2100 FS_StripExtension(cl.worldmodel->name, locfilename, sizeof(locfilename));
2101 strlcat(locfilename, ".loc", sizeof(locfilename));
2102 filedata = (char *)FS_LoadFile(locfilename, cls.levelmempool, false, &filesize);
2105 // try proquake name as well (LordHavoc: I hate path mangling)
2106 FS_StripExtension(va("locs/%s", FS_FileWithoutPath(cl.worldmodel->name)), locfilename, sizeof(locfilename));
2107 strlcat(locfilename, ".loc", sizeof(locfilename));
2108 filedata = (char *)FS_LoadFile(locfilename, cls.levelmempool, false, &filesize);
2113 textend = filedata + filesize;
2114 for (linenumber = 1;text < textend;linenumber++)
2117 for (;text < textend && *text != '\r' && *text != '\n';text++)
2120 if (text + 1 < textend && *text == '\r' && text[1] == '\n')
2124 // trim trailing whitespace
2125 while (lineend > linestart && lineend[-1] <= ' ')
2127 // trim leading whitespace
2128 while (linestart < lineend && *linestart <= ' ')
2130 // check if this is a comment
2131 if (linestart + 2 <= lineend && !strncmp(linestart, "//", 2))
2133 linetext = linestart;
2135 for (i = 0;i < limit;i++)
2137 if (linetext >= lineend)
2139 // note: a missing number is interpreted as 0
2141 mins[i] = atof(linetext);
2143 maxs[i - 3] = atof(linetext);
2144 // now advance past the number
2145 while (linetext < lineend && *linetext > ' ' && *linetext != ',')
2147 // advance through whitespace
2148 if (linetext < lineend)
2150 if (*linetext == ',')
2154 // note: comma can be followed by whitespace
2156 if (*linetext <= ' ')
2159 while (linetext < lineend && *linetext <= ' ')
2164 // if this is a quoted name, remove the quotes
2167 if (linetext >= lineend || *linetext != '"')
2168 continue; // proquake location names are always quoted
2171 len = min(lineend - linetext, (int)sizeof(name) - 1);
2172 memcpy(name, linetext, len);
2174 // add the box to the list
2175 CL_Locs_AddNode(mins, maxs, name);
2177 // if a point was parsed, it needs to be scaled down by 8 (since
2178 // point-based loc files were invented by a proxy which dealt
2179 // directly with quake protocol coordinates, which are *8), turn
2183 // interpret silly fuhquake macros
2184 for (len = 0;len < (int)sizeof(name) - 1 && linetext < lineend;)
2186 if (*linetext == '$')
2188 if (linetext + 18 <= lineend && !strncmp(linetext, "$loc_name_separator", 19)) {s = " ";linetext += 19;}
2189 else if (linetext + 13 <= lineend && !strncmp(linetext, "$loc_name_ssg", 13)) {s = "SSG";linetext += 13;}
2190 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_ng", 12)) {s = "NG";linetext += 12;}
2191 else if (linetext + 13 <= lineend && !strncmp(linetext, "$loc_name_sng", 13)) {s = "SNG";linetext += 13;}
2192 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_gl", 12)) {s = "GL";linetext += 12;}
2193 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_rl", 12)) {s = "RL";linetext += 12;}
2194 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_lg", 12)) {s = "LG";linetext += 12;}
2195 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_ga", 12)) {s = "GA";linetext += 12;}
2196 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_ya", 12)) {s = "YA";linetext += 12;}
2197 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_ra", 12)) {s = "RA";linetext += 12;}
2198 else if (linetext + 12 <= lineend && !strncmp(linetext, "$loc_name_mh", 12)) {s = "MEGA";linetext += 12;}
2202 while (len < (int)sizeof(name) - 1 && *s)
2207 name[len++] = *linetext++;
2210 // add the point to the list
2211 VectorScale(mins, (1.0 / 8.0), mins);
2212 CL_Locs_AddNode(mins, mins, name);
2224 void CL_Shutdown (void)
2226 CL_Screen_Shutdown();
2227 CL_Particles_Shutdown();
2228 CL_Parse_Shutdown();
2230 Mem_FreePool (&cls.permanentmempool);
2231 Mem_FreePool (&cls.levelmempool);
2241 cls.levelmempool = Mem_AllocPool("client (per-level memory)", 0, NULL);
2242 cls.permanentmempool = Mem_AllocPool("client (long term memory)", 0, NULL);
2244 memset(&r_refdef, 0, sizeof(r_refdef));
2245 // max entities sent to renderer per frame
2246 r_refdef.maxentities = MAX_EDICTS + 256 + 512;
2247 r_refdef.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * r_refdef.maxentities);
2252 // register our commands
2254 Cvar_RegisterVariable (&cl_upspeed);
2255 Cvar_RegisterVariable (&cl_forwardspeed);
2256 Cvar_RegisterVariable (&cl_backspeed);
2257 Cvar_RegisterVariable (&cl_sidespeed);
2258 Cvar_RegisterVariable (&cl_movespeedkey);
2259 Cvar_RegisterVariable (&cl_yawspeed);
2260 Cvar_RegisterVariable (&cl_pitchspeed);
2261 Cvar_RegisterVariable (&cl_anglespeedkey);
2262 Cvar_RegisterVariable (&cl_shownet);
2263 Cvar_RegisterVariable (&cl_nolerp);
2264 Cvar_RegisterVariable (&lookspring);
2265 Cvar_RegisterVariable (&lookstrafe);
2266 Cvar_RegisterVariable (&sensitivity);
2267 Cvar_RegisterVariable (&freelook);
2269 Cvar_RegisterVariable (&m_pitch);
2270 Cvar_RegisterVariable (&m_yaw);
2271 Cvar_RegisterVariable (&m_forward);
2272 Cvar_RegisterVariable (&m_side);
2274 Cvar_RegisterVariable (&cl_itembobspeed);
2275 Cvar_RegisterVariable (&cl_itembobheight);
2277 Cmd_AddCommand ("entities", CL_PrintEntities_f, "print information on network entities known to client");
2278 Cmd_AddCommand ("disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)");
2279 Cmd_AddCommand ("record", CL_Record_f, "record a demo");
2280 Cmd_AddCommand ("stop", CL_Stop_f, "stop recording or playing a demo");
2281 Cmd_AddCommand ("playdemo", CL_PlayDemo_f, "watch a demo file");
2282 Cmd_AddCommand ("timedemo", CL_TimeDemo_f, "play back a demo as fast as possible and save statistics to benchmark.log");
2284 // Support Client-side Model Index List
2285 Cmd_AddCommand ("cl_modelindexlist", CL_ModelIndexList_f, "list information on all models in the client modelindex");
2286 // Support Client-side Sound Index List
2287 Cmd_AddCommand ("cl_soundindexlist", CL_SoundIndexList_f, "list all sounds in the client soundindex");
2289 Cvar_RegisterVariable (&cl_autodemo);
2290 Cvar_RegisterVariable (&cl_autodemo_nameformat);
2292 Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist maxdist]])");
2294 // LordHavoc: added pausedemo
2295 Cmd_AddCommand ("pausedemo", CL_PauseDemo_f, "pause demo playback (can also safely pause demo recording if using QUAKE, QUAKEDP or NEHAHRAMOVIE protocol, useful for making movies)");
2297 Cmd_AddCommand ("cl_areastats", CL_AreaStats_f, "prints statistics on entity culling during collision traces");
2299 Cvar_RegisterVariable(&r_draweffects);
2300 Cvar_RegisterVariable(&cl_explosions_alpha_start);
2301 Cvar_RegisterVariable(&cl_explosions_alpha_end);
2302 Cvar_RegisterVariable(&cl_explosions_size_start);
2303 Cvar_RegisterVariable(&cl_explosions_size_end);
2304 Cvar_RegisterVariable(&cl_explosions_lifetime);
2305 Cvar_RegisterVariable(&cl_stainmaps);
2306 Cvar_RegisterVariable(&cl_stainmaps_clearonload);
2307 Cvar_RegisterVariable(&cl_beams_polygons);
2308 Cvar_RegisterVariable(&cl_beams_quakepositionhack);
2309 Cvar_RegisterVariable(&cl_beams_instantaimhack);
2310 Cvar_RegisterVariable(&cl_beams_lightatend);
2311 Cvar_RegisterVariable(&cl_noplayershadow);
2312 Cvar_RegisterVariable(&cl_dlights_decayradius);
2313 Cvar_RegisterVariable(&cl_dlights_decaybrightness);
2315 Cvar_RegisterVariable(&cl_prydoncursor);
2317 Cvar_RegisterVariable(&cl_deathnoviewmodel);
2319 // for QW connections
2320 Cvar_RegisterVariable(&qport);
2321 Cvar_SetValueQuick(&qport, (rand() * RAND_MAX + rand()) & 0xffff);
2323 Cmd_AddCommand("timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs");
2325 Cvar_RegisterVariable(&cl_locs_enable);
2326 Cvar_RegisterVariable(&cl_locs_show);
2327 Cmd_AddCommand("locs_add", CL_Locs_Add_f, "add a point or box location (usage: x y z[ x y z] \"name\", if two sets of xyz are supplied it is a box, otherwise point)");
2328 Cmd_AddCommand("locs_removenearest", CL_Locs_RemoveNearest_f, "remove the nearest point or box (note: you need to be very near a box to remove it)");
2329 Cmd_AddCommand("locs_clear", CL_Locs_Clear_f, "remove all loc points/boxes");
2330 Cmd_AddCommand("locs_reload", CL_Locs_Reload_f, "reload .loc file for this map");
2331 Cmd_AddCommand("locs_save", CL_Locs_Save_f, "save .loc file for this map containing currently defined points and boxes");
2334 CL_Particles_Init();
2338 #ifdef SUPPORT_GECKO