r_main.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include "doomdef.h"
  25. #include "d_net.h"
  26. #include "m_bbox.h"
  27. #include "r_local.h"
  28. #include "r_sky.h"
  29. #include "i_system.h"
  30. // Fineangles in the SCREENWIDTH wide window.
  31. // increment every time a check is made
  32. // just for profiling purposes
  33. // 0 = high, 1 = low
  34. //
  35. // precalculated math tables
  36. //
  37. // The ::g->viewangletox[::g->viewangle + FINEANGLES/4] lookup
  38. // maps the visible view angles to screen X coordinates,
  39. // flattening the arc to a flat ::g->projection plane.
  40. // There will be many angles mapped to the same X.
  41. // The xtoviewangleangle[] table maps a screen pixel
  42. // to the lowest ::g->viewangle that maps back to x ranges
  43. // from ::g->clipangle to -::g->clipangle.
  44. // UNUSED.
  45. // The finetangentgent[angle+FINEANGLES/4] table
  46. // holds the fixed_t tangent values for view angles,
  47. // ranging from MININT to 0 to MAXINT.
  48. // fixed_t finetangent[FINEANGLES/2];
  49. // fixed_t finesine[5*FINEANGLES/4];
  50. const fixed_t* finecosine = &finesine[FINEANGLES/4];
  51. // bumped light from gun blasts
  52. void (*colfunc) (lighttable_t * dc_colormap,
  53. byte * dc_source);
  54. void (*basecolfunc) (lighttable_t * dc_colormap,
  55. byte * dc_source);
  56. void (*fuzzcolfunc) (lighttable_t * dc_colormap,
  57. byte * dc_source);
  58. void (*transcolfunc) (lighttable_t * dc_colormap,
  59. byte * dc_source);
  60. void (*spanfunc) (fixed_t xfrac,
  61. fixed_t yfrac,
  62. fixed_t ds_y,
  63. int ds_x1,
  64. int ds_x2,
  65. fixed_t ds_xstep,
  66. fixed_t ds_ystep,
  67. lighttable_t * ds_colormap,
  68. byte * ds_source);
  69. //
  70. // R_AddPointToBox
  71. // Expand a given bbox
  72. // so that it encloses a given point.
  73. //
  74. void
  75. R_AddPointToBox
  76. ( int x,
  77. int y,
  78. fixed_t* box )
  79. {
  80. if (x< box[BOXLEFT])
  81. box[BOXLEFT] = x;
  82. if (x> box[BOXRIGHT])
  83. box[BOXRIGHT] = x;
  84. if (y< box[BOXBOTTOM])
  85. box[BOXBOTTOM] = y;
  86. if (y> box[BOXTOP])
  87. box[BOXTOP] = y;
  88. }
  89. //
  90. // R_PointOnSide
  91. // Traverse BSP (sub) tree,
  92. // check point against partition plane.
  93. // Returns side 0 (front) or 1 (back).
  94. //
  95. int
  96. R_PointOnSide
  97. ( fixed_t x,
  98. fixed_t y,
  99. node_t* node )
  100. {
  101. fixed_t dx;
  102. fixed_t dy;
  103. fixed_t left;
  104. fixed_t right;
  105. if (!node->dx)
  106. {
  107. if (x <= node->x)
  108. return node->dy > 0;
  109. return node->dy < 0;
  110. }
  111. if (!node->dy)
  112. {
  113. if (y <= node->y)
  114. return node->dx < 0;
  115. return node->dx > 0;
  116. }
  117. dx = (x - node->x);
  118. dy = (y - node->y);
  119. // Try to quickly decide by looking at sign bits.
  120. if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 )
  121. {
  122. if ( (node->dy ^ dx) & 0x80000000 )
  123. {
  124. // (left is negative)
  125. return 1;
  126. }
  127. return 0;
  128. }
  129. left = FixedMul ( node->dy>>FRACBITS , dx );
  130. right = FixedMul ( dy , node->dx>>FRACBITS );
  131. if (right < left)
  132. {
  133. // front side
  134. return 0;
  135. }
  136. // back side
  137. return 1;
  138. }
  139. int
  140. R_PointOnSegSide
  141. ( fixed_t x,
  142. fixed_t y,
  143. seg_t* line )
  144. {
  145. fixed_t lx;
  146. fixed_t ly;
  147. fixed_t ldx;
  148. fixed_t ldy;
  149. fixed_t dx;
  150. fixed_t dy;
  151. fixed_t left;
  152. fixed_t right;
  153. lx = line->v1->x;
  154. ly = line->v1->y;
  155. ldx = line->v2->x - lx;
  156. ldy = line->v2->y - ly;
  157. if (!ldx)
  158. {
  159. if (x <= lx)
  160. return ldy > 0;
  161. return ldy < 0;
  162. }
  163. if (!ldy)
  164. {
  165. if (y <= ly)
  166. return ldx < 0;
  167. return ldx > 0;
  168. }
  169. dx = (x - lx);
  170. dy = (y - ly);
  171. // Try to quickly decide by looking at sign bits.
  172. if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 )
  173. {
  174. if ( (ldy ^ dx) & 0x80000000 )
  175. {
  176. // (left is negative)
  177. return 1;
  178. }
  179. return 0;
  180. }
  181. left = FixedMul ( ldy>>FRACBITS , dx );
  182. right = FixedMul ( dy , ldx>>FRACBITS );
  183. if (right < left)
  184. {
  185. // front side
  186. return 0;
  187. }
  188. // back side
  189. return 1;
  190. }
  191. //
  192. // R_PointToAngle
  193. // To get a global angle from cartesian coordinates,
  194. // the coordinates are flipped until they are in
  195. // the first octant of the coordinate system, then
  196. // the y (<=x) is scaled and divided by x to get a
  197. // tangent (slope) value which is looked up in the
  198. // tantoangle[] table.
  199. //
  200. angle_t
  201. R_PointToAngle
  202. ( fixed_t x,
  203. fixed_t y )
  204. {
  205. extern fixed_t GetViewX(); extern fixed_t GetViewY();
  206. x -= GetViewX();
  207. y -= GetViewY();
  208. if ( (!x) && (!y) )
  209. return 0;
  210. if (x>= 0)
  211. {
  212. // x >=0
  213. if (y>= 0)
  214. {
  215. // y>= 0
  216. if (x>y)
  217. {
  218. // octant 0
  219. return tantoangle[ SlopeDiv(y,x)];
  220. }
  221. else
  222. {
  223. // octant 1
  224. return ANG90-1-tantoangle[ SlopeDiv(x,y)];
  225. }
  226. }
  227. else
  228. {
  229. // y<0
  230. y = -y;
  231. if (x>y)
  232. {
  233. // octant 8
  234. return -tantoangle[SlopeDiv(y,x)]; // // ALANHACK UNSIGNED
  235. }
  236. else
  237. {
  238. // octant 7
  239. return ANG270+tantoangle[ SlopeDiv(x,y)];
  240. }
  241. }
  242. }
  243. else
  244. {
  245. // x<0
  246. x = -x;
  247. if (y>= 0)
  248. {
  249. // y>= 0
  250. if (x>y)
  251. {
  252. // octant 3
  253. return ANG180-1-tantoangle[ SlopeDiv(y,x)];
  254. }
  255. else
  256. {
  257. // octant 2
  258. return ANG90+ tantoangle[ SlopeDiv(x,y)];
  259. }
  260. }
  261. else
  262. {
  263. // y<0
  264. y = -y;
  265. if (x>y)
  266. {
  267. // octant 4
  268. return ANG180+tantoangle[ SlopeDiv(y,x)];
  269. }
  270. else
  271. {
  272. // octant 5
  273. return ANG270-1-tantoangle[ SlopeDiv(x,y)];
  274. }
  275. }
  276. }
  277. return 0;
  278. }
  279. angle_t
  280. R_PointToAngle2
  281. ( fixed_t x1,
  282. fixed_t y1,
  283. fixed_t x2,
  284. fixed_t y2 )
  285. {
  286. extern void SetViewX( fixed_t ); extern void SetViewY( fixed_t );
  287. SetViewX( x1 );
  288. SetViewY( y1 );
  289. return R_PointToAngle (x2, y2);
  290. }
  291. fixed_t
  292. R_PointToDist
  293. ( fixed_t x,
  294. fixed_t y )
  295. {
  296. int angle;
  297. fixed_t dx;
  298. fixed_t dy;
  299. fixed_t temp;
  300. fixed_t dist;
  301. extern fixed_t GetViewX(); extern fixed_t GetViewY();
  302. dx = abs(x - GetViewX());
  303. dy = abs(y - GetViewY());
  304. if (dy>dx)
  305. {
  306. temp = dx;
  307. dx = dy;
  308. dy = temp;
  309. }
  310. angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT;
  311. // use as cosine
  312. dist = FixedDiv (dx, finesine[angle] );
  313. return dist;
  314. }
  315. //
  316. // R_InitPointToAngle
  317. //
  318. void R_InitPointToAngle (void)
  319. {
  320. // UNUSED - now getting from tables.c
  321. #if 0
  322. int i;
  323. long t;
  324. float f;
  325. //
  326. // slope (tangent) to angle lookup
  327. //
  328. for (i=0 ; i<=SLOPERANGE ; i++)
  329. {
  330. f = atan( (float)i/SLOPERANGE )/(3.141592657*2);
  331. t = 0xffffffff*f;
  332. tantoangle[i] = t;
  333. }
  334. #endif
  335. }
  336. //
  337. // R_ScaleFromGlobalAngle
  338. // Returns the texture mapping scale
  339. // for the current line (horizontal span)
  340. // at the given angle.
  341. // ::g->rw_distance must be calculated first.
  342. //
  343. fixed_t R_ScaleFromGlobalAngle (angle_t visangle)
  344. {
  345. fixed_t scale;
  346. //int anglea;
  347. //int angleb;
  348. angle_t anglea;
  349. angle_t angleb;
  350. int sinea;
  351. int sineb;
  352. fixed_t num;
  353. int den;
  354. // UNUSED
  355. #if 0
  356. {
  357. fixed_t dist;
  358. fixed_t z;
  359. fixed_t sinv;
  360. fixed_t cosv;
  361. sinv = finesine[(visangle-::g->rw_normalangle)>>ANGLETOFINESHIFT];
  362. dist = FixedDiv (::g->rw_distance, sinv);
  363. cosv = finecosine[(::g->viewangle-visangle)>>ANGLETOFINESHIFT];
  364. z = abs(FixedMul (dist, cosv));
  365. scale = FixedDiv(::g->projection, z);
  366. return scale;
  367. }
  368. #endif
  369. extern angle_t GetViewAngle();
  370. anglea = ANG90 + (visangle-GetViewAngle());
  371. angleb = ANG90 + (visangle-::g->rw_normalangle);
  372. // both sines are allways positive
  373. sinea = finesine[anglea>>ANGLETOFINESHIFT];
  374. sineb = finesine[angleb>>ANGLETOFINESHIFT];
  375. num = FixedMul(::g->projection,sineb) << ::g->detailshift;
  376. den = FixedMul(::g->rw_distance,sinea);
  377. // DHM - Nerve :: If the den is pretty much 0, don't try the divide
  378. if (den>>8 > 0 && den > num>>16)
  379. {
  380. scale = FixedDiv (num, den);
  381. if (scale > 64*FRACUNIT)
  382. scale = 64*FRACUNIT;
  383. else if (scale < 256)
  384. scale = 256;
  385. }
  386. else
  387. scale = 64*FRACUNIT;
  388. return scale;
  389. }
  390. //
  391. // R_InitTables
  392. //
  393. void R_InitTables (void)
  394. {
  395. // UNUSED: now getting from tables.c
  396. #if 0
  397. int i;
  398. float a;
  399. float fv;
  400. int t;
  401. // ::g->viewangle tangent table
  402. for (i=0 ; i<FINEANGLES/2 ; i++)
  403. {
  404. a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES;
  405. fv = FRACUNIT*tan (a);
  406. t = fv;
  407. finetangent[i] = t;
  408. }
  409. // finesine table
  410. for (i=0 ; i<5*FINEANGLES/4 ; i++)
  411. {
  412. // OPTIMIZE: mirror...
  413. a = (i+0.5)*PI*2/FINEANGLES;
  414. t = FRACUNIT*sin (a);
  415. finesine[i] = t;
  416. }
  417. #endif
  418. }
  419. //
  420. // R_InitTextureMapping
  421. //
  422. void R_InitTextureMapping (void)
  423. {
  424. int i;
  425. int x;
  426. int t;
  427. fixed_t focallength;
  428. // Use tangent table to generate viewangletox:
  429. // ::g->viewangletox will give the next greatest x
  430. // after the view angle.
  431. //
  432. // Calc focallength
  433. // so FIELDOFVIEW angles covers SCREENWIDTH.
  434. focallength = FixedDiv (::g->centerxfrac,
  435. finetangent[FINEANGLES/4+FIELDOFVIEW/2] );
  436. for (i=0 ; i<FINEANGLES/2 ; i++)
  437. {
  438. if (finetangent[i] > FRACUNIT*2)
  439. t = -1;
  440. else if (finetangent[i] < -FRACUNIT*2)
  441. t = ::g->viewwidth+1;
  442. else
  443. {
  444. t = FixedMul (finetangent[i], focallength);
  445. t = (::g->centerxfrac - t+FRACUNIT-1)>>FRACBITS;
  446. if (t < -1)
  447. t = -1;
  448. else if (t>::g->viewwidth+1)
  449. t = ::g->viewwidth+1;
  450. }
  451. ::g->viewangletox[i] = t;
  452. }
  453. // Scan ::g->viewangletox[] to generate ::g->xtoviewangle[]:
  454. // ::g->xtoviewangle will give the smallest view angle
  455. // that maps to x.
  456. for (x=0;x<=::g->viewwidth;x++)
  457. {
  458. i = 0;
  459. while (::g->viewangletox[i]>x)
  460. i++;
  461. ::g->xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
  462. }
  463. // Take out the fencepost cases from ::g->viewangletox.
  464. for (i=0 ; i<FINEANGLES/2 ; i++)
  465. {
  466. t = FixedMul (finetangent[i], focallength);
  467. t = ::g->centerx - t;
  468. if (::g->viewangletox[i] == -1)
  469. ::g->viewangletox[i] = 0;
  470. else if (::g->viewangletox[i] == ::g->viewwidth+1)
  471. ::g->viewangletox[i] = ::g->viewwidth;
  472. }
  473. ::g->clipangle = ::g->xtoviewangle[0];
  474. }
  475. //
  476. // R_InitLightTables
  477. // Only inits the ::g->zlight table,
  478. // because the ::g->scalelight table changes with view size.
  479. //
  480. void R_InitLightTables (void)
  481. {
  482. int i;
  483. int j;
  484. int level;
  485. int nocollide_startmap;
  486. int scale;
  487. // Calculate the light levels to use
  488. // for each level / distance combination.
  489. for (i=0 ; i< LIGHTLEVELS ; i++)
  490. {
  491. nocollide_startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
  492. for (j=0 ; j<MAXLIGHTZ ; j++)
  493. {
  494. scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT);
  495. scale >>= LIGHTSCALESHIFT;
  496. level = nocollide_startmap - scale/DISTMAP;
  497. if (level < 0)
  498. level = 0;
  499. if (level >= NUMCOLORMAPS)
  500. level = NUMCOLORMAPS-1;
  501. ::g->zlight[i][j] = ::g->colormaps + level*256;
  502. }
  503. }
  504. }
  505. //
  506. // R_SetViewSize
  507. // Do not really change anything here,
  508. // because it might be in the middle of a refresh.
  509. // The change will take effect next refresh.
  510. //
  511. void
  512. R_SetViewSize
  513. ( int blocks,
  514. int detail )
  515. {
  516. ::g->setsizeneeded = true;
  517. ::g->setblocks = blocks;
  518. ::g->setdetail = detail;
  519. }
  520. //
  521. // R_ExecuteSetViewSize
  522. //
  523. void R_ExecuteSetViewSize (void)
  524. {
  525. fixed_t cosadj;
  526. fixed_t dy;
  527. int i;
  528. int j;
  529. int level;
  530. int nocollide_startmap;
  531. ::g->setsizeneeded = false;
  532. if (::g->setblocks == 11)
  533. {
  534. ::g->scaledviewwidth = ORIGINAL_WIDTH;
  535. ::g->viewheight = ORIGINAL_HEIGHT;
  536. }
  537. else
  538. {
  539. ::g->scaledviewwidth = ::g->setblocks*32;
  540. ::g->viewheight = (::g->setblocks*168/10)&~7;
  541. }
  542. // SMF - temp
  543. ::g->scaledviewwidth *= GLOBAL_IMAGE_SCALER;
  544. ::g->viewheight *= GLOBAL_IMAGE_SCALER;
  545. ::g->detailshift = ::g->setdetail;
  546. ::g->viewwidth = ::g->scaledviewwidth>>::g->detailshift;
  547. ::g->centery = ::g->viewheight/2;
  548. ::g->centerx = ::g->viewwidth/2;
  549. ::g->centerxfrac = ::g->centerx<<FRACBITS;
  550. ::g->centeryfrac = ::g->centery<<FRACBITS;
  551. ::g->projection = ::g->centerxfrac;
  552. if (!::g->detailshift)
  553. {
  554. colfunc = basecolfunc = R_DrawColumn;
  555. fuzzcolfunc = R_DrawFuzzColumn;
  556. transcolfunc = R_DrawTranslatedColumn;
  557. spanfunc = R_DrawSpan;
  558. }
  559. else
  560. {
  561. colfunc = basecolfunc = R_DrawColumnLow;
  562. fuzzcolfunc = R_DrawFuzzColumn;
  563. transcolfunc = R_DrawTranslatedColumn;
  564. spanfunc = R_DrawSpanLow;
  565. }
  566. R_InitBuffer (::g->scaledviewwidth, ::g->viewheight);
  567. R_InitTextureMapping ();
  568. // psprite scales
  569. ::g->pspritescale = FRACUNIT*::g->viewwidth/ORIGINAL_WIDTH;
  570. ::g->pspriteiscale = FRACUNIT*ORIGINAL_WIDTH/::g->viewwidth;
  571. // thing clipping
  572. for (i=0 ; i < ::g->viewwidth ; i++)
  573. ::g->screenheightarray[i] = ::g->viewheight;
  574. // planes
  575. for (i=0 ; i < ::g->viewheight ; i++)
  576. {
  577. dy = ((i-::g->viewheight/2)<<FRACBITS)+FRACUNIT/2;
  578. dy = abs(dy);
  579. ::g->yslope[i] = FixedDiv ( (::g->viewwidth << ::g->detailshift)/2*FRACUNIT, dy);
  580. }
  581. for (i=0 ; i < ::g->viewwidth ; i++)
  582. {
  583. cosadj = abs(finecosine[::g->xtoviewangle[i]>>ANGLETOFINESHIFT]);
  584. ::g->distscale[i] = FixedDiv (FRACUNIT,cosadj);
  585. }
  586. // Calculate the light levels to use
  587. // for each level / scale combination.
  588. for (i=0 ; i< LIGHTLEVELS ; i++)
  589. {
  590. nocollide_startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
  591. for (j=0 ; j<MAXLIGHTSCALE ; j++)
  592. {
  593. level = nocollide_startmap - j*SCREENWIDTH/(::g->viewwidth << ::g->detailshift)/DISTMAP;
  594. if (level < 0)
  595. level = 0;
  596. if (level >= NUMCOLORMAPS)
  597. level = NUMCOLORMAPS-1;
  598. ::g->scalelight[i][j] = ::g->colormaps + level*256;
  599. }
  600. }
  601. }
  602. //
  603. // R_Init
  604. //
  605. void R_Init (void)
  606. {
  607. R_InitData ();
  608. I_Printf ("\nR_InitData");
  609. R_InitPointToAngle ();
  610. I_Printf ("\nR_InitPointToAngle");
  611. R_InitTables ();
  612. // ::g->viewwidth / ::g->viewheight / ::g->detailLevel are set by the defaults
  613. I_Printf ("\nR_InitTables");
  614. R_SetViewSize (::g->screenblocks, ::g->detailLevel);
  615. R_InitPlanes ();
  616. I_Printf ("\nR_InitPlanes");
  617. R_InitLightTables ();
  618. I_Printf ("\nR_InitLightTables");
  619. R_InitSkyMap ();
  620. I_Printf ("\nR_InitSkyMap");
  621. R_InitTranslationTables ();
  622. I_Printf ("\nR_InitTranslationsTables");
  623. ::g->framecount = 0;
  624. }
  625. //
  626. // R_PointInSubsector
  627. //
  628. subsector_t*
  629. R_PointInSubsector
  630. ( fixed_t x,
  631. fixed_t y )
  632. {
  633. node_t* node;
  634. int side;
  635. int nodenum;
  636. // single subsector is a special case
  637. if (!::g->numnodes)
  638. return ::g->subsectors;
  639. nodenum = ::g->numnodes-1;
  640. while (! (nodenum & NF_SUBSECTOR) )
  641. {
  642. node = &::g->nodes[nodenum];
  643. side = R_PointOnSide (x, y, node);
  644. nodenum = node->children[side];
  645. }
  646. return &::g->subsectors[nodenum & ~NF_SUBSECTOR];
  647. }
  648. //
  649. // R_SetupFrame
  650. //
  651. void R_SetupFrame (player_t* player)
  652. {
  653. int i;
  654. ::g->viewplayer = player;
  655. extern void SetViewX( fixed_t ); extern void SetViewY( fixed_t ); extern void SetViewAngle( angle_t );
  656. SetViewX( player->mo->x );
  657. SetViewY( player->mo->y );
  658. SetViewAngle( player->mo->angle + ::g->viewangleoffset );
  659. ::g->extralight = player->extralight;
  660. ::g->viewz = player->viewz;
  661. extern angle_t GetViewAngle();
  662. ::g->viewsin = finesine[GetViewAngle()>>ANGLETOFINESHIFT];
  663. ::g->viewcos = finecosine[GetViewAngle()>>ANGLETOFINESHIFT];
  664. ::g->sscount = 0;
  665. if (player->fixedcolormap)
  666. {
  667. ::g->fixedcolormap =
  668. ::g->colormaps
  669. + player->fixedcolormap*256*sizeof(lighttable_t);
  670. ::g->walllights = ::g->scalelightfixed;
  671. for (i=0 ; i<MAXLIGHTSCALE ; i++)
  672. ::g->scalelightfixed[i] = ::g->fixedcolormap;
  673. }
  674. else
  675. ::g->fixedcolormap = 0;
  676. ::g->framecount++;
  677. ::g->validcount++;
  678. }
  679. //
  680. // R_RenderView
  681. //
  682. void R_RenderPlayerView (player_t* player)
  683. {
  684. if ( player->mo == NULL ) {
  685. return;
  686. }
  687. R_SetupFrame (player);
  688. // Clear buffers.
  689. R_ClearClipSegs ();
  690. R_ClearDrawSegs ();
  691. R_ClearPlanes ();
  692. R_ClearSprites ();
  693. // check for new console commands.
  694. NetUpdate ( NULL );
  695. // The head node is the last node output.
  696. R_RenderBSPNode (::g->numnodes-1);
  697. // Check for new console commands.
  698. NetUpdate ( NULL );
  699. R_DrawPlanes ();
  700. // Check for new console commands.
  701. NetUpdate ( NULL );
  702. R_DrawMasked ();
  703. // Check for new console commands.
  704. NetUpdate ( NULL );
  705. }