⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hw_main.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 5 页
字号:
            lowfrac  = HWR_ClipViewSegment ( max(start->last-1,start->first) , (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2 );            HWR_StoreWallRange (lowfrac, 1 );        }    }}// --------------------------------------------------------------------------//  HWR_ClipToSolidSegs check if it is hide by wall (solidsegs)// --------------------------------------------------------------------------static boolean HWR_ClipToSolidSegs (int   first,                                    int   last ){    cliprange_t*        start;    // Find the first range that touches the range    //  (adjacent pixels are touching).    start = gr_solidsegs;    while (start->last < first-1)        start++;    if (first < start->first)        return true;    // Bottom contained in start?    if (last <= start->last)        return false;    return true;}//// HWR_ClearClipSegs//static void HWR_ClearClipSegs (void){    gr_solidsegs[0].first = -0x7fffffff;    gr_solidsegs[0].last = -1;    gr_solidsegs[1].first = VIDWIDTH;    //viewwidth;    gr_solidsegs[1].last = 0x7fffffff;    newend = gr_solidsegs+2;}// -----------------+// HWR_AddLine      : Clips the given segment and adds any visible pieces to the line list.// Notes            : gr_cursectorlight is set to the current subsector -> sector -> light value//                  : ( it may be mixed with the wall's own flat colour in the future ... )// -----------------+static void HWR_AddLine( seg_t * line ){    int                 x1;    int                 x2;    angle_t             angle1;    angle_t             angle2;    angle_t             span;    angle_t             tspan;    // SoM: Backsector needs to be run through R_FakeFlat    sector_t            tempsec;     gr_curline = line;    // OPTIMIZE: quickly reject orthogonal back sides.    angle1 = R_PointToAngle (((polyvertex_t *)line->v1)->x*FRACUNIT, ((polyvertex_t *)line->v1)->y*FRACUNIT);    angle2 = R_PointToAngle (((polyvertex_t *)line->v2)->x*FRACUNIT, ((polyvertex_t *)line->v2)->y*FRACUNIT);    // Clip to view edges.    span = angle1 - angle2;    // backface culling : span is < ANG180 if ang1 > ang2 : the seg is facing    if (span >= ANG180)        return;    // Global angle needed by segcalc.    //rw_angle1 = angle1;    angle1 -= dup_viewangle;    angle2 -= dup_viewangle;    tspan = angle1 + gr_clipangle;    if (tspan > 2*gr_clipangle)    {        tspan -= 2*gr_clipangle;        // Totally off the left edge?        if (tspan >= span)            return;        angle1 = gr_clipangle;    }    tspan = gr_clipangle - angle2;    if (tspan > 2*gr_clipangle)    {        tspan -= 2*gr_clipangle;        // Totally off the left edge?        if (tspan >= span)            return;        angle2 = -gr_clipangle;    }#if 0    {    float fx1,fx2,fy1,fy2;    //BP: test with a better projection than viewangletox[R_PointToAngle(angle)]    // do not enable this at release 4 mul and 2 div    fx1=((polyvertex_t *)(line->v1))->x-gr_viewx;    fy1=((polyvertex_t *)(line->v1))->y-gr_viewy;    fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin);    if(fy2<0)        // the point is back        fx1 = 0;    else        fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2;    fx2=((polyvertex_t *)(line->v2))->x-gr_viewx;    fy2=((polyvertex_t *)(line->v2))->y-gr_viewy;    fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin);    if(fy1<0)        // the point is back        fx2 = VIDWIDTH;    else        fx2 = gr_windowcenterx + (fx2 * gr_viewsin - fy2 * gr_viewcos) * gr_centerx / fy1;    x1 = fx1+0.5;    x2 = fx2+0.5;    }#else    // The seg is in the view range,    // but not necessarily visible.    angle1 = (angle1+ANG90)>>ANGLETOFINESHIFT;    angle2 = (angle2+ANG90)>>ANGLETOFINESHIFT;    x1 = gr_viewangletox[angle1];    x2 = gr_viewangletox[angle2];#endif    // Does not cross a pixel?//    if (x1 == x2)/*    {        // BP: HERE IS THE MAIN PROBLEM !        //CONS_Printf("tineline\n");        return;    }*/    gr_backsector = line->backsector;    // Single sided line?    if (!gr_backsector)        goto clipsolid;    gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true);    // Closed door.    if (gr_backsector->ceilingheight <= gr_frontsector->floorheight ||        gr_backsector->floorheight >= gr_frontsector->ceilingheight)        goto clipsolid;    // Window.    if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight ||        gr_backsector->floorheight != gr_frontsector->floorheight)        goto clippass;    // Reject empty lines used for triggers and special events.    // Identical floor and ceiling on both sides,    //  identical light levels on both sides,    //  and no middle texture.    if (   gr_backsector->ceilingpic == gr_frontsector->ceilingpic        && gr_backsector->floorpic == gr_frontsector->floorpic        && gr_backsector->lightlevel == gr_frontsector->lightlevel        && gr_curline->sidedef->midtexture == 0        && !gr_backsector->ffloors && !gr_frontsector->ffloors)        // SoM: For 3D sides... Boris, would you like to take a         // crack at rendering 3D sides? You would need to add the        // above check and add code to HWR_StoreWallRange...    {        return;    }clippass:    if (x1 == x2)    {  x2++;x1-=2; }    HWR_ClipPassWallSegment (x1, x2-1);    return;clipsolid:    if (x1 == x2)        goto clippass;    HWR_ClipSolidWallSegment (x1, x2-1);}// HWR_CheckBBox// Checks BSP node/subtree bounding box.// Returns true//  if some part of the bbox might be visible.//// modified to use local variablesextern  int     checkcoord[12][4];  //r_bsp.cstatic boolean  HWR_CheckBBox (fixed_t*   bspcoord){    int                 boxpos;    fixed_t             x1;    fixed_t             y1;    fixed_t             x2;    fixed_t             y2;    angle_t             angle1;    angle_t             angle2;    angle_t             span;    angle_t             tspan;    int                 sx1;    int                 sx2;    // Find the corners of the box    // that define the edges from current viewpoint.    if (dup_viewx <= bspcoord[BOXLEFT])        boxpos = 0;    else if (dup_viewx < bspcoord[BOXRIGHT])        boxpos = 1;    else        boxpos = 2;    if (dup_viewy >= bspcoord[BOXTOP])        boxpos |= 0;    else if (dup_viewy > bspcoord[BOXBOTTOM])        boxpos |= 1<<2;    else        boxpos |= 2<<2;    if (boxpos == 5)        return true;    x1 = bspcoord[checkcoord[boxpos][0]];    y1 = bspcoord[checkcoord[boxpos][1]];    x2 = bspcoord[checkcoord[boxpos][2]];    y2 = bspcoord[checkcoord[boxpos][3]];    // check clip list for an open space    angle1 = R_PointToAngle (x1, y1) - dup_viewangle;    angle2 = R_PointToAngle (x2, y2) - dup_viewangle;    span = angle1 - angle2;    // Sitting on a line?    if (span >= ANG180)        return true;    tspan = angle1 + gr_clipangle;    if (tspan > 2*gr_clipangle)    {        tspan -= 2*gr_clipangle;        // Totally off the left edge?        if (tspan >= span)            return false;        angle1 = gr_clipangle;    }    tspan = gr_clipangle - angle2;    if (tspan > 2*gr_clipangle)    {        tspan -= 2*gr_clipangle;        // Totally off the left edge?        if (tspan >= span)            return false;        angle2 = -gr_clipangle;    }    // Find the first clippost    //  that touches the source post    //  (adjacent pixels are touching).    angle1 = (angle1+ANG90)>>ANGLETOFINESHIFT;    angle2 = (angle2+ANG90)>>ANGLETOFINESHIFT;    sx1 = gr_viewangletox[angle1];    sx2 = gr_viewangletox[angle2];    // Does not cross a pixel.    if (sx1 == sx2)        return false;    return HWR_ClipToSolidSegs (sx1,sx2-1);}sector_t *R_FakeFlat(sector_t *, sector_t *, int *, int *, boolean);// -----------------+// HWR_Subsector    : Determine floor/ceiling planes.//                  : Add sprites of things in sector.//                  : Draw one or more line segments.// Notes            : Sets gr_cursectorlight to the light of the parent sector, to modulate wall textures// -----------------+static int doomwaterflat;  //set by R_InitFlats hackstatic void HWR_Subsector( int num ){    int                     count;    seg_t*                  line;    subsector_t*            sub;    sector_t                tempsec; //SoM: 4/7/2000    int                     floorlightlevel;    int                     ceilinglightlevel;    int locFloorHeight, locCeilingHeight;    fixed_t                 wh;//no risk while developing, enough debugging nights!#ifdef PARANOIA    if (num>=addsubsector)        I_Error ("HWR_Subsector: ss %i with numss = %i, addss = %d",                                num,numsubsectors,addsubsector );    /*if (num>=numsubsectors)        I_Error ("HWR_Subsector: ss %i with numss = %i",                         num,                         numsubsectors );*/#endif    if (num < numsubsectors)    {        sscount++;        // subsector        sub = &subsectors[num];        // sector        gr_frontsector = sub->sector;        // how many linedefs        count = sub->numlines;        // first line seg        line = &segs[sub->firstline];    }    else    {        // there are no segs but only planes        sub = &subsectors[0];        gr_frontsector = sub->sector;        count = 0;        line = NULL;    }    //SoM: 4/7/2000: Test to make Boom water work in Hardware mode.    gr_frontsector = R_FakeFlat(gr_frontsector, &tempsec, &floorlightlevel,                                &ceilinglightlevel, false);    //FIXME: Use floorlightlevel and ceilinglightlevel insted of lightlevel.    // ------------------------------------------------------------------------    // sector lighting, DISABLED because it's done in HWR_StoreWallRange    // ------------------------------------------------------------------------    // TODO : store a RGBA instead of just intensity, allow coloured sector lighting    //light = (FUBYTE)(sub->sector->lightlevel & 0xFF) / 255.0f;    //gr_cursectorlight.red   = light;    //gr_cursectorlight.green = light;    //gr_cursectorlight.blue  = light;    //gr_cursectorlight.alpha = light;// ----- for special tricks with HW renderer -----    if(gr_frontsector->pseudoSector)    {        locFloorHeight   = gr_frontsector->virtualFloorheight;        locCeilingHeight = gr_frontsector->virtualCeilingheight;    }    else    {        locFloorHeight   = gr_frontsector->floorheight;        locCeilingHeight = gr_frontsector->ceilingheight;           }// ----- end special tricks -----    // render floor ?#ifdef DOPLANES    // yeah, easy backface cull! :)    if (locFloorHeight < dup_viewz) {        if(gr_frontsector->floorpic != skyflatnum) {            HWR_GetFlat ( levelflats[gr_frontsector->floorpic].lumpnum  );            HWR_RenderPlane( &extrasubsectors[num], locFloorHeight, PF_Occlude );        }        else        {#ifdef POLYSKY            HWR_RenderSkyPlane (&extrasubsectors[num], locFloorHeight);#endif            cv_grsky.value = true;        }    }    if (locCeilingHeight > dup_viewz)    {        if(gr_frontsector->ceilingpic != skyflatnum) {            HWR_GetFlat ( levelflats[gr_frontsector->ceilingpic].lumpnum );            HWR_RenderPlane (&extrasubsectors[num], locCeilingHeight, PF_Occlude );        }        else        {#ifdef POLYSKY           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -