📄 r_segs.c
字号:
//**************************************************************************//**//** r_segs.c : Heretic 2 : Raven Software, Corp.//**//** $RCSfile: r_segs.c,v $//** $Revision: 1.4 $//** $Date: 95/08/28 17:02:44 $//** $Author: cjr $//**//** This version has the tall-sector-crossing-precision-bug fixed.//**//**************************************************************************#include "h2def.h"#include "r_local.h"// OPTIMIZE: closed two sided lines as single sidedboolean segtextured; // true if any of the segs textures might be visboolean markfloor; // false if the back side is the same planeboolean markceiling;boolean maskedtexture;int toptexture, bottomtexture, midtexture;angle_t rw_normalangle;int rw_angle1; // angle to line origin//// wall//int rw_x;int rw_stopx;angle_t rw_centerangle;fixed_t rw_offset;fixed_t rw_distance;fixed_t rw_scale;fixed_t rw_scalestep;fixed_t rw_midtexturemid;fixed_t rw_toptexturemid;fixed_t rw_bottomtexturemid;int worldtop, worldbottom, worldhigh, worldlow;fixed_t pixhigh, pixlow;fixed_t pixhighstep, pixlowstep;fixed_t topfrac, topstep;fixed_t bottomfrac, bottomstep;lighttable_t **walllights;short *maskedtexturecol;/*================== R_RenderMaskedSegRange=================*/void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2){ unsigned index; column_t *col; int lightnum; int texnum;//// calculate light table// use different light tables for horizontal / vertical / diagonal// OPTIMIZE: get rid of LIGHTSEGSHIFT globally curline = ds->curline; frontsector = curline->frontsector; backsector = curline->backsector; texnum = texturetranslation[curline->sidedef->midtexture]; lightnum = (frontsector->lightlevel >> LIGHTSEGSHIFT)+extralight; //if (curline->v1->y == curline->v2->y) // lightnum--; //else if (curline->v1->x == curline->v2->x) // lightnum++; //if (lightnum < 0) // walllights = scalelight[0]; if (lightnum >= LIGHTLEVELS) walllights = scalelight[LIGHTLEVELS-1]; else walllights = scalelight[lightnum]; maskedtexturecol = ds->maskedtexturecol; rw_scalestep = ds->scalestep; spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep; mfloorclip = ds->sprbottomclip; mceilingclip = ds->sprtopclip;//// find positioning// if (curline->linedef->flags & ML_DONTPEGBOTTOM) { dc_texturemid = frontsector->floorheight > backsector->floorheight ? frontsector->floorheight : backsector->floorheight; dc_texturemid = dc_texturemid + textureheight[texnum] - viewz; } else { dc_texturemid =frontsector->ceilingheight<backsector->ceilingheight ? frontsector->ceilingheight : backsector->ceilingheight; dc_texturemid = dc_texturemid - viewz; } dc_texturemid += curline->sidedef->rowoffset; if (fixedcolormap) dc_colormap = fixedcolormap;//// draw the columns// for (dc_x = x1 ; dc_x <= x2 ; dc_x++) { // calculate lighting if (maskedtexturecol[dc_x] != MAXSHORT) { if (!fixedcolormap) { index = spryscale>>LIGHTSCALESHIFT; if (index >= MAXLIGHTSCALE ) index = MAXLIGHTSCALE-1; dc_colormap = walllights[index]; } sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale); dc_iscale = 0xffffffffu / (unsigned)spryscale; // // draw the texture // col = (column_t *)( (byte *)R_GetColumn(texnum,maskedtexturecol[dc_x]) -3); R_DrawMaskedColumn (col, -1); maskedtexturecol[dc_x] = MAXSHORT; } spryscale += rw_scalestep; }}/*================== R_RenderSegLoop== Draws zero, one, or two textures (and possibly a masked texture) for walls= Can draw or mark the starting pixel of floor and ceiling textures== CALLED: CORE LOOPING ROUTINE================*/#define HEIGHTBITS 12#define HEIGHTUNIT (1<<HEIGHTBITS)void R_RenderSegLoop (void){ angle_t angle; unsigned index; int yl, yh, mid; fixed_t texturecolumn; int top, bottom;// texturecolumn = 0; // shut up compiler warning for ( ; rw_x < rw_stopx ; rw_x++) {//// mark floor / ceiling areas// yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; if (yl < ceilingclip[rw_x]+1) yl = ceilingclip[rw_x]+1; // no space above wall if (markceiling) { top = ceilingclip[rw_x]+1; bottom = yl-1; if (bottom >= floorclip[rw_x]) bottom = floorclip[rw_x]-1; if (top <= bottom) { ceilingplane->top[rw_x] = top; ceilingplane->bottom[rw_x] = bottom; } } yh = bottomfrac>>HEIGHTBITS; if (yh >= floorclip[rw_x]) yh = floorclip[rw_x]-1; if (markfloor) { top = yh+1; bottom = floorclip[rw_x]-1; if (top <= ceilingclip[rw_x]) top = ceilingclip[rw_x]+1; if (top <= bottom) { floorplane->top[rw_x] = top; floorplane->bottom[rw_x] = bottom; } }//// texturecolumn and lighting are independent of wall tiers// if (segtextured) { // calculate texture offset angle = (rw_centerangle + xtoviewangle[rw_x])>>ANGLETOFINESHIFT; texturecolumn = rw_offset-FixedMul(finetangent[angle],rw_distance); texturecolumn >>= FRACBITS; // calculate lighting index = rw_scale>>LIGHTSCALESHIFT; if (index >= MAXLIGHTSCALE ) index = MAXLIGHTSCALE-1; dc_colormap = walllights[index]; dc_x = rw_x; dc_iscale = 0xffffffffu / (unsigned)rw_scale; }//// draw the wall tiers// if (midtexture) { // single sided line dc_yl = yl; dc_yh = yh; dc_texturemid = rw_midtexturemid; dc_source = R_GetColumn(midtexture,texturecolumn); colfunc (); ceilingclip[rw_x] = viewheight; floorclip[rw_x] = -1; } else { // two sided line if (toptexture) { // top wall mid = pixhigh>>HEIGHTBITS; pixhigh += pixhighstep; if (mid >= floorclip[rw_x]) mid = floorclip[rw_x]-1; if (mid >= yl) { dc_yl = yl; dc_yh = mid; dc_texturemid = rw_toptexturemid; dc_source = R_GetColumn(toptexture,texturecolumn); colfunc (); ceilingclip[rw_x] = mid; } else ceilingclip[rw_x] = yl-1; } else { // no top wall if (markceiling) ceilingclip[rw_x] = yl-1; } if (bottomtexture) { // bottom wall mid = (pixlow+HEIGHTUNIT-1)>>HEIGHTBITS; pixlow += pixlowstep; if (mid <= ceilingclip[rw_x]) mid = ceilingclip[rw_x]+1; // no space above wall if (mid <= yh) { dc_yl = mid; dc_yh = yh; dc_texturemid = rw_bottomtexturemid; dc_source = R_GetColumn(bottomtexture, texturecolumn); colfunc (); floorclip[rw_x] = mid; } else floorclip[rw_x] = yh+1; } else { // no bottom wall if (markfloor) floorclip[rw_x] = yh+1; } if (maskedtexture) { // save texturecol for backdrawing of masked mid texture maskedtexturecol[rw_x] = texturecolumn; } } rw_scale += rw_scalestep; topfrac += topstep; bottomfrac += bottomstep; }}/*======================= R_StoreWallRange== A wall segment will be drawn between start and stop pixels (inclusive)=======================*/void R_StoreWallRange (int start, int stop){ fixed_t hyp; fixed_t sineval; angle_t distangle, offsetangle; fixed_t vtop; int lightnum;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -