cl_ents.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // cl_ents.c -- entity parsing and management
  16. #include "quakedef.h"
  17. extern cvar_t cl_predict_players;
  18. extern cvar_t cl_predict_players2;
  19. extern cvar_t cl_solid_players;
  20. static struct predicted_player {
  21. int flags;
  22. qboolean active;
  23. vec3_t origin; // predicted origin
  24. } predicted_players[MAX_CLIENTS];
  25. //============================================================
  26. /*
  27. ===============
  28. CL_AllocDlight
  29. ===============
  30. */
  31. dlight_t *CL_AllocDlight (int key)
  32. {
  33. int i;
  34. dlight_t *dl;
  35. // first look for an exact key match
  36. if (key)
  37. {
  38. dl = cl_dlights;
  39. for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
  40. {
  41. if (dl->key == key)
  42. {
  43. memset (dl, 0, sizeof(*dl));
  44. dl->key = key;
  45. return dl;
  46. }
  47. }
  48. }
  49. // then look for anything else
  50. dl = cl_dlights;
  51. for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
  52. {
  53. if (dl->die < cl.time)
  54. {
  55. memset (dl, 0, sizeof(*dl));
  56. dl->key = key;
  57. return dl;
  58. }
  59. }
  60. dl = &cl_dlights[0];
  61. memset (dl, 0, sizeof(*dl));
  62. dl->key = key;
  63. return dl;
  64. }
  65. /*
  66. ===============
  67. CL_NewDlight
  68. ===============
  69. */
  70. void CL_NewDlight (int key, float x, float y, float z, float radius, float time,
  71. int type)
  72. {
  73. dlight_t *dl;
  74. dl = CL_AllocDlight (key);
  75. dl->origin[0] = x;
  76. dl->origin[1] = y;
  77. dl->origin[2] = z;
  78. dl->radius = radius;
  79. dl->die = cl.time + time;
  80. if (type == 0) {
  81. dl->color[0] = 0.2;
  82. dl->color[1] = 0.1;
  83. dl->color[2] = 0.05;
  84. dl->color[3] = 0.7;
  85. } else if (type == 1) {
  86. dl->color[0] = 0.05;
  87. dl->color[1] = 0.05;
  88. dl->color[2] = 0.3;
  89. dl->color[3] = 0.7;
  90. } else if (type == 2) {
  91. dl->color[0] = 0.5;
  92. dl->color[1] = 0.05;
  93. dl->color[2] = 0.05;
  94. dl->color[3] = 0.7;
  95. } else if (type == 3) {
  96. dl->color[0]=0.5;
  97. dl->color[1] = 0.05;
  98. dl->color[2] = 0.4;
  99. dl->color[3] = 0.7;
  100. }
  101. }
  102. /*
  103. ===============
  104. CL_DecayLights
  105. ===============
  106. */
  107. void CL_DecayLights (void)
  108. {
  109. int i;
  110. dlight_t *dl;
  111. dl = cl_dlights;
  112. for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
  113. {
  114. if (dl->die < cl.time || !dl->radius)
  115. continue;
  116. dl->radius -= host_frametime*dl->decay;
  117. if (dl->radius < 0)
  118. dl->radius = 0;
  119. }
  120. }
  121. /*
  122. =========================================================================
  123. PACKET ENTITY PARSING / LINKING
  124. =========================================================================
  125. */
  126. /*
  127. ==================
  128. CL_ParseDelta
  129. Can go from either a baseline or a previous packet_entity
  130. ==================
  131. */
  132. int bitcounts[32]; /// just for protocol profiling
  133. void CL_ParseDelta (entity_state_t *from, entity_state_t *to, int bits)
  134. {
  135. int i;
  136. // set everything to the state we are delta'ing from
  137. *to = *from;
  138. to->number = bits & 511;
  139. bits &= ~511;
  140. if (bits & U_MOREBITS)
  141. { // read in the low order bits
  142. i = MSG_ReadByte ();
  143. bits |= i;
  144. }
  145. // count the bits for net profiling
  146. for (i=0 ; i<16 ; i++)
  147. if (bits&(1<<i))
  148. bitcounts[i]++;
  149. to->flags = bits;
  150. if (bits & U_MODEL)
  151. to->modelindex = MSG_ReadByte ();
  152. if (bits & U_FRAME)
  153. to->frame = MSG_ReadByte ();
  154. if (bits & U_COLORMAP)
  155. to->colormap = MSG_ReadByte();
  156. if (bits & U_SKIN)
  157. to->skinnum = MSG_ReadByte();
  158. if (bits & U_EFFECTS)
  159. to->effects = MSG_ReadByte();
  160. if (bits & U_ORIGIN1)
  161. to->origin[0] = MSG_ReadCoord ();
  162. if (bits & U_ANGLE1)
  163. to->angles[0] = MSG_ReadAngle();
  164. if (bits & U_ORIGIN2)
  165. to->origin[1] = MSG_ReadCoord ();
  166. if (bits & U_ANGLE2)
  167. to->angles[1] = MSG_ReadAngle();
  168. if (bits & U_ORIGIN3)
  169. to->origin[2] = MSG_ReadCoord ();
  170. if (bits & U_ANGLE3)
  171. to->angles[2] = MSG_ReadAngle();
  172. if (bits & U_SOLID)
  173. {
  174. // FIXME
  175. }
  176. }
  177. /*
  178. =================
  179. FlushEntityPacket
  180. =================
  181. */
  182. void FlushEntityPacket (void)
  183. {
  184. int word;
  185. entity_state_t olde, newe;
  186. Con_DPrintf ("FlushEntityPacket\n");
  187. memset (&olde, 0, sizeof(olde));
  188. cl.validsequence = 0; // can't render a frame
  189. cl.frames[cls.netchan.incoming_sequence&UPDATE_MASK].invalid = true;
  190. // read it all, but ignore it
  191. while (1)
  192. {
  193. word = (unsigned short)MSG_ReadShort ();
  194. if (msg_badread)
  195. { // something didn't parse right...
  196. Host_EndGame ("msg_badread in packetentities");
  197. return;
  198. }
  199. if (!word)
  200. break; // done
  201. CL_ParseDelta (&olde, &newe, word);
  202. }
  203. }
  204. /*
  205. ==================
  206. CL_ParsePacketEntities
  207. An svc_packetentities has just been parsed, deal with the
  208. rest of the data stream.
  209. ==================
  210. */
  211. void CL_ParsePacketEntities (qboolean delta)
  212. {
  213. int oldpacket, newpacket;
  214. packet_entities_t *oldp, *newp, dummy;
  215. int oldindex, newindex;
  216. int word, newnum, oldnum;
  217. qboolean full;
  218. byte from;
  219. newpacket = cls.netchan.incoming_sequence&UPDATE_MASK;
  220. newp = &cl.frames[newpacket].packet_entities;
  221. cl.frames[newpacket].invalid = false;
  222. if (delta)
  223. {
  224. from = MSG_ReadByte ();
  225. oldpacket = cl.frames[newpacket].delta_sequence;
  226. if ( (from&UPDATE_MASK) != (oldpacket&UPDATE_MASK) )
  227. Con_DPrintf ("WARNING: from mismatch\n");
  228. }
  229. else
  230. oldpacket = -1;
  231. full = false;
  232. if (oldpacket != -1)
  233. {
  234. if (cls.netchan.outgoing_sequence - oldpacket >= UPDATE_BACKUP-1)
  235. { // we can't use this, it is too old
  236. FlushEntityPacket ();
  237. return;
  238. }
  239. cl.validsequence = cls.netchan.incoming_sequence;
  240. oldp = &cl.frames[oldpacket&UPDATE_MASK].packet_entities;
  241. }
  242. else
  243. { // this is a full update that we can start delta compressing from now
  244. oldp = &dummy;
  245. dummy.num_entities = 0;
  246. cl.validsequence = cls.netchan.incoming_sequence;
  247. full = true;
  248. }
  249. oldindex = 0;
  250. newindex = 0;
  251. newp->num_entities = 0;
  252. while (1)
  253. {
  254. word = (unsigned short)MSG_ReadShort ();
  255. if (msg_badread)
  256. { // something didn't parse right...
  257. Host_EndGame ("msg_badread in packetentities");
  258. return;
  259. }
  260. if (!word)
  261. {
  262. while (oldindex < oldp->num_entities)
  263. { // copy all the rest of the entities from the old packet
  264. //Con_Printf ("copy %i\n", oldp->entities[oldindex].number);
  265. if (newindex >= MAX_PACKET_ENTITIES)
  266. Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES");
  267. newp->entities[newindex] = oldp->entities[oldindex];
  268. newindex++;
  269. oldindex++;
  270. }
  271. break;
  272. }
  273. newnum = word&511;
  274. oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[oldindex].number;
  275. while (newnum > oldnum)
  276. {
  277. if (full)
  278. {
  279. Con_Printf ("WARNING: oldcopy on full update");
  280. FlushEntityPacket ();
  281. return;
  282. }
  283. //Con_Printf ("copy %i\n", oldnum);
  284. // copy one of the old entities over to the new packet unchanged
  285. if (newindex >= MAX_PACKET_ENTITIES)
  286. Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES");
  287. newp->entities[newindex] = oldp->entities[oldindex];
  288. newindex++;
  289. oldindex++;
  290. oldnum = oldindex >= oldp->num_entities ? 9999 : oldp->entities[oldindex].number;
  291. }
  292. if (newnum < oldnum)
  293. { // new from baseline
  294. //Con_Printf ("baseline %i\n", newnum);
  295. if (word & U_REMOVE)
  296. {
  297. if (full)
  298. {
  299. cl.validsequence = 0;
  300. Con_Printf ("WARNING: U_REMOVE on full update\n");
  301. FlushEntityPacket ();
  302. return;
  303. }
  304. continue;
  305. }
  306. if (newindex >= MAX_PACKET_ENTITIES)
  307. Host_EndGame ("CL_ParsePacketEntities: newindex == MAX_PACKET_ENTITIES");
  308. CL_ParseDelta (&cl_baselines[newnum], &newp->entities[newindex], word);
  309. newindex++;
  310. continue;
  311. }
  312. if (newnum == oldnum)
  313. { // delta from previous
  314. if (full)
  315. {
  316. cl.validsequence = 0;
  317. Con_Printf ("WARNING: delta on full update");
  318. }
  319. if (word & U_REMOVE)
  320. {
  321. oldindex++;
  322. continue;
  323. }
  324. //Con_Printf ("delta %i\n",newnum);
  325. CL_ParseDelta (&oldp->entities[oldindex], &newp->entities[newindex], word);
  326. newindex++;
  327. oldindex++;
  328. }
  329. }
  330. newp->num_entities = newindex;
  331. }
  332. /*
  333. ===============
  334. CL_LinkPacketEntities
  335. ===============
  336. */
  337. void CL_LinkPacketEntities (void)
  338. {
  339. entity_t *ent;
  340. packet_entities_t *pack;
  341. entity_state_t *s1, *s2;
  342. float f;
  343. model_t *model;
  344. vec3_t old_origin;
  345. float autorotate;
  346. int i;
  347. int pnum;
  348. dlight_t *dl;
  349. pack = &cl.frames[cls.netchan.incoming_sequence&UPDATE_MASK].packet_entities;
  350. autorotate = anglemod(100*cl.time);
  351. f = 0; // FIXME: no interpolation right now
  352. for (pnum=0 ; pnum<pack->num_entities ; pnum++)
  353. {
  354. s1 = &pack->entities[pnum];
  355. s2 = s1; // FIXME: no interpolation right now
  356. // spawn light flashes, even ones coming from invisible objects
  357. if ((s1->effects & (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
  358. CL_NewDlight (s1->number, s1->origin[0], s1->origin[1], s1->origin[2], 200 + (rand()&31), 0.1, 3);
  359. else if (s1->effects & EF_BLUE)
  360. CL_NewDlight (s1->number, s1->origin[0], s1->origin[1], s1->origin[2], 200 + (rand()&31), 0.1, 1);
  361. else if (s1->effects & EF_RED)
  362. CL_NewDlight (s1->number, s1->origin[0], s1->origin[1], s1->origin[2], 200 + (rand()&31), 0.1, 2);
  363. else if (s1->effects & EF_BRIGHTLIGHT)
  364. CL_NewDlight (s1->number, s1->origin[0], s1->origin[1], s1->origin[2] + 16, 400 + (rand()&31), 0.1, 0);
  365. else if (s1->effects & EF_DIMLIGHT)
  366. CL_NewDlight (s1->number, s1->origin[0], s1->origin[1], s1->origin[2], 200 + (rand()&31), 0.1, 0);
  367. // if set to invisible, skip
  368. if (!s1->modelindex)
  369. continue;
  370. // create a new entity
  371. if (cl_numvisedicts == MAX_VISEDICTS)
  372. break; // object list is full
  373. ent = &cl_visedicts[cl_numvisedicts];
  374. cl_numvisedicts++;
  375. ent->keynum = s1->number;
  376. ent->model = model = cl.model_precache[s1->modelindex];
  377. // set colormap
  378. if (s1->colormap && (s1->colormap < MAX_CLIENTS)
  379. && !strcmp(ent->model->name,"progs/player.mdl") )
  380. {
  381. ent->colormap = cl.players[s1->colormap-1].translations;
  382. ent->scoreboard = &cl.players[s1->colormap-1];
  383. }
  384. else
  385. {
  386. ent->colormap = vid.colormap;
  387. ent->scoreboard = NULL;
  388. }
  389. // set skin
  390. ent->skinnum = s1->skinnum;
  391. // set frame
  392. ent->frame = s1->frame;
  393. // rotate binary objects locally
  394. if (model->flags & EF_ROTATE)
  395. {
  396. ent->angles[0] = 0;
  397. ent->angles[1] = autorotate;
  398. ent->angles[2] = 0;
  399. }
  400. else
  401. {
  402. float a1, a2;
  403. for (i=0 ; i<3 ; i++)
  404. {
  405. a1 = s1->angles[i];
  406. a2 = s2->angles[i];
  407. if (a1 - a2 > 180)
  408. a1 -= 360;
  409. if (a1 - a2 < -180)
  410. a1 += 360;
  411. ent->angles[i] = a2 + f * (a1 - a2);
  412. }
  413. }
  414. // calculate origin
  415. for (i=0 ; i<3 ; i++)
  416. ent->origin[i] = s2->origin[i] +
  417. f * (s1->origin[i] - s2->origin[i]);
  418. // add automatic particle trails
  419. if (!model->flags)
  420. continue;
  421. // scan the old entity display list for a matching
  422. for (i=0 ; i<cl_oldnumvisedicts ; i++)
  423. {
  424. if (cl_oldvisedicts[i].keynum == ent->keynum)
  425. {
  426. VectorCopy (cl_oldvisedicts[i].origin, old_origin);
  427. break;
  428. }
  429. }
  430. if (i == cl_oldnumvisedicts)
  431. continue; // not in last message
  432. for (i=0 ; i<3 ; i++)
  433. if ( abs(old_origin[i] - ent->origin[i]) > 128)
  434. { // no trail if too far
  435. VectorCopy (ent->origin, old_origin);
  436. break;
  437. }
  438. if (model->flags & EF_ROCKET)
  439. {
  440. R_RocketTrail (old_origin, ent->origin, 0);
  441. dl = CL_AllocDlight (s1->number);
  442. VectorCopy (ent->origin, dl->origin);
  443. dl->radius = 200;
  444. dl->die = cl.time + 0.1;
  445. }
  446. else if (model->flags & EF_GRENADE)
  447. R_RocketTrail (old_origin, ent->origin, 1);
  448. else if (model->flags & EF_GIB)
  449. R_RocketTrail (old_origin, ent->origin, 2);
  450. else if (model->flags & EF_ZOMGIB)
  451. R_RocketTrail (old_origin, ent->origin, 4);
  452. else if (model->flags & EF_TRACER)
  453. R_RocketTrail (old_origin, ent->origin, 3);
  454. else if (model->flags & EF_TRACER2)
  455. R_RocketTrail (old_origin, ent->origin, 5);
  456. else if (model->flags & EF_TRACER3)
  457. R_RocketTrail (old_origin, ent->origin, 6);
  458. }
  459. }
  460. /*
  461. =========================================================================
  462. PROJECTILE PARSING / LINKING
  463. =========================================================================
  464. */
  465. typedef struct
  466. {
  467. int modelindex;
  468. vec3_t origin;
  469. vec3_t angles;
  470. } projectile_t;
  471. #define MAX_PROJECTILES 32
  472. projectile_t cl_projectiles[MAX_PROJECTILES];
  473. int cl_num_projectiles;
  474. extern int cl_spikeindex;
  475. void CL_ClearProjectiles (void)
  476. {
  477. cl_num_projectiles = 0;
  478. }
  479. /*
  480. =====================
  481. CL_ParseProjectiles
  482. Nails are passed as efficient temporary entities
  483. =====================
  484. */
  485. void CL_ParseProjectiles (void)
  486. {
  487. int i, c, j;
  488. byte bits[6];
  489. projectile_t *pr;
  490. c = MSG_ReadByte ();
  491. for (i=0 ; i<c ; i++)
  492. {
  493. for (j=0 ; j<6 ; j++)
  494. bits[j] = MSG_ReadByte ();
  495. if (cl_num_projectiles == MAX_PROJECTILES)
  496. continue;
  497. pr = &cl_projectiles[cl_num_projectiles];
  498. cl_num_projectiles++;
  499. pr->modelindex = cl_spikeindex;
  500. pr->origin[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
  501. pr->origin[1] = ( ( (bits[1]>>4) + (bits[2]<<4) ) <<1) - 4096;
  502. pr->origin[2] = ( ( bits[3] + ((bits[4]&15)<<8) ) <<1) - 4096;
  503. pr->angles[0] = 360*(bits[4]>>4)/16;
  504. pr->angles[1] = 360*bits[5]/256;
  505. }
  506. }
  507. /*
  508. =============
  509. CL_LinkProjectiles
  510. =============
  511. */
  512. void CL_LinkProjectiles (void)
  513. {
  514. int i;
  515. projectile_t *pr;
  516. entity_t *ent;
  517. for (i=0, pr=cl_projectiles ; i<cl_num_projectiles ; i++, pr++)
  518. {
  519. // grab an entity to fill in
  520. if (cl_numvisedicts == MAX_VISEDICTS)
  521. break; // object list is full
  522. ent = &cl_visedicts[cl_numvisedicts];
  523. cl_numvisedicts++;
  524. ent->keynum = 0;
  525. if (pr->modelindex < 1)
  526. continue;
  527. ent->model = cl.model_precache[pr->modelindex];
  528. ent->skinnum = 0;
  529. ent->frame = 0;
  530. ent->colormap = vid.colormap;
  531. ent->scoreboard = NULL;
  532. VectorCopy (pr->origin, ent->origin);
  533. VectorCopy (pr->angles, ent->angles);
  534. }
  535. }
  536. //========================================
  537. extern int cl_spikeindex, cl_playerindex, cl_flagindex;
  538. entity_t *CL_NewTempEntity (void);
  539. /*
  540. ===================
  541. CL_ParsePlayerinfo
  542. ===================
  543. */
  544. extern int parsecountmod;
  545. extern double parsecounttime;
  546. void CL_ParsePlayerinfo (void)
  547. {
  548. int msec;
  549. int flags;
  550. player_info_t *info;
  551. player_state_t *state;
  552. int num;
  553. int i;
  554. num = MSG_ReadByte ();
  555. if (num > MAX_CLIENTS)
  556. Sys_Error ("CL_ParsePlayerinfo: bad num");
  557. info = &cl.players[num];
  558. state = &cl.frames[parsecountmod].playerstate[num];
  559. flags = state->flags = MSG_ReadShort ();
  560. state->messagenum = cl.parsecount;
  561. state->origin[0] = MSG_ReadCoord ();
  562. state->origin[1] = MSG_ReadCoord ();
  563. state->origin[2] = MSG_ReadCoord ();
  564. state->frame = MSG_ReadByte ();
  565. // the other player's last move was likely some time
  566. // before the packet was sent out, so accurately track
  567. // the exact time it was valid at
  568. if (flags & PF_MSEC)
  569. {
  570. msec = MSG_ReadByte ();
  571. state->state_time = parsecounttime - msec*0.001;
  572. }
  573. else
  574. state->state_time = parsecounttime;
  575. if (flags & PF_COMMAND)
  576. MSG_ReadDeltaUsercmd (&nullcmd, &state->command);
  577. for (i=0 ; i<3 ; i++)
  578. {
  579. if (flags & (PF_VELOCITY1<<i) )
  580. state->velocity[i] = MSG_ReadShort();
  581. else
  582. state->velocity[i] = 0;
  583. }
  584. if (flags & PF_MODEL)
  585. state->modelindex = MSG_ReadByte ();
  586. else
  587. state->modelindex = cl_playerindex;
  588. if (flags & PF_SKINNUM)
  589. state->skinnum = MSG_ReadByte ();
  590. else
  591. state->skinnum = 0;
  592. if (flags & PF_EFFECTS)
  593. state->effects = MSG_ReadByte ();
  594. else
  595. state->effects = 0;
  596. if (flags & PF_WEAPONFRAME)
  597. state->weaponframe = MSG_ReadByte ();
  598. else
  599. state->weaponframe = 0;
  600. VectorCopy (state->command.angles, state->viewangles);
  601. }
  602. /*
  603. ================
  604. CL_AddFlagModels
  605. Called when the CTF flags are set
  606. ================
  607. */
  608. void CL_AddFlagModels (entity_t *ent, int team)
  609. {
  610. int i;
  611. float f;
  612. vec3_t v_forward, v_right, v_up;
  613. entity_t *newent;
  614. if (cl_flagindex == -1)
  615. return;
  616. f = 14;
  617. if (ent->frame >= 29 && ent->frame <= 40) {
  618. if (ent->frame >= 29 && ent->frame <= 34) { //axpain
  619. if (ent->frame == 29) f = f + 2;
  620. else if (ent->frame == 30) f = f + 8;
  621. else if (ent->frame == 31) f = f + 12;
  622. else if (ent->frame == 32) f = f + 11;
  623. else if (ent->frame == 33) f = f + 10;
  624. else if (ent->frame == 34) f = f + 4;
  625. } else if (ent->frame >= 35 && ent->frame <= 40) { // pain
  626. if (ent->frame == 35) f = f + 2;
  627. else if (ent->frame == 36) f = f + 10;
  628. else if (ent->frame == 37) f = f + 10;
  629. else if (ent->frame == 38) f = f + 8;
  630. else if (ent->frame == 39) f = f + 4;
  631. else if (ent->frame == 40) f = f + 2;
  632. }
  633. } else if (ent->frame >= 103 && ent->frame <= 118) {
  634. if (ent->frame >= 103 && ent->frame <= 104) f = f + 6; //nailattack
  635. else if (ent->frame >= 105 && ent->frame <= 106) f = f + 6; //light
  636. else if (ent->frame >= 107 && ent->frame <= 112) f = f + 7; //rocketattack
  637. else if (ent->frame >= 112 && ent->frame <= 118) f = f + 7; //shotattack
  638. }
  639. newent = CL_NewTempEntity ();
  640. newent->model = cl.model_precache[cl_flagindex];
  641. newent->skinnum = team;
  642. AngleVectors (ent->angles, v_forward, v_right, v_up);
  643. v_forward[2] = -v_forward[2]; // reverse z component
  644. for (i=0 ; i<3 ; i++)
  645. newent->origin[i] = ent->origin[i] - f*v_forward[i] + 22*v_right[i];
  646. newent->origin[2] -= 16;
  647. VectorCopy (ent->angles, newent->angles)
  648. newent->angles[2] -= 45;
  649. }
  650. /*
  651. =============
  652. CL_LinkPlayers
  653. Create visible entities in the correct position
  654. for all current players
  655. =============
  656. */
  657. void CL_LinkPlayers (void)
  658. {
  659. int j;
  660. player_info_t *info;
  661. player_state_t *state;
  662. player_state_t exact;
  663. double playertime;
  664. entity_t *ent;
  665. int msec;
  666. frame_t *frame;
  667. int oldphysent;
  668. playertime = realtime - cls.latency + 0.02;
  669. if (playertime > realtime)
  670. playertime = realtime;
  671. frame = &cl.frames[cl.parsecount&UPDATE_MASK];
  672. for (j=0, info=cl.players, state=frame->playerstate ; j < MAX_CLIENTS
  673. ; j++, info++, state++)
  674. {
  675. if (state->messagenum != cl.parsecount)
  676. continue; // not present this frame
  677. // spawn light flashes, even ones coming from invisible objects
  678. #ifdef GLQUAKE
  679. if (!gl_flashblend.value || j != cl.playernum) {
  680. #endif
  681. if ((state->effects & (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
  682. CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 3);
  683. else if (state->effects & EF_BLUE)
  684. CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 1);
  685. else if (state->effects & EF_RED)
  686. CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 2);
  687. else if (state->effects & EF_BRIGHTLIGHT)
  688. CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2] + 16, 400 + (rand()&31), 0.1, 0);
  689. else if (state->effects & EF_DIMLIGHT)
  690. CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 0);
  691. #ifdef GLQUAKE
  692. }
  693. #endif
  694. // the player object never gets added
  695. if (j == cl.playernum)
  696. continue;
  697. if (!state->modelindex)
  698. continue;
  699. if (!Cam_DrawPlayer(j))
  700. continue;
  701. // grab an entity to fill in
  702. if (cl_numvisedicts == MAX_VISEDICTS)
  703. break; // object list is full
  704. ent = &cl_visedicts[cl_numvisedicts];
  705. cl_numvisedicts++;
  706. ent->keynum = 0;
  707. ent->model = cl.model_precache[state->modelindex];
  708. ent->skinnum = state->skinnum;
  709. ent->frame = state->frame;
  710. ent->colormap = info->translations;
  711. if (state->modelindex == cl_playerindex)
  712. ent->scoreboard = info; // use custom skin
  713. else
  714. ent->scoreboard = NULL;
  715. //
  716. // angles
  717. //
  718. ent->angles[PITCH] = -state->viewangles[PITCH]/3;
  719. ent->angles[YAW] = state->viewangles[YAW];
  720. ent->angles[ROLL] = 0;
  721. ent->angles[ROLL] = V_CalcRoll (ent->angles, state->velocity)*4;
  722. // only predict half the move to minimize overruns
  723. msec = 500*(playertime - state->state_time);
  724. if (msec <= 0 || (!cl_predict_players.value && !cl_predict_players2.value))
  725. {
  726. VectorCopy (state->origin, ent->origin);
  727. //Con_DPrintf ("nopredict\n");
  728. }
  729. else
  730. {
  731. // predict players movement
  732. if (msec > 255)
  733. msec = 255;
  734. state->command.msec = msec;
  735. //Con_DPrintf ("predict: %i\n", msec);
  736. oldphysent = pmove.numphysent;
  737. CL_SetSolidPlayers (j);
  738. CL_PredictUsercmd (state, &exact, &state->command, false);
  739. pmove.numphysent = oldphysent;
  740. VectorCopy (exact.origin, ent->origin);
  741. }
  742. if (state->effects & EF_FLAG1)
  743. CL_AddFlagModels (ent, 0);
  744. else if (state->effects & EF_FLAG2)
  745. CL_AddFlagModels (ent, 1);
  746. }
  747. }
  748. //======================================================================
  749. /*
  750. ===============
  751. CL_SetSolid
  752. Builds all the pmove physents for the current frame
  753. ===============
  754. */
  755. void CL_SetSolidEntities (void)
  756. {
  757. int i;
  758. frame_t *frame;
  759. packet_entities_t *pak;
  760. entity_state_t *state;
  761. pmove.physents[0].model = cl.worldmodel;
  762. VectorCopy (vec3_origin, pmove.physents[0].origin);
  763. pmove.physents[0].info = 0;
  764. pmove.numphysent = 1;
  765. frame = &cl.frames[parsecountmod];
  766. pak = &frame->packet_entities;
  767. for (i=0 ; i<pak->num_entities ; i++)
  768. {
  769. state = &pak->entities[i];
  770. if (!state->modelindex)
  771. continue;
  772. if (!cl.model_precache[state->modelindex])
  773. continue;
  774. if ( cl.model_precache[state->modelindex]->hulls[1].firstclipnode
  775. || cl.model_precache[state->modelindex]->clipbox )
  776. {
  777. pmove.physents[pmove.numphysent].model = cl.model_precache[state->modelindex];
  778. VectorCopy (state->origin, pmove.physents[pmove.numphysent].origin);
  779. pmove.numphysent++;
  780. }
  781. }
  782. }
  783. /*
  784. ===
  785. Calculate the new position of players, without other player clipping
  786. We do this to set up real player prediction.
  787. Players are predicted twice, first without clipping other players,
  788. then with clipping against them.
  789. This sets up the first phase.
  790. ===
  791. */
  792. void CL_SetUpPlayerPrediction(qboolean dopred)
  793. {
  794. int j;
  795. player_state_t *state;
  796. player_state_t exact;
  797. double playertime;
  798. int msec;
  799. frame_t *frame;
  800. struct predicted_player *pplayer;
  801. playertime = realtime - cls.latency + 0.02;
  802. if (playertime > realtime)
  803. playertime = realtime;
  804. frame = &cl.frames[cl.parsecount&UPDATE_MASK];
  805. for (j=0, pplayer = predicted_players, state=frame->playerstate;
  806. j < MAX_CLIENTS;
  807. j++, pplayer++, state++) {
  808. pplayer->active = false;
  809. if (state->messagenum != cl.parsecount)
  810. continue; // not present this frame
  811. if (!state->modelindex)
  812. continue;
  813. pplayer->active = true;
  814. pplayer->flags = state->flags;
  815. // note that the local player is special, since he moves locally
  816. // we use his last predicted postition
  817. if (j == cl.playernum) {
  818. VectorCopy(cl.frames[cls.netchan.outgoing_sequence&UPDATE_MASK].playerstate[cl.playernum].origin,
  819. pplayer->origin);
  820. } else {
  821. // only predict half the move to minimize overruns
  822. msec = 500*(playertime - state->state_time);
  823. if (msec <= 0 ||
  824. (!cl_predict_players.value && !cl_predict_players2.value) ||
  825. !dopred)
  826. {
  827. VectorCopy (state->origin, pplayer->origin);
  828. //Con_DPrintf ("nopredict\n");
  829. }
  830. else
  831. {
  832. // predict players movement
  833. if (msec > 255)
  834. msec = 255;
  835. state->command.msec = msec;
  836. //Con_DPrintf ("predict: %i\n", msec);
  837. CL_PredictUsercmd (state, &exact, &state->command, false);
  838. VectorCopy (exact.origin, pplayer->origin);
  839. }
  840. }
  841. }
  842. }
  843. /*
  844. ===============
  845. CL_SetSolid
  846. Builds all the pmove physents for the current frame
  847. Note that CL_SetUpPlayerPrediction() must be called first!
  848. pmove must be setup with world and solid entity hulls before calling
  849. (via CL_PredictMove)
  850. ===============
  851. */
  852. void CL_SetSolidPlayers (int playernum)
  853. {
  854. int j;
  855. extern vec3_t player_mins;
  856. extern vec3_t player_maxs;
  857. struct predicted_player *pplayer;
  858. physent_t *pent;
  859. if (!cl_solid_players.value)
  860. return;
  861. pent = pmove.physents + pmove.numphysent;
  862. for (j=0, pplayer = predicted_players; j < MAX_CLIENTS; j++, pplayer++) {
  863. if (!pplayer->active)
  864. continue; // not present this frame
  865. // the player object never gets added
  866. if (j == playernum)
  867. continue;
  868. if (pplayer->flags & PF_DEAD)
  869. continue; // dead players aren't solid
  870. pent->model = 0;
  871. VectorCopy(pplayer->origin, pent->origin);
  872. VectorCopy(player_mins, pent->mins);
  873. VectorCopy(player_maxs, pent->maxs);
  874. pmove.numphysent++;
  875. pent++;
  876. }
  877. }
  878. /*
  879. ===============
  880. CL_EmitEntities
  881. Builds the visedicts array for cl.time
  882. Made up of: clients, packet_entities, nails, and tents
  883. ===============
  884. */
  885. void CL_EmitEntities (void)
  886. {
  887. if (cls.state != ca_active)
  888. return;
  889. if (!cl.validsequence)
  890. return;
  891. cl_oldnumvisedicts = cl_numvisedicts;
  892. cl_oldvisedicts = cl_visedicts_list[(cls.netchan.incoming_sequence-1)&1];
  893. cl_visedicts = cl_visedicts_list[cls.netchan.incoming_sequence&1];
  894. cl_numvisedicts = 0;
  895. CL_LinkPlayers ();
  896. CL_LinkPacketEntities ();
  897. CL_LinkProjectiles ();
  898. CL_UpdateTEnts ();
  899. }