r_segs.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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 "i_system.h"
  24. #include "doomdef.h"
  25. #include "doomstat.h"
  26. #include "r_local.h"
  27. #include "r_sky.h"
  28. // OPTIMIZE: closed two sided ::g->lines as single sided
  29. // True if any of the ::g->segs textures might be visible.
  30. // False if the back side is the same plane.
  31. // angle to line origin
  32. //
  33. // regular wall
  34. //
  35. //
  36. // R_RenderMaskedSegRange
  37. //
  38. void
  39. R_RenderMaskedSegRange
  40. ( drawseg_t* ds,
  41. int x1,
  42. int x2 )
  43. {
  44. unsigned index;
  45. postColumn_t* col;
  46. int lightnum;
  47. int texnum;
  48. // Calculate light table.
  49. // Use different light tables
  50. // for horizontal / vertical / diagonal. Diagonal?
  51. // OPTIMIZE: get rid of LIGHTSEGSHIFT globally
  52. ::g->curline = ds->curline;
  53. ::g->frontsector = ::g->curline->frontsector;
  54. ::g->backsector = ::g->curline->backsector;
  55. texnum = ::g->texturetranslation[::g->curline->sidedef->midtexture];
  56. lightnum = (::g->frontsector->lightlevel >> LIGHTSEGSHIFT)+::g->extralight;
  57. if (::g->curline->v1->y == ::g->curline->v2->y)
  58. lightnum--;
  59. else if (::g->curline->v1->x == ::g->curline->v2->x)
  60. lightnum++;
  61. if (lightnum < 0)
  62. ::g->walllights = ::g->scalelight[0];
  63. else if (lightnum >= LIGHTLEVELS)
  64. ::g->walllights = ::g->scalelight[LIGHTLEVELS-1];
  65. else
  66. ::g->walllights = ::g->scalelight[lightnum];
  67. ::g->maskedtexturecol = ds->maskedtexturecol;
  68. ::g->rw_scalestep = ds->scalestep;
  69. ::g->spryscale = ds->scale1 + (x1 - ds->x1)*::g->rw_scalestep;
  70. ::g->mfloorclip = ds->sprbottomclip;
  71. ::g->mceilingclip = ds->sprtopclip;
  72. // find positioning
  73. if (::g->curline->linedef->flags & ML_DONTPEGBOTTOM)
  74. {
  75. ::g->dc_texturemid = ::g->frontsector->floorheight > ::g->backsector->floorheight
  76. ? ::g->frontsector->floorheight : ::g->backsector->floorheight;
  77. ::g->dc_texturemid = ::g->dc_texturemid + ::g->s_textureheight[texnum] - ::g->viewz;
  78. }
  79. else
  80. {
  81. ::g->dc_texturemid =::g->frontsector->ceilingheight < ::g->backsector->ceilingheight
  82. ? ::g->frontsector->ceilingheight : ::g->backsector->ceilingheight;
  83. ::g->dc_texturemid = ::g->dc_texturemid - ::g->viewz;
  84. }
  85. ::g->dc_texturemid += ::g->curline->sidedef->rowoffset;
  86. if (::g->fixedcolormap)
  87. ::g->dc_colormap = ::g->fixedcolormap;
  88. // draw the columns
  89. for (::g->dc_x = x1 ; ::g->dc_x <= x2 ; ::g->dc_x++)
  90. {
  91. // calculate lighting
  92. if (::g->maskedtexturecol[::g->dc_x] != SHRT_MAX)
  93. {
  94. if (!::g->fixedcolormap)
  95. {
  96. index = ::g->spryscale>>LIGHTSCALESHIFT;
  97. if (index >= MAXLIGHTSCALE )
  98. index = MAXLIGHTSCALE-1;
  99. ::g->dc_colormap = ::g->walllights[index];
  100. }
  101. ::g->sprtopscreen = ::g->centeryfrac - FixedMul(::g->dc_texturemid, ::g->spryscale);
  102. ::g->dc_iscale = 0xffffffffu / (unsigned)::g->spryscale;
  103. // draw the texture
  104. col = (postColumn_t *)(
  105. (byte *)R_GetColumn(texnum,::g->maskedtexturecol[::g->dc_x]) -3);
  106. R_DrawMaskedColumn (col);
  107. ::g->maskedtexturecol[::g->dc_x] = SHRT_MAX;
  108. }
  109. ::g->spryscale += ::g->rw_scalestep;
  110. }
  111. }
  112. //
  113. // R_RenderSegLoop
  114. // Draws zero, one, or two textures (and possibly a masked
  115. // texture) for walls.
  116. // Can draw or mark the starting pixel of floor and ceiling
  117. // textures.
  118. // CALLED: CORE LOOPING ROUTINE.
  119. //
  120. void R_RenderSegLoop (void)
  121. {
  122. angle_t angle;
  123. unsigned index;
  124. int yl;
  125. int yh;
  126. int mid;
  127. fixed_t texturecolumn;
  128. int top;
  129. int bottom;
  130. texturecolumn = 0; // shut up compiler warning
  131. for ( ; ::g->rw_x < ::g->rw_stopx ; ::g->rw_x++)
  132. {
  133. // mark floor / ceiling areas
  134. yl = (::g->topfrac+HEIGHTUNIT-1)>>HEIGHTBITS;
  135. // no space above wall?
  136. if (yl < ::g->ceilingclip[::g->rw_x]+1)
  137. yl = ::g->ceilingclip[::g->rw_x]+1;
  138. if (::g->markceiling)
  139. {
  140. top = ::g->ceilingclip[::g->rw_x]+1;
  141. bottom = yl-1;
  142. if (bottom >= ::g->floorclip[::g->rw_x])
  143. bottom = ::g->floorclip[::g->rw_x]-1;
  144. if (top <= bottom)
  145. {
  146. ::g->ceilingplane->top[::g->rw_x] = top;
  147. ::g->ceilingplane->bottom[::g->rw_x] = bottom;
  148. }
  149. }
  150. yh = ::g->bottomfrac>>HEIGHTBITS;
  151. if (yh >= ::g->floorclip[::g->rw_x])
  152. yh = ::g->floorclip[::g->rw_x]-1;
  153. if (::g->markfloor)
  154. {
  155. top = yh+1;
  156. bottom = ::g->floorclip[::g->rw_x]-1;
  157. if (top <= ::g->ceilingclip[::g->rw_x])
  158. top = ::g->ceilingclip[::g->rw_x]+1;
  159. if (top <= bottom)
  160. {
  161. ::g->floorplane->top[::g->rw_x] = top;
  162. ::g->floorplane->bottom[::g->rw_x] = bottom;
  163. }
  164. }
  165. // texturecolumn and lighting are independent of wall tiers
  166. if (::g->segtextured)
  167. {
  168. // calculate texture offset
  169. angle = (::g->rw_centerangle + ::g->xtoviewangle[::g->rw_x])>>ANGLETOFINESHIFT;
  170. texturecolumn = ::g->rw_offset-FixedMul(finetangent[angle],::g->rw_distance);
  171. texturecolumn >>= FRACBITS;
  172. // calculate lighting
  173. index = ::g->rw_scale>>LIGHTSCALESHIFT;
  174. if (index >= MAXLIGHTSCALE )
  175. index = MAXLIGHTSCALE-1;
  176. ::g->dc_colormap = ::g->walllights[index];
  177. ::g->dc_x = ::g->rw_x;
  178. ::g->dc_iscale = 0xffffffffu / (unsigned)::g->rw_scale;
  179. }
  180. // draw the wall tiers
  181. if (::g->midtexture)
  182. {
  183. // single sided line
  184. ::g->dc_yl = yl;
  185. ::g->dc_yh = yh;
  186. ::g->dc_texturemid = ::g->rw_midtexturemid;
  187. ::g->dc_source = R_GetColumn(::g->midtexture,texturecolumn);
  188. colfunc ( ::g->dc_colormap, ::g->dc_source );
  189. ::g->ceilingclip[::g->rw_x] = ::g->viewheight;
  190. ::g->floorclip[::g->rw_x] = -1;
  191. }
  192. else
  193. {
  194. // two sided line
  195. if (::g->toptexture)
  196. {
  197. // top wall
  198. mid = ::g->pixhigh>>HEIGHTBITS;
  199. ::g->pixhigh += ::g->pixhighstep;
  200. if (mid >= ::g->floorclip[::g->rw_x])
  201. mid = ::g->floorclip[::g->rw_x]-1;
  202. if (mid >= yl)
  203. {
  204. ::g->dc_yl = yl;
  205. ::g->dc_yh = mid;
  206. ::g->dc_texturemid = ::g->rw_toptexturemid;
  207. ::g->dc_source = R_GetColumn(::g->toptexture,texturecolumn);
  208. colfunc ( ::g->dc_colormap, ::g->dc_source );
  209. ::g->ceilingclip[::g->rw_x] = mid;
  210. }
  211. else
  212. ::g->ceilingclip[::g->rw_x] = yl-1;
  213. }
  214. else
  215. {
  216. // no top wall
  217. if (::g->markceiling)
  218. ::g->ceilingclip[::g->rw_x] = yl-1;
  219. }
  220. if (::g->bottomtexture)
  221. {
  222. // bottom wall
  223. mid = (::g->pixlow+HEIGHTUNIT-1)>>HEIGHTBITS;
  224. ::g->pixlow += ::g->pixlowstep;
  225. // no space above wall?
  226. if (mid <= ::g->ceilingclip[::g->rw_x])
  227. mid = ::g->ceilingclip[::g->rw_x]+1;
  228. if (mid <= yh)
  229. {
  230. ::g->dc_yl = mid;
  231. ::g->dc_yh = yh;
  232. ::g->dc_texturemid = ::g->rw_bottomtexturemid;
  233. ::g->dc_source = R_GetColumn(::g->bottomtexture,
  234. texturecolumn);
  235. colfunc ( ::g->dc_colormap, ::g->dc_source );
  236. ::g->floorclip[::g->rw_x] = mid;
  237. }
  238. else
  239. ::g->floorclip[::g->rw_x] = yh+1;
  240. }
  241. else
  242. {
  243. // no bottom wall
  244. if (::g->markfloor)
  245. ::g->floorclip[::g->rw_x] = yh+1;
  246. }
  247. if (::g->maskedtexture)
  248. {
  249. // save texturecol
  250. // for backdrawing of masked mid texture
  251. ::g->maskedtexturecol[::g->rw_x] = texturecolumn;
  252. }
  253. }
  254. ::g->rw_scale += ::g->rw_scalestep;
  255. ::g->topfrac += ::g->topstep;
  256. ::g->bottomfrac += ::g->bottomstep;
  257. }
  258. }
  259. //
  260. // R_StoreWallRange
  261. // A wall segment will be drawn
  262. // between start and stop pixels (inclusive).
  263. //
  264. void
  265. R_StoreWallRange
  266. ( int start,
  267. int stop )
  268. {
  269. fixed_t hyp;
  270. fixed_t sineval;
  271. angle_t distangle, offsetangle;
  272. fixed_t vtop;
  273. int lightnum;
  274. // don't overflow and crash
  275. if (::g->ds_p == &::g->drawsegs[MAXDRAWSEGS])
  276. return;
  277. #ifdef RANGECHECK
  278. if (start >=::g->viewwidth || start > stop)
  279. I_Error ("Bad R_RenderWallRange: %i to %i", start , stop);
  280. #endif
  281. ::g->sidedef = ::g->curline->sidedef;
  282. ::g->linedef = ::g->curline->linedef;
  283. // mark the segment as visible for auto map
  284. ::g->linedef->flags |= ML_MAPPED;
  285. // calculate ::g->rw_distance for scale calculation
  286. ::g->rw_normalangle = ::g->curline->angle + ANG90;
  287. offsetangle = abs((long)(::g->rw_normalangle-::g->rw_angle1));
  288. if (offsetangle > ANG90)
  289. offsetangle = ANG90;
  290. distangle = ANG90 - offsetangle;
  291. hyp = R_PointToDist (::g->curline->v1->x, ::g->curline->v1->y);
  292. sineval = finesine[distangle>>ANGLETOFINESHIFT];
  293. ::g->rw_distance = FixedMul (hyp, sineval);
  294. ::g->ds_p->x1 = ::g->rw_x = start;
  295. ::g->ds_p->x2 = stop;
  296. ::g->ds_p->curline = ::g->curline;
  297. ::g->rw_stopx = stop+1;
  298. // calculate scale at both ends and step
  299. extern angle_t GetViewAngle();
  300. ::g->ds_p->scale1 = ::g->rw_scale =
  301. R_ScaleFromGlobalAngle (GetViewAngle() + ::g->xtoviewangle[start]);
  302. if (stop > start )
  303. {
  304. ::g->ds_p->scale2 = R_ScaleFromGlobalAngle (GetViewAngle() + ::g->xtoviewangle[stop]);
  305. ::g->ds_p->scalestep = ::g->rw_scalestep =
  306. (::g->ds_p->scale2 - ::g->rw_scale) / (stop-start);
  307. }
  308. else
  309. {
  310. // UNUSED: try to fix the stretched line bug
  311. #if 0
  312. if (::g->rw_distance < FRACUNIT/2)
  313. {
  314. fixed_t trx,try;
  315. fixed_t gxt,gyt;
  316. extern fixed_t GetViewX(); extern fixed_t GetViewY();
  317. trx = ::g->curline->v1->x - GetViewX();
  318. try = ::g->curline->v1->y - GetVewY();
  319. gxt = FixedMul(trx,::g->viewcos);
  320. gyt = -FixedMul(try,::g->viewsin);
  321. ::g->ds_p->scale1 = FixedDiv(::g->projection, gxt-gyt) << ::g->detailshift;
  322. }
  323. #endif
  324. ::g->ds_p->scale2 = ::g->ds_p->scale1;
  325. }
  326. // calculate texture boundaries
  327. // and decide if floor / ceiling marks are needed
  328. ::g->worldtop = ::g->frontsector->ceilingheight - ::g->viewz;
  329. ::g->worldbottom = ::g->frontsector->floorheight - ::g->viewz;
  330. ::g->midtexture = ::g->toptexture = ::g->bottomtexture = ::g->maskedtexture = 0;
  331. ::g->ds_p->maskedtexturecol = NULL;
  332. if (!::g->backsector)
  333. {
  334. // single sided line
  335. ::g->midtexture = ::g->texturetranslation[::g->sidedef->midtexture];
  336. // a single sided line is terminal, so it must mark ends
  337. ::g->markfloor = ::g->markceiling = true;
  338. if (::g->linedef->flags & ML_DONTPEGBOTTOM)
  339. {
  340. vtop = ::g->frontsector->floorheight +
  341. ::g->s_textureheight[::g->sidedef->midtexture];
  342. // bottom of texture at bottom
  343. ::g->rw_midtexturemid = vtop - ::g->viewz;
  344. }
  345. else
  346. {
  347. // top of texture at top
  348. ::g->rw_midtexturemid = ::g->worldtop;
  349. }
  350. ::g->rw_midtexturemid += ::g->sidedef->rowoffset;
  351. ::g->ds_p->silhouette = SIL_BOTH;
  352. ::g->ds_p->sprtopclip = ::g->screenheightarray;
  353. ::g->ds_p->sprbottomclip = ::g->negonearray;
  354. ::g->ds_p->bsilheight = MAXINT;
  355. ::g->ds_p->tsilheight = MININT;
  356. }
  357. else
  358. {
  359. // two sided line
  360. ::g->ds_p->sprtopclip = ::g->ds_p->sprbottomclip = NULL;
  361. ::g->ds_p->silhouette = 0;
  362. if (::g->frontsector->floorheight > ::g->backsector->floorheight)
  363. {
  364. ::g->ds_p->silhouette = SIL_BOTTOM;
  365. ::g->ds_p->bsilheight = ::g->frontsector->floorheight;
  366. }
  367. else if (::g->backsector->floorheight > ::g->viewz)
  368. {
  369. ::g->ds_p->silhouette = SIL_BOTTOM;
  370. ::g->ds_p->bsilheight = MAXINT;
  371. // ::g->ds_p->sprbottomclip = ::g->negonearray;
  372. }
  373. if (::g->frontsector->ceilingheight < ::g->backsector->ceilingheight)
  374. {
  375. ::g->ds_p->silhouette |= SIL_TOP;
  376. ::g->ds_p->tsilheight = ::g->frontsector->ceilingheight;
  377. }
  378. else if (::g->backsector->ceilingheight < ::g->viewz)
  379. {
  380. ::g->ds_p->silhouette |= SIL_TOP;
  381. ::g->ds_p->tsilheight = MININT;
  382. // ::g->ds_p->sprtopclip = ::g->screenheightarray;
  383. }
  384. if (::g->backsector->ceilingheight <= ::g->frontsector->floorheight)
  385. {
  386. ::g->ds_p->sprbottomclip = ::g->negonearray;
  387. ::g->ds_p->bsilheight = MAXINT;
  388. ::g->ds_p->silhouette |= SIL_BOTTOM;
  389. }
  390. if (::g->backsector->floorheight >= ::g->frontsector->ceilingheight)
  391. {
  392. ::g->ds_p->sprtopclip = ::g->screenheightarray;
  393. ::g->ds_p->tsilheight = MININT;
  394. ::g->ds_p->silhouette |= SIL_TOP;
  395. }
  396. ::g->worldhigh = ::g->backsector->ceilingheight - ::g->viewz;
  397. ::g->worldlow = ::g->backsector->floorheight - ::g->viewz;
  398. // hack to allow height changes in outdoor areas
  399. if (::g->frontsector->ceilingpic == ::g->skyflatnum
  400. && ::g->backsector->ceilingpic == ::g->skyflatnum)
  401. {
  402. ::g->worldtop = ::g->worldhigh;
  403. }
  404. if (::g->worldlow != ::g->worldbottom
  405. || ::g->backsector->floorpic != ::g->frontsector->floorpic
  406. || ::g->backsector->lightlevel != ::g->frontsector->lightlevel)
  407. {
  408. ::g->markfloor = true;
  409. }
  410. else
  411. {
  412. // same plane on both ::g->sides
  413. ::g->markfloor = false;
  414. }
  415. if (::g->worldhigh != ::g->worldtop
  416. || ::g->backsector->ceilingpic != ::g->frontsector->ceilingpic
  417. || ::g->backsector->lightlevel != ::g->frontsector->lightlevel)
  418. {
  419. ::g->markceiling = true;
  420. }
  421. else
  422. {
  423. // same plane on both ::g->sides
  424. ::g->markceiling = false;
  425. }
  426. if (::g->backsector->ceilingheight <= ::g->frontsector->floorheight
  427. || ::g->backsector->floorheight >= ::g->frontsector->ceilingheight)
  428. {
  429. // closed door
  430. ::g->markceiling = ::g->markfloor = true;
  431. }
  432. if (::g->worldhigh < ::g->worldtop)
  433. {
  434. // top texture
  435. ::g->toptexture = ::g->texturetranslation[::g->sidedef->toptexture];
  436. if (::g->linedef->flags & ML_DONTPEGTOP)
  437. {
  438. // top of texture at top
  439. ::g->rw_toptexturemid = ::g->worldtop;
  440. }
  441. else
  442. {
  443. vtop =
  444. ::g->backsector->ceilingheight
  445. + ::g->s_textureheight[::g->sidedef->toptexture];
  446. // bottom of texture
  447. ::g->rw_toptexturemid = vtop - ::g->viewz;
  448. }
  449. }
  450. if (::g->worldlow > ::g->worldbottom)
  451. {
  452. // bottom texture
  453. ::g->bottomtexture = ::g->texturetranslation[::g->sidedef->bottomtexture];
  454. if (::g->linedef->flags & ML_DONTPEGBOTTOM )
  455. {
  456. // bottom of texture at bottom
  457. // top of texture at top
  458. ::g->rw_bottomtexturemid = ::g->worldtop;
  459. }
  460. else // top of texture at top
  461. ::g->rw_bottomtexturemid = ::g->worldlow;
  462. }
  463. ::g->rw_toptexturemid += ::g->sidedef->rowoffset;
  464. ::g->rw_bottomtexturemid += ::g->sidedef->rowoffset;
  465. // allocate space for masked texture tables
  466. if (::g->sidedef->midtexture)
  467. {
  468. // masked ::g->midtexture
  469. ::g->maskedtexture = true;
  470. ::g->ds_p->maskedtexturecol = ::g->maskedtexturecol = ::g->lastopening - ::g->rw_x;
  471. ::g->lastopening += ::g->rw_stopx - ::g->rw_x;
  472. }
  473. }
  474. // calculate ::g->rw_offset (only needed for textured ::g->lines)
  475. ::g->segtextured = ::g->midtexture | ::g->toptexture | ::g->bottomtexture | ::g->maskedtexture;
  476. if (::g->segtextured)
  477. {
  478. offsetangle = ::g->rw_normalangle-::g->rw_angle1;
  479. if (offsetangle > ANG180)
  480. offsetangle = -offsetangle; // ALANHACK UNSIGNED
  481. if (offsetangle > ANG90)
  482. offsetangle = ANG90;
  483. sineval = finesine[offsetangle >>ANGLETOFINESHIFT];
  484. ::g->rw_offset = FixedMul (hyp, sineval);
  485. if (::g->rw_normalangle-::g->rw_angle1 < ANG180)
  486. ::g->rw_offset = -::g->rw_offset;
  487. ::g->rw_offset += ::g->sidedef->textureoffset + ::g->curline->offset;
  488. ::g->rw_centerangle = ANG90 + GetViewAngle() - ::g->rw_normalangle;
  489. // calculate light table
  490. // use different light tables
  491. // for horizontal / vertical / diagonal
  492. // OPTIMIZE: get rid of LIGHTSEGSHIFT globally
  493. if (!::g->fixedcolormap)
  494. {
  495. lightnum = (::g->frontsector->lightlevel >> LIGHTSEGSHIFT)+::g->extralight;
  496. if (::g->curline->v1->y == ::g->curline->v2->y)
  497. lightnum--;
  498. else if (::g->curline->v1->x == ::g->curline->v2->x)
  499. lightnum++;
  500. if (lightnum < 0)
  501. ::g->walllights = ::g->scalelight[0];
  502. else if (lightnum >= LIGHTLEVELS)
  503. ::g->walllights = ::g->scalelight[LIGHTLEVELS-1];
  504. else
  505. ::g->walllights = ::g->scalelight[lightnum];
  506. }
  507. }
  508. // if a floor / ceiling plane is on the wrong side
  509. // of the view plane, it is definitely invisible
  510. // and doesn't need to be marked.
  511. if (::g->frontsector->floorheight >= ::g->viewz)
  512. {
  513. // above view plane
  514. ::g->markfloor = false;
  515. }
  516. if (::g->frontsector->ceilingheight <= ::g->viewz
  517. && ::g->frontsector->ceilingpic != ::g->skyflatnum)
  518. {
  519. // below view plane
  520. ::g->markceiling = false;
  521. }
  522. // calculate incremental stepping values for texture edges
  523. ::g->worldtop >>= 4;
  524. ::g->worldbottom >>= 4;
  525. ::g->topstep = -FixedMul (::g->rw_scalestep, ::g->worldtop);
  526. ::g->topfrac = (::g->centeryfrac>>4) - FixedMul (::g->worldtop, ::g->rw_scale);
  527. ::g->bottomstep = -FixedMul (::g->rw_scalestep,::g->worldbottom);
  528. ::g->bottomfrac = (::g->centeryfrac>>4) - FixedMul (::g->worldbottom, ::g->rw_scale);
  529. if (::g->backsector)
  530. {
  531. ::g->worldhigh >>= 4;
  532. ::g->worldlow >>= 4;
  533. if (::g->worldhigh < ::g->worldtop)
  534. {
  535. ::g->pixhigh = (::g->centeryfrac>>4) - FixedMul (::g->worldhigh, ::g->rw_scale);
  536. ::g->pixhighstep = -FixedMul (::g->rw_scalestep,::g->worldhigh);
  537. }
  538. if (::g->worldlow > ::g->worldbottom)
  539. {
  540. ::g->pixlow = (::g->centeryfrac>>4) - FixedMul (::g->worldlow, ::g->rw_scale);
  541. ::g->pixlowstep = -FixedMul (::g->rw_scalestep,::g->worldlow);
  542. }
  543. }
  544. // render it
  545. if (::g->markceiling)
  546. ::g->ceilingplane = R_CheckPlane (::g->ceilingplane, ::g->rw_x, ::g->rw_stopx-1);
  547. if (::g->markfloor)
  548. ::g->floorplane = R_CheckPlane (::g->floorplane, ::g->rw_x, ::g->rw_stopx-1);
  549. R_RenderSegLoop ();
  550. // save sprite clipping info
  551. if ( ((::g->ds_p->silhouette & SIL_TOP) || ::g->maskedtexture)
  552. && !::g->ds_p->sprtopclip)
  553. {
  554. memcpy (::g->lastopening, ::g->ceilingclip+start, 2*(::g->rw_stopx-start));
  555. ::g->ds_p->sprtopclip = ::g->lastopening - start;
  556. ::g->lastopening += ::g->rw_stopx - start;
  557. }
  558. if ( ((::g->ds_p->silhouette & SIL_BOTTOM) || ::g->maskedtexture)
  559. && !::g->ds_p->sprbottomclip)
  560. {
  561. memcpy (::g->lastopening, ::g->floorclip+start, 2*(::g->rw_stopx-start));
  562. ::g->ds_p->sprbottomclip = ::g->lastopening - start;
  563. ::g->lastopening += ::g->rw_stopx - start;
  564. }
  565. if (::g->maskedtexture && !(::g->ds_p->silhouette&SIL_TOP))
  566. {
  567. ::g->ds_p->silhouette |= SIL_TOP;
  568. ::g->ds_p->tsilheight = MININT;
  569. }
  570. if (::g->maskedtexture && !(::g->ds_p->silhouette&SIL_BOTTOM))
  571. {
  572. ::g->ds_p->silhouette |= SIL_BOTTOM;
  573. ::g->ds_p->bsilheight = MAXINT;
  574. }
  575. ::g->ds_p++;
  576. }