cl_ents.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. /*
  2. Copyright (C) 1997-2001 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 "client.h"
  17. extern struct model_s *cl_mod_powerscreen;
  18. //PGM
  19. int vidref_val;
  20. //PGM
  21. /*
  22. =========================================================================
  23. FRAME PARSING
  24. =========================================================================
  25. */
  26. #if 0
  27. typedef struct
  28. {
  29. int modelindex;
  30. int num; // entity number
  31. int effects;
  32. vec3_t origin;
  33. vec3_t oldorigin;
  34. vec3_t angles;
  35. qboolean present;
  36. } projectile_t;
  37. #define MAX_PROJECTILES 64
  38. projectile_t cl_projectiles[MAX_PROJECTILES];
  39. void CL_ClearProjectiles (void)
  40. {
  41. int i;
  42. for (i = 0; i < MAX_PROJECTILES; i++) {
  43. // if (cl_projectiles[i].present)
  44. // Com_DPrintf("PROJ: %d CLEARED\n", cl_projectiles[i].num);
  45. cl_projectiles[i].present = false;
  46. }
  47. }
  48. /*
  49. =====================
  50. CL_ParseProjectiles
  51. Flechettes are passed as efficient temporary entities
  52. =====================
  53. */
  54. void CL_ParseProjectiles (void)
  55. {
  56. int i, c, j;
  57. byte bits[8];
  58. byte b;
  59. projectile_t pr;
  60. int lastempty = -1;
  61. qboolean old = false;
  62. c = MSG_ReadByte (&net_message);
  63. for (i=0 ; i<c ; i++)
  64. {
  65. bits[0] = MSG_ReadByte (&net_message);
  66. bits[1] = MSG_ReadByte (&net_message);
  67. bits[2] = MSG_ReadByte (&net_message);
  68. bits[3] = MSG_ReadByte (&net_message);
  69. bits[4] = MSG_ReadByte (&net_message);
  70. pr.origin[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
  71. pr.origin[1] = ( ( (bits[1]>>4) + (bits[2]<<4) ) <<1) - 4096;
  72. pr.origin[2] = ( ( bits[3] + ((bits[4]&15)<<8) ) <<1) - 4096;
  73. VectorCopy(pr.origin, pr.oldorigin);
  74. if (bits[4] & 64)
  75. pr.effects = EF_BLASTER;
  76. else
  77. pr.effects = 0;
  78. if (bits[4] & 128) {
  79. old = true;
  80. bits[0] = MSG_ReadByte (&net_message);
  81. bits[1] = MSG_ReadByte (&net_message);
  82. bits[2] = MSG_ReadByte (&net_message);
  83. bits[3] = MSG_ReadByte (&net_message);
  84. bits[4] = MSG_ReadByte (&net_message);
  85. pr.oldorigin[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
  86. pr.oldorigin[1] = ( ( (bits[1]>>4) + (bits[2]<<4) ) <<1) - 4096;
  87. pr.oldorigin[2] = ( ( bits[3] + ((bits[4]&15)<<8) ) <<1) - 4096;
  88. }
  89. bits[0] = MSG_ReadByte (&net_message);
  90. bits[1] = MSG_ReadByte (&net_message);
  91. bits[2] = MSG_ReadByte (&net_message);
  92. pr.angles[0] = 360*bits[0]/256;
  93. pr.angles[1] = 360*bits[1]/256;
  94. pr.modelindex = bits[2];
  95. b = MSG_ReadByte (&net_message);
  96. pr.num = (b & 0x7f);
  97. if (b & 128) // extra entity number byte
  98. pr.num |= (MSG_ReadByte (&net_message) << 7);
  99. pr.present = true;
  100. // find if this projectile already exists from previous frame
  101. for (j = 0; j < MAX_PROJECTILES; j++) {
  102. if (cl_projectiles[j].modelindex) {
  103. if (cl_projectiles[j].num == pr.num) {
  104. // already present, set up oldorigin for interpolation
  105. if (!old)
  106. VectorCopy(cl_projectiles[j].origin, pr.oldorigin);
  107. cl_projectiles[j] = pr;
  108. break;
  109. }
  110. } else
  111. lastempty = j;
  112. }
  113. // not present previous frame, add it
  114. if (j == MAX_PROJECTILES) {
  115. if (lastempty != -1) {
  116. cl_projectiles[lastempty] = pr;
  117. }
  118. }
  119. }
  120. }
  121. /*
  122. =============
  123. CL_LinkProjectiles
  124. =============
  125. */
  126. void CL_AddProjectiles (void)
  127. {
  128. int i, j;
  129. projectile_t *pr;
  130. entity_t ent;
  131. memset (&ent, 0, sizeof(ent));
  132. for (i=0, pr=cl_projectiles ; i < MAX_PROJECTILES ; i++, pr++)
  133. {
  134. // grab an entity to fill in
  135. if (pr->modelindex < 1)
  136. continue;
  137. if (!pr->present) {
  138. pr->modelindex = 0;
  139. continue; // not present this frame (it was in the previous frame)
  140. }
  141. ent.model = cl.model_draw[pr->modelindex];
  142. // interpolate origin
  143. for (j=0 ; j<3 ; j++)
  144. {
  145. ent.origin[j] = ent.oldorigin[j] = pr->oldorigin[j] + cl.lerpfrac *
  146. (pr->origin[j] - pr->oldorigin[j]);
  147. }
  148. if (pr->effects & EF_BLASTER)
  149. CL_BlasterTrail (pr->oldorigin, ent.origin);
  150. V_AddLight (pr->origin, 200, 1, 1, 0);
  151. VectorCopy (pr->angles, ent.angles);
  152. V_AddEntity (&ent);
  153. }
  154. }
  155. #endif
  156. /*
  157. =================
  158. CL_ParseEntityBits
  159. Returns the entity number and the header bits
  160. =================
  161. */
  162. int bitcounts[32]; /// just for protocol profiling
  163. int CL_ParseEntityBits (unsigned *bits)
  164. {
  165. unsigned b, total;
  166. int i;
  167. int number;
  168. total = MSG_ReadByte (&net_message);
  169. if (total & U_MOREBITS1)
  170. {
  171. b = MSG_ReadByte (&net_message);
  172. total |= b<<8;
  173. }
  174. if (total & U_MOREBITS2)
  175. {
  176. b = MSG_ReadByte (&net_message);
  177. total |= b<<16;
  178. }
  179. if (total & U_MOREBITS3)
  180. {
  181. b = MSG_ReadByte (&net_message);
  182. total |= b<<24;
  183. }
  184. // count the bits for net profiling
  185. for (i=0 ; i<32 ; i++)
  186. if (total&(1<<i))
  187. bitcounts[i]++;
  188. if (total & U_NUMBER16)
  189. number = MSG_ReadShort (&net_message);
  190. else
  191. number = MSG_ReadByte (&net_message);
  192. *bits = total;
  193. return number;
  194. }
  195. /*
  196. ==================
  197. CL_ParseDelta
  198. Can go from either a baseline or a previous packet_entity
  199. ==================
  200. */
  201. void CL_ParseDelta (entity_state_t *from, entity_state_t *to, int number, int bits)
  202. {
  203. // set everything to the state we are delta'ing from
  204. *to = *from;
  205. VectorCopy (from->origin, to->old_origin);
  206. to->number = number;
  207. if (bits & U_MODEL)
  208. to->modelindex = MSG_ReadByte (&net_message);
  209. if (bits & U_MODEL2)
  210. to->modelindex2 = MSG_ReadByte (&net_message);
  211. if (bits & U_MODEL3)
  212. to->modelindex3 = MSG_ReadByte (&net_message);
  213. if (bits & U_MODEL4)
  214. to->modelindex4 = MSG_ReadByte (&net_message);
  215. if (bits & U_FRAME8)
  216. to->frame = MSG_ReadByte (&net_message);
  217. if (bits & U_FRAME16)
  218. to->frame = MSG_ReadShort (&net_message);
  219. if ((bits & U_SKIN8) && (bits & U_SKIN16)) //used for laser colors
  220. to->skinnum = MSG_ReadLong(&net_message);
  221. else if (bits & U_SKIN8)
  222. to->skinnum = MSG_ReadByte(&net_message);
  223. else if (bits & U_SKIN16)
  224. to->skinnum = MSG_ReadShort(&net_message);
  225. if ( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) )
  226. to->effects = MSG_ReadLong(&net_message);
  227. else if (bits & U_EFFECTS8)
  228. to->effects = MSG_ReadByte(&net_message);
  229. else if (bits & U_EFFECTS16)
  230. to->effects = MSG_ReadShort(&net_message);
  231. if ( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) )
  232. to->renderfx = MSG_ReadLong(&net_message);
  233. else if (bits & U_RENDERFX8)
  234. to->renderfx = MSG_ReadByte(&net_message);
  235. else if (bits & U_RENDERFX16)
  236. to->renderfx = MSG_ReadShort(&net_message);
  237. if (bits & U_ORIGIN1)
  238. to->origin[0] = MSG_ReadCoord (&net_message);
  239. if (bits & U_ORIGIN2)
  240. to->origin[1] = MSG_ReadCoord (&net_message);
  241. if (bits & U_ORIGIN3)
  242. to->origin[2] = MSG_ReadCoord (&net_message);
  243. if (bits & U_ANGLE1)
  244. to->angles[0] = MSG_ReadAngle(&net_message);
  245. if (bits & U_ANGLE2)
  246. to->angles[1] = MSG_ReadAngle(&net_message);
  247. if (bits & U_ANGLE3)
  248. to->angles[2] = MSG_ReadAngle(&net_message);
  249. if (bits & U_OLDORIGIN)
  250. MSG_ReadPos (&net_message, to->old_origin);
  251. if (bits & U_SOUND)
  252. to->sound = MSG_ReadByte (&net_message);
  253. if (bits & U_EVENT)
  254. to->event = MSG_ReadByte (&net_message);
  255. else
  256. to->event = 0;
  257. if (bits & U_SOLID)
  258. to->solid = MSG_ReadShort (&net_message);
  259. }
  260. /*
  261. ==================
  262. CL_DeltaEntity
  263. Parses deltas from the given base and adds the resulting entity
  264. to the current frame
  265. ==================
  266. */
  267. void CL_DeltaEntity (frame_t *frame, int newnum, entity_state_t *old, int bits)
  268. {
  269. centity_t *ent;
  270. entity_state_t *state;
  271. ent = &cl_entities[newnum];
  272. state = &cl_parse_entities[cl.parse_entities & (MAX_PARSE_ENTITIES-1)];
  273. cl.parse_entities++;
  274. frame->num_entities++;
  275. CL_ParseDelta (old, state, newnum, bits);
  276. // some data changes will force no lerping
  277. if (state->modelindex != ent->current.modelindex
  278. || state->modelindex2 != ent->current.modelindex2
  279. || state->modelindex3 != ent->current.modelindex3
  280. || state->modelindex4 != ent->current.modelindex4
  281. || abs(state->origin[0] - ent->current.origin[0]) > 512
  282. || abs(state->origin[1] - ent->current.origin[1]) > 512
  283. || abs(state->origin[2] - ent->current.origin[2]) > 512
  284. || state->event == EV_PLAYER_TELEPORT
  285. || state->event == EV_OTHER_TELEPORT
  286. )
  287. {
  288. ent->serverframe = -99;
  289. }
  290. if (ent->serverframe != cl.frame.serverframe - 1)
  291. { // wasn't in last update, so initialize some things
  292. ent->trailcount = 1024; // for diminishing rocket / grenade trails
  293. // duplicate the current state so lerping doesn't hurt anything
  294. ent->prev = *state;
  295. if (state->event == EV_OTHER_TELEPORT)
  296. {
  297. VectorCopy (state->origin, ent->prev.origin);
  298. VectorCopy (state->origin, ent->lerp_origin);
  299. }
  300. else
  301. {
  302. VectorCopy (state->old_origin, ent->prev.origin);
  303. VectorCopy (state->old_origin, ent->lerp_origin);
  304. }
  305. }
  306. else
  307. { // shuffle the last state to previous
  308. ent->prev = ent->current;
  309. }
  310. ent->serverframe = cl.frame.serverframe;
  311. ent->current = *state;
  312. }
  313. /*
  314. ==================
  315. CL_ParsePacketEntities
  316. An svc_packetentities has just been parsed, deal with the
  317. rest of the data stream.
  318. ==================
  319. */
  320. void CL_ParsePacketEntities (frame_t *oldframe, frame_t *newframe)
  321. {
  322. int newnum;
  323. int bits;
  324. entity_state_t *oldstate;
  325. int oldindex, oldnum;
  326. newframe->parse_entities = cl.parse_entities;
  327. newframe->num_entities = 0;
  328. // delta from the entities present in oldframe
  329. oldindex = 0;
  330. if (!oldframe)
  331. oldnum = 99999;
  332. else
  333. {
  334. if (oldindex >= oldframe->num_entities)
  335. oldnum = 99999;
  336. else
  337. {
  338. oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
  339. oldnum = oldstate->number;
  340. }
  341. }
  342. while (1)
  343. {
  344. newnum = CL_ParseEntityBits (&bits);
  345. if (newnum >= MAX_EDICTS)
  346. Com_Error (ERR_DROP,"CL_ParsePacketEntities: bad number:%i", newnum);
  347. if (net_message.readcount > net_message.cursize)
  348. Com_Error (ERR_DROP,"CL_ParsePacketEntities: end of message");
  349. if (!newnum)
  350. break;
  351. while (oldnum < newnum)
  352. { // one or more entities from the old packet are unchanged
  353. if (cl_shownet->value == 3)
  354. Com_Printf (" unchanged: %i\n", oldnum);
  355. CL_DeltaEntity (newframe, oldnum, oldstate, 0);
  356. oldindex++;
  357. if (oldindex >= oldframe->num_entities)
  358. oldnum = 99999;
  359. else
  360. {
  361. oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
  362. oldnum = oldstate->number;
  363. }
  364. }
  365. if (bits & U_REMOVE)
  366. { // the entity present in oldframe is not in the current frame
  367. if (cl_shownet->value == 3)
  368. Com_Printf (" remove: %i\n", newnum);
  369. if (oldnum != newnum)
  370. Com_Printf ("U_REMOVE: oldnum != newnum\n");
  371. oldindex++;
  372. if (oldindex >= oldframe->num_entities)
  373. oldnum = 99999;
  374. else
  375. {
  376. oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
  377. oldnum = oldstate->number;
  378. }
  379. continue;
  380. }
  381. if (oldnum == newnum)
  382. { // delta from previous state
  383. if (cl_shownet->value == 3)
  384. Com_Printf (" delta: %i\n", newnum);
  385. CL_DeltaEntity (newframe, newnum, oldstate, bits);
  386. oldindex++;
  387. if (oldindex >= oldframe->num_entities)
  388. oldnum = 99999;
  389. else
  390. {
  391. oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
  392. oldnum = oldstate->number;
  393. }
  394. continue;
  395. }
  396. if (oldnum > newnum)
  397. { // delta from baseline
  398. if (cl_shownet->value == 3)
  399. Com_Printf (" baseline: %i\n", newnum);
  400. CL_DeltaEntity (newframe, newnum, &cl_entities[newnum].baseline, bits);
  401. continue;
  402. }
  403. }
  404. // any remaining entities in the old frame are copied over
  405. while (oldnum != 99999)
  406. { // one or more entities from the old packet are unchanged
  407. if (cl_shownet->value == 3)
  408. Com_Printf (" unchanged: %i\n", oldnum);
  409. CL_DeltaEntity (newframe, oldnum, oldstate, 0);
  410. oldindex++;
  411. if (oldindex >= oldframe->num_entities)
  412. oldnum = 99999;
  413. else
  414. {
  415. oldstate = &cl_parse_entities[(oldframe->parse_entities+oldindex) & (MAX_PARSE_ENTITIES-1)];
  416. oldnum = oldstate->number;
  417. }
  418. }
  419. }
  420. /*
  421. ===================
  422. CL_ParsePlayerstate
  423. ===================
  424. */
  425. void CL_ParsePlayerstate (frame_t *oldframe, frame_t *newframe)
  426. {
  427. int flags;
  428. player_state_t *state;
  429. int i;
  430. int statbits;
  431. state = &newframe->playerstate;
  432. // clear to old value before delta parsing
  433. if (oldframe)
  434. *state = oldframe->playerstate;
  435. else
  436. memset (state, 0, sizeof(*state));
  437. flags = MSG_ReadShort (&net_message);
  438. //
  439. // parse the pmove_state_t
  440. //
  441. if (flags & PS_M_TYPE)
  442. state->pmove.pm_type = MSG_ReadByte (&net_message);
  443. if (flags & PS_M_ORIGIN)
  444. {
  445. state->pmove.origin[0] = MSG_ReadShort (&net_message);
  446. state->pmove.origin[1] = MSG_ReadShort (&net_message);
  447. state->pmove.origin[2] = MSG_ReadShort (&net_message);
  448. }
  449. if (flags & PS_M_VELOCITY)
  450. {
  451. state->pmove.velocity[0] = MSG_ReadShort (&net_message);
  452. state->pmove.velocity[1] = MSG_ReadShort (&net_message);
  453. state->pmove.velocity[2] = MSG_ReadShort (&net_message);
  454. }
  455. if (flags & PS_M_TIME)
  456. state->pmove.pm_time = MSG_ReadByte (&net_message);
  457. if (flags & PS_M_FLAGS)
  458. state->pmove.pm_flags = MSG_ReadByte (&net_message);
  459. if (flags & PS_M_GRAVITY)
  460. state->pmove.gravity = MSG_ReadShort (&net_message);
  461. if (flags & PS_M_DELTA_ANGLES)
  462. {
  463. state->pmove.delta_angles[0] = MSG_ReadShort (&net_message);
  464. state->pmove.delta_angles[1] = MSG_ReadShort (&net_message);
  465. state->pmove.delta_angles[2] = MSG_ReadShort (&net_message);
  466. }
  467. if (cl.attractloop)
  468. state->pmove.pm_type = PM_FREEZE; // demo playback
  469. //
  470. // parse the rest of the player_state_t
  471. //
  472. if (flags & PS_VIEWOFFSET)
  473. {
  474. state->viewoffset[0] = MSG_ReadChar (&net_message) * 0.25;
  475. state->viewoffset[1] = MSG_ReadChar (&net_message) * 0.25;
  476. state->viewoffset[2] = MSG_ReadChar (&net_message) * 0.25;
  477. }
  478. if (flags & PS_VIEWANGLES)
  479. {
  480. state->viewangles[0] = MSG_ReadAngle16 (&net_message);
  481. state->viewangles[1] = MSG_ReadAngle16 (&net_message);
  482. state->viewangles[2] = MSG_ReadAngle16 (&net_message);
  483. }
  484. if (flags & PS_KICKANGLES)
  485. {
  486. state->kick_angles[0] = MSG_ReadChar (&net_message) * 0.25;
  487. state->kick_angles[1] = MSG_ReadChar (&net_message) * 0.25;
  488. state->kick_angles[2] = MSG_ReadChar (&net_message) * 0.25;
  489. }
  490. if (flags & PS_WEAPONINDEX)
  491. {
  492. state->gunindex = MSG_ReadByte (&net_message);
  493. }
  494. if (flags & PS_WEAPONFRAME)
  495. {
  496. state->gunframe = MSG_ReadByte (&net_message);
  497. state->gunoffset[0] = MSG_ReadChar (&net_message)*0.25;
  498. state->gunoffset[1] = MSG_ReadChar (&net_message)*0.25;
  499. state->gunoffset[2] = MSG_ReadChar (&net_message)*0.25;
  500. state->gunangles[0] = MSG_ReadChar (&net_message)*0.25;
  501. state->gunangles[1] = MSG_ReadChar (&net_message)*0.25;
  502. state->gunangles[2] = MSG_ReadChar (&net_message)*0.25;
  503. }
  504. if (flags & PS_BLEND)
  505. {
  506. state->blend[0] = MSG_ReadByte (&net_message)/255.0;
  507. state->blend[1] = MSG_ReadByte (&net_message)/255.0;
  508. state->blend[2] = MSG_ReadByte (&net_message)/255.0;
  509. state->blend[3] = MSG_ReadByte (&net_message)/255.0;
  510. }
  511. if (flags & PS_FOV)
  512. state->fov = MSG_ReadByte (&net_message);
  513. if (flags & PS_RDFLAGS)
  514. state->rdflags = MSG_ReadByte (&net_message);
  515. // parse stats
  516. statbits = MSG_ReadLong (&net_message);
  517. for (i=0 ; i<MAX_STATS ; i++)
  518. if (statbits & (1<<i) )
  519. state->stats[i] = MSG_ReadShort(&net_message);
  520. }
  521. /*
  522. ==================
  523. CL_FireEntityEvents
  524. ==================
  525. */
  526. void CL_FireEntityEvents (frame_t *frame)
  527. {
  528. entity_state_t *s1;
  529. int pnum, num;
  530. for (pnum = 0 ; pnum<frame->num_entities ; pnum++)
  531. {
  532. num = (frame->parse_entities + pnum)&(MAX_PARSE_ENTITIES-1);
  533. s1 = &cl_parse_entities[num];
  534. if (s1->event)
  535. CL_EntityEvent (s1);
  536. // EF_TELEPORTER acts like an event, but is not cleared each frame
  537. if (s1->effects & EF_TELEPORTER)
  538. CL_TeleporterParticles (s1);
  539. }
  540. }
  541. /*
  542. ================
  543. CL_ParseFrame
  544. ================
  545. */
  546. void CL_ParseFrame (void)
  547. {
  548. int cmd;
  549. int len;
  550. frame_t *old;
  551. memset (&cl.frame, 0, sizeof(cl.frame));
  552. #if 0
  553. CL_ClearProjectiles(); // clear projectiles for new frame
  554. #endif
  555. cl.frame.serverframe = MSG_ReadLong (&net_message);
  556. cl.frame.deltaframe = MSG_ReadLong (&net_message);
  557. cl.frame.servertime = cl.frame.serverframe*100;
  558. // BIG HACK to let old demos continue to work
  559. if (cls.serverProtocol != 26)
  560. cl.surpressCount = MSG_ReadByte (&net_message);
  561. if (cl_shownet->value == 3)
  562. Com_Printf (" frame:%i delta:%i\n", cl.frame.serverframe,
  563. cl.frame.deltaframe);
  564. // If the frame is delta compressed from data that we
  565. // no longer have available, we must suck up the rest of
  566. // the frame, but not use it, then ask for a non-compressed
  567. // message
  568. if (cl.frame.deltaframe <= 0)
  569. {
  570. cl.frame.valid = true; // uncompressed frame
  571. old = NULL;
  572. cls.demowaiting = false; // we can start recording now
  573. }
  574. else
  575. {
  576. old = &cl.frames[cl.frame.deltaframe & UPDATE_MASK];
  577. if (!old->valid)
  578. { // should never happen
  579. Com_Printf ("Delta from invalid frame (not supposed to happen!).\n");
  580. }
  581. if (old->serverframe != cl.frame.deltaframe)
  582. { // The frame that the server did the delta from
  583. // is too old, so we can't reconstruct it properly.
  584. Com_Printf ("Delta frame too old.\n");
  585. }
  586. else if (cl.parse_entities - old->parse_entities > MAX_PARSE_ENTITIES-128)
  587. {
  588. Com_Printf ("Delta parse_entities too old.\n");
  589. }
  590. else
  591. cl.frame.valid = true; // valid delta parse
  592. }
  593. // clamp time
  594. if (cl.time > cl.frame.servertime)
  595. cl.time = cl.frame.servertime;
  596. else if (cl.time < cl.frame.servertime - 100)
  597. cl.time = cl.frame.servertime - 100;
  598. // read areabits
  599. len = MSG_ReadByte (&net_message);
  600. MSG_ReadData (&net_message, &cl.frame.areabits, len);
  601. // read playerinfo
  602. cmd = MSG_ReadByte (&net_message);
  603. SHOWNET(svc_strings[cmd]);
  604. if (cmd != svc_playerinfo)
  605. Com_Error (ERR_DROP, "CL_ParseFrame: not playerinfo");
  606. CL_ParsePlayerstate (old, &cl.frame);
  607. // read packet entities
  608. cmd = MSG_ReadByte (&net_message);
  609. SHOWNET(svc_strings[cmd]);
  610. if (cmd != svc_packetentities)
  611. Com_Error (ERR_DROP, "CL_ParseFrame: not packetentities");
  612. CL_ParsePacketEntities (old, &cl.frame);
  613. #if 0
  614. if (cmd == svc_packetentities2)
  615. CL_ParseProjectiles();
  616. #endif
  617. // save the frame off in the backup array for later delta comparisons
  618. cl.frames[cl.frame.serverframe & UPDATE_MASK] = cl.frame;
  619. if (cl.frame.valid)
  620. {
  621. // getting a valid frame message ends the connection process
  622. if (cls.state != ca_active)
  623. {
  624. cls.state = ca_active;
  625. cl.force_refdef = true;
  626. cl.predicted_origin[0] = cl.frame.playerstate.pmove.origin[0]*0.125;
  627. cl.predicted_origin[1] = cl.frame.playerstate.pmove.origin[1]*0.125;
  628. cl.predicted_origin[2] = cl.frame.playerstate.pmove.origin[2]*0.125;
  629. VectorCopy (cl.frame.playerstate.viewangles, cl.predicted_angles);
  630. if (cls.disable_servercount != cl.servercount
  631. && cl.refresh_prepped)
  632. SCR_EndLoadingPlaque (); // get rid of loading plaque
  633. }
  634. cl.sound_prepped = true; // can start mixing ambient sounds
  635. // fire entity events
  636. CL_FireEntityEvents (&cl.frame);
  637. CL_CheckPredictionError ();
  638. }
  639. }
  640. /*
  641. ==========================================================================
  642. INTERPOLATE BETWEEN FRAMES TO GET RENDERING PARMS
  643. ==========================================================================
  644. */
  645. struct model_s *S_RegisterSexedModel (entity_state_t *ent, char *base)
  646. {
  647. int n;
  648. char *p;
  649. struct model_s *mdl;
  650. char model[MAX_QPATH];
  651. char buffer[MAX_QPATH];
  652. // determine what model the client is using
  653. model[0] = 0;
  654. n = CS_PLAYERSKINS + ent->number - 1;
  655. if (cl.configstrings[n][0])
  656. {
  657. p = strchr(cl.configstrings[n], '\\');
  658. if (p)
  659. {
  660. p += 1;
  661. strcpy(model, p);
  662. p = strchr(model, '/');
  663. if (p)
  664. *p = 0;
  665. }
  666. }
  667. // if we can't figure it out, they're male
  668. if (!model[0])
  669. strcpy(model, "male");
  670. Com_sprintf (buffer, sizeof(buffer), "players/%s/%s", model, base+1);
  671. mdl = re.RegisterModel(buffer);
  672. if (!mdl) {
  673. // not found, try default weapon model
  674. Com_sprintf (buffer, sizeof(buffer), "players/%s/weapon.md2", model);
  675. mdl = re.RegisterModel(buffer);
  676. if (!mdl) {
  677. // no, revert to the male model
  678. Com_sprintf (buffer, sizeof(buffer), "players/%s/%s", "male", base+1);
  679. mdl = re.RegisterModel(buffer);
  680. if (!mdl) {
  681. // last try, default male weapon.md2
  682. Com_sprintf (buffer, sizeof(buffer), "players/male/weapon.md2");
  683. mdl = re.RegisterModel(buffer);
  684. }
  685. }
  686. }
  687. return mdl;
  688. }
  689. /*
  690. ===============
  691. CL_AddPacketEntities
  692. ===============
  693. */
  694. void CL_AddPacketEntities (frame_t *frame)
  695. {
  696. entity_t ent;
  697. entity_state_t *s1;
  698. float autorotate;
  699. int i;
  700. int pnum;
  701. centity_t *cent;
  702. int autoanim;
  703. clientinfo_t *ci;
  704. unsigned int effects, renderfx;
  705. // bonus items rotate at a fixed rate
  706. autorotate = anglemod(cl.time/10);
  707. // brush models can auto animate their frames
  708. autoanim = 2*cl.time/1000;
  709. memset (&ent, 0, sizeof(ent));
  710. for (pnum = 0 ; pnum<frame->num_entities ; pnum++)
  711. {
  712. s1 = &cl_parse_entities[(frame->parse_entities+pnum)&(MAX_PARSE_ENTITIES-1)];
  713. cent = &cl_entities[s1->number];
  714. effects = s1->effects;
  715. renderfx = s1->renderfx;
  716. // set frame
  717. if (effects & EF_ANIM01)
  718. ent.frame = autoanim & 1;
  719. else if (effects & EF_ANIM23)
  720. ent.frame = 2 + (autoanim & 1);
  721. else if (effects & EF_ANIM_ALL)
  722. ent.frame = autoanim;
  723. else if (effects & EF_ANIM_ALLFAST)
  724. ent.frame = cl.time / 100;
  725. else
  726. ent.frame = s1->frame;
  727. // quad and pent can do different things on client
  728. if (effects & EF_PENT)
  729. {
  730. effects &= ~EF_PENT;
  731. effects |= EF_COLOR_SHELL;
  732. renderfx |= RF_SHELL_RED;
  733. }
  734. if (effects & EF_QUAD)
  735. {
  736. effects &= ~EF_QUAD;
  737. effects |= EF_COLOR_SHELL;
  738. renderfx |= RF_SHELL_BLUE;
  739. }
  740. //======
  741. // PMM
  742. if (effects & EF_DOUBLE)
  743. {
  744. effects &= ~EF_DOUBLE;
  745. effects |= EF_COLOR_SHELL;
  746. renderfx |= RF_SHELL_DOUBLE;
  747. }
  748. if (effects & EF_HALF_DAMAGE)
  749. {
  750. effects &= ~EF_HALF_DAMAGE;
  751. effects |= EF_COLOR_SHELL;
  752. renderfx |= RF_SHELL_HALF_DAM;
  753. }
  754. // pmm
  755. //======
  756. ent.oldframe = cent->prev.frame;
  757. ent.backlerp = 1.0 - cl.lerpfrac;
  758. if (renderfx & (RF_FRAMELERP|RF_BEAM))
  759. { // step origin discretely, because the frames
  760. // do the animation properly
  761. VectorCopy (cent->current.origin, ent.origin);
  762. VectorCopy (cent->current.old_origin, ent.oldorigin);
  763. }
  764. else
  765. { // interpolate origin
  766. for (i=0 ; i<3 ; i++)
  767. {
  768. ent.origin[i] = ent.oldorigin[i] = cent->prev.origin[i] + cl.lerpfrac *
  769. (cent->current.origin[i] - cent->prev.origin[i]);
  770. }
  771. }
  772. // create a new entity
  773. // tweak the color of beams
  774. if ( renderfx & RF_BEAM )
  775. { // the four beam colors are encoded in 32 bits of skinnum (hack)
  776. ent.alpha = 0.30;
  777. ent.skinnum = (s1->skinnum >> ((rand() % 4)*8)) & 0xff;
  778. ent.model = NULL;
  779. }
  780. else
  781. {
  782. // set skin
  783. if (s1->modelindex == 255)
  784. { // use custom player skin
  785. ent.skinnum = 0;
  786. ci = &cl.clientinfo[s1->skinnum & 0xff];
  787. ent.skin = ci->skin;
  788. ent.model = ci->model;
  789. if (!ent.skin || !ent.model)
  790. {
  791. ent.skin = cl.baseclientinfo.skin;
  792. ent.model = cl.baseclientinfo.model;
  793. }
  794. //============
  795. //PGM
  796. if (renderfx & RF_USE_DISGUISE)
  797. {
  798. if(!strncmp((char *)ent.skin, "players/male", 12))
  799. {
  800. ent.skin = re.RegisterSkin ("players/male/disguise.pcx");
  801. ent.model = re.RegisterModel ("players/male/tris.md2");
  802. }
  803. else if(!strncmp((char *)ent.skin, "players/female", 14))
  804. {
  805. ent.skin = re.RegisterSkin ("players/female/disguise.pcx");
  806. ent.model = re.RegisterModel ("players/female/tris.md2");
  807. }
  808. else if(!strncmp((char *)ent.skin, "players/cyborg", 14))
  809. {
  810. ent.skin = re.RegisterSkin ("players/cyborg/disguise.pcx");
  811. ent.model = re.RegisterModel ("players/cyborg/tris.md2");
  812. }
  813. }
  814. //PGM
  815. //============
  816. }
  817. else
  818. {
  819. ent.skinnum = s1->skinnum;
  820. ent.skin = NULL;
  821. ent.model = cl.model_draw[s1->modelindex];
  822. }
  823. }
  824. // only used for black hole model right now, FIXME: do better
  825. if (renderfx == RF_TRANSLUCENT)
  826. ent.alpha = 0.70;
  827. // render effects (fullbright, translucent, etc)
  828. if ((effects & EF_COLOR_SHELL))
  829. ent.flags = 0; // renderfx go on color shell entity
  830. else
  831. ent.flags = renderfx;
  832. // calculate angles
  833. if (effects & EF_ROTATE)
  834. { // some bonus items auto-rotate
  835. ent.angles[0] = 0;
  836. ent.angles[1] = autorotate;
  837. ent.angles[2] = 0;
  838. }
  839. // RAFAEL
  840. else if (effects & EF_SPINNINGLIGHTS)
  841. {
  842. ent.angles[0] = 0;
  843. ent.angles[1] = anglemod(cl.time/2) + s1->angles[1];
  844. ent.angles[2] = 180;
  845. {
  846. vec3_t forward;
  847. vec3_t start;
  848. AngleVectors (ent.angles, forward, NULL, NULL);
  849. VectorMA (ent.origin, 64, forward, start);
  850. V_AddLight (start, 100, 1, 0, 0);
  851. }
  852. }
  853. else
  854. { // interpolate angles
  855. float a1, a2;
  856. for (i=0 ; i<3 ; i++)
  857. {
  858. a1 = cent->current.angles[i];
  859. a2 = cent->prev.angles[i];
  860. ent.angles[i] = LerpAngle (a2, a1, cl.lerpfrac);
  861. }
  862. }
  863. if (s1->number == cl.playernum+1)
  864. {
  865. ent.flags |= RF_VIEWERMODEL; // only draw from mirrors
  866. // FIXME: still pass to refresh
  867. if (effects & EF_FLAG1)
  868. V_AddLight (ent.origin, 225, 1.0, 0.1, 0.1);
  869. else if (effects & EF_FLAG2)
  870. V_AddLight (ent.origin, 225, 0.1, 0.1, 1.0);
  871. else if (effects & EF_TAGTRAIL) //PGM
  872. V_AddLight (ent.origin, 225, 1.0, 1.0, 0.0); //PGM
  873. else if (effects & EF_TRACKERTRAIL) //PGM
  874. V_AddLight (ent.origin, 225, -1.0, -1.0, -1.0); //PGM
  875. continue;
  876. }
  877. // if set to invisible, skip
  878. if (!s1->modelindex)
  879. continue;
  880. if (effects & EF_BFG)
  881. {
  882. ent.flags |= RF_TRANSLUCENT;
  883. ent.alpha = 0.30;
  884. }
  885. // RAFAEL
  886. if (effects & EF_PLASMA)
  887. {
  888. ent.flags |= RF_TRANSLUCENT;
  889. ent.alpha = 0.6;
  890. }
  891. if (effects & EF_SPHERETRANS)
  892. {
  893. ent.flags |= RF_TRANSLUCENT;
  894. // PMM - *sigh* yet more EF overloading
  895. if (effects & EF_TRACKERTRAIL)
  896. ent.alpha = 0.6;
  897. else
  898. ent.alpha = 0.3;
  899. }
  900. //pmm
  901. // add to refresh list
  902. V_AddEntity (&ent);
  903. // color shells generate a seperate entity for the main model
  904. if (effects & EF_COLOR_SHELL)
  905. {
  906. ent.flags = renderfx | RF_TRANSLUCENT;
  907. ent.alpha = 0.30;
  908. V_AddEntity (&ent);
  909. }
  910. ent.skin = NULL; // never use a custom skin on others
  911. ent.skinnum = 0;
  912. ent.flags = 0;
  913. ent.alpha = 0;
  914. // duplicate for linked models
  915. if (s1->modelindex2)
  916. {
  917. if (s1->modelindex2 == 255)
  918. { // custom weapon
  919. ci = &cl.clientinfo[s1->skinnum & 0xff];
  920. i = (s1->skinnum >> 8); // 0 is default weapon model
  921. if (!cl_vwep->value || i > MAX_CLIENTWEAPONMODELS - 1)
  922. i = 0;
  923. ent.model = ci->weaponmodel[i];
  924. if (!ent.model) {
  925. if (i != 0)
  926. ent.model = ci->weaponmodel[0];
  927. if (!ent.model)
  928. ent.model = cl.baseclientinfo.weaponmodel[0];
  929. }
  930. }
  931. //PGM - hack to allow translucent linked models (defender sphere's shell)
  932. // set the high bit 0x80 on modelindex2 to enable translucency
  933. else if(s1->modelindex2 & 0x80)
  934. {
  935. ent.model = cl.model_draw[s1->modelindex2 & 0x7F];
  936. ent.alpha = 0.32;
  937. ent.flags = RF_TRANSLUCENT;
  938. }
  939. //PGM
  940. else
  941. ent.model = cl.model_draw[s1->modelindex2];
  942. V_AddEntity (&ent);
  943. //PGM - make sure these get reset.
  944. ent.flags = 0;
  945. ent.alpha = 0;
  946. //PGM
  947. }
  948. if (s1->modelindex3)
  949. {
  950. ent.model = cl.model_draw[s1->modelindex3];
  951. V_AddEntity (&ent);
  952. }
  953. if (s1->modelindex4)
  954. {
  955. ent.model = cl.model_draw[s1->modelindex4];
  956. V_AddEntity (&ent);
  957. }
  958. if ( effects & EF_POWERSCREEN )
  959. {
  960. ent.model = cl_mod_powerscreen;
  961. ent.oldframe = 0;
  962. ent.frame = 0;
  963. ent.flags |= (RF_TRANSLUCENT | RF_SHELL_GREEN);
  964. ent.alpha = 0.30;
  965. V_AddEntity (&ent);
  966. }
  967. // add automatic particle trails
  968. if ( (effects&~EF_ROTATE) )
  969. {
  970. if (effects & EF_ROCKET)
  971. {
  972. CL_RocketTrail (cent->lerp_origin, ent.origin, cent);
  973. V_AddLight (ent.origin, 200, 1, 1, 0);
  974. }
  975. // PGM - Do not reorder EF_BLASTER and EF_HYPERBLASTER.
  976. // EF_BLASTER | EF_TRACKER is a special case for EF_BLASTER2... Cheese!
  977. else if (effects & EF_BLASTER)
  978. {
  979. // CL_BlasterTrail (cent->lerp_origin, ent.origin);
  980. //PGM
  981. if (effects & EF_TRACKER) // lame... problematic?
  982. {
  983. CL_BlasterTrail2 (cent->lerp_origin, ent.origin);
  984. V_AddLight (ent.origin, 200, 0, 1, 0);
  985. }
  986. else
  987. {
  988. CL_BlasterTrail (cent->lerp_origin, ent.origin);
  989. V_AddLight (ent.origin, 200, 1, 1, 0);
  990. }
  991. //PGM
  992. }
  993. else if (effects & EF_HYPERBLASTER)
  994. {
  995. if (effects & EF_TRACKER) // PGM overloaded for blaster2.
  996. V_AddLight (ent.origin, 200, 0, 1, 0); // PGM
  997. else // PGM
  998. V_AddLight (ent.origin, 200, 1, 1, 0);
  999. }
  1000. else if (effects & EF_GIB)
  1001. {
  1002. CL_DiminishingTrail (cent->lerp_origin, ent.origin, cent, effects);
  1003. }
  1004. else if (effects & EF_GRENADE)
  1005. {
  1006. CL_DiminishingTrail (cent->lerp_origin, ent.origin, cent, effects);
  1007. }
  1008. else if (effects & EF_FLIES)
  1009. {
  1010. CL_FlyEffect (cent, ent.origin);
  1011. }
  1012. else if (effects & EF_BFG)
  1013. {
  1014. static int bfg_lightramp[6] = {300, 400, 600, 300, 150, 75};
  1015. if (effects & EF_ANIM_ALLFAST)
  1016. {
  1017. CL_BfgParticles (&ent);
  1018. i = 200;
  1019. }
  1020. else
  1021. {
  1022. i = bfg_lightramp[s1->frame];
  1023. }
  1024. V_AddLight (ent.origin, i, 0, 1, 0);
  1025. }
  1026. // RAFAEL
  1027. else if (effects & EF_TRAP)
  1028. {
  1029. ent.origin[2] += 32;
  1030. CL_TrapParticles (&ent);
  1031. i = (rand()%100) + 100;
  1032. V_AddLight (ent.origin, i, 1, 0.8, 0.1);
  1033. }
  1034. else if (effects & EF_FLAG1)
  1035. {
  1036. CL_FlagTrail (cent->lerp_origin, ent.origin, 242);
  1037. V_AddLight (ent.origin, 225, 1, 0.1, 0.1);
  1038. }
  1039. else if (effects & EF_FLAG2)
  1040. {
  1041. CL_FlagTrail (cent->lerp_origin, ent.origin, 115);
  1042. V_AddLight (ent.origin, 225, 0.1, 0.1, 1);
  1043. }
  1044. //======
  1045. //ROGUE
  1046. else if (effects & EF_TAGTRAIL)
  1047. {
  1048. CL_TagTrail (cent->lerp_origin, ent.origin, 220);
  1049. V_AddLight (ent.origin, 225, 1.0, 1.0, 0.0);
  1050. }
  1051. else if (effects & EF_TRACKERTRAIL)
  1052. {
  1053. if (effects & EF_TRACKER)
  1054. {
  1055. float intensity;
  1056. intensity = 50 + (500 * (sin(cl.time/500.0) + 1.0));
  1057. // FIXME - check out this effect in rendition
  1058. if(vidref_val == VIDREF_GL)
  1059. V_AddLight (ent.origin, intensity, -1.0, -1.0, -1.0);
  1060. else
  1061. V_AddLight (ent.origin, -1.0 * intensity, 1.0, 1.0, 1.0);
  1062. }
  1063. else
  1064. {
  1065. CL_Tracker_Shell (cent->lerp_origin);
  1066. V_AddLight (ent.origin, 155, -1.0, -1.0, -1.0);
  1067. }
  1068. }
  1069. else if (effects & EF_TRACKER)
  1070. {
  1071. CL_TrackerTrail (cent->lerp_origin, ent.origin, 0);
  1072. // FIXME - check out this effect in rendition
  1073. if(vidref_val == VIDREF_GL)
  1074. V_AddLight (ent.origin, 200, -1, -1, -1);
  1075. else
  1076. V_AddLight (ent.origin, -200, 1, 1, 1);
  1077. }
  1078. //ROGUE
  1079. //======
  1080. // RAFAEL
  1081. else if (effects & EF_GREENGIB)
  1082. {
  1083. CL_DiminishingTrail (cent->lerp_origin, ent.origin, cent, effects);
  1084. }
  1085. // RAFAEL
  1086. else if (effects & EF_IONRIPPER)
  1087. {
  1088. CL_IonripperTrail (cent->lerp_origin, ent.origin);
  1089. V_AddLight (ent.origin, 100, 1, 0.5, 0.5);
  1090. }
  1091. // RAFAEL
  1092. else if (effects & EF_BLUEHYPERBLASTER)
  1093. {
  1094. V_AddLight (ent.origin, 200, 0, 0, 1);
  1095. }
  1096. // RAFAEL
  1097. else if (effects & EF_PLASMA)
  1098. {
  1099. if (effects & EF_ANIM_ALLFAST)
  1100. {
  1101. CL_BlasterTrail (cent->lerp_origin, ent.origin);
  1102. }
  1103. V_AddLight (ent.origin, 130, 1, 0.5, 0.5);
  1104. }
  1105. }
  1106. VectorCopy (ent.origin, cent->lerp_origin);
  1107. }
  1108. }
  1109. /*
  1110. ==============
  1111. CL_AddViewWeapon
  1112. ==============
  1113. */
  1114. void CL_AddViewWeapon (player_state_t *ps, player_state_t *ops)
  1115. {
  1116. entity_t gun; // view model
  1117. int i;
  1118. // allow the gun to be completely removed
  1119. if (!cl_gun->value)
  1120. return;
  1121. // don't draw gun if in wide angle view
  1122. if (ps->fov > 90)
  1123. return;
  1124. memset (&gun, 0, sizeof(gun));
  1125. if (gun_model)
  1126. gun.model = gun_model; // development tool
  1127. else
  1128. gun.model = cl.model_draw[ps->gunindex];
  1129. if (!gun.model)
  1130. return;
  1131. // set up gun position
  1132. for (i=0 ; i<3 ; i++)
  1133. {
  1134. gun.origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i]
  1135. + cl.lerpfrac * (ps->gunoffset[i] - ops->gunoffset[i]);
  1136. gun.angles[i] = cl.refdef.viewangles[i] + LerpAngle (ops->gunangles[i],
  1137. ps->gunangles[i], cl.lerpfrac);
  1138. }
  1139. if (gun_frame)
  1140. {
  1141. gun.frame = gun_frame; // development tool
  1142. gun.oldframe = gun_frame; // development tool
  1143. }
  1144. else
  1145. {
  1146. gun.frame = ps->gunframe;
  1147. if (gun.frame == 0)
  1148. gun.oldframe = 0; // just changed weapons, don't lerp from old
  1149. else
  1150. gun.oldframe = ops->gunframe;
  1151. }
  1152. gun.flags = RF_MINLIGHT | RF_DEPTHHACK | RF_WEAPONMODEL;
  1153. gun.backlerp = 1.0 - cl.lerpfrac;
  1154. VectorCopy (gun.origin, gun.oldorigin); // don't lerp at all
  1155. V_AddEntity (&gun);
  1156. }
  1157. /*
  1158. ===============
  1159. CL_CalcViewValues
  1160. Sets cl.refdef view values
  1161. ===============
  1162. */
  1163. void CL_CalcViewValues (void)
  1164. {
  1165. int i;
  1166. float lerp, backlerp;
  1167. centity_t *ent;
  1168. frame_t *oldframe;
  1169. player_state_t *ps, *ops;
  1170. // find the previous frame to interpolate from
  1171. ps = &cl.frame.playerstate;
  1172. i = (cl.frame.serverframe - 1) & UPDATE_MASK;
  1173. oldframe = &cl.frames[i];
  1174. if (oldframe->serverframe != cl.frame.serverframe-1 || !oldframe->valid)
  1175. oldframe = &cl.frame; // previous frame was dropped or involid
  1176. ops = &oldframe->playerstate;
  1177. // see if the player entity was teleported this frame
  1178. if ( fabs(ops->pmove.origin[0] - ps->pmove.origin[0]) > 256*8
  1179. || abs(ops->pmove.origin[1] - ps->pmove.origin[1]) > 256*8
  1180. || abs(ops->pmove.origin[2] - ps->pmove.origin[2]) > 256*8)
  1181. ops = ps; // don't interpolate
  1182. ent = &cl_entities[cl.playernum+1];
  1183. lerp = cl.lerpfrac;
  1184. // calculate the origin
  1185. if ((cl_predict->value) && !(cl.frame.playerstate.pmove.pm_flags & PMF_NO_PREDICTION))
  1186. { // use predicted values
  1187. unsigned delta;
  1188. backlerp = 1.0 - lerp;
  1189. for (i=0 ; i<3 ; i++)
  1190. {
  1191. cl.refdef.vieworg[i] = cl.predicted_origin[i] + ops->viewoffset[i]
  1192. + cl.lerpfrac * (ps->viewoffset[i] - ops->viewoffset[i])
  1193. - backlerp * cl.prediction_error[i];
  1194. }
  1195. // smooth out stair climbing
  1196. delta = cls.realtime - cl.predicted_step_time;
  1197. if (delta < 100)
  1198. cl.refdef.vieworg[2] -= cl.predicted_step * (100 - delta) * 0.01;
  1199. }
  1200. else
  1201. { // just use interpolated values
  1202. for (i=0 ; i<3 ; i++)
  1203. cl.refdef.vieworg[i] = ops->pmove.origin[i]*0.125 + ops->viewoffset[i]
  1204. + lerp * (ps->pmove.origin[i]*0.125 + ps->viewoffset[i]
  1205. - (ops->pmove.origin[i]*0.125 + ops->viewoffset[i]) );
  1206. }
  1207. // if not running a demo or on a locked frame, add the local angle movement
  1208. if ( cl.frame.playerstate.pmove.pm_type < PM_DEAD )
  1209. { // use predicted values
  1210. for (i=0 ; i<3 ; i++)
  1211. cl.refdef.viewangles[i] = cl.predicted_angles[i];
  1212. }
  1213. else
  1214. { // just use interpolated values
  1215. for (i=0 ; i<3 ; i++)
  1216. cl.refdef.viewangles[i] = LerpAngle (ops->viewangles[i], ps->viewangles[i], lerp);
  1217. }
  1218. for (i=0 ; i<3 ; i++)
  1219. cl.refdef.viewangles[i] += LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
  1220. AngleVectors (cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
  1221. // interpolate field of view
  1222. cl.refdef.fov_x = ops->fov + lerp * (ps->fov - ops->fov);
  1223. // don't interpolate blend color
  1224. for (i=0 ; i<4 ; i++)
  1225. cl.refdef.blend[i] = ps->blend[i];
  1226. // add the weapon
  1227. CL_AddViewWeapon (ps, ops);
  1228. }
  1229. /*
  1230. ===============
  1231. CL_AddEntities
  1232. Emits all entities, particles, and lights to the refresh
  1233. ===============
  1234. */
  1235. void CL_AddEntities (void)
  1236. {
  1237. if (cls.state != ca_active)
  1238. return;
  1239. if (cl.time > cl.frame.servertime)
  1240. {
  1241. if (cl_showclamp->value)
  1242. Com_Printf ("high clamp %i\n", cl.time - cl.frame.servertime);
  1243. cl.time = cl.frame.servertime;
  1244. cl.lerpfrac = 1.0;
  1245. }
  1246. else if (cl.time < cl.frame.servertime - 100)
  1247. {
  1248. if (cl_showclamp->value)
  1249. Com_Printf ("low clamp %i\n", cl.frame.servertime-100 - cl.time);
  1250. cl.time = cl.frame.servertime - 100;
  1251. cl.lerpfrac = 0;
  1252. }
  1253. else
  1254. cl.lerpfrac = 1.0 - (cl.frame.servertime - cl.time) * 0.01;
  1255. if (cl_timedemo->value)
  1256. cl.lerpfrac = 1.0;
  1257. // CL_AddPacketEntities (&cl.frame);
  1258. // CL_AddTEnts ();
  1259. // CL_AddParticles ();
  1260. // CL_AddDLights ();
  1261. // CL_AddLightStyles ();
  1262. CL_CalcViewValues ();
  1263. // PMM - moved this here so the heat beam has the right values for the vieworg, and can lock the beam to the gun
  1264. CL_AddPacketEntities (&cl.frame);
  1265. #if 0
  1266. CL_AddProjectiles ();
  1267. #endif
  1268. CL_AddTEnts ();
  1269. CL_AddParticles ();
  1270. CL_AddDLights ();
  1271. CL_AddLightStyles ();
  1272. }
  1273. /*
  1274. ===============
  1275. CL_GetEntitySoundOrigin
  1276. Called to get the sound spatialization origin
  1277. ===============
  1278. */
  1279. void CL_GetEntitySoundOrigin (int ent, vec3_t org)
  1280. {
  1281. centity_t *old;
  1282. if (ent < 0 || ent >= MAX_EDICTS)
  1283. Com_Error (ERR_DROP, "CL_GetEntitySoundOrigin: bad ent");
  1284. old = &cl_entities[ent];
  1285. VectorCopy (old->lerp_origin, org);
  1286. // FIXME: bmodel issues...
  1287. }